Skip to content

Commit

Permalink
Auto merge of rust-lang#8780 - Alexendoo:init-numbered-field-alias, r…
Browse files Browse the repository at this point in the history
…=flip1995

Ignore type aliases in `init_numbered_fields`

changelog: Ignore type aliases in [`init_numbered_fields`]

Fixes rust-lang#8638
  • Loading branch information
bors committed May 4, 2022
2 parents a10fe90 + d53293d commit 751fd0d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clippy_lints/src/init_numbered_fields.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::source::snippet_with_applicability;
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -49,6 +50,7 @@ impl<'tcx> LateLintPass<'tcx> for NumberedFields {
&& fields
.iter()
.all(|f| f.ident.as_str().as_bytes().iter().all(u8::is_ascii_digit))
&& !matches!(cx.qpath_res(path, e.hir_id), Res::Def(DefKind::TyAlias, ..))
{
let expr_spans = fields
.iter()
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 @@ -30,4 +30,9 @@ fn main() {

// Ok because it's in macro
let _ = tuple_struct_init!();

type Alias = TupleStruct;

// Aliases can't be tuple constructed #8638
let _ = Alias { 0: 0, 1: 1, 2: 2 };
}
5 changes: 5 additions & 0 deletions tests/ui/numbered_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ fn main() {

// Ok because it's in macro
let _ = tuple_struct_init!();

type Alias = TupleStruct;

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

0 comments on commit 751fd0d

Please sign in to comment.