Skip to content

Commit 751fd0d

Browse files
committed
Auto merge of rust-lang#8780 - Alexendoo:init-numbered-field-alias, r=flip1995
Ignore type aliases in `init_numbered_fields` changelog: Ignore type aliases in [`init_numbered_fields`] Fixes rust-lang#8638
2 parents a10fe90 + d53293d commit 751fd0d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

clippy_lints/src/init_numbered_fields.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use rustc_errors::Applicability;
4+
use rustc_hir::def::{DefKind, Res};
45
use rustc_hir::{Expr, ExprKind};
56
use rustc_lint::{LateContext, LateLintPass};
67
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -49,6 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
4950
&& fields
5051
.iter()
5152
.all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit))
53+
&& !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..))
5254
{
5355
let expr_spans = fields
5456
.iter()

tests/ui/numbered_fields.fixed

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

3131
// Ok because it's in macro
3232
let _ = tuple_struct_init!();
33+
34+
type Alias = TupleStruct;
35+
36+
// Aliases can't be tuple constructed #8638
37+
let _ = Alias { 0: 0, 1: 1, 2: 2 };
3338
}

tests/ui/numbered_fields.rs

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

3939
// Ok because it's in macro
4040
let _ = tuple_struct_init!();
41+
42+
type Alias = TupleStruct;
43+
44+
// Aliases can't be tuple constructed #8638
45+
let _ = Alias { 0: 0, 1: 1, 2: 2 };
4146
}

0 commit comments

Comments
 (0)