Skip to content

Commit

Permalink
Auto merge of rust-lang#12398 - WeiTheShinobi:bug-lint-numbered_field…
Browse files Browse the repository at this point in the history
…s, r=Manishearth

bug fix: lint numbered_fields message error

fixes rust-lang#12367

changelog: [`numbered_fields`]: fix macro expand message error.
  • Loading branch information
bors committed May 22, 2024
2 parents ea535c9 + 038f617 commit 05c4053
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/init_numbered_fields.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind};
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
snippet_with_applicability(cx, path.span(), "..", &mut appl),
expr_spans
.into_iter_sorted()
.map(|(_, span)| snippet_with_applicability(cx, span, "..", &mut appl))
.map(|(_, span)| snippet_with_context(cx, span, path.span().ctxt(), "..", &mut appl).0)
.intersperse(Cow::Borrowed(", "))
.collect::<String>()
);
Expand Down
5 changes: 5 additions & 0 deletions tests/ui/numbered_fields.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ fn main() {

// Aliases can't be tuple constructed #8638
let _ = Alias { 0: 0, 1: 1, 2: 2 };

// Issue #12367
struct TupleStructVec(Vec<usize>);

let _ = TupleStructVec(vec![0, 1, 2, 3]);
}
5 changes: 5 additions & 0 deletions tests/ui/numbered_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ fn main() {

// Aliases can't be tuple constructed #8638
let _ = Alias { 0: 0, 1: 1, 2: 2 };

// Issue #12367
struct TupleStructVec(Vec<usize>);

let _ = TupleStructVec { 0: vec![0, 1, 2, 3] };
}
8 changes: 7 additions & 1 deletion tests/ui/numbered_fields.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,11 @@ LL | | 1: 3u32,
LL | | };
| |_____^ help: try: `TupleStruct(1u32, 3u32, 2u8)`

error: aborting due to 2 previous errors
error: used a field initializer for a tuple struct
--> tests/ui/numbered_fields.rs:49:13
|
LL | let _ = TupleStructVec { 0: vec![0, 1, 2, 3] };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `TupleStructVec(vec![0, 1, 2, 3])`

error: aborting due to 3 previous errors

0 comments on commit 05c4053

Please sign in to comment.