From b7ed4147a1f87f82ca19a2c66d6dac894e76fff2 Mon Sep 17 00:00:00 2001 From: tmiasko Date: Fri, 13 Nov 2026 11:20:26 +0000 Subject: [PATCH 01/17] MirPatch: reduce new statement insertion complexity MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous implementation inserted each new statement in a block separately, which in the worst case moved all existing statements each time. Use a simple merging strategy to improve complexity from O(num existing statements × num new statements) to O(num existing statements + num new statements). --- compiler/rustc_mir_transform/src/patch.rs | 61 ++++++++++++++++++----- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_mir_transform/src/patch.rs b/compiler/rustc_mir_transform/src/patch.rs index f1476108557a8..81aeaf708c2e8 100644 --- a/compiler/rustc_mir_transform/src/patch.rs +++ b/compiler/rustc_mir_transform/src/patch.rs @@ -289,20 +289,30 @@ impl<'tcx> MirPatch<'tcx> { // comment for `add_statement`. new_statements.sort_by_key(|s| s.0); - let mut delta = 0; - let mut last_bb = START_BLOCK; - for (mut loc, stmt) in new_statements { - if loc.block != last_bb { - delta = 0; - last_bb = loc.block; + while !new_statements.is_empty() { + // Identify a subslice of statements to be inserted to the same block: new_statements[i..]. + let mut i = new_statements.len() - 1; + let block = new_statements[i].0.block; + while i != 0 && new_statements[i - 1].0.block == block { + i -= 1; + } + if i + 1 == new_statements.len() { + let (loc, s) = new_statements.pop().unwrap(); + let source_info = Self::source_info_for_index(&bbs[block], loc); + bbs[block].statements.insert(loc.statement_index, Statement::new(source_info, s)); + } else { + let new: Vec<(usize, Statement<'tcx>)> = new_statements + .drain(i..) + .enumerate() + .map(|(idx, (loc, s))| { + let source_info = Self::source_info_for_index(&bbs[block], loc); + // Record the final statement index, after accounting for statements inserted before. + (loc.statement_index + idx, Statement::new(source_info, s)) + }) + .collect(); + let old = std::mem::take(&mut bbs[block].statements); + merge(old, new, &mut bbs[block].statements); } - debug!("MirPatch: adding statement {:?} at loc {:?}+{}", stmt, loc, delta); - loc.statement_index += delta; - let source_info = Self::source_info_for_index(&bbs[loc.block], loc); - bbs[loc.block] - .statements - .insert(loc.statement_index, Statement::new(source_info, stmt)); - delta += 1; } // The order in which we patch terminators does not change the result. @@ -329,3 +339,28 @@ impl<'tcx> MirPatch<'tcx> { Self::source_info_for_index(data, loc) } } + +fn merge<'tcx>( + xs: Vec>, + ys: Vec<(usize, Statement<'tcx>)>, + zs: &mut Vec>, +) { + zs.reserve(xs.len() + ys.len()); + let mut xs = xs.into_iter().peekable(); + let mut ys = ys.into_iter().peekable(); + + let mut zi = 0; + while let (Some(_), Some((yi, _))) = (xs.peek(), ys.peek()) { + if *yi != zi { + zs.push(xs.next().unwrap()); + } else { + zs.push(ys.next().unwrap().1); + } + zi += 1; + } + + zs.extend(xs); + for (_, s) in ys { + zs.push(s); + } +} From a73aaf44dec7ce56bca6bfb66c1d3df7427a804a Mon Sep 17 00:00:00 2001 From: Jules Bertholet Date: Sun, 15 Nov 2026 22:15:59 -0500 Subject: [PATCH 02/17] `rustc_mir_build`: de-duplicate `local_temp_lifetime()` --- compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 013be91d1669a..9e8293f5a35b2 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -30,12 +30,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block: BasicBlock, expr_id: ExprId, ) -> BlockAnd> { - let local_scope = self.local_scope(); - self.as_rvalue( - block, - TempLifetime { temp_lifetime: Some(local_scope), backwards_incompatible: None }, - expr_id, - ) + self.as_rvalue(block, self.local_temp_lifetime(), expr_id) } /// Compile `expr`, yielding an rvalue. From b0c9ab58b5cb1dbd957ebcab16e18afd14e2d025 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 17 Nov 2026 01:23:39 +0100 Subject: [PATCH 03/17] test asm const ptr operand of a vtable --- tests/ui/asm/x86_64/const-operand-vtable.rs | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/ui/asm/x86_64/const-operand-vtable.rs diff --git a/tests/ui/asm/x86_64/const-operand-vtable.rs b/tests/ui/asm/x86_64/const-operand-vtable.rs new file mode 100644 index 0000000000000..b9e7c7c02ac3d --- /dev/null +++ b/tests/ui/asm/x86_64/const-operand-vtable.rs @@ -0,0 +1,76 @@ +//@ only-x86_64 +//@ only-linux +//@ needs-asm-support +//@ run-pass +#![feature(asm_const_ptr, ptr_metadata)] +use std::mem::MaybeUninit; + +// Test an asm const operand being passed a vtable. + +trait Trait { + #[allow(unused)] + extern "C" fn method(&self, a: i32, b: i32) -> i32 { + a.wrapping_add(b) + } +} + +struct Struct; + +impl Trait for Struct {} + +/// Get a pointer to the vtable from a `&dyn Trait`. +const fn vtable_of(x: &dyn Trait) -> *const () { + let meta: std::ptr::DynMetadata = std::ptr::metadata(x); + unsafe { std::mem::transmute(meta) } +} + +const VTABLE: *const () = vtable_of(&Struct); + +#[repr(C)] +struct ManualVTable { + drop_in_place: Option, + size: usize, + align: usize, + method: extern "C" fn(_: &Struct, _: i32, _: i32) -> i32, +} + +fn read() -> ManualVTable { + let drop_in_place: MaybeUninit; + let size: usize; + let align: usize; + let method: extern "C" fn(_: &Struct, _: i32, _: i32) -> i32; + + unsafe { + #[rustfmt::skip] + std::arch::asm!( + "lea {vtable}, [rip + {input}]", + "mov {drop_in_place}, qword ptr [{vtable}]", + "mov {size}, qword ptr [{vtable} + 8]", + "mov {align}, qword ptr [{vtable} + 16]", + "mov {method}, qword ptr [{vtable} + 24]", + input = const VTABLE, + vtable = out(reg) _, + drop_in_place = out(reg) drop_in_place, + size = out(reg) size, + align = out(reg) align, + method = out(reg) method, + ); + + let drop_in_place: Option = + std::mem::transmute::<_, MaybeUninit<_>>(drop_in_place).assume_init(); + + ManualVTable { drop_in_place, size, align, method } + } +} + +fn main() { + let ManualVTable { drop_in_place, size, align, method } = read(); + + assert!(drop_in_place.is_none()); + + assert_eq!(size, 0); + assert_eq!(align, 1); + + assert_eq!(method(&Struct, 1, 2), 3); + assert_eq!(method(&Struct, 4, 5), 9); +} From 82638ac2b0c6aa60e8262b0c60d82de10e170075 Mon Sep 17 00:00:00 2001 From: Hardik Kumar Date: Sat, 14 Nov 2026 01:50:45 +0530 Subject: [PATCH 04/17] lint: Avoid unused_parens warning for ref patterns with compound types For reference patterns like `&(v @ S{a, b})` the compiler emits the unused parens warning. Without the parenthesis the pattern becomes `&v @ S{a, b}` which makes the expression look a little confusing and it seems like `v` is being binded by reference. Add an explicit pattern matcher to catch such a pattern that would involve an identifier binding with a compound type and avoid emitting the `unused_parens` diagnostics for this. Signed-off-by: Hardik Kumar --- compiler/rustc_lint/src/unused.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 49b468a699396..87027669e98eb 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -943,6 +943,18 @@ impl EarlyLintPass for UnusedParens { // FIXME(pin_ergonomics): Remove this gate once pinned patterns are stable. || cx.builder.features().pin_ergonomics() => { + // Avoid linting on patterns like `&(x @ S{a, b})`, as without parens `&x @ S{a, b}` + // it creates confusion and seems like `x` is binding by reference, #165636. + if let Paren(ref pat) = p.kind + && let Ident(_, _, Some(ref inner_pat)) = pat.kind + && matches!( + inner_pat.kind, + Struct(..) | Tuple(..) | TupleStruct(..) | Slice(..) + ) + { + return; + } + // Check other cases. self.check_unused_parens_pat( cx, p, From 1b8f8b0992575cc26c2ecbf0992a9b5d665dc621 Mon Sep 17 00:00:00 2001 From: Hardik Kumar Date: Sat, 14 Nov 2026 13:27:53 +0530 Subject: [PATCH 05/17] Avoid linting all reference patterns binding an identifier Signed-off-by: Hardik Kumar --- compiler/rustc_lint/src/unused.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 87027669e98eb..2bdc0581c9879 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -943,14 +943,10 @@ impl EarlyLintPass for UnusedParens { // FIXME(pin_ergonomics): Remove this gate once pinned patterns are stable. || cx.builder.features().pin_ergonomics() => { - // Avoid linting on patterns like `&(x @ S{a, b})`, as without parens `&x @ S{a, b}` + // Avoid linting on patterns like `&(x @ _)`, as without parens `&x @ _` // it creates confusion and seems like `x` is binding by reference, #165636. if let Paren(ref pat) = p.kind - && let Ident(_, _, Some(ref inner_pat)) = pat.kind - && matches!( - inner_pat.kind, - Struct(..) | Tuple(..) | TupleStruct(..) | Slice(..) - ) + && let Ident(_, _, Some(..)) = pat.kind { return; } From 4f844e2afef6dee915ad564909235fc3275b1bc3 Mon Sep 17 00:00:00 2001 From: Hardik Kumar Date: Sat, 14 Nov 2026 14:40:33 +0530 Subject: [PATCH 06/17] Ignore pinned patterns Signed-off-by: Hardik Kumar --- compiler/rustc_lint/src/unused.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 2bdc0581c9879..1e879da282b2d 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -946,6 +946,7 @@ impl EarlyLintPass for UnusedParens { // Avoid linting on patterns like `&(x @ _)`, as without parens `&x @ _` // it creates confusion and seems like `x` is binding by reference, #165636. if let Paren(ref pat) = p.kind + && *pinned == Pinnedness::Not && let Ident(_, _, Some(..)) = pat.kind { return; From 4ec30202621f3ec403bb2d0ff7b37b05e7739ad9 Mon Sep 17 00:00:00 2001 From: Hardik Kumar Date: Tue, 17 Nov 2026 17:24:33 +0530 Subject: [PATCH 07/17] Add tests for unused_parens warning on binding by reference patterns Signed-off-by: Hardik Kumar --- .../unused_parens_reference_binding.fixed | 29 +++++++++++++++++ .../lint/unused_parens_reference_binding.rs | 29 +++++++++++++++++ .../unused_parens_reference_binding.stderr | 31 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 tests/ui/lint/unused_parens_reference_binding.fixed create mode 100644 tests/ui/lint/unused_parens_reference_binding.rs create mode 100644 tests/ui/lint/unused_parens_reference_binding.stderr diff --git a/tests/ui/lint/unused_parens_reference_binding.fixed b/tests/ui/lint/unused_parens_reference_binding.fixed new file mode 100644 index 0000000000000..419f130aa814c --- /dev/null +++ b/tests/ui/lint/unused_parens_reference_binding.fixed @@ -0,0 +1,29 @@ +//@ run-rustfix +//@ check-pass +#![allow(dead_code)] +#![warn(unused_parens)] + +pub struct S {} +pub struct TS (); + +fn main() { + let _x @ S{}; //~ WARN: unnecessary parentheses around pattern + + let &_y: &i32; //~ WARN: unnecessary parentheses around pattern + + let &(_x @ S{}); + + let &(_x @ ()): &(); + + let &(_x @ TS()); + + let &(_x @ _nums): &[i32; 0]; + + let &(_x @ _y): &i32; + + let &(mut _x @ S{}); + + let &(ref _x @ S{}); + + let &(ref mut _x @ S{}); +} diff --git a/tests/ui/lint/unused_parens_reference_binding.rs b/tests/ui/lint/unused_parens_reference_binding.rs new file mode 100644 index 0000000000000..01b5562d52ba8 --- /dev/null +++ b/tests/ui/lint/unused_parens_reference_binding.rs @@ -0,0 +1,29 @@ +//@ run-rustfix +//@ check-pass +#![allow(dead_code)] +#![warn(unused_parens)] + +pub struct S {} +pub struct TS (); + +fn main() { + let (_x @ S{}); //~ WARN: unnecessary parentheses around pattern + + let &(_y): &i32; //~ WARN: unnecessary parentheses around pattern + + let &(_x @ S{}); + + let &(_x @ ()): &(); + + let &(_x @ TS()); + + let &(_x @ _nums): &[i32; 0]; + + let &(_x @ _y): &i32; + + let &(mut _x @ S{}); + + let &(ref _x @ S{}); + + let &(ref mut _x @ S{}); +} diff --git a/tests/ui/lint/unused_parens_reference_binding.stderr b/tests/ui/lint/unused_parens_reference_binding.stderr new file mode 100644 index 0000000000000..acddb7e40da04 --- /dev/null +++ b/tests/ui/lint/unused_parens_reference_binding.stderr @@ -0,0 +1,31 @@ +warning: unnecessary parentheses around pattern + --> $DIR/unused_parens_reference_binding.rs:10:9 + | +LL | let (_x @ S{}); + | ^ ^ + | +note: the lint level is defined here + --> $DIR/unused_parens_reference_binding.rs:4:9 + | +LL | #![warn(unused_parens)] + | ^^^^^^^^^^^^^ +help: remove these parentheses + | +LL - let (_x @ S{}); +LL + let _x @ S{}; + | + +warning: unnecessary parentheses around pattern + --> $DIR/unused_parens_reference_binding.rs:12:10 + | +LL | let &(_y): &i32; + | ^ ^ + | +help: remove these parentheses + | +LL - let &(_y): &i32; +LL + let &_y: &i32; + | + +warning: 2 warnings emitted + From 30ae715e18832f39ba84025817c27b3cfa0fc107 Mon Sep 17 00:00:00 2001 From: Gennaro Biondi Date: Tue, 17 Nov 2026 17:04:13 +0100 Subject: [PATCH 08/17] Add `cd` alias to `std::env::set_current_dir` --- library/std/src/env.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/env.rs b/library/std/src/env.rs index 3e7634092132b..596aec04a6277 100644 --- a/library/std/src/env.rs +++ b/library/std/src/env.rs @@ -75,7 +75,7 @@ pub fn current_dir() -> io::Result { /// assert!(env::set_current_dir(&root).is_ok()); /// println!("Successfully changed working directory to {}!", root.display()); /// ``` -#[doc(alias = "chdir", alias = "SetCurrentDirectory", alias = "SetCurrentDirectoryW")] +#[doc(alias = "cd", alias = "chdir", alias = "SetCurrentDirectory", alias = "SetCurrentDirectoryW")] #[stable(feature = "env", since = "1.0.0")] pub fn set_current_dir>(path: P) -> io::Result<()> { paths_imp::chdir(path.as_ref()) From 23e72c74b22be1255f061541172f89db095c7da7 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Mon, 16 Nov 2026 22:54:34 +0100 Subject: [PATCH 09/17] Add test for unused variant in manual clone impl --- .../unused-variant-manual-clone-impl.rs | 29 +++++++++++++++++++ .../unused-variant-manual-clone-impl.stderr | 22 ++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs create mode 100644 tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs new file mode 100644 index 0000000000000..aba7d07a92c77 --- /dev/null +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs @@ -0,0 +1,29 @@ +#![deny(dead_code)] + +// Previously, the variants which are matched with `Self::...` below +// were not marked as dead. +enum Enum { + Variant1, //~ ERROR: variants `Variant1`, `Variant3`, and `Variant5` are never constructed + Variant2, + Variant3(i32), + Variant4(i32), + Variant5 { x: i32 }, + Variant6 { x: i32 }, +} + +impl Clone for Enum { + fn clone(&self) -> Enum { + match &self { + Enum::Variant1 => Enum::Variant1, + Self::Variant2 => Self::Variant2, + Enum::Variant3(b) => Enum::Variant3(*b), + Self::Variant4(b) => Self::Variant4(*b), + Enum::Variant5 { x } => Enum::Variant5 { x: *x }, + Self::Variant6 { x } => Self::Variant6 { x: *x }, + } + } +} + +fn main() { + let _: Enum = todo!(); +} diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr new file mode 100644 index 0000000000000..6be00bbf7a356 --- /dev/null +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr @@ -0,0 +1,22 @@ +error: variants `Variant1`, `Variant3`, and `Variant5` are never constructed + --> $DIR/unused-variant-manual-clone-impl.rs:6:5 + | +LL | enum Enum { + | ---- variants in this enum +LL | Variant1, + | ^^^^^^^^ +LL | Variant2, +LL | Variant3(i32), + | ^^^^^^^^ +LL | Variant4(i32), +LL | Variant5 { x: i32 }, + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-variant-manual-clone-impl.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to 1 previous error + From 711c0ce1ab7891e8366b55fb3104682fd45418dd Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 17 Nov 2026 12:46:53 -0500 Subject: [PATCH 10/17] rustc_target: catch up with LLVM 24 movement on ppc64le bsd data layout --- compiler/rustc_codegen_llvm/src/context.rs | 5 +++++ .../src/spec/targets/powerpc64_unknown_freebsd.rs | 2 +- .../src/spec/targets/powerpc64le_unknown_freebsd.rs | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 999613db146a3..e0d606627a52b 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -214,6 +214,11 @@ fn init_module<'ll, 'tcx>(tcx: TyCtxt<'tcx>, llcx: llvm::Context<'ll>, llmod: ll target_data_layout = target_data_layout .replace("-p10:32:32-p11:32:32-p12:32:32-p13:32:32-p14:32:32-p15:32:32", ""); } + if sess.target.arch == Arch::PowerPC64 && sess.target.os == Os::FreeBsd { + // LLVM 24 updated the powerpc64 FreeBSD layout to use 16-byte stack and vector + // alignment: https://github.com/llvm/llvm-project/pull/232336 + target_data_layout = target_data_layout.replace("-S128-v256:256:256-v512:512:512", ""); + } } // Ensure the data-layout values hardcoded remain the defaults. { diff --git a/compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs b/compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs index 537b21c54b7c8..c29b4cbe33c35 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc64_unknown_freebsd.rs @@ -23,7 +23,7 @@ pub(crate) fn target() -> Target { std: Some(true), }, pointer_width: 64, - data_layout: "E-m:e-Fn32-i64:64-i128:128-n32:64".into(), + data_layout: "E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512".into(), arch: Arch::PowerPC64, options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base }, } diff --git a/compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs b/compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs index 1e6b9a7bdc267..b6a5349247088 100644 --- a/compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs +++ b/compiler/rustc_target/src/spec/targets/powerpc64le_unknown_freebsd.rs @@ -24,7 +24,7 @@ pub(crate) fn target() -> Target { std: Some(true), }, pointer_width: 64, - data_layout: "e-m:e-Fn32-i64:64-i128:128-n32:64".into(), + data_layout: "e-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512".into(), arch: Arch::PowerPC64, options: TargetOptions { mcount: "_mcount".into(), ..base }, } From 6f0ff78104cbf94fc20bc3efcd85af68a4e38a59 Mon Sep 17 00:00:00 2001 From: Francisco Gouveia Date: Tue, 17 Nov 2026 09:03:37 +0000 Subject: [PATCH 11/17] Change the span building of qualified paths from first-to-last to chained --- compiler/rustc_parse/src/parser/path.rs | 21 +++++++++++----- tests/ui/attributes/show_spans_macros.rs | 11 +++++++++ tests/ui/attributes/show_spans_macros.stderr | 26 ++++++++++++++++++-- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 139e3d31cce8b..b97ae6d7e7098 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -74,8 +74,9 @@ impl<'a> Parser<'a> { /// `::F::a` (without disambiguator) /// `::F::a::` (with disambiguator) pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (Box, Path)> { - let lo = self.prev_token.span; + let mut qpath_span = Some(self.prev_token.span); let ty = self.parse_ty()?; + chain_span(&mut qpath_span, ty.span); // `path` will contain the prefix of the path up to the `>`, // if any (e.g., `U` in the `::*` examples @@ -83,16 +84,18 @@ impl<'a> Parser<'a> { // span in the case of something like `::Bar`. let (mut path, path_span); if self.eat_keyword(exp!(As)) { - let path_lo = self.token.span; + chain_span(&mut qpath_span, self.prev_token.span); path = self.parse_path(PathStyle::Type)?; - path_span = path_lo.to(self.prev_token.span); + path_span = path.span; + chain_span(&mut qpath_span, path_span); } else { - path_span = self.token.span.to(self.token.span); + path_span = self.token.span; // `>` path = ast::Path { segments: ThinVec::new(), span: path_span }; } // See doc comment for `unmatched_angle_bracket_count`. self.expect(exp!(Gt))?; + chain_span(&mut qpath_span, self.prev_token.span); if self.unmatched_angle_bracket_count > 0 { self.unmatched_angle_bracket_count -= 1; debug!("parse_qpath: (decrement) count={:?}", self.unmatched_angle_bracket_count); @@ -105,10 +108,16 @@ impl<'a> Parser<'a> { let qself = Box::new(QSelf { ty, path_span, position: path.segments.len() }); if !is_import_coupler { - self.parse_path_segments(&mut path.segments, style, None)?; + chain_span(&mut qpath_span, self.prev_token.span); // `::` + self.parse_path_segments_with_path_span( + &mut path.segments, + style, + None, + &mut qpath_span, + )?; } - Ok((qself, Path { segments: path.segments, span: lo.to(self.prev_token.span) })) + Ok((qself, Path { segments: path.segments, span: qpath_span.unwrap() })) } /// Recover from an invalid single colon, when the user likely meant a qualified path. diff --git a/tests/ui/attributes/show_spans_macros.rs b/tests/ui/attributes/show_spans_macros.rs index b7c3dc1f57bd1..9f2b8e285e9d0 100644 --- a/tests/ui/attributes/show_spans_macros.rs +++ b/tests/ui/attributes/show_spans_macros.rs @@ -26,6 +26,17 @@ fn path_from_tts() { path!(foo, BAR); } +macro_rules! qpath { + ($lt:tt, $f:tt) => { + let _ = $lt u8 as Default>::$f; + }; +} + +#[rustc_show_spans(path)] +fn qpath_from_tts() { + qpath!(<, default); +} + // FIXME(#126763): the field access span should be `$a.$f` in the macro body. macro_rules! field { ($a:tt, $f:tt) => { diff --git a/tests/ui/attributes/show_spans_macros.stderr b/tests/ui/attributes/show_spans_macros.stderr index 68f94199b6321..a02362aae9c5e 100644 --- a/tests/ui/attributes/show_spans_macros.stderr +++ b/tests/ui/attributes/show_spans_macros.stderr @@ -9,14 +9,36 @@ LL | let _ = $a::$b; LL | path!(foo, BAR); | --------------- in this macro invocation +note: showing the spans of the path + --> $DIR/show_spans_macros.rs:31:21 + | +LL | macro_rules! qpath { +LL | ($lt:tt, $f:tt) => { +LL | let _ = $lt u8 as Default>::$f; + | ^^ +... +LL | qpath!(<, default); + | ------------------ in this macro invocation + +note: showing the spans of the path + --> $DIR/show_spans_macros.rs:31:17 + | +LL | macro_rules! qpath { +LL | ($lt:tt, $f:tt) => { +LL | let _ = $lt u8 as Default>::$f; + | ^^^^^^^^^^^^^^^^^^^^^^ +... +LL | qpath!(<, default); + | ------------------ in this macro invocation + note: showing the spans of the expr - --> $DIR/show_spans_macros.rs:40:12 + --> $DIR/show_spans_macros.rs:51:12 | LL | field!(T, 0); | ^^^^ note: showing the spans of the expr - --> $DIR/show_spans_macros.rs:40:12 + --> $DIR/show_spans_macros.rs:51:12 | LL | field!(T, 0); | ^ From d88bc8a33bff96db91be3d3308b1c6f6506c70a0 Mon Sep 17 00:00:00 2001 From: Toni Peter Date: Mon, 16 Nov 2026 23:05:40 +0100 Subject: [PATCH 12/17] Fix dead-code not ignoring variants in patterns with `Self` type --- compiler/rustc_hir/src/pat_util.rs | 30 ++++++------------- compiler/rustc_passes/src/dead.rs | 12 ++++++-- .../unused-variant-manual-clone-impl-tuple.rs | 19 ++++++++++++ ...sed-variant-manual-clone-impl-tuple.stderr | 17 +++++++++++ .../unused-variant-manual-clone-impl.rs | 4 +-- .../unused-variant-manual-clone-impl.stderr | 8 +++-- tests/ui/lint/dead-code/unused-variant.stderr | 5 ---- 7 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.rs create mode 100644 tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.stderr diff --git a/compiler/rustc_hir/src/pat_util.rs b/compiler/rustc_hir/src/pat_util.rs index a47d9d5ca57c4..b70d33f53dced 100644 --- a/compiler/rustc_hir/src/pat_util.rs +++ b/compiler/rustc_hir/src/pat_util.rs @@ -3,8 +3,7 @@ use std::iter::Enumerate; use rustc_hir_id::HirId; use rustc_span::{Ident, Span}; -use crate::def::{CtorOf, DefKind, Res}; -use crate::def_id::{DefId, DefIdSet}; +use crate::QPath; use crate::hir::{self, BindingMode, ByRef, PatKind}; pub struct EnumerateAndAdjust { enumerate: Enumerate, @@ -100,31 +99,20 @@ impl hir::Pat<'_> { } } - /// Returns variants that are necessary to exist for the pattern to match. - pub fn necessary_variants(&self) -> Vec { - let mut variants = vec![]; + /// Call 'f' on every variant which is necessary for the pattern to match + pub fn each_necessary_variant(&self, mut f: impl FnMut(&QPath<'_>, HirId)) { self.walk(|p| match &p.kind { PatKind::Or(_) => false, - PatKind::Expr(hir::PatExpr { - kind: hir::PatExprKind::Path(hir::QPath::Resolved(_, path)), - .. - }) - | PatKind::TupleStruct(hir::QPath::Resolved(_, path), ..) - | PatKind::Struct(hir::QPath::Resolved(_, path), ..) => { - if let Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), id) = - path.res - { - variants.push(id); - } + PatKind::Expr(hir::PatExpr { hir_id, kind: hir::PatExprKind::Path(qpath), .. }) => { + f(qpath, *hir_id); + true + } + PatKind::TupleStruct(qpath, ..) | PatKind::Struct(qpath, ..) => { + f(qpath, p.hir_id); true } _ => true, }); - // We remove duplicates by inserting into a hash set to avoid re-ordering - // the bounds - let mut duplicates = DefIdSet::default(); - variants.retain(|def_id| duplicates.insert(*def_id)); - variants } /// Checks if the pattern contains any `ref` or `ref mut` bindings, and if diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index 6cd8e254b503f..a0df63d650602 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -13,7 +13,7 @@ use rustc_attr_ir::find_attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_errors::{ErrorGuaranteed, MultiSpan}; use rustc_hir::def::{CtorOf, DefKind, Res}; -use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdMap, LocalModId}; +use rustc_hir::def_id::{DefId, DefIdSet, LocalDefId, LocalDefIdMap, LocalModId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{self as hir, ForeignItemId, ItemId, Node, PatKind, QPath}; use rustc_lint_defs::builtin::{DEAD_CODE, DEAD_CODE_PUB_IN_BINARY}; @@ -860,7 +860,15 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { // necessary for the pattern to match. Those construction sites // can't be reached unless the variant is constructed elsewhere. let len = self.ignore_variant_stack.len(); - self.ignore_variant_stack.extend(arm.pat.necessary_variants()); + let mut seen_variants = DefIdSet::default(); + arm.pat.each_necessary_variant(|qpath, hir_id| { + if let Res::Def(DefKind::Variant | DefKind::Ctor(CtorOf::Variant, ..), id) = + self.typeck_results().qpath_res(qpath, hir_id) + && seen_variants.insert(id) + { + self.ignore_variant_stack.push(id); + } + }); let result = intravisit::walk_arm(self, arm); self.ignore_variant_stack.truncate(len); diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.rs b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.rs new file mode 100644 index 0000000000000..d048915a9ea6d --- /dev/null +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.rs @@ -0,0 +1,19 @@ +#![deny(dead_code)] + +enum Enum { + Variant1, + Variant2(i32), //~ ERROR: `Variant2` is never constructed +} + +impl Clone for Enum { + fn clone(&self) -> Self { + match (self,) { + (Self::Variant1,) => Self::Variant1, + (Self::Variant2(value),) => Self::Variant2(*value), + } + } +} + +fn main() { + let _ = Enum::Variant1; +} diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.stderr b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.stderr new file mode 100644 index 0000000000000..b7b973d1e03f2 --- /dev/null +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl-tuple.stderr @@ -0,0 +1,17 @@ +error: variant `Variant2` is never constructed + --> $DIR/unused-variant-manual-clone-impl-tuple.rs:5:5 + | +LL | enum Enum { + | ---- variant in this enum +LL | Variant1, +LL | Variant2(i32), + | ^^^^^^^^ + | +note: the lint level is defined here + --> $DIR/unused-variant-manual-clone-impl-tuple.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs index aba7d07a92c77..98c3970d629b2 100644 --- a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.rs @@ -1,9 +1,7 @@ #![deny(dead_code)] -// Previously, the variants which are matched with `Self::...` below -// were not marked as dead. enum Enum { - Variant1, //~ ERROR: variants `Variant1`, `Variant3`, and `Variant5` are never constructed + Variant1, //~ ERROR: variants `Variant1`, `Variant2`, `Variant3`, `Variant4`, `Variant5`, and `Variant6` are never constructed Variant2, Variant3(i32), Variant4(i32), diff --git a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr index 6be00bbf7a356..ef9c52e126066 100644 --- a/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr +++ b/tests/ui/lint/dead-code/unused-variant-manual-clone-impl.stderr @@ -1,16 +1,20 @@ -error: variants `Variant1`, `Variant3`, and `Variant5` are never constructed - --> $DIR/unused-variant-manual-clone-impl.rs:6:5 +error: variants `Variant1`, `Variant2`, `Variant3`, `Variant4`, `Variant5`, and `Variant6` are never constructed + --> $DIR/unused-variant-manual-clone-impl.rs:4:5 | LL | enum Enum { | ---- variants in this enum LL | Variant1, | ^^^^^^^^ LL | Variant2, + | ^^^^^^^^ LL | Variant3(i32), | ^^^^^^^^ LL | Variant4(i32), + | ^^^^^^^^ LL | Variant5 { x: i32 }, | ^^^^^^^^ +LL | Variant6 { x: i32 }, + | ^^^^^^^^ | note: the lint level is defined here --> $DIR/unused-variant-manual-clone-impl.rs:1:9 diff --git a/tests/ui/lint/dead-code/unused-variant.stderr b/tests/ui/lint/dead-code/unused-variant.stderr index 7a36092c903fd..4ba2090abca09 100644 --- a/tests/ui/lint/dead-code/unused-variant.stderr +++ b/tests/ui/lint/dead-code/unused-variant.stderr @@ -6,11 +6,6 @@ LL | enum Enum { LL | Variant1, | ^^^^^^^^ | -note: `Variant1` is used in the expansion of the derive macro `Clone`, but this is intentionally ignored during dead code analysis - --> $DIR/unused-variant.rs:3:10 - | -LL | #[derive(Clone)] - | ^^^^^ note: the lint level is defined here --> $DIR/unused-variant.rs:1:9 | From 438f8b66c27f68c13a00e6219f4c62231325810c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 18 Nov 2026 14:46:01 +0100 Subject: [PATCH 13/17] windows seek_write: document interaction with append mode --- library/std/src/os/windows/fs.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/std/src/os/windows/fs.rs b/library/std/src/os/windows/fs.rs index a955567b57465..b7b2ad6e403d7 100644 --- a/library/std/src/os/windows/fs.rs +++ b/library/std/src/os/windows/fs.rs @@ -219,6 +219,9 @@ pub trait FileExt { /// from the current cursor. The current cursor **is** affected by this /// function, it is set to the end of the write. /// + /// If the file was opened for appending (via [`OpenOptions::append`]), this is equivalent + /// to `write`: the `offset` is ignored, and `buf` is appended at the end of the file. + /// /// When writing beyond the end of the file, the file is appropriately /// extended and the intermediate bytes are set to zero. /// From 2a94a9fa3d2e1a3a9e188ed673b6aa8a0f76277e Mon Sep 17 00:00:00 2001 From: Jonathan Brouwer Date: Wed, 18 Nov 2026 15:52:23 +0100 Subject: [PATCH 14/17] Go through `ShouldEmit` error path for invalid literals --- compiler/rustc_attr_parsing/src/parser.rs | 22 ++------------------ tests/ui/lint/pre-expansion-parsing.rs | 2 ++ tests/ui/parser/bad-lit-suffixes.rs | 1 - tests/ui/parser/bad-lit-suffixes.stderr | 25 +++-------------------- 4 files changed, 7 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/parser.rs b/compiler/rustc_attr_parsing/src/parser.rs index 350b502e2899e..820ce9224e2e7 100644 --- a/compiler/rustc_attr_parsing/src/parser.rs +++ b/compiler/rustc_attr_parsing/src/parser.rs @@ -15,9 +15,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rustc_ast::token::{self, Delimiter, MetaVarKind}; use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{ - AttrArgs, Expr, ExprKind, LitKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp, -}; +use rustc_ast::{AttrArgs, Expr, ExprKind, MetaItemLit, Path, PathSegment, StmtKind, UnOp}; use rustc_ast_pretty::pprust; use rustc_attr_ir::AttrPath; use rustc_errors::{Applicability, Diag, PResult}; @@ -424,23 +422,7 @@ fn expr_to_lit<'sess>( Err(psess.dcx().create_err(SuffixedLiteralInAttribute { span: lit.span })) } } - Err(err) => { - let err = create_lit_error(psess, err, token_lit, expr.span); - if matches!( - should_emit, - ShouldEmit::ErrorsAndLints { recovery: Recovery::Forbidden } - ) { - Err(err) - } else { - let lit = MetaItemLit { - symbol: token_lit.symbol, - suffix: token_lit.suffix, - kind: LitKind::Err(err.emit_err()), - span: expr.span, - }; - Ok(Some(lit)) - } - } + Err(err) => Err(create_lit_error(psess, err, token_lit, expr.span)), } } else { if matches!(should_emit, ShouldEmit::Nothing) || matches!(expr.kind, ExprKind::Err(_)) { diff --git a/tests/ui/lint/pre-expansion-parsing.rs b/tests/ui/lint/pre-expansion-parsing.rs index 11a55beb77d65..772c61b8e212f 100644 --- a/tests/ui/lint/pre-expansion-parsing.rs +++ b/tests/ui/lint/pre-expansion-parsing.rs @@ -6,5 +6,7 @@ #[expect(expect(expect))] //~ ERROR malformed #[deny(({!}))] // OK #[expect[helix::]] // OK +#[allow = 1u7] // OK +#[allow = "x"suffix] // OK #[cfg(false)] const _: () = (); diff --git a/tests/ui/parser/bad-lit-suffixes.rs b/tests/ui/parser/bad-lit-suffixes.rs index 70e3f7aa6c3b2..1279059514e60 100644 --- a/tests/ui/parser/bad-lit-suffixes.rs +++ b/tests/ui/parser/bad-lit-suffixes.rs @@ -33,7 +33,6 @@ fn f() {} #[must_use = "string"suffix] //~^ ERROR suffixes on string literals are invalid -//~| ERROR malformed `must_use` attribute input fn g() {} #[link(name = "string"suffix)] diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 6ac912797d2a8..2aa48b04cc5bb 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -136,36 +136,17 @@ error: suffixes on string literals are invalid LL | #[must_use = "string"suffix] | ^^^^^^^^^^^^^^ invalid suffix `suffix` -error[E0539]: malformed `must_use` attribute input - --> $DIR/bad-lit-suffixes.rs:34:3 - | -LL | #[must_use = "string"suffix] - | ^^^^^^^^^^^-------------- - | | - | expected a string literal here - | - = note: for more information, visit -help: try changing it to one of the following valid forms of the attribute - | -LL - #[must_use = "string"suffix] -LL + #[must_use] - | -LL - #[must_use = "string"suffix] -LL + #[must_use = "reason"] - | - error: suffixes on string literals are invalid - --> $DIR/bad-lit-suffixes.rs:39:15 + --> $DIR/bad-lit-suffixes.rs:38:15 | LL | #[link(name = "string"suffix)] | ^^^^^^^^^^^^^^ invalid suffix `suffix` error: suffixes on string literals are invalid - --> $DIR/bad-lit-suffixes.rs:46:25 + --> $DIR/bad-lit-suffixes.rs:45:25 | LL | #[rustc_confusables("blah"suffix)] | ^^^^^^^^^^^^ invalid suffix `suffix` -error: aborting due to 21 previous errors; 2 warnings emitted +error: aborting due to 20 previous errors; 2 warnings emitted -For more information about this error, try `rustc --explain E0539`. From 01f9f7ac161eccabc3d4dae09900dee341ac30e9 Mon Sep 17 00:00:00 2001 From: Petrichor Park Date: Thu, 12 Nov 2026 15:25:55 -0600 Subject: [PATCH 15/17] Fold `UnusedDuplicate` and `UnusedMultiple` diagnostics into `DuplicateAttribute` Currently, `UnusedDuplicate` is used when a duplicate attribute is a warning, and `UnusedMultiple` is used when it is an error. This commit removes the redundancy in favor of a new lint, `DuplicateAttribute`. The error messages now look like "duplicate `X` attributes", instead of "multiple `X` attributes" or "duplicate attribute". Thanks to @JonathanBrouwer for the suggestion to work on this --- .../src/attributes/codegen_attrs.rs | 8 +- .../src/attributes/diagnostic/opaque.rs | 5 +- .../rustc_attr_parsing/src/attributes/doc.rs | 10 +- .../src/attributes/inline.rs | 11 +- .../src/attributes/macro_attrs.rs | 6 +- .../rustc_attr_parsing/src/attributes/mod.rs | 33 ++-- compiler/rustc_attr_parsing/src/context.rs | 16 +- .../rustc_attr_parsing/src/diagnostics.rs | 21 +-- compiler/rustc_attr_parsing/src/lib.rs | 2 +- compiler/rustc_builtin_macros/src/util.rs | 4 +- tests/rustdoc-ui/lints/duplicated-attr.stderr | 2 +- .../lints/invalid-crate-level-lint.rs | 2 +- .../lints/invalid-crate-level-lint.stderr | 2 +- tests/ui/attributes/args-checked.rs | 2 +- tests/ui/attributes/args-checked.stderr | 2 +- tests/ui/attributes/attr-order-deprecated.rs | 2 +- .../attributes/attr-order-deprecated.stderr | 2 +- tests/ui/attributes/attr-order-must-use.rs | 2 +- .../ui/attributes/attr-order-must-use.stderr | 2 +- tests/ui/attributes/duplicated-attributes.rs | 12 +- .../attributes/duplicated-attributes.stderr | 12 +- tests/ui/attributes/invalid-macro-use.rs | 6 +- tests/ui/attributes/invalid-macro-use.stderr | 6 +- tests/ui/attributes/malformed-no-std.rs | 8 +- tests/ui/attributes/malformed-no-std.stderr | 8 +- tests/ui/attributes/optimize.rs | 4 +- tests/ui/attributes/optimize.stderr | 4 +- tests/ui/attributes/used_with_arg.rs | 6 +- tests/ui/attributes/used_with_arg.stderr | 6 +- .../cfg-attr-duplicate-attrs.rs | 12 +- .../cfg-attr-duplicate-attrs.stderr | 12 +- tests/ui/coverage-attr/bad-syntax.rs | 4 +- tests/ui/coverage-attr/bad-syntax.stderr | 4 +- tests/ui/deprecation/deprecation-sanity.rs | 2 +- .../ui/deprecation/deprecation-sanity.stderr | 2 +- .../diagnostic_namespace/opaque/duplicate.rs | 4 +- .../opaque/duplicate.stderr | 2 +- .../windows/link-ordinal-multiple.rs | 4 +- .../windows/link-ordinal-multiple.stderr | 4 +- tests/ui/lint/unused/unused-attr-duplicate.rs | 70 +++++---- .../lint/unused/unused-attr-duplicate.stderr | 144 +++++++++--------- tests/ui/sanitize-attr/invalid-sanitize.rs | 4 +- .../ui/sanitize-attr/invalid-sanitize.stderr | 4 +- tests/ui/splat/splat-invalid.rs | 8 +- tests/ui/splat/splat-invalid.stderr | 8 +- .../stability-attribute-sanity.rs | 2 +- .../stability-attribute-sanity.stderr | 2 +- 47 files changed, 262 insertions(+), 236 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index 7da22862f7e80..e26f8681a5516 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -221,7 +221,7 @@ impl AttributeParser for NakedParser { if let Some(earlier) = this.span { let span = cx.attr_span; - cx.warn_unused_duplicate(earlier, span); + cx.warn_unused_duplicate(earlier, span, sym::naked); } else { this.span = Some(cx.attr_span); } @@ -505,14 +505,14 @@ impl AttributeParser for UsedParser { UsedBy::Compiler => &mut group.first_compiler, UsedBy::Linker => { if let Some(prev) = group.first_default { - cx.warn_unused_duplicate(prev, attr_span); + cx.warn_unused_duplicate(prev, attr_span, sym::used); return; } &mut group.first_linker } UsedBy::Default => { if let Some(prev) = group.first_linker { - cx.warn_unused_duplicate(prev, attr_span); + cx.warn_unused_duplicate(prev, attr_span, sym::used); return; } &mut group.first_default @@ -520,7 +520,7 @@ impl AttributeParser for UsedParser { }; if let Some(prev) = *target { - cx.warn_unused_duplicate(prev, attr_span); + cx.warn_unused_duplicate(prev, attr_span, sym::used); } else { *target = Some(attr_span); } diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs index 0e4a524080149..302c1ef21d7e8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs @@ -2,7 +2,7 @@ use rustc_attr_ir::AttributeKind; use rustc_attr_ir::target::Target; use rustc_feature::AttributeStability; use rustc_lint_defs::builtin::MALFORMED_DIAGNOSTIC_ATTRIBUTES; -use rustc_span::{Span, sym}; +use rustc_span::{Span, Symbol, sym}; use crate::attributes::diagnostic::gate_diagnostic_attr; use crate::attributes::{AcceptMapping, AttributeParser}; @@ -52,7 +52,8 @@ impl OpaqueParser { fn parse<'sess>(&mut self, cx: &mut AcceptContext<'_, 'sess>, args: &ArgParser) { let attr_span = cx.attr_span; if let Some(earlier_span) = self.attr_span { - cx.warn_unused_duplicate(earlier_span, attr_span); + let attr_path_interned = Symbol::intern(&cx.attr_path.to_string()); + cx.warn_unused_duplicate(earlier_span, attr_span, attr_path_interned); } self.attr_span = Some(attr_span); diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index c8090ffcd1e9f..6c81f5c9aaef9 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -12,6 +12,7 @@ use rustc_span::{Span, Symbol, edition, kw, sym}; use super::prelude::AllowedTargets; use super::{AcceptMapping, AttributeParser, template}; +use crate::DuplicateAttribute; use crate::attributes::doc_comment::DOC_TARGETS; use crate::context::{AcceptContext, FinalizeContext}; use crate::diagnostics::{ @@ -24,7 +25,7 @@ use crate::diagnostics::{ DocKeywordNotKeyword, DocTestLiteral, DocTestTakesList, DocTestUnknown, DocUnknownAny, DocUnknownInclude, DocUnknownPasses, DocUnknownPlugins, DocUnknownSpotlight, DuplicateNotableTraitColor, ExpectedNameValue, ExpectedNoArgs, IllFormedAttributeInput, - InvalidNotableTraitAttr, InvalidNotableTraitColor, MalformedDoc, UnusedDuplicate, + InvalidNotableTraitAttr, InvalidNotableTraitColor, MalformedDoc, }; use crate::parser::{ ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser, @@ -279,7 +280,12 @@ impl DocParser { let unused_span = path.span(); cx.emit_lint( INVALID_DOC_ATTRIBUTES, - UnusedDuplicate { this: unused_span, other: used_span, warning: true }, + DuplicateAttribute { + this: unused_span, + other: used_span, + name: sym::no_crate_inject, + warning: true, + }, unused_span, ); return; diff --git a/compiler/rustc_attr_parsing/src/attributes/inline.rs b/compiler/rustc_attr_parsing/src/attributes/inline.rs index 5dd46bf0922de..b41f418fb986c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/inline.rs +++ b/compiler/rustc_attr_parsing/src/attributes/inline.rs @@ -3,7 +3,7 @@ use rustc_feature::AttributeStability; use rustc_lint_defs::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNUSED_ATTRIBUTES}; use super::prelude::*; -use crate::diagnostics::{InlineForceInlineConflict, InlineIgnoredForExported, UnusedMultiple}; +use crate::diagnostics::{DuplicateAttribute, InlineForceInlineConflict, InlineIgnoredForExported}; #[derive(Default)] pub(crate) struct InlineParser(Option<(InlineAttr, Span)>); @@ -70,7 +70,11 @@ impl AttributeParser for InlineParser { cx.emit_err(InlineForceInlineConflict { inline_span, force_inline_span }); } Some((_, first_inline_span)) => { - cx.warn_unused_duplicate_future_error(first_inline_span, inline_span); + cx.warn_unused_duplicate_future_error( + first_inline_span, + inline_span, + sym::inline, + ); } } }, @@ -108,10 +112,11 @@ impl AttributeParser for InlineParser { match this.0 { None => this.0 = Some((attr, force_inline_span)), Some((InlineAttr::Force { .. }, first_force_inline_span)) => { - cx.emit_err(UnusedMultiple { + cx.emit_err(DuplicateAttribute { this: force_inline_span, other: first_force_inline_span, name: sym::rustc_force_inline, + warning: false, }); } Some((_, inline_span)) => { diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index 5be8df4d141c8..1ecda268ee3e8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -58,14 +58,14 @@ impl AttributeParser for MacroUseParser { "State is UseAll is some so this is not the first attribute", ); // Since there is a `#[macro_use]` import already, give a warning - cx.warn_unused_duplicate(first_span, span); + cx.warn_unused_duplicate(first_span, span, sym::macro_use); } MacroUseArgs::UseSpecific(_) => { group.state = MacroUseArgs::UseAll; group.first_span = Some(span); // If there is a `#[macro_use]` attribute, warn on all `#[macro_use(...)]` attributes since everything is already imported for specific_use in group.uses_attr_spans.drain(..) { - cx.warn_unused_duplicate(span, specific_use); + cx.warn_unused_duplicate(span, specific_use, sym::macro_use); } } } @@ -81,7 +81,7 @@ impl AttributeParser for MacroUseParser { let first_span = group.first_span.expect( "State is UseAll is some so this is not the first attribute", ); - cx.warn_unused_duplicate(first_span, span); + cx.warn_unused_duplicate(first_span, span, sym::macro_use); } MacroUseArgs::UseSpecific(arguments) => { // Store here so if we encounter a `UseAll` later we can still lint this attribute diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 7475c86ba14d0..456ae1ee31afb 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -27,7 +27,7 @@ use rustc_span::{Span, Symbol}; use thin_vec::ThinVec; use crate::context::{AcceptContext, FinalizeCheckContext, FinalizeCheckFn, FinalizeContext}; -use crate::diagnostics::UnusedMultiple; +use crate::diagnostics::DuplicateAttribute; use crate::parser::ArgParser; use crate::target_checking::AllowedTargets; use crate::{AttributeTemplate, template}; @@ -235,18 +235,27 @@ impl OnDuplicate { unused: Span, ) { match self { - OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused), - OnDuplicate::WarnButFutureError => cx.warn_unused_duplicate_future_error(used, unused), - OnDuplicate::Error => { - cx.emit_err(UnusedMultiple { - this: unused, - other: used, - name: Symbol::intern( - &P::PATH.iter().map(|i| i.to_string()).collect::>().join(".."), - ), - }); - } OnDuplicate::Ignore => {} + _ => { + let name = Symbol::intern( + &P::PATH.iter().map(|i| i.to_string()).collect::>().join(".."), + ); + match self { + OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused, name), + OnDuplicate::WarnButFutureError => { + cx.warn_unused_duplicate_future_error(used, unused, name) + } + OnDuplicate::Error => { + cx.emit_err(DuplicateAttribute { + this: unused, + other: used, + name, + warning: false, + }); + } + OnDuplicate::Ignore => unreachable!(), + } + } } } } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index cb70e10b2d92f..17fc9bb8789a3 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -70,14 +70,14 @@ use crate::attributes::unroll::*; use crate::attributes::{AttributeParser as _, AttributeSafety, Combine, Single, WithoutArgs}; use crate::diagnostics::{ AttributeParseError, AttributeParseErrorReason, AttributeParseErrorSuggestions, - ParsedDescription, UnusedDuplicate, + ParsedDescription, }; use crate::parser::{ ArgParser, MetaItemListParser, MetaItemOrLitParser, MetaItemParser, NameValueParser, RefPathParser, }; use crate::target_checking::AllowedTargets; -use crate::{AttributeParser, AttributeTemplate, EmitAttribute}; +use crate::{AttributeParser, AttributeTemplate, DuplicateAttribute, EmitAttribute}; type GroupType = LazyLock; @@ -475,10 +475,15 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> { (self.emit_lint)(LintId::of(lint), span.into(), kind); } - pub(crate) fn warn_unused_duplicate(&mut self, used_span: Span, unused_span: Span) { + pub(crate) fn warn_unused_duplicate( + &mut self, + used_span: Span, + unused_span: Span, + name: Symbol, + ) { self.emit_lint( UNUSED_ATTRIBUTES, - UnusedDuplicate { this: unused_span, other: used_span, warning: false }, + DuplicateAttribute { this: unused_span, other: used_span, name, warning: false }, unused_span, ) } @@ -487,10 +492,11 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> { &mut self, used_span: Span, unused_span: Span, + name: Symbol, ) { self.emit_lint( UNUSED_ATTRIBUTES, - UnusedDuplicate { this: unused_span, other: used_span, warning: true }, + DuplicateAttribute { this: unused_span, other: used_span, name, warning: true }, unused_span, ) } diff --git a/compiler/rustc_attr_parsing/src/diagnostics.rs b/compiler/rustc_attr_parsing/src/diagnostics.rs index 39bd300957f5c..12b2fe8cff6e8 100644 --- a/compiler/rustc_attr_parsing/src/diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/diagnostics.rs @@ -1350,14 +1350,18 @@ pub(crate) struct UnknownVersionLiteral { } #[derive(Diagnostic)] -#[diag("multiple `{$name}` attributes")] -pub struct UnusedMultiple { +#[diag("duplicate `{$name}` attributes")] +pub struct DuplicateAttribute { #[primary_span] #[suggestion("remove this attribute", code = "", applicability = "unspecified")] pub this: Span, #[note("attribute also specified here")] pub other: Span, pub name: Symbol, + #[warning( + "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" + )] + pub warning: bool, } #[derive(Diagnostic)] @@ -2191,19 +2195,6 @@ pub(crate) struct AdditionalCommaSuggestion { pub span: Span, } -#[derive(Diagnostic)] -#[diag("unused attribute")] -pub(crate) struct UnusedDuplicate { - #[suggestion("remove this attribute", code = "", applicability = "unspecified")] - pub this: Span, - #[note("attribute also specified here")] - pub other: Span, - #[warning( - "this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!" - )] - pub warning: bool, -} - #[derive(Diagnostic)] #[diag("`#[macro_export]` is not allowed on declarative macro definitions")] #[note("declarative macros follow the same exporting rules as regular items")] diff --git a/compiler/rustc_attr_parsing/src/lib.rs b/compiler/rustc_attr_parsing/src/lib.rs index a348bcdc3fc47..009ea86b762b2 100644 --- a/compiler/rustc_attr_parsing/src/lib.rs +++ b/compiler/rustc_attr_parsing/src/lib.rs @@ -119,7 +119,7 @@ pub use attributes::cfg_select::*; pub use attributes::crate_level::PREDEFINED_TOOLS; pub use attributes::util::{is_builtin_attr, parse_version}; pub use context::ShouldEmit; -pub use diagnostics::{ParsedDescription, UnusedMultiple}; +pub use diagnostics::{DuplicateAttribute, ParsedDescription}; pub use interface::{AttributeParser, EmitAttribute}; pub use rustc_parse::parser::Recovery; pub use template::AttributeTemplate; diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs index 903f08e2b7ebd..c4c90d2cb5378 100644 --- a/compiler/rustc_builtin_macros/src/util.rs +++ b/compiler/rustc_builtin_macros/src/util.rs @@ -1,6 +1,6 @@ use rustc_ast::tokenstream::TokenStream; use rustc_ast::{self as ast, AttrStyle, Attribute, MetaItem, attr, token}; -use rustc_attr_parsing::{AttributeTemplate, UnusedMultiple, validate_attr}; +use rustc_attr_parsing::{AttributeTemplate, DuplicateAttribute, validate_attr}; use rustc_errors::{Applicability, Diag, ErrorGuaranteed}; use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt}; use rustc_expand::expand::AstFragment; @@ -51,7 +51,7 @@ pub(crate) fn warn_on_duplicate_attribute( DUPLICATE_MACRO_ATTRIBUTES, attr.span, ecx.current_expansion.lint_node_id, - UnusedMultiple { this: attr.span, other: span, name }, + DuplicateAttribute { this: attr.span, other: span, name, warning: false }, ); } } diff --git a/tests/rustdoc-ui/lints/duplicated-attr.stderr b/tests/rustdoc-ui/lints/duplicated-attr.stderr index 3682710bb54a1..5e59b68f3158d 100644 --- a/tests/rustdoc-ui/lints/duplicated-attr.stderr +++ b/tests/rustdoc-ui/lints/duplicated-attr.stderr @@ -1,4 +1,4 @@ -error: unused attribute +error: duplicate `no_crate_inject` attributes --> $DIR/duplicated-attr.rs:4:13 | LL | #![doc(test(no_crate_inject))] diff --git a/tests/rustdoc-ui/lints/invalid-crate-level-lint.rs b/tests/rustdoc-ui/lints/invalid-crate-level-lint.rs index e38a63cd12550..38ae3553dce05 100644 --- a/tests/rustdoc-ui/lints/invalid-crate-level-lint.rs +++ b/tests/rustdoc-ui/lints/invalid-crate-level-lint.rs @@ -6,7 +6,7 @@ pub mod bar { #![doc(test(no_crate_inject))] - //~^ ERROR unused attribute + //~^ ERROR duplicate `no_crate_inject` attribute //~| WARN this was previously accepted by the compiler but is being phased out #[doc(test(no_crate_inject))] diff --git a/tests/rustdoc-ui/lints/invalid-crate-level-lint.stderr b/tests/rustdoc-ui/lints/invalid-crate-level-lint.stderr index b98b6fda035f4..28b01870c4abc 100644 --- a/tests/rustdoc-ui/lints/invalid-crate-level-lint.stderr +++ b/tests/rustdoc-ui/lints/invalid-crate-level-lint.stderr @@ -11,7 +11,7 @@ note: the lint level is defined here LL | #![deny(invalid_doc_attributes)] | ^^^^^^^^^^^^^^^^^^^^^^ -error: unused attribute +error: duplicate `no_crate_inject` attributes --> $DIR/invalid-crate-level-lint.rs:8:17 | LL | #![doc(test(no_crate_inject))] diff --git a/tests/ui/attributes/args-checked.rs b/tests/ui/attributes/args-checked.rs index b9c6769449577..cc389c7d5d7c3 100644 --- a/tests/ui/attributes/args-checked.rs +++ b/tests/ui/attributes/args-checked.rs @@ -20,7 +20,7 @@ //~^ ERROR malformed #[optimize(size(x, y, z))] //~^ ERROR malformed -//~| ERROR multiple `optimize` attributes +//~| ERROR duplicate `optimize` attributes #[coverage(off = 5)] //~^ ERROR malformed #[coverage(off(x, y, z))] diff --git a/tests/ui/attributes/args-checked.stderr b/tests/ui/attributes/args-checked.stderr index a5e0176ed37a2..417007cd8579a 100644 --- a/tests/ui/attributes/args-checked.stderr +++ b/tests/ui/attributes/args-checked.stderr @@ -138,7 +138,7 @@ LL - #[optimize(size(x, y, z))] LL + #[optimize(speed)] | -error: multiple `optimize` attributes +error: duplicate `optimize` attributes --> $DIR/args-checked.rs:21:1 | LL | #[optimize(size(x, y, z))] diff --git a/tests/ui/attributes/attr-order-deprecated.rs b/tests/ui/attributes/attr-order-deprecated.rs index 606e714819b50..5decb7f55f0d2 100644 --- a/tests/ui/attributes/attr-order-deprecated.rs +++ b/tests/ui/attributes/attr-order-deprecated.rs @@ -1,7 +1,7 @@ #[deprecated = "AAA"] //~^ NOTE also specified here #[deprecated = "BBB"] -//~^ ERROR multiple `deprecated` attributes +//~^ ERROR duplicate `deprecated` attributes fn deprecated() { } fn main() { diff --git a/tests/ui/attributes/attr-order-deprecated.stderr b/tests/ui/attributes/attr-order-deprecated.stderr index 41e26bec761ee..3d8df4f226131 100644 --- a/tests/ui/attributes/attr-order-deprecated.stderr +++ b/tests/ui/attributes/attr-order-deprecated.stderr @@ -1,4 +1,4 @@ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/attr-order-deprecated.rs:3:1 | LL | #[deprecated = "BBB"] diff --git a/tests/ui/attributes/attr-order-must-use.rs b/tests/ui/attributes/attr-order-must-use.rs index 36ffe9d5ed708..245aab0f49ad4 100644 --- a/tests/ui/attributes/attr-order-must-use.rs +++ b/tests/ui/attributes/attr-order-must-use.rs @@ -4,7 +4,7 @@ #[must_use = "AAA"] //~^ NOTE also specified here #[must_use = "BBB"] -//~^ ERROR unused attribute +//~^ ERROR duplicate `must_use` attributes //~| WARN previously accepted //~| NOTE `#[deny(unused_attributes)]` implied by `#[deny(unused)]` fn must_use() -> usize { diff --git a/tests/ui/attributes/attr-order-must-use.stderr b/tests/ui/attributes/attr-order-must-use.stderr index 79c040cebe9c3..abf2772d120b9 100644 --- a/tests/ui/attributes/attr-order-must-use.stderr +++ b/tests/ui/attributes/attr-order-must-use.stderr @@ -1,4 +1,4 @@ -error: unused attribute +error: duplicate `must_use` attributes --> $DIR/attr-order-must-use.rs:6:1 | LL | #[must_use = "BBB"] diff --git a/tests/ui/attributes/duplicated-attributes.rs b/tests/ui/attributes/duplicated-attributes.rs index 31a54fb45a99a..a2285faaf1102 100644 --- a/tests/ui/attributes/duplicated-attributes.rs +++ b/tests/ui/attributes/duplicated-attributes.rs @@ -11,7 +11,7 @@ #[test] #[test] -//~^ WARNING multiple `test` attributes +//~^ WARNING duplicate `test` attributes fn f() {} // The following shouldn't trigger an error. The attribute is not duplicated. @@ -28,24 +28,24 @@ use test::Bencher; #[bench] #[bench] -//~^ WARNING multiple `bench` attributes +//~^ WARNING duplicate `bench` attributes fn f4(_: &mut Bencher) {} #[test] #[test] -//~^ WARNING multiple `test` attributes +//~^ WARNING duplicate `test` attributes #[test] -//~^ WARNING multiple `test` attributes +//~^ WARNING duplicate `test` attributes fn f5() {} #[test_case] #[test_case] -//~^ WARNING multiple `test_case` attributes +//~^ WARNING duplicate `test_case` attributes struct T; #[cfg_eval] #[cfg_eval] -//~^ WARNING multiple `cfg_eval` attributes +//~^ WARNING duplicate `cfg_eval` attributes struct S; #[cfg_eval] diff --git a/tests/ui/attributes/duplicated-attributes.stderr b/tests/ui/attributes/duplicated-attributes.stderr index 1230b90127a90..c676ccbeac245 100644 --- a/tests/ui/attributes/duplicated-attributes.stderr +++ b/tests/ui/attributes/duplicated-attributes.stderr @@ -1,4 +1,4 @@ -warning: multiple `test` attributes +warning: duplicate `test` attributes --> $DIR/duplicated-attributes.rs:13:1 | LL | #[test] @@ -11,7 +11,7 @@ LL | #[test] | ^^^^^^^ = note: `#[warn(duplicate_macro_attributes)]` on by default -warning: multiple `bench` attributes +warning: duplicate `bench` attributes --> $DIR/duplicated-attributes.rs:30:1 | LL | #[bench] @@ -23,7 +23,7 @@ note: attribute also specified here LL | #[bench] | ^^^^^^^^ -warning: multiple `test` attributes +warning: duplicate `test` attributes --> $DIR/duplicated-attributes.rs:35:1 | LL | #[test] @@ -35,7 +35,7 @@ note: attribute also specified here LL | #[test] | ^^^^^^^ -warning: multiple `test` attributes +warning: duplicate `test` attributes --> $DIR/duplicated-attributes.rs:37:1 | LL | #[test] @@ -47,7 +47,7 @@ note: attribute also specified here LL | #[test] | ^^^^^^^ -warning: multiple `test_case` attributes +warning: duplicate `test_case` attributes --> $DIR/duplicated-attributes.rs:42:1 | LL | #[test_case] @@ -59,7 +59,7 @@ note: attribute also specified here LL | #[test_case] | ^^^^^^^^^^^^ -warning: multiple `cfg_eval` attributes +warning: duplicate `cfg_eval` attributes --> $DIR/duplicated-attributes.rs:47:1 | LL | #[cfg_eval] diff --git a/tests/ui/attributes/invalid-macro-use.rs b/tests/ui/attributes/invalid-macro-use.rs index 4d05e933647be..2de50785a0d48 100644 --- a/tests/ui/attributes/invalid-macro-use.rs +++ b/tests/ui/attributes/invalid-macro-use.rs @@ -32,7 +32,7 @@ extern crate std as s4; extern crate std as s5; #[macro_use(a)] -//~^ ERROR unused attribute +//~^ ERROR duplicate `macro_use` attributes #[macro_use] //~^ NOTE attribute also specified here extern crate std as s6; @@ -40,13 +40,13 @@ extern crate std as s6; #[macro_use] //~^ NOTE attribute also specified here #[macro_use(a)] -//~^ ERROR unused attribute +//~^ ERROR duplicate `macro_use` attributes extern crate std as s7; #[macro_use] //~^ NOTE attribute also specified here #[macro_use] -//~^ ERROR unused attribute +//~^ ERROR duplicate `macro_use` attributes extern crate std as s8; // This is fine, both are importing different names diff --git a/tests/ui/attributes/invalid-macro-use.stderr b/tests/ui/attributes/invalid-macro-use.stderr index 9b611c41bf9dc..730b0d939fddf 100644 --- a/tests/ui/attributes/invalid-macro-use.stderr +++ b/tests/ui/attributes/invalid-macro-use.stderr @@ -100,7 +100,7 @@ LL - #[macro_use(a::b)] LL + #[macro_use(name1, name2, ...)] | -error: unused attribute +error: duplicate `macro_use` attributes --> $DIR/invalid-macro-use.rs:34:1 | LL | #[macro_use(a)] @@ -117,7 +117,7 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: unused attribute +error: duplicate `macro_use` attributes --> $DIR/invalid-macro-use.rs:42:1 | LL | #[macro_use(a)] @@ -129,7 +129,7 @@ note: attribute also specified here LL | #[macro_use] | ^^^^^^^^^^^^ -error: unused attribute +error: duplicate `macro_use` attributes --> $DIR/invalid-macro-use.rs:48:1 | LL | #[macro_use] diff --git a/tests/ui/attributes/malformed-no-std.rs b/tests/ui/attributes/malformed-no-std.rs index 7383bcb2de348..8b75005b315e1 100644 --- a/tests/ui/attributes/malformed-no-std.rs +++ b/tests/ui/attributes/malformed-no-std.rs @@ -4,18 +4,18 @@ //~^ ERROR malformed `no_std` attribute input #![no_std("bar")] //~^ ERROR malformed `no_std` attribute input -//~| WARN unused attribute +//~| WARN duplicate `no_std` attributes #![no_std(foo = "bar")] //~^ ERROR malformed `no_std` attribute input -//~| WARN unused attribute +//~| WARN duplicate `no_std` attributes #![no_core = "foo"] //~^ ERROR malformed `no_core` attribute input #![no_core("bar")] //~^ ERROR malformed `no_core` attribute input -//~| ERROR multiple `no_core` attributes +//~| ERROR duplicate `no_core` attributes #![no_core(foo = "bar")] //~^ ERROR malformed `no_core` attribute input -//~| ERROR multiple `no_core` attributes +//~| ERROR duplicate `no_core` attributes #[deny(unused_attributes)] #[no_std] diff --git a/tests/ui/attributes/malformed-no-std.stderr b/tests/ui/attributes/malformed-no-std.stderr index eec74b589f127..177422c3d1ec9 100644 --- a/tests/ui/attributes/malformed-no-std.stderr +++ b/tests/ui/attributes/malformed-no-std.stderr @@ -68,7 +68,7 @@ LL - #![no_core("bar")] LL + #![no_core] | -error: multiple `no_core` attributes +error: duplicate `no_core` attributes --> $DIR/malformed-no-std.rs:13:1 | LL | #![no_core("bar")] @@ -94,7 +94,7 @@ LL - #![no_core(foo = "bar")] LL + #![no_core] | -error: multiple `no_core` attributes +error: duplicate `no_core` attributes --> $DIR/malformed-no-std.rs:16:1 | LL | #![no_core(foo = "bar")] @@ -118,7 +118,7 @@ note: this attribute does not have an `!`, which means it is applied to this ext LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ -warning: unused attribute +warning: duplicate `no_std` attributes --> $DIR/malformed-no-std.rs:5:1 | LL | #![no_std("bar")] @@ -131,7 +131,7 @@ LL | #![no_std = "foo"] | ^^^^^^^^^^^^^^^^^^ = note: requested on the command line with `-W unused-attributes` -warning: unused attribute +warning: duplicate `no_std` attributes --> $DIR/malformed-no-std.rs:8:1 | LL | #![no_std(foo = "bar")] diff --git a/tests/ui/attributes/optimize.rs b/tests/ui/attributes/optimize.rs index 41c716e0e9854..c11858be02273 100644 --- a/tests/ui/attributes/optimize.rs +++ b/tests/ui/attributes/optimize.rs @@ -55,11 +55,11 @@ impl Foo for () { } #[optimize(speed)] -#[optimize(speed)] //~ ERROR multiple `optimize` attributes +#[optimize(speed)] //~ ERROR duplicate `optimize` attributes fn duplicate_same() {} #[optimize(speed)] -#[optimize(size)] //~ ERROR multiple `optimize` attributes +#[optimize(size)] //~ ERROR duplicate `optimize` attributes fn duplicate_different() {} #[optimize(none)] //~ ERROR `#[optimize(none)]` cannot be used with `#[inline]` attributes diff --git a/tests/ui/attributes/optimize.stderr b/tests/ui/attributes/optimize.stderr index d35b43b86c1bb..05099ed31598d 100644 --- a/tests/ui/attributes/optimize.stderr +++ b/tests/ui/attributes/optimize.stderr @@ -43,7 +43,7 @@ LL | fn invalid(); | = help: the `optimize` attribute can only be applied to functions with a body -error: multiple `optimize` attributes +error: duplicate `optimize` attributes --> $DIR/optimize.rs:58:1 | LL | #[optimize(speed)] @@ -55,7 +55,7 @@ note: attribute also specified here LL | #[optimize(speed)] | ^^^^^^^^^^^^^^^^^^ -error: multiple `optimize` attributes +error: duplicate `optimize` attributes --> $DIR/optimize.rs:62:1 | LL | #[optimize(size)] diff --git a/tests/ui/attributes/used_with_arg.rs b/tests/ui/attributes/used_with_arg.rs index bc7a6f07442ba..366caee82f7e6 100644 --- a/tests/ui/attributes/used_with_arg.rs +++ b/tests/ui/attributes/used_with_arg.rs @@ -13,8 +13,8 @@ static mut USED_COMPILER_LINKER2: [usize; 1] = [0]; #[used(compiler)] #[used(linker)] -#[used(compiler)] //~ ERROR unused attribute -#[used(linker)] //~ ERROR unused attribute +#[used(compiler)] //~ ERROR duplicate `used` attributes +#[used(linker)] //~ ERROR duplicate `used` attributes static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; #[used(compiler)] @@ -22,7 +22,7 @@ static mut USED_COMPILER_LINKER3: [usize; 1] = [0]; static mut USED_WITHOUT_ATTR1: [usize; 1] = [0]; #[used(linker)] -#[used] //~ ERROR unused attribute +#[used] //~ ERROR duplicate `used` attributes static mut USED_WITHOUT_ATTR2: [usize; 1] = [0]; fn main() {} diff --git a/tests/ui/attributes/used_with_arg.stderr b/tests/ui/attributes/used_with_arg.stderr index 9ff91a4e03b3e..0b551d49cf811 100644 --- a/tests/ui/attributes/used_with_arg.stderr +++ b/tests/ui/attributes/used_with_arg.stderr @@ -1,4 +1,4 @@ -error: unused attribute +error: duplicate `used` attributes --> $DIR/used_with_arg.rs:16:1 | LL | #[used(compiler)] @@ -15,7 +15,7 @@ note: the lint level is defined here LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ -error: unused attribute +error: duplicate `used` attributes --> $DIR/used_with_arg.rs:17:1 | LL | #[used(linker)] @@ -27,7 +27,7 @@ note: attribute also specified here LL | #[used(linker)] | ^^^^^^^^^^^^^^^ -error: unused attribute +error: duplicate `used` attributes --> $DIR/used_with_arg.rs:25:1 | LL | #[used] diff --git a/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.rs b/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.rs index 30434569dbe73..e545499f2fc55 100644 --- a/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.rs +++ b/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.rs @@ -3,32 +3,32 @@ #[inline] #[inline] -//~^ WARN unused attribute +//~^ WARN duplicate `inline` attributes //~| WARN this was previously accepted fn f1() {} #[deprecated] #[deprecated] -//~^ ERROR multiple `deprecated` attributes +//~^ ERROR duplicate `deprecated` attributes fn f2() {} #[inline] #[cfg_attr(true, inline)] -//~^ WARN unused attribute +//~^ WARN duplicate `inline` attributes //~| WARN this was previously accepted fn f3() {} #[deprecated] #[cfg_attr(true, deprecated)] -//~^ ERROR multiple `deprecated` attributes +//~^ ERROR duplicate `deprecated` attributes fn f4() {} #[inline] #[deprecated] #[cfg_attr(true, inline, deprecated)] -//~^ WARN unused attribute +//~^ WARN duplicate `inline` attributes //~| WARN this was previously accepted -//~| ERROR multiple `deprecated` attributes +//~| ERROR duplicate `deprecated` attributes fn f5() {} fn main() {} diff --git a/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.stderr b/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.stderr index c30bc26b22ce7..9c73d3490bc7a 100644 --- a/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-duplicate-attrs.stderr @@ -1,4 +1,4 @@ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:11:1 | LL | #[deprecated] @@ -10,7 +10,7 @@ note: attribute also specified here LL | #[deprecated] | ^^^^^^^^^^^^^ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:22:18 | LL | #[cfg_attr(true, deprecated)] @@ -22,7 +22,7 @@ note: attribute also specified here LL | #[deprecated] | ^^^^^^^^^^^^^ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:28:26 | LL | #[cfg_attr(true, inline, deprecated)] @@ -34,7 +34,7 @@ note: attribute also specified here LL | #[deprecated] | ^^^^^^^^^^^^^ -warning: unused attribute +warning: duplicate `inline` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:5:1 | LL | #[inline] @@ -48,7 +48,7 @@ LL | #[inline] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: requested on the command line with `-W unused-attributes` -warning: unused attribute +warning: duplicate `inline` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:16:18 | LL | #[cfg_attr(true, inline)] @@ -61,7 +61,7 @@ LL | #[inline] | ^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -warning: unused attribute +warning: duplicate `inline` attributes --> $DIR/cfg-attr-duplicate-attrs.rs:28:18 | LL | #[cfg_attr(true, inline, deprecated)] diff --git a/tests/ui/coverage-attr/bad-syntax.rs b/tests/ui/coverage-attr/bad-syntax.rs index ea29fd6ae63a3..0d744d1847c49 100644 --- a/tests/ui/coverage-attr/bad-syntax.rs +++ b/tests/ui/coverage-attr/bad-syntax.rs @@ -5,11 +5,11 @@ // uses of the `#[coverage(..)]` attribute. #[coverage(off)] -#[coverage(off)] //~ ERROR multiple `coverage` attributes +#[coverage(off)] //~ ERROR duplicate `coverage` attributes fn multiple_consistent() {} #[coverage(off)] -#[coverage(on)] //~ ERROR multiple `coverage` attributes +#[coverage(on)] //~ ERROR duplicate `coverage` attributes fn multiple_inconsistent() {} #[coverage] //~ ERROR malformed `coverage` attribute input diff --git a/tests/ui/coverage-attr/bad-syntax.stderr b/tests/ui/coverage-attr/bad-syntax.stderr index 8269228444262..c01d70402e0ba 100644 --- a/tests/ui/coverage-attr/bad-syntax.stderr +++ b/tests/ui/coverage-attr/bad-syntax.stderr @@ -1,4 +1,4 @@ -error: multiple `coverage` attributes +error: duplicate `coverage` attributes --> $DIR/bad-syntax.rs:8:1 | LL | #[coverage(off)] @@ -10,7 +10,7 @@ note: attribute also specified here LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -error: multiple `coverage` attributes +error: duplicate `coverage` attributes --> $DIR/bad-syntax.rs:12:1 | LL | #[coverage(on)] diff --git a/tests/ui/deprecation/deprecation-sanity.rs b/tests/ui/deprecation/deprecation-sanity.rs index 0ad491186cc38..884754e2b5ea8 100644 --- a/tests/ui/deprecation/deprecation-sanity.rs +++ b/tests/ui/deprecation/deprecation-sanity.rs @@ -29,7 +29,7 @@ mod bogus_attribute_types_1 { } #[deprecated(since = "a", note = "b")] -#[deprecated(since = "a", note = "b")] //~ ERROR multiple `deprecated` attributes +#[deprecated(since = "a", note = "b")] //~ ERROR duplicate `deprecated` attributes fn multiple1() { } #[deprecated(since = "a", since = "b", note = "c")] //~ ERROR malformed `deprecated` attribute input [E0538] diff --git a/tests/ui/deprecation/deprecation-sanity.stderr b/tests/ui/deprecation/deprecation-sanity.stderr index 7bc5e57ba75ac..b4cbf283eab8f 100644 --- a/tests/ui/deprecation/deprecation-sanity.stderr +++ b/tests/ui/deprecation/deprecation-sanity.stderr @@ -75,7 +75,7 @@ help: try specifying a deprecated since version LL | #[deprecated(since = "1.2.3")] | +++++++ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/deprecation-sanity.rs:32:1 | LL | #[deprecated(since = "a", note = "b")] diff --git a/tests/ui/diagnostic_namespace/opaque/duplicate.rs b/tests/ui/diagnostic_namespace/opaque/duplicate.rs index 2341e72ddc5e3..4ef03429520fc 100644 --- a/tests/ui/diagnostic_namespace/opaque/duplicate.rs +++ b/tests/ui/diagnostic_namespace/opaque/duplicate.rs @@ -3,7 +3,7 @@ #![deny(unused_attributes)] #[diagnostic::opaque] #[diagnostic::opaque] -//~^ERROR unused attribute +//~^ERROR duplicate `diagnostic::opaque` attributes macro_rules! m { - () => {} + () => {}; } diff --git a/tests/ui/diagnostic_namespace/opaque/duplicate.stderr b/tests/ui/diagnostic_namespace/opaque/duplicate.stderr index d4420d3b63a9f..c7f0ccb10eecd 100644 --- a/tests/ui/diagnostic_namespace/opaque/duplicate.stderr +++ b/tests/ui/diagnostic_namespace/opaque/duplicate.stderr @@ -1,4 +1,4 @@ -error: unused attribute +error: duplicate `diagnostic::opaque` attributes --> $DIR/duplicate.rs:5:1 | LL | #[diagnostic::opaque] diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.rs b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.rs index d9251f6950df6..d1f23f698dd92 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.rs +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.rs @@ -2,10 +2,10 @@ #[link(name = "foo", kind = "raw-dylib")] extern "C" { #[link_ordinal(1)] - #[link_ordinal(2)] //~ ERROR multiple `link_ordinal` attributes + #[link_ordinal(2)] //~ ERROR duplicate `link_ordinal` attributes fn foo(); #[link_ordinal(1)] - #[link_ordinal(2)] //~ ERROR multiple `link_ordinal` attributes + #[link_ordinal(2)] //~ ERROR duplicate `link_ordinal` attributes static mut imported_variable: i32; } diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.stderr b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.stderr index 26d735154fccc..d309d82095e46 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-multiple.stderr @@ -1,4 +1,4 @@ -error: multiple `link_ordinal` attributes +error: duplicate `link_ordinal` attributes --> $DIR/link-ordinal-multiple.rs:5:5 | LL | #[link_ordinal(2)] @@ -10,7 +10,7 @@ note: attribute also specified here LL | #[link_ordinal(1)] | ^^^^^^^^^^^^^^^^^^ -error: multiple `link_ordinal` attributes +error: duplicate `link_ordinal` attributes --> $DIR/link-ordinal-multiple.rs:8:5 | LL | #[link_ordinal(2)] diff --git a/tests/ui/lint/unused/unused-attr-duplicate.rs b/tests/ui/lint/unused/unused-attr-duplicate.rs index 033edc241afd1..dce565340c31f 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.rs +++ b/tests/ui/lint/unused/unused-attr-duplicate.rs @@ -12,79 +12,85 @@ #![deny(unused_attributes)] #![crate_name = "unused_attr_duplicate"] #![crate_name = "unused_attr_duplicate2"] -//~^ ERROR unused attribute +//~^ ERROR duplicate `crate_name` attributes //~| WARN this was previously accepted -//~| ERROR unused attribute +//~| ERROR duplicate `crate_name` attributes //~| WARN this was previously accepted // FIXME(jdonszelmann) this error is given twice now. I'll look at this in the future #![recursion_limit = "128"] -#![recursion_limit = "256"] //~ ERROR unused attribute -//~^ WARN this was previously accepted +#![recursion_limit = "256"] +//~^ ERROR duplicate `recursion_limit` attributes +//~| WARN this was previously accepted #![type_length_limit = "1048576"] -#![type_length_limit = "1"] //~ ERROR unused attribute -//~^ WARN this was previously accepted +#![type_length_limit = "1"] +//~^ ERROR duplicate `type_length_limit` attributes +//~| WARN this was previously accepted #![no_std] -#![no_std] //~ ERROR unused attribute +#![no_std] //~ ERROR duplicate `no_std` attributes #![no_implicit_prelude] -#![no_implicit_prelude] //~ ERROR unused attribute +#![no_implicit_prelude] //~ ERROR duplicate `no_implicit_prelude` attributes #![windows_subsystem = "console"] -#![windows_subsystem = "windows"] //~ ERROR unused attribute -//~^ WARN this was previously accepted +#![windows_subsystem = "windows"] +//~^ ERROR duplicate `windows_subsystem` attributes +//~| WARN this was previously accepted #![no_builtins] -#![no_builtins] //~ ERROR unused attribute +#![no_builtins] //~ ERROR duplicate `no_builtins` attributes #[no_link] //~^ ERROR use of deprecated `no_link` attribute //~| WARN this was previously accepted by the compiler -#[no_link] //~ ERROR unused attribute +#[no_link] //~ ERROR duplicate `no_link` attributes extern crate lint_unused_extern_crate; #[macro_use] -#[macro_use] //~ ERROR unused attribute +#[macro_use] //~ ERROR duplicate `macro_use` attributes pub mod m { #[macro_export] - #[macro_export] //~ ERROR unused attribute + #[macro_export] //~ ERROR duplicate `macro_export` attributes macro_rules! foo { () => {}; } } #[path = "auxiliary/lint_unused_extern_crate.rs"] -#[path = "bar.rs"] //~ ERROR unused attribute +#[path = "bar.rs"] //~ ERROR duplicate `path` attributes //~^ WARN this was previously accepted pub mod from_path; #[test] #[ignore] -#[ignore = "some text"] //~ ERROR unused attribute +#[ignore = "some text"] +//~^ ERROR duplicate `ignore` attributes #[should_panic] -#[should_panic(expected = "values don't match")] //~ ERROR unused attribute -//~^ WARN this was previously accepted +#[should_panic(expected = "values don't match")] +//~^ ERROR duplicate `should_panic` attributes +//~| WARN this was previously accepted fn t1() {} #[must_use] #[must_use = "some message"] -//~^ ERROR unused attribute +//~^ ERROR duplicate `must_use` attributes //~| WARN this was previously accepted #[repr(C)] //~ WARN `#[repr(..)]` attribute is specified more than once [repeated_reprs] #[repr(C)] #[non_exhaustive] -#[non_exhaustive] //~ ERROR unused attribute +#[non_exhaustive] //~ ERROR duplicate `non_exhaustive` attributes pub struct X; trait Trait {} #[automatically_derived] -#[automatically_derived] //~ ERROR unused attribute +#[automatically_derived] +//~^ ERROR duplicate `automatically_derived` attributes impl Trait for X {} #[inline(always)] -#[inline(never)] //~ ERROR unused attribute +#[inline(never)] //~ ERROR duplicate `inline` attributes //~^ WARN this was previously accepted #[cold] -#[cold] //~ ERROR unused attribute +#[cold] //~ ERROR duplicate `cold` attributes #[track_caller] -#[track_caller] //~ ERROR unused attribute +#[track_caller] //~ ERROR duplicate `track_caller` attributes pub fn xyz() {} // No warnings for #[link], would require more logic. @@ -92,27 +98,29 @@ pub fn xyz() {} #[link(name = "rust_test_helpers", kind = "static")] extern "C" { #[link_name = "this_does_not_exist"] - #[link_name = "rust_dbg_extern_identity_u32"] //~ ERROR unused attribute - //~^ WARN this was previously accepted + #[link_name = "rust_dbg_extern_identity_u32"] + //~^ ERROR duplicate `link_name` attributes + //~| WARN this was previously accepted pub fn name_in_rust(v: u32) -> u32; } #[export_name = "exported_symbol_name"] -#[export_name = "exported_symbol_name2"] //~ ERROR unused attribute -//~^ WARN this was previously accepted +#[export_name = "exported_symbol_name2"] +//~^ ERROR duplicate `export_name` attributes +//~| WARN this was previously accepted pub fn export_test() {} #[no_mangle] -#[no_mangle] //~ ERROR unused attribute +#[no_mangle] //~ ERROR duplicate `no_mangle` attributes pub fn no_mangle_test() {} #[used] -#[used] //~ ERROR unused attribute +#[used] //~ ERROR duplicate `used` attributes static FOO: u32 = 0; #[link_section = "__TEXT,__text"] #[link_section = "__DATA,__mod_init_func"] -//~^ ERROR unused attribute +//~^ ERROR duplicate `link_section` attributes //~| WARN this was previously accepted pub extern "C" fn example() {} diff --git a/tests/ui/lint/unused/unused-attr-duplicate.stderr b/tests/ui/lint/unused/unused-attr-duplicate.stderr index 97a1dca61be44..d31786517333b 100644 --- a/tests/ui/lint/unused/unused-attr-duplicate.stderr +++ b/tests/ui/lint/unused/unused-attr-duplicate.stderr @@ -1,4 +1,4 @@ -error: unused attribute +error: duplicate `crate_name` attributes --> $DIR/unused-attr-duplicate.rs:14:1 | LL | #![crate_name = "unused_attr_duplicate2"] @@ -17,7 +17,7 @@ LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ warning: `#[repr(..)]` attribute is specified more than once - --> $DIR/unused-attr-duplicate.rs:69:8 + --> $DIR/unused-attr-duplicate.rs:74:8 | LL | #[repr(C)] | ^ @@ -27,7 +27,7 @@ LL | #[repr(C)] = note: for consistency, only specify the representation once = note: requested on the command line with `-W repeated-reprs` -error: unused attribute +error: duplicate `crate_name` attributes --> $DIR/unused-attr-duplicate.rs:14:1 | LL | #![crate_name = "unused_attr_duplicate2"] @@ -41,7 +41,7 @@ LL | #![crate_name = "unused_attr_duplicate"] = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: unused attribute +error: duplicate `recursion_limit` attributes --> $DIR/unused-attr-duplicate.rs:21:1 | LL | #![recursion_limit = "256"] @@ -54,82 +54,82 @@ LL | #![recursion_limit = "128"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:24:1 +error: duplicate `type_length_limit` attributes + --> $DIR/unused-attr-duplicate.rs:25:1 | LL | #![type_length_limit = "1"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:23:1 + --> $DIR/unused-attr-duplicate.rs:24:1 | LL | #![type_length_limit = "1048576"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:27:1 +error: duplicate `no_std` attributes + --> $DIR/unused-attr-duplicate.rs:29:1 | LL | #![no_std] | ^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:26:1 + --> $DIR/unused-attr-duplicate.rs:28:1 | LL | #![no_std] | ^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:29:1 +error: duplicate `no_implicit_prelude` attributes + --> $DIR/unused-attr-duplicate.rs:31:1 | LL | #![no_implicit_prelude] | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:28:1 + --> $DIR/unused-attr-duplicate.rs:30:1 | LL | #![no_implicit_prelude] | ^^^^^^^^^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:31:1 +error: duplicate `windows_subsystem` attributes + --> $DIR/unused-attr-duplicate.rs:33:1 | LL | #![windows_subsystem = "windows"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:30:1 + --> $DIR/unused-attr-duplicate.rs:32:1 | LL | #![windows_subsystem = "console"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:34:1 +error: duplicate `no_builtins` attributes + --> $DIR/unused-attr-duplicate.rs:37:1 | LL | #![no_builtins] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:33:1 + --> $DIR/unused-attr-duplicate.rs:36:1 | LL | #![no_builtins] | ^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:39:1 +error: duplicate `no_link` attributes + --> $DIR/unused-attr-duplicate.rs:42:1 | LL | #[no_link] | ^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:36:1 + --> $DIR/unused-attr-duplicate.rs:39:1 | LL | #[no_link] | ^^^^^^^^^^ error: use of deprecated `no_link` attribute - --> $DIR/unused-attr-duplicate.rs:36:1 + --> $DIR/unused-attr-duplicate.rs:39:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -138,200 +138,200 @@ LL | #[no_link] = note: for more information, see issue #164032 = note: `#[deny(no_link_attributes)]` (part of `#[deny(future_incompatible)]`) on by default -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:43:1 +error: duplicate `macro_use` attributes + --> $DIR/unused-attr-duplicate.rs:46:1 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:42:1 + --> $DIR/unused-attr-duplicate.rs:45:1 | LL | #[macro_use] | ^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:46:5 +error: duplicate `macro_export` attributes + --> $DIR/unused-attr-duplicate.rs:49:5 | LL | #[macro_export] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:45:5 + --> $DIR/unused-attr-duplicate.rs:48:5 | LL | #[macro_export] | ^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:53:1 +error: duplicate `path` attributes + --> $DIR/unused-attr-duplicate.rs:56:1 | LL | #[path = "bar.rs"] | ^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:52:1 + --> $DIR/unused-attr-duplicate.rs:55:1 | LL | #[path = "auxiliary/lint_unused_extern_crate.rs"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:59:1 +error: duplicate `ignore` attributes + --> $DIR/unused-attr-duplicate.rs:62:1 | LL | #[ignore = "some text"] | ^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:58:1 + --> $DIR/unused-attr-duplicate.rs:61:1 | LL | #[ignore] | ^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:61:1 +error: duplicate `should_panic` attributes + --> $DIR/unused-attr-duplicate.rs:65:1 | LL | #[should_panic(expected = "values don't match")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:60:1 + --> $DIR/unused-attr-duplicate.rs:64:1 | LL | #[should_panic] | ^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:66:1 +error: duplicate `must_use` attributes + --> $DIR/unused-attr-duplicate.rs:71:1 | LL | #[must_use = "some message"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:65:1 + --> $DIR/unused-attr-duplicate.rs:70:1 | LL | #[must_use] | ^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:72:1 +error: duplicate `non_exhaustive` attributes + --> $DIR/unused-attr-duplicate.rs:77:1 | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:71:1 + --> $DIR/unused-attr-duplicate.rs:76:1 | LL | #[non_exhaustive] | ^^^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:78:1 +error: duplicate `automatically_derived` attributes + --> $DIR/unused-attr-duplicate.rs:83:1 | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:77:1 + --> $DIR/unused-attr-duplicate.rs:82:1 | LL | #[automatically_derived] | ^^^^^^^^^^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:82:1 +error: duplicate `inline` attributes + --> $DIR/unused-attr-duplicate.rs:88:1 | LL | #[inline(never)] | ^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:81:1 + --> $DIR/unused-attr-duplicate.rs:87:1 | LL | #[inline(always)] | ^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:85:1 +error: duplicate `cold` attributes + --> $DIR/unused-attr-duplicate.rs:91:1 | LL | #[cold] | ^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:84:1 + --> $DIR/unused-attr-duplicate.rs:90:1 | LL | #[cold] | ^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:87:1 +error: duplicate `track_caller` attributes + --> $DIR/unused-attr-duplicate.rs:93:1 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:86:1 + --> $DIR/unused-attr-duplicate.rs:92:1 | LL | #[track_caller] | ^^^^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:101:1 +error: duplicate `export_name` attributes + --> $DIR/unused-attr-duplicate.rs:108:1 | LL | #[export_name = "exported_symbol_name2"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:100:1 + --> $DIR/unused-attr-duplicate.rs:107:1 | LL | #[export_name = "exported_symbol_name"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:106:1 +error: duplicate `no_mangle` attributes + --> $DIR/unused-attr-duplicate.rs:114:1 | LL | #[no_mangle] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:105:1 + --> $DIR/unused-attr-duplicate.rs:113:1 | LL | #[no_mangle] | ^^^^^^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:110:1 +error: duplicate `used` attributes + --> $DIR/unused-attr-duplicate.rs:118:1 | LL | #[used] | ^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:109:1 + --> $DIR/unused-attr-duplicate.rs:117:1 | LL | #[used] | ^^^^^^^ -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:114:1 +error: duplicate `link_section` attributes + --> $DIR/unused-attr-duplicate.rs:122:1 | LL | #[link_section = "__DATA,__mod_init_func"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:113:1 + --> $DIR/unused-attr-duplicate.rs:121:1 | LL | #[link_section = "__TEXT,__text"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! -error: unused attribute - --> $DIR/unused-attr-duplicate.rs:95:5 +error: duplicate `link_name` attributes + --> $DIR/unused-attr-duplicate.rs:101:5 | LL | #[link_name = "rust_dbg_extern_identity_u32"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/unused-attr-duplicate.rs:94:5 + --> $DIR/unused-attr-duplicate.rs:100:5 | LL | #[link_name = "this_does_not_exist"] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -341,7 +341,7 @@ error: aborting due to 26 previous errors; 1 warning emitted Future incompatibility report: Future breakage diagnostic: error: use of deprecated `no_link` attribute - --> $DIR/unused-attr-duplicate.rs:36:1 + --> $DIR/unused-attr-duplicate.rs:39:1 | LL | #[no_link] | ^^^^^^^^^^ diff --git a/tests/ui/sanitize-attr/invalid-sanitize.rs b/tests/ui/sanitize-attr/invalid-sanitize.rs index 5574661fcf5dc..55f712e20dbb8 100644 --- a/tests/ui/sanitize-attr/invalid-sanitize.rs +++ b/tests/ui/sanitize-attr/invalid-sanitize.rs @@ -5,11 +5,11 @@ fn main() {} #[sanitize(address = "off")] -#[sanitize(address = "off")] //~ ERROR multiple `sanitize` attributes +#[sanitize(address = "off")] //~ ERROR duplicate `sanitize` attributes fn multiple_consistent() {} #[sanitize(address = "on")] -#[sanitize(address = "off")] //~ ERROR multiple `sanitize` attributes +#[sanitize(address = "off")] //~ ERROR duplicate `sanitize` attributes fn multiple_inconsistent() {} #[sanitize(address = "bogus")] //~ ERROR malformed `sanitize` attribute input diff --git a/tests/ui/sanitize-attr/invalid-sanitize.stderr b/tests/ui/sanitize-attr/invalid-sanitize.stderr index f5d8778975216..baa4eeb391400 100644 --- a/tests/ui/sanitize-attr/invalid-sanitize.stderr +++ b/tests/ui/sanitize-attr/invalid-sanitize.stderr @@ -6,7 +6,7 @@ LL | #[sanitize(brontosaurus = "off")] | | | valid arguments are "address", "kernel_address", "cfi", "kcfi", "memory", "memtag", "safestack", "shadow_call_stack", "thread", "hwaddress", "kernel_hwaddress" or "realtime" -error: multiple `sanitize` attributes +error: duplicate `sanitize` attributes --> $DIR/invalid-sanitize.rs:8:1 | LL | #[sanitize(address = "off")] @@ -18,7 +18,7 @@ note: attribute also specified here LL | #[sanitize(address = "off")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: multiple `sanitize` attributes +error: duplicate `sanitize` attributes --> $DIR/invalid-sanitize.rs:12:1 | LL | #[sanitize(address = "off")] diff --git a/tests/ui/splat/splat-invalid.rs b/tests/ui/splat/splat-invalid.rs index e30ac4a9af276..9458cf13b0b89 100644 --- a/tests/ui/splat/splat-invalid.rs +++ b/tests/ui/splat/splat-invalid.rs @@ -9,7 +9,7 @@ fn multisplat_fn_bad(#[rustc_splat] (_a, _b): (u32, i8), #[rustc_splat] (_c, _d) fn multisplat_arg_bad( #[rustc_splat] #[rustc_splat] - //~^ ERROR multiple `rustc_splat` attributes + //~^ ERROR duplicate `rustc_splat` attributes (_a, _b): (u32, i8), ) { } @@ -18,7 +18,7 @@ fn multisplat_arg_fn_bad( #[rustc_splat] //~^ ERROR multiple `#[rustc_splat]`s are not allowed in the same function argument list #[rustc_splat] - //~^ ERROR multiple `rustc_splat` attributes + //~^ ERROR duplicate `rustc_splat` attributes (_a, _b): (u32, i8), #[rustc_splat] (_c, _d): (u32, i8), ) { @@ -69,14 +69,14 @@ fn main() { let multisplat_arg_bad_: fn( #[rustc_splat] #[rustc_splat] - //~^ ERROR multiple `rustc_splat` attributes + //~^ ERROR duplicate `rustc_splat` attributes (u32, i8), ) = multisplat_arg_bad; let multisplat_arg_fn_bad_: fn( #[rustc_splat] //~^ ERROR multiple `#[rustc_splat]`s are not allowed in the same function argument list #[rustc_splat] - //~^ ERROR multiple `rustc_splat` attributes + //~^ ERROR duplicate `rustc_splat` attributes (u32, i8), #[rustc_splat] (u32, i8), ) = multisplat_arg_fn_bad; diff --git a/tests/ui/splat/splat-invalid.stderr b/tests/ui/splat/splat-invalid.stderr index 5ef430046ab10..b21d962ece6e3 100644 --- a/tests/ui/splat/splat-invalid.stderr +++ b/tests/ui/splat/splat-invalid.stderr @@ -131,7 +131,7 @@ LL | let splat_variadic2_: unsafe extern "C" fn(..., #[rustc_splat] (u32, i8 | = help: remove `#[rustc_splat]` or remove `...` -error: multiple `rustc_splat` attributes +error: duplicate `rustc_splat` attributes --> $DIR/splat-invalid.rs:11:5 | LL | #[rustc_splat] @@ -143,7 +143,7 @@ note: attribute also specified here LL | #[rustc_splat] | ^^^^^^^^^^^^^^ -error: multiple `rustc_splat` attributes +error: duplicate `rustc_splat` attributes --> $DIR/splat-invalid.rs:20:5 | LL | #[rustc_splat] @@ -155,7 +155,7 @@ note: attribute also specified here LL | #[rustc_splat] | ^^^^^^^^^^^^^^ -error: multiple `rustc_splat` attributes +error: duplicate `rustc_splat` attributes --> $DIR/splat-invalid.rs:71:9 | LL | #[rustc_splat] @@ -167,7 +167,7 @@ note: attribute also specified here LL | #[rustc_splat] | ^^^^^^^^^^^^^^ -error: multiple `rustc_splat` attributes +error: duplicate `rustc_splat` attributes --> $DIR/splat-invalid.rs:78:9 | LL | #[rustc_splat] diff --git a/tests/ui/stability-attribute/stability-attribute-sanity.rs b/tests/ui/stability-attribute/stability-attribute-sanity.rs index cee8d5fae1d2e..0764d43fd65ac 100644 --- a/tests/ui/stability-attribute/stability-attribute-sanity.rs +++ b/tests/ui/stability-attribute/stability-attribute-sanity.rs @@ -59,7 +59,7 @@ fn multiple3() { } #[stable(feature = "e", since = "b")] //~ ERROR 'since' must be a Rust version number, such as "1.31.0" #[deprecated(since = "5.5.5", note = "text")] -#[deprecated(since = "5.5.5", note = "text")] //~ ERROR multiple `deprecated` attributes +#[deprecated(since = "5.5.5", note = "text")] //~ ERROR duplicate `deprecated` attributes #[rustc_const_unstable(feature = "c", issue = "none")] #[rustc_const_unstable(feature = "d", issue = "none")] //~ ERROR multiple stability levels pub const fn multiple4() { } diff --git a/tests/ui/stability-attribute/stability-attribute-sanity.stderr b/tests/ui/stability-attribute/stability-attribute-sanity.stderr index ba17980c177e2..2b760d4b8e681 100644 --- a/tests/ui/stability-attribute/stability-attribute-sanity.stderr +++ b/tests/ui/stability-attribute/stability-attribute-sanity.stderr @@ -128,7 +128,7 @@ error: 'since' must be a Rust version number, such as "1.31.0" LL | #[stable(feature = "e", since = "b")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: multiple `deprecated` attributes +error: duplicate `deprecated` attributes --> $DIR/stability-attribute-sanity.rs:62:1 | LL | #[deprecated(since = "5.5.5", note = "text")] From 5795cdb13b595076d010973a08822be2b5b29869 Mon Sep 17 00:00:00 2001 From: Petrichor Park Date: Fri, 13 Nov 2026 11:59:23 -0600 Subject: [PATCH 16/17] Fix SingleAttributeParser printing duplicate paths with .. instead of :: separator --- compiler/rustc_attr_parsing/src/attributes/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 456ae1ee31afb..32e12d5f41695 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -238,7 +238,7 @@ impl OnDuplicate { OnDuplicate::Ignore => {} _ => { let name = Symbol::intern( - &P::PATH.iter().map(|i| i.to_string()).collect::>().join(".."), + &P::PATH.iter().map(|i| i.to_string()).collect::>().join("::"), ); match self { OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused, name), From 3dc32c0b64dc18d1730c920294c18e0cf03ad6fa Mon Sep 17 00:00:00 2001 From: Petrichor Park Date: Mon, 16 Nov 2026 09:28:22 -0600 Subject: [PATCH 17/17] Collapse warn_unused_duplicate and warn_unused_duplicate_future_error --- .../src/attributes/codegen_attrs.rs | 8 +++--- .../src/attributes/diagnostic/opaque.rs | 2 +- .../src/attributes/inline.rs | 6 +---- .../src/attributes/macro_attrs.rs | 6 ++--- .../rustc_attr_parsing/src/attributes/mod.rs | 25 +++++-------------- compiler/rustc_attr_parsing/src/context.rs | 16 ++---------- 6 files changed, 17 insertions(+), 46 deletions(-) diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index e26f8681a5516..a09431fcbced9 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -221,7 +221,7 @@ impl AttributeParser for NakedParser { if let Some(earlier) = this.span { let span = cx.attr_span; - cx.warn_unused_duplicate(earlier, span, sym::naked); + cx.warn_unused_duplicate(earlier, span, sym::naked, false); } else { this.span = Some(cx.attr_span); } @@ -505,14 +505,14 @@ impl AttributeParser for UsedParser { UsedBy::Compiler => &mut group.first_compiler, UsedBy::Linker => { if let Some(prev) = group.first_default { - cx.warn_unused_duplicate(prev, attr_span, sym::used); + cx.warn_unused_duplicate(prev, attr_span, sym::used, false); return; } &mut group.first_linker } UsedBy::Default => { if let Some(prev) = group.first_linker { - cx.warn_unused_duplicate(prev, attr_span, sym::used); + cx.warn_unused_duplicate(prev, attr_span, sym::used, false); return; } &mut group.first_default @@ -520,7 +520,7 @@ impl AttributeParser for UsedParser { }; if let Some(prev) = *target { - cx.warn_unused_duplicate(prev, attr_span, sym::used); + cx.warn_unused_duplicate(prev, attr_span, sym::used, false); } else { *target = Some(attr_span); } diff --git a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs index 302c1ef21d7e8..1d06afc44b5a6 100644 --- a/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs +++ b/compiler/rustc_attr_parsing/src/attributes/diagnostic/opaque.rs @@ -53,7 +53,7 @@ impl OpaqueParser { let attr_span = cx.attr_span; if let Some(earlier_span) = self.attr_span { let attr_path_interned = Symbol::intern(&cx.attr_path.to_string()); - cx.warn_unused_duplicate(earlier_span, attr_span, attr_path_interned); + cx.warn_unused_duplicate(earlier_span, attr_span, attr_path_interned, false); } self.attr_span = Some(attr_span); diff --git a/compiler/rustc_attr_parsing/src/attributes/inline.rs b/compiler/rustc_attr_parsing/src/attributes/inline.rs index b41f418fb986c..dc9e26a601f65 100644 --- a/compiler/rustc_attr_parsing/src/attributes/inline.rs +++ b/compiler/rustc_attr_parsing/src/attributes/inline.rs @@ -70,11 +70,7 @@ impl AttributeParser for InlineParser { cx.emit_err(InlineForceInlineConflict { inline_span, force_inline_span }); } Some((_, first_inline_span)) => { - cx.warn_unused_duplicate_future_error( - first_inline_span, - inline_span, - sym::inline, - ); + cx.warn_unused_duplicate(first_inline_span, inline_span, sym::inline, true); } } }, diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index 1ecda268ee3e8..a949015dde5c2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -58,14 +58,14 @@ impl AttributeParser for MacroUseParser { "State is UseAll is some so this is not the first attribute", ); // Since there is a `#[macro_use]` import already, give a warning - cx.warn_unused_duplicate(first_span, span, sym::macro_use); + cx.warn_unused_duplicate(first_span, span, sym::macro_use, false); } MacroUseArgs::UseSpecific(_) => { group.state = MacroUseArgs::UseAll; group.first_span = Some(span); // If there is a `#[macro_use]` attribute, warn on all `#[macro_use(...)]` attributes since everything is already imported for specific_use in group.uses_attr_spans.drain(..) { - cx.warn_unused_duplicate(span, specific_use, sym::macro_use); + cx.warn_unused_duplicate(span, specific_use, sym::macro_use, false); } } } @@ -81,7 +81,7 @@ impl AttributeParser for MacroUseParser { let first_span = group.first_span.expect( "State is UseAll is some so this is not the first attribute", ); - cx.warn_unused_duplicate(first_span, span, sym::macro_use); + cx.warn_unused_duplicate(first_span, span, sym::macro_use, false); } MacroUseArgs::UseSpecific(arguments) => { // Store here so if we encounter a `UseAll` later we can still lint this attribute diff --git a/compiler/rustc_attr_parsing/src/attributes/mod.rs b/compiler/rustc_attr_parsing/src/attributes/mod.rs index 32e12d5f41695..25eb0b9887c53 100644 --- a/compiler/rustc_attr_parsing/src/attributes/mod.rs +++ b/compiler/rustc_attr_parsing/src/attributes/mod.rs @@ -234,27 +234,14 @@ impl OnDuplicate { used: Span, unused: Span, ) { + let name = + Symbol::intern(&P::PATH.iter().map(|i| i.to_string()).collect::>().join("::")); match self { OnDuplicate::Ignore => {} - _ => { - let name = Symbol::intern( - &P::PATH.iter().map(|i| i.to_string()).collect::>().join("::"), - ); - match self { - OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused, name), - OnDuplicate::WarnButFutureError => { - cx.warn_unused_duplicate_future_error(used, unused, name) - } - OnDuplicate::Error => { - cx.emit_err(DuplicateAttribute { - this: unused, - other: used, - name, - warning: false, - }); - } - OnDuplicate::Ignore => unreachable!(), - } + OnDuplicate::Warn => cx.warn_unused_duplicate(used, unused, name, false), + OnDuplicate::WarnButFutureError => cx.warn_unused_duplicate(used, unused, name, true), + OnDuplicate::Error => { + cx.emit_err(DuplicateAttribute { this: unused, other: used, name, warning: false }); } } } diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 17fc9bb8789a3..59c583d4eb435 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -480,23 +480,11 @@ impl<'f, 'sess: 'f> SharedContext<'f, 'sess> { used_span: Span, unused_span: Span, name: Symbol, + future_error: bool, ) { self.emit_lint( UNUSED_ATTRIBUTES, - DuplicateAttribute { this: unused_span, other: used_span, name, warning: false }, - unused_span, - ) - } - - pub(crate) fn warn_unused_duplicate_future_error( - &mut self, - used_span: Span, - unused_span: Span, - name: Symbol, - ) { - self.emit_lint( - UNUSED_ATTRIBUTES, - DuplicateAttribute { this: unused_span, other: used_span, name, warning: true }, + DuplicateAttribute { this: unused_span, other: used_span, name, warning: future_error }, unused_span, ) }