Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore type aliases in init_numbered_fields #8780

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 };
}