From 2bc2a0db6956f960a5218cea19f07ff8dd4c04cd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 10 Dec 2025 20:18:42 +0100 Subject: [PATCH] For now, ignore target checking for doc attributes in attr_parsing --- .../rustc_attr_parsing/src/attributes/doc.rs | 66 ++++++++++--------- .../ui/attributes/issue-115264-expr-field.rs | 2 - .../attributes/issue-115264-expr-field.stderr | 12 ---- tests/ui/attributes/issue-115264-pat-field.rs | 2 - .../attributes/issue-115264-pat-field.stderr | 12 ---- tests/ui/lint/unused/useless-comment.rs | 6 -- tests/ui/lint/unused/useless-comment.stderr | 62 +++++------------ .../rustdoc/check-doc-alias-attr-location.rs | 8 --- .../check-doc-alias-attr-location.stderr | 45 ++----------- 9 files changed, 53 insertions(+), 162 deletions(-) delete mode 100644 tests/ui/attributes/issue-115264-expr-field.stderr delete mode 100644 tests/ui/attributes/issue-115264-pat-field.stderr diff --git a/compiler/rustc_attr_parsing/src/attributes/doc.rs b/compiler/rustc_attr_parsing/src/attributes/doc.rs index ccb6a873fb12..2fe1b4ad174c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/doc.rs +++ b/compiler/rustc_attr_parsing/src/attributes/doc.rs @@ -7,7 +7,7 @@ use rustc_hir::lints::AttributeLintKind; use rustc_span::{Span, Symbol, edition, sym}; use thin_vec::ThinVec; -use super::prelude::{Allow, AllowedTargets, Error, MethodKind, Target}; +use super::prelude::{ALL_TARGETS, AllowedTargets}; use super::{AcceptMapping, AttributeParser}; use crate::context::{AcceptContext, FinalizeContext, Stage}; use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, PathParser}; @@ -583,37 +583,39 @@ impl AttributeParser for DocParser { this.accept_single_doc_attr(cx, args); }, )]; - const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[ - Allow(Target::ExternCrate), - Allow(Target::Use), - Allow(Target::Static), - Allow(Target::Const), - Allow(Target::Fn), - Allow(Target::Mod), - Allow(Target::ForeignMod), - Allow(Target::TyAlias), - Allow(Target::Enum), - Allow(Target::Variant), - Allow(Target::Struct), - Allow(Target::Field), - Allow(Target::Union), - Allow(Target::Trait), - Allow(Target::TraitAlias), - Allow(Target::Impl { of_trait: true }), - Allow(Target::Impl { of_trait: false }), - Allow(Target::AssocConst), - Allow(Target::Method(MethodKind::Inherent)), - Allow(Target::Method(MethodKind::Trait { body: true })), - Allow(Target::Method(MethodKind::Trait { body: false })), - Allow(Target::Method(MethodKind::TraitImpl)), - Allow(Target::AssocTy), - Allow(Target::ForeignFn), - Allow(Target::ForeignStatic), - Allow(Target::ForeignTy), - Allow(Target::MacroDef), - Allow(Target::Crate), - Error(Target::WherePredicate), - ]); + // FIXME: Currently emitted from 2 different places, generating duplicated warnings. + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS); + // const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[ + // Allow(Target::ExternCrate), + // Allow(Target::Use), + // Allow(Target::Static), + // Allow(Target::Const), + // Allow(Target::Fn), + // Allow(Target::Mod), + // Allow(Target::ForeignMod), + // Allow(Target::TyAlias), + // Allow(Target::Enum), + // Allow(Target::Variant), + // Allow(Target::Struct), + // Allow(Target::Field), + // Allow(Target::Union), + // Allow(Target::Trait), + // Allow(Target::TraitAlias), + // Allow(Target::Impl { of_trait: true }), + // Allow(Target::Impl { of_trait: false }), + // Allow(Target::AssocConst), + // Allow(Target::Method(MethodKind::Inherent)), + // Allow(Target::Method(MethodKind::Trait { body: true })), + // Allow(Target::Method(MethodKind::Trait { body: false })), + // Allow(Target::Method(MethodKind::TraitImpl)), + // Allow(Target::AssocTy), + // Allow(Target::ForeignFn), + // Allow(Target::ForeignStatic), + // Allow(Target::ForeignTy), + // Allow(Target::MacroDef), + // Allow(Target::Crate), + // Error(Target::WherePredicate), + // ]); fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option { if self.nb_doc_attrs != 0 { diff --git a/tests/ui/attributes/issue-115264-expr-field.rs b/tests/ui/attributes/issue-115264-expr-field.rs index d8189626fb0f..8adb68deb5b4 100644 --- a/tests/ui/attributes/issue-115264-expr-field.rs +++ b/tests/ui/attributes/issue-115264-expr-field.rs @@ -12,8 +12,6 @@ struct X { fn main() { let _ = X { #[doc(alias = "StructItem")] - //~^ WARN: attribute cannot be used on struct fields - //~| WARN: this was previously accepted by the compiler but is being phased out foo: 123, }; } diff --git a/tests/ui/attributes/issue-115264-expr-field.stderr b/tests/ui/attributes/issue-115264-expr-field.stderr deleted file mode 100644 index 6bb9dfc90c93..000000000000 --- a/tests/ui/attributes/issue-115264-expr-field.stderr +++ /dev/null @@ -1,12 +0,0 @@ -warning: `#[doc]` attribute cannot be used on struct fields - --> $DIR/issue-115264-expr-field.rs:14:9 - | -LL | #[doc(alias = "StructItem")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - = note: requested on the command line with `-W unused-attributes` - -warning: 1 warning emitted - diff --git a/tests/ui/attributes/issue-115264-pat-field.rs b/tests/ui/attributes/issue-115264-pat-field.rs index 0c8966b5893f..53e3b4524d60 100644 --- a/tests/ui/attributes/issue-115264-pat-field.rs +++ b/tests/ui/attributes/issue-115264-pat-field.rs @@ -12,8 +12,6 @@ struct X { fn main() { let X { #[doc(alias = "StructItem")] - //~^ WARN: attribute cannot be used on pattern fields - //~| WARN: this was previously accepted by the compiler but is being phased out foo } = X { foo: 123 diff --git a/tests/ui/attributes/issue-115264-pat-field.stderr b/tests/ui/attributes/issue-115264-pat-field.stderr deleted file mode 100644 index a5b221110789..000000000000 --- a/tests/ui/attributes/issue-115264-pat-field.stderr +++ /dev/null @@ -1,12 +0,0 @@ -warning: `#[doc]` attribute cannot be used on pattern fields - --> $DIR/issue-115264-pat-field.rs:14:9 - | -LL | #[doc(alias = "StructItem")] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - = note: requested on the command line with `-W unused-attributes` - -warning: 1 warning emitted - diff --git a/tests/ui/lint/unused/useless-comment.rs b/tests/ui/lint/unused/useless-comment.rs index fee6cff640f6..24ff91752081 100644 --- a/tests/ui/lint/unused/useless-comment.rs +++ b/tests/ui/lint/unused/useless-comment.rs @@ -18,8 +18,6 @@ fn foo() { /// a //~ ERROR unused doc comment #[doc(test(attr(allow(dead_code))))] //~^ ERROR unused doc comment - //~| ERROR `#[doc]` attribute cannot be used on statements - //~| WARN this was previously accepted by the compiler let x = 12; /// multi-line //~ ERROR unused doc comment @@ -30,8 +28,6 @@ fn foo() { 1 => {}, #[doc(test(attr(allow(dead_code))))] //~^ ERROR unused doc comment - //~| ERROR `#[doc]` attribute cannot be used on match arms [unused_attributes] - //~| WARN this was previously accepted by the compiler _ => {} } @@ -47,8 +43,6 @@ fn foo() { #[doc(test(attr(allow(dead_code))))] //~^ ERROR unused doc comment - //~| ERROR `#[doc]` attribute cannot be used on statements - //~| WARN this was previously accepted by the compiler let x = /** comment */ 47; //~ ERROR unused doc comment /// dox //~ ERROR unused doc comment diff --git a/tests/ui/lint/unused/useless-comment.stderr b/tests/ui/lint/unused/useless-comment.stderr index 3d3937e7a402..22e63caf607a 100644 --- a/tests/ui/lint/unused/useless-comment.stderr +++ b/tests/ui/lint/unused/useless-comment.stderr @@ -33,7 +33,7 @@ LL | unsafe extern "C" { } = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:45:5 + --> $DIR/useless-comment.rs:41:5 | LL | /// bar | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ rustdoc does not generate documentation for macro invocations @@ -56,14 +56,14 @@ error: unused doc comment | LL | #[doc(test(attr(allow(dead_code))))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... +LL | LL | let x = 12; | ----------- rustdoc does not generate documentation for statements | = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:25:5 + --> $DIR/useless-comment.rs:23:5 | LL | / /// multi-line LL | | /// doc comment @@ -73,7 +73,7 @@ LL | / match x { LL | | /// c LL | | 1 => {}, LL | | #[doc(test(attr(allow(dead_code))))] -... | +LL | | LL | | _ => {} LL | | } | |_____- rustdoc does not generate documentation for expressions @@ -81,7 +81,7 @@ LL | | } = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:29:9 + --> $DIR/useless-comment.rs:27:9 | LL | /// c | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -91,18 +91,18 @@ LL | 1 => {}, = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:31:9 + --> $DIR/useless-comment.rs:29:9 | LL | #[doc(test(attr(allow(dead_code))))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... +LL | LL | _ => {} | ------- rustdoc does not generate documentation for match arms | = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:38:5 + --> $DIR/useless-comment.rs:34:5 | LL | /// foo | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -112,7 +112,7 @@ LL | unsafe {} = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:41:5 + --> $DIR/useless-comment.rs:37:5 | LL | #[doc = "foo"] | ^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | 3; = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:42:5 + --> $DIR/useless-comment.rs:38:5 | LL | #[doc = "bar"] | ^^^^^^^^^^^^^^ @@ -133,18 +133,18 @@ LL | 3; = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:48:5 + --> $DIR/useless-comment.rs:44:5 | LL | #[doc(test(attr(allow(dead_code))))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... +LL | LL | let x = /** comment */ 47; | -------------------------- rustdoc does not generate documentation for statements | = help: use `//` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:52:13 + --> $DIR/useless-comment.rs:46:13 | LL | let x = /** comment */ 47; | ^^^^^^^^^^^^^^ -- rustdoc does not generate documentation for expressions @@ -152,7 +152,7 @@ LL | let x = /** comment */ 47; = help: use `/* */` for a plain comment error: unused doc comment - --> $DIR/useless-comment.rs:54:5 + --> $DIR/useless-comment.rs:48:5 | LL | /// dox | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -163,37 +163,5 @@ LL | | } | = help: use `//` for a plain comment -error: `#[doc]` attribute cannot be used on statements - --> $DIR/useless-comment.rs:19:5 - | -LL | #[doc(test(attr(allow(dead_code))))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements -note: the lint level is defined here - --> $DIR/useless-comment.rs:4:9 - | -LL | #![deny(unused_attributes)] - | ^^^^^^^^^^^^^^^^^ - -error: `#[doc]` attribute cannot be used on match arms - --> $DIR/useless-comment.rs:31:9 - | -LL | #[doc(test(attr(allow(dead_code))))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - -error: `#[doc]` attribute cannot be used on statements - --> $DIR/useless-comment.rs:48:5 - | -LL | #[doc(test(attr(allow(dead_code))))] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - -error: aborting due to 18 previous errors +error: aborting due to 15 previous errors diff --git a/tests/ui/rustdoc/check-doc-alias-attr-location.rs b/tests/ui/rustdoc/check-doc-alias-attr-location.rs index 8ba6cfde2d6d..45777c5edf4d 100644 --- a/tests/ui/rustdoc/check-doc-alias-attr-location.rs +++ b/tests/ui/rustdoc/check-doc-alias-attr-location.rs @@ -21,22 +21,14 @@ impl Foo for Bar { type X = i32; fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X { //~^ ERROR - //~| WARN `#[doc]` attribute cannot be used on function params - //~| WARN: this was previously accepted by the compiler #[doc(alias = "stmt")] //~^ ERROR - //~| WARN `#[doc]` attribute cannot be used on statements - //~| WARN: this was previously accepted by the compiler let x = 0; #[doc(alias = "expr")] //~^ ERROR - //~| WARN `#[doc]` attribute cannot be used on expressions - //~| WARN: this was previously accepted by the compiler match x { #[doc(alias = "arm")] //~^ ERROR - //~| WARN `#[doc]` attribute cannot be used on match arms - //~| WARN: this was previously accepted by the compiler _ => 0 } } diff --git a/tests/ui/rustdoc/check-doc-alias-attr-location.stderr b/tests/ui/rustdoc/check-doc-alias-attr-location.stderr index 24be42036f6f..f587c17c1f3e 100644 --- a/tests/ui/rustdoc/check-doc-alias-attr-location.stderr +++ b/tests/ui/rustdoc/check-doc-alias-attr-location.stderr @@ -29,59 +29,22 @@ LL | #[doc(alias = "assoc")] | ^^^^^^^ error: `#[doc(alias = "...")]` isn't allowed on statement - --> $DIR/check-doc-alias-attr-location.rs:26:23 + --> $DIR/check-doc-alias-attr-location.rs:24:23 | LL | #[doc(alias = "stmt")] | ^^^^^^ error: `#[doc(alias = "...")]` isn't allowed on expression - --> $DIR/check-doc-alias-attr-location.rs:31:23 + --> $DIR/check-doc-alias-attr-location.rs:27:23 | LL | #[doc(alias = "expr")] | ^^^^^^ error: `#[doc(alias = "...")]` isn't allowed on match arm - --> $DIR/check-doc-alias-attr-location.rs:36:27 + --> $DIR/check-doc-alias-attr-location.rs:30:27 | LL | #[doc(alias = "arm")] | ^^^^^ -warning: `#[doc]` attribute cannot be used on function params - --> $DIR/check-doc-alias-attr-location.rs:22:12 - | -LL | fn foo(#[doc(alias = "qux")] _x: u32) -> Self::X { - | ^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - = note: requested on the command line with `-W unused-attributes` - -warning: `#[doc]` attribute cannot be used on statements - --> $DIR/check-doc-alias-attr-location.rs:26:9 - | -LL | #[doc(alias = "stmt")] - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - -warning: `#[doc]` attribute cannot be used on expressions - --> $DIR/check-doc-alias-attr-location.rs:31:9 - | -LL | #[doc(alias = "expr")] - | ^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - -warning: `#[doc]` attribute cannot be used on match arms - --> $DIR/check-doc-alias-attr-location.rs:36:13 - | -LL | #[doc(alias = "arm")] - | ^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = help: `#[doc]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, extern crates, foreign modules, foreign statics, functions, impl blocks, macro defs, modules, statics, struct fields, trait aliases, traits, type aliases, unions, and use statements - -error: aborting due to 8 previous errors; 4 warnings emitted +error: aborting due to 8 previous errors