Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
a8ffa1c
docs: update default branch name of `rust-lang/rust`
jieyouxu Dec 6, 2025
ccdda58
clean-up
ada4a Jan 16, 2026
19bfad0
Introduce `AssocTag::descr` & refactor in the vicinity
fmease Jan 6, 2026
454842a
update `dbg!` clippy lint
joboet Dec 12, 2025
e8c449d
Move assert_matches to planned stable path
Voultapher Jan 19, 2026
76a536c
test: remove `unwrap.rs`
ada4a Jan 21, 2026
a0d33e0
Bump stage0
Mark-Simulacrum Jan 21, 2026
63c69a7
Rollup merge of #151439 - Mark-Simulacrum:bootstrap-bump, r=nnethercote
jhpratt Jan 22, 2026
3c9a084
Rollup merge of #151423 - Voultapher:move-assert-matches, r=Amanieu
JonathanBrouwer Jan 22, 2026
977edde
Merge commit '54482290b5f32e6c6b57cc9e0a17153f432b0036' into clippy-s…
flip1995 Jan 22, 2026
62846d2
test: remove `unwrap.rs` (#16437)
dswij Jan 23, 2026
1ebafc5
fix(manual_let_else): add trailing comma when necessary
vogelbirb Jan 22, 2026
3157c0b
reduce suggestion diff
ada4a Jan 16, 2026
f43f1d6
Update default branch name of `rust-lang/rust` in subtree sync docs (…
flip1995 Jan 23, 2026
529b820
Auto merge of #151501 - flip1995:clippy-subtree-update, r=Manishearth
bors Jan 23, 2026
4e4651b
Return ExitCode from rustc_driver::main
ChrisDenton Dec 25, 2025
dc57e57
fix(manual_let_else): add trailing comma to struct patterns ending wi…
dswij Jan 24, 2026
e4d146e
fix: `doc_markdown` add PowerShell to whitelist
profetia Jan 24, 2026
cc29987
fix: `test_attr_in_doctest` FP on `test_harness`
profetia Jan 24, 2026
d7281ea
Enhance `question_mark` to cover `else if`
profetia Jan 25, 2026
ed1d154
Rollup merge of #149869 - joboet:torn-dbg, r=Mark-Simulacrum
matthiaskrgr Jan 25, 2026
0f17b47
Add PowerShell to `doc_markdown` whitelist (#16453)
dswij Jan 25, 2026
8416c54
Also ignore cases with comments in `let_and_return`
Alexendoo Jan 25, 2026
4a6c0de
rhs of short-circuit expression doesn't always run
samueltardieu Jan 25, 2026
7ffda53
Also ignore cases with comments in `let_and_return` (#16461)
samueltardieu Jan 25, 2026
187893e
rhs of short-circuit expression doesn't always run (#16463)
Jarcho Jan 25, 2026
30dbf82
Fix `test_attr_in_doctest` FP on `test_harness` (#16454)
Jarcho Jan 25, 2026
02d9865
Enhance `manual_is_variant_and` to cover manual `is_none_or`
profetia Jan 17, 2026
1b33602
Make `manual_is_variant_and` to cover manual `is_none_or` (#16424)
Jarcho Jan 25, 2026
fdfbe73
Only `Duration` constructors taking `u64` are covered
samueltardieu Jan 25, 2026
9f308b7
Do not mention `-Zmacro-backtrace` for std macros that are a wrapper …
estebank Nov 8, 2025
dfcfd73
fix: `cmp_owned` FP when `to_string` comes from macro input
profetia Jan 26, 2026
c3ab233
fix: `manual_dangling_ptr` FP when pointee type is not `Sized`
profetia Jan 26, 2026
17f89e7
Fix `useless_attribute` FP on `exported_private_dependencies` lint at…
kpreid Jan 26, 2026
3075db4
Fix `manual_dangling_ptr` FP when pointee type is not `Sized` (#16469)
Jarcho Jan 26, 2026
d463a8d
Update `askama` version to `0.15.2`
GuillaumeGomez Jan 27, 2026
2b16dcd
Only `Duration` constructors taking `u64` are covered (#16465)
dswij Jan 27, 2026
7e3cf26
Update `askama` version to `0.15.2` (#16472)
samueltardieu Jan 27, 2026
b5f31e2
Fix `useless_attribute` FP on `exported_private_dependencies` lint at…
samueltardieu Jan 27, 2026
e882593
Fix grammar in doc comments in `conf.rs`
Cardosaum Jan 28, 2026
736e4b8
Fix grammar in doc comments in `conf.rs` (#16479)
samueltardieu Jan 28, 2026
f992358
Part 2 refactoring of moving placeholder types to `rustc_type_ir`
Jamesbarford Dec 22, 2025
cf66256
Update `askama` to `0.15.4`
GuillaumeGomez Jan 28, 2026
dc8b277
Update `askama` to `0.15.4` (#16485)
samueltardieu Jan 29, 2026
01eba55
Rollup merge of #150271 - Jamesbarford:chore/refactor-struct-placehol…
JonathanBrouwer Jan 29, 2026
cdee2fb
refactor: add an `enum DerefAdjustKind` in favor of `Option<Overloade…
frank-king Jan 30, 2026
9c1ca3a
doc_paragraphs_missing_punctuation: allow some non-punctuated paragraphs
AudaciousAxiom Jan 31, 2026
631120b
fix: `unwrap_used` and `expect_used` FN when using fully qualified sy…
profetia Jan 31, 2026
62c5f16
Fix `unwrap_used` and `expect_used` FN when using fully qualified syn…
Jarcho Jan 31, 2026
37c127c
`doc_paragraphs_missing_punctuation`: allow some non-punctuated parag…
dswij Feb 2, 2026
992a6f6
fix: allow_attributes false negative on attributes with whitespace
vishnupoddar12 Feb 2, 2026
301aae6
fix: allow_attributes false negative on attributes with whitespace (#…
llogiq Feb 2, 2026
267f40d
Fix missing unused_variables lint when using a match guard
eggyal Feb 2, 2026
b3d81e3
`str_split`: reduce suggestion diff (#16418)
dswij Feb 2, 2026
1826ec0
Extend `question_mark` to cover `else if` (#16455)
Jarcho Feb 3, 2026
691e226
fix: handle false negative for `str_to_string`
nyurik Feb 5, 2026
cec007b
Rollup merge of #150379 - ChrisDenton:exitcode, r=jieyouxu
JonathanBrouwer Feb 5, 2026
b303ab4
fix: handle false negative for `str_to_string` (#16512)
samueltardieu Feb 5, 2026
e94a62d
mGCA: Support directly represented negated literals
khyperia Feb 6, 2026
da779a0
Rollup merge of #152139 - khyperia:mgca-negative-literals, r=BoxyUwU
JonathanBrouwer Feb 6, 2026
f090e9c
Port rustc_intrinsic to the new attribute parser
jdonszelmann Feb 5, 2026
15e0ce9
Fix `cmp_owned` FP when `to_string` comes from macro input (#16468)
dswij Feb 7, 2026
236dac8
fix: remove unnecessary trailing commas in format strings
nyurik Feb 7, 2026
7c95f57
fix outdated doc comments
mikhailofff Feb 8, 2026
389294d
Fix documentation for `indexing_slicing`
puzzlewolf Feb 9, 2026
00432c0
fix dead links in type checking section of the doc
mikhailofff Feb 9, 2026
9bf9a12
Allow provisional mgca syntax of type const <IDENT> = <EXPR> to be re…
Keith-Cancel Feb 6, 2026
7eec730
chore: remove unnecessary trailing commas in format strings (#16533)
samueltardieu Feb 9, 2026
b1847b5
Remove SubdiagMessage in favour of the identical DiagMessage
JonathanBrouwer Feb 10, 2026
bbc5b53
Rollup merge of #152351 - JonathanBrouwer:remove_subdiag, r=nnethercote
JonathanBrouwer Feb 10, 2026
ae8a9d1
Fix documentation for `indexing_slicing` (#16543)
dswij Feb 10, 2026
fdaa633
Fix dead links in type checking section of the doc (#16544)
flip1995 Feb 10, 2026
5dac025
Do not lint main function in `must_use_candidates`
flip1995 Feb 10, 2026
b20572e
change to github permalinks
mikhailofff Feb 11, 2026
5d35527
Fix outdated doc comments (#16536)
flip1995 Feb 11, 2026
a9a368a
Do not lint main function in `must_use_candidates` (#16552)
Jarcho Feb 11, 2026
e1ade99
Enable triagebot new `[view-all-comments-link]` feature
Urgau Feb 11, 2026
4ccb80b
Enable triagebot new `[view-all-comments-link]` feature (#16554)
flip1995 Feb 11, 2026
c9841a6
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Feb 11, 2026
24b1392
Bump nightly version -> 2026-02-11
flip1995 Feb 11, 2026
a62c6af
Rustup (#16551)
flip1995 Feb 11, 2026
0e2af75
Merge commit 'a62c6af53676bb15a40488ce2d632de558f001de' into clippy-s…
flip1995 Feb 12, 2026
eaad11c
cg_gcc: remove Clippy expect attribute
flip1995 Feb 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/rustc_codegen_gcc/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
///
/// If there’s a value with the same name already declared, the function will
/// update the declaration and return existing Value instead.
#[expect(clippy::let_and_return)]
fn declare_raw_fn<'gcc>(
cx: &CodegenCx<'gcc, '_>,
name: &str,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ walkdir = "2.3"
filetime = "0.2.9"
itertools = "0.12"
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
askama = { version = "0.15", default-features = false, features = ["alloc", "config", "derive"] }
askama = { version = "0.15.4", default-features = false, features = ["alloc", "config", "derive"] }

[dev-dependencies.toml]
version = "0.9.7"
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/book/src/development/infrastructure/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ to be run inside the `rust` directory):
```bash
git fetch upstream # assuming upstream is the rust-lang/rust remote
git switch rustup
git merge upstream/master --no-ff
git merge upstream/main --no-ff
```
> Note: This is one of the few instances where a merge commit is allowed in
> a PR.
Expand All @@ -99,7 +99,7 @@ to be run inside the `rust` directory):

All the following commands have to be run inside the `rust` directory.

1. Make sure you have checked out the latest `master` of `rust-lang/rust`.
1. Make sure you have checked out the latest `main` of `rust-lang/rust`.
2. Sync the `rust-lang/rust-clippy` master to the rust-copy of Clippy:
```bash
git switch -c clippy-subtree-update
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/book/src/development/type_checking.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ in this chapter:

- [Stages of compilation](https://rustc-dev-guide.rust-lang.org/compiler-src.html#the-main-stages-of-compilation)
- [Diagnostic items](https://rustc-dev-guide.rust-lang.org/diagnostics/diagnostic-items.html)
- [Type checking](https://rustc-dev-guide.rust-lang.org/type-checking.html)
- [Type checking](https://rustc-dev-guide.rust-lang.org/hir-typeck/summary.html)
- [Ty module](https://rustc-dev-guide.rust-lang.org/ty.html)

[Adt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html#variant.Adt
[AdtDef]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/adt/struct.AdtDef.html
[expr_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.expr_ty
[node_type]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html#method.node_type
[is_char]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.is_char
[is_char_source]: https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/sty.rs.html#1831-1834
[is_char_source]: https://github.com/rust-lang/rust/blob/d34f1f931489618efffc4007e6b6bdb9e10f6467/compiler/rustc_middle/src/ty/sty.rs#L1429-L1432
[kind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html#method.kind
[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html
[LateLintPass]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/trait.LateLintPass.html
Expand All @@ -163,5 +163,5 @@ in this chapter:
[TyKind]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_type_ir/ty_kind/enum.TyKind.html
[TypeckResults]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TypeckResults.html
[middle_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Ty.html
[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/struct.Ty.html
[hir_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/struct.Ty.html
[lower_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir_analysis/fn.lower_ty.html
6 changes: 3 additions & 3 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ A list of crate names to allow duplicates of

## `allowed-idents-below-min-chars`
Allowed names below the minimum allowed characters. The value `".."` can be used as part of
the list to indicate, that the configured values should be appended to the default
the list to indicate that the configured values should be appended to the default
configuration of Clippy. By default, any configuration will replace the default value.

**Default Value:** `["i", "j", "x", "y", "z", "w", "n"]`
Expand Down Expand Up @@ -570,12 +570,12 @@ The list of disallowed types, written as fully qualified paths.

## `doc-valid-idents`
The list of words this lint should not consider as identifiers needing ticks. The value
`".."` can be used as part of the list to indicate, that the configured values should be appended to the
`".."` can be used as part of the list to indicate that the configured values should be appended to the
default configuration of Clippy. By default, any configuration will replace the default value. For example:
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.

**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "InfiniBand", "RoCE", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "MHz", "GHz", "THz", "AccessKit", "CoAP", "CoreFoundation", "CoreGraphics", "CoreText", "DevOps", "Direct2D", "Direct3D", "DirectWrite", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "InfiniBand", "RoCE", "ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript", "PowerPC", "PowerShell", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenAL", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "OpenType", "WebGL", "WebGL2", "WebGPU", "WebRTC", "WebSocket", "WebTransport", "WebP", "OpenExr", "YCbCr", "sRGB", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "NetBSD", "OpenBSD", "NixOS", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`

---
**Affected lints:**
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
"IPv4", "IPv6",
"InfiniBand", "RoCE",
"ClojureScript", "CoffeeScript", "JavaScript", "PostScript", "PureScript", "TypeScript",
"PowerPC", "WebAssembly",
"PowerPC", "PowerShell", "WebAssembly",
"NaN", "NaNs",
"OAuth", "GraphQL",
"OCaml",
Expand Down Expand Up @@ -423,7 +423,7 @@ define_Conf! {
#[lints(multiple_crate_versions)]
allowed_duplicate_crates: Vec<String> = Vec::new(),
/// Allowed names below the minimum allowed characters. The value `".."` can be used as part of
/// the list to indicate, that the configured values should be appended to the default
/// the list to indicate that the configured values should be appended to the default
/// configuration of Clippy. By default, any configuration will replace the default value.
#[lints(min_ident_chars)]
allowed_idents_below_min_chars: Vec<String> =
Expand Down Expand Up @@ -620,7 +620,7 @@ define_Conf! {
#[lints(disallowed_types)]
disallowed_types: Vec<DisallowedPath> = Vec::new(),
/// The list of words this lint should not consider as identifiers needing ticks. The value
/// `".."` can be used as part of the list to indicate, that the configured values should be appended to the
/// `".."` can be used as part of the list to indicate that the configured values should be appended to the
/// default configuration of Clippy. By default, any configuration will replace the default value. For example:
/// * `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
/// * `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ fn add_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
let camel_name = to_camel_case(lint.name);

let new_lint = if enable_msrv {
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ",)
format!("Box::new(move |{ctor_arg}| Box::new({module_name}::{camel_name}::new(conf))),\n ")
} else {
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ",)
format!("Box::new(|{ctor_arg}| Box::new({module_name}::{camel_name})),\n ")
};

lib_rs.insert_str(comment_start, &new_lint);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub(super) fn check(cx: &EarlyContext<'_>, item: &Item, attrs: &[Attribute]) {
| sym::dead_code
| sym::deprecated
| sym::deprecated_in_future
| sym::exported_private_dependencies
| sym::hidden_glob_reexports
| sym::unreachable_pub
| sym::unused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn check_table(cx: &LateContext<'_>, table: &DeTable<'_>, known_groups: &FxHashS
"to have lints override the group set `{}` to a lower priority",
group.as_ref()
),
format!("{{ level = {:?}, priority = {low_priority} }}", group_config.level,),
format!("{{ level = {:?}, priority = {low_priority} }}", group_config.level),
Applicability::MaybeIncorrect,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub(super) fn check(
return;
}

format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}",)
format!("casting `{cast_from}` to `{cast_to}` may truncate the value{suffix}")
},

(ty::Adt(def, _), Some(to_nbits)) if def.is_enum() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, from: &Expr<'_>, to:
let init_expr = expr_or_init(cx, from);
if is_expr_const_aligned(cx, init_expr, ptr_ty.ty)
&& let Some(std_or_core) = std_or_core(cx)
&& let pointee_ty = cx.typeck_results().node_type(ptr_ty.ty.hir_id)
&& pointee_ty.is_sized(cx.tcx, cx.typing_env())
{
let sugg_fn = match ptr_ty.mutbl {
Mutability::Not => "ptr::dangling",
Expand Down
94 changes: 51 additions & 43 deletions src/tools/clippy/clippy_lints/src/dbg_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,45 +75,47 @@ impl LateLintPass<'_> for DbgMacro {
"the `dbg!` macro is intended as a debugging tool",
|diag| {
let mut applicability = Applicability::MachineApplicable;
let (sugg_span, suggestion) =
match is_async_move_desugar(expr).unwrap_or(expr).peel_drop_temps().kind {
// dbg!()
ExprKind::Block(..) => {
// If the `dbg!` macro is a "free" statement and not contained within other expressions,
// remove the whole statement.
if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id)
&& let Some(semi_span) =
cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span)
{
(macro_call.span.to(semi_span), String::new())
} else {
(macro_call.span, String::from("()"))
}
},
ExprKind::Match(first, arms, _) => {
let vals = collect_vals(first, arms);
let suggestion = match vals.as_slice() {
// dbg!(1) => 1
&[val] => {
snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability)
.to_string()
}
// dbg!(2, 3) => (2, 3)
&[first, .., last] => {
let snippet = snippet_with_applicability(
cx,
first.span.source_callsite().to(last.span.source_callsite()),
"..",
&mut applicability,
);
format!("({snippet})")
}
_ => unreachable!(),
};
(macro_call.span, suggestion)
},
_ => unreachable!(),
};
let (sugg_span, suggestion) = match is_async_move_desugar(expr)
.unwrap_or(expr)
.peel_drop_temps()
.kind
{
// dbg!()
ExprKind::Block(..) => {
// If the `dbg!` macro is a "free" statement and not contained within other expressions,
// remove the whole statement.
if let Node::Stmt(_) = cx.tcx.parent_hir_node(expr.hir_id)
&& let Some(semi_span) = cx.sess().source_map().mac_call_stmt_semi_span(macro_call.span)
{
(macro_call.span.to(semi_span), String::new())
} else {
(macro_call.span, String::from("()"))
}
},
ExprKind::Match(first, arms, _) => {
let vals = collect_vals(first, arms);
let suggestion = match *vals.as_slice() {
// dbg!(1) => 1
[val] => {
snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability)
.to_string()
},
// dbg!(2, 3) => (2, 3)
[first, .., last] => {
let snippet = snippet_with_applicability(
cx,
first.span.source_callsite().to(last.span.source_callsite()),
"..",
&mut applicability,
);
format!("({snippet})")
},
_ => unreachable!(),
};
(macro_call.span, suggestion)
},
_ => unreachable!(),
};

diag.span_suggestion(
sugg_span,
Expand Down Expand Up @@ -165,7 +167,7 @@ fn first_dbg_macro_in_expansion(cx: &LateContext<'_>, span: Span) -> Option<Macr
}

/// Extracts all value expressions from the `match`-tree generated by `dbg!`.
///
///
/// E.g. from
/// ```rust, ignore
/// match 1 {
Expand All @@ -181,14 +183,20 @@ fn first_dbg_macro_in_expansion(cx: &LateContext<'_>, span: Span) -> Option<Macr
fn collect_vals<'hir>(first: &'hir Expr<'hir>, mut arms: &'hir [Arm<'hir>]) -> Vec<&'hir Expr<'hir>> {
let mut vals = vec![first];
loop {
let [arm] = arms else { unreachable!("dbg! macro expansion only has single-arm matches") };
let [arm] = arms else {
unreachable!("dbg! macro expansion only has single-arm matches")
};

match is_async_move_desugar(arm.body).unwrap_or(arm.body).peel_drop_temps().kind {
match is_async_move_desugar(arm.body)
.unwrap_or(arm.body)
.peel_drop_temps()
.kind
{
ExprKind::Block(..) => return vals,
ExprKind::Match(val, a, _) => {
vals.push(val);
arms = a;
}
},
_ => unreachable!("dbg! macro expansion only results in block or match expressions"),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,26 @@ fn is_missing_punctuation(doc_string: &str) -> Vec<MissingPunctuation> {
let mut no_report_depth = 0;
let mut missing_punctuation = Vec::new();
let mut current_paragraph = None;
let mut current_event_is_missing_punctuation = false;

for (event, offset) in
Parser::new_ext(doc_string, main_body_opts() - Options::ENABLE_SMART_PUNCTUATION).into_offset_iter()
{
let last_event_was_missing_punctuation = current_event_is_missing_punctuation;
current_event_is_missing_punctuation = false;

match event {
Event::Start(
Tag::CodeBlock(..)
| Tag::FootnoteDefinition(_)
| Tag::Heading { .. }
| Tag::HtmlBlock
| Tag::List(..)
| Tag::Table(_),
) => {
Event::Start(Tag::FootnoteDefinition(_) | Tag::Heading { .. } | Tag::HtmlBlock | Tag::Table(_)) => {
no_report_depth += 1;
},
Event::Start(Tag::CodeBlock(..) | Tag::List(..)) => {
no_report_depth += 1;
if last_event_was_missing_punctuation {
// Remove the error from the previous paragraph as it is followed by a code
// block or a list.
missing_punctuation.pop();
}
},
Event::End(TagEnd::FootnoteDefinition) => {
no_report_depth -= 1;
},
Expand All @@ -83,6 +88,7 @@ fn is_missing_punctuation(doc_string: &str) -> Vec<MissingPunctuation> {
Event::End(TagEnd::Paragraph) => {
if let Some(mp) = current_paragraph {
missing_punctuation.push(mp);
current_event_is_missing_punctuation = true;
}
},
Event::Code(..) | Event::Start(Tag::Link { .. }) | Event::End(TagEnd::Link)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
diag.span_suggestion_verbose(
this_fragment.span.shrink_to_hi(),
"add footnote definition",
format!("\n\n{label}: <!-- description -->", label = &doc[start..end],),
format!("\n\n{label}: <!-- description -->", label = &doc[start..end]),
Applicability::HasPlaceholders,
);
} else {
Expand Down
Loading
Loading