Skip to content

Commit 05c4053

Browse files
committed
Auto merge of rust-lang#12398 - WeiTheShinobi:bug-lint-numbered_fields, r=Manishearth
bug fix: lint numbered_fields message error fixes rust-lang#12367 changelog: [`numbered_fields`]: fix macro expand message error.
2 parents ea535c9 + 038f617 commit 05c4053

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

clippy_lints/src/init_numbered_fields.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
2-
use clippy_utils::source::snippet_with_applicability;
2+
use clippy_utils::source::{snippet_with_applicability, snippet_with_context};
33
use rustc_errors::Applicability;
44
use rustc_hir::def::{DefKind, Res};
55
use rustc_hir::{Expr, ExprKind};
@@ -62,7 +62,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
6262
snippet_with_applicability(cx, path.span(), "..", &mut appl),
6363
expr_spans
6464
.into_iter_sorted()
65-
.map(|(_, span)| snippet_with_applicability(cx, span, "..", &mut appl))
65+
.map(|(_, span)| snippet_with_context(cx, span, path.span().ctxt(), "..", &mut appl).0)
6666
.intersperse(Cow::Borrowed(", "))
6767
.collect::<String>()
6868
);

tests/ui/numbered_fields.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,9 @@ fn main() {
3434

3535
// Aliases can't be tuple constructed #8638
3636
let _ = Alias { 0: 0, 1: 1, 2: 2 };
37+
38+
// Issue #12367
39+
struct TupleStructVec(Vec<usize>);
40+
41+
let _ = TupleStructVec(vec![0, 1, 2, 3]);
3742
}

tests/ui/numbered_fields.rs

+5
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,9 @@ fn main() {
4242

4343
// Aliases can't be tuple constructed #8638
4444
let _ = Alias { 0: 0, 1: 1, 2: 2 };
45+
46+
// Issue #12367
47+
struct TupleStructVec(Vec<usize>);
48+
49+
let _ = TupleStructVec { 0: vec![0, 1, 2, 3] };
4550
}

tests/ui/numbered_fields.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,11 @@ LL | | 1: 3u32,
2323
LL | | };
2424
| |_____^ help: try: `TupleStruct(1u32, 3u32, 2u8)`
2525

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

0 commit comments

Comments
 (0)