Skip to content

Commit 9ad2305

Browse files
wip
1 parent 20f922e commit 9ad2305

File tree

12 files changed

+118
-28
lines changed

12 files changed

+118
-28
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use rustc_hir::{MethodKind, Target};
66
use rustc_span::{Span, Symbol, sym};
77

88
use super::{CombineAttributeParser, ConvertFn};
9-
use crate::context::{AcceptContext, AllowedTargets, Stage};
109
use crate::context::MaybeWarn::Allow;
10+
use crate::context::{AcceptContext, AllowedTargets, Stage};
1111
use crate::parser::ArgParser;
1212
use crate::session_diagnostics;
1313

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ use super::{
88
AcceptMapping, AttributeOrder, AttributeParser, CombineAttributeParser, ConvertFn,
99
NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
1010
};
11-
use crate::context::MaybeWarn::Allow;
12-
use crate::context::{
13-
AcceptContext, AllowedTargets, FinalizeContext, Stage,
14-
};
11+
use crate::context::MaybeWarn::{Allow, Warn};
12+
use crate::context::{AcceptContext, AllowedTargets, FinalizeContext, Stage};
1513
use crate::parser::ArgParser;
1614
use crate::session_diagnostics::{NakedFunctionIncompatibleAttribute, NullOnExport};
1715

@@ -66,6 +64,14 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
6664
Allow(Target::Method(MethodKind::Inherent)),
6765
Allow(Target::ForeignFn),
6866
Allow(Target::Closure),
67+
Warn(Target::Crate),
68+
Warn(Target::Mod),
69+
Warn(Target::Struct),
70+
Warn(Target::Enum),
71+
Warn(Target::Union),
72+
Warn(Target::TyAlias),
73+
Warn(Target::Impl { of_trait: false }),
74+
Warn(Target::Impl { of_trait: true }),
6975
]);
7076
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
7177
}
@@ -288,6 +294,15 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
288294
Allow(Target::Static),
289295
Allow(Target::Method(MethodKind::Inherent)),
290296
Allow(Target::Method(MethodKind::Trait { body: true })),
297+
Allow(Target::Method(MethodKind::Trait { body: false })),
298+
Warn(Target::Struct),
299+
Warn(Target::Enum),
300+
Warn(Target::Union),
301+
Warn(Target::TyAlias),
302+
Warn(Target::Impl { of_trait: false }),
303+
Warn(Target::Impl { of_trait: true }),
304+
Warn(Target::Trait),
305+
Warn(Target::Mod),
291306
]);
292307
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
293308
}

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5757
Allow(Target::AssocTy),
5858
Allow(Target::Variant),
5959
Warn(Target::Expression),
60+
Warn(Target::Impl { of_trait: false }),
61+
Warn(Target::Impl { of_trait: true }),
6062
]);
6163
const TEMPLATE: AttributeTemplate = template!(
6264
Word,

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::{Span, Symbol, sym};
77
use crate::attributes::{
88
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
99
};
10-
use crate::context::MaybeWarn::Allow;
10+
use crate::context::MaybeWarn::{Allow, Warn};
1111
use crate::context::{AcceptContext, AllowedTargets, Stage, parse_single_integer};
1212
use crate::parser::ArgParser;
1313
use crate::session_diagnostics::{LinkOrdinalOutOfRange, NullOnLinkSection};
@@ -17,8 +17,20 @@ impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
1717
const PATH: &[Symbol] = &[sym::link_name];
1818
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1919
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
20-
const ALLOWED_TARGETS: AllowedTargets =
21-
AllowedTargets::AllowList(&[Allow(Target::ForeignFn), Allow(Target::ForeignStatic)]);
20+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
21+
Allow(Target::ForeignFn),
22+
Allow(Target::ForeignStatic),
23+
Warn(Target::ForeignMod),
24+
Warn(Target::Crate),
25+
Warn(Target::Fn),
26+
Warn(Target::Mod),
27+
Warn(Target::Struct),
28+
Warn(Target::Enum),
29+
Warn(Target::Union),
30+
Warn(Target::TyAlias),
31+
Warn(Target::Impl { of_trait: false }),
32+
Warn(Target::Impl { of_trait: true }),
33+
]);
2234
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
2335

2436
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
@@ -42,7 +54,15 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
4254
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4355
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
4456
const ALLOWED_TARGETS: AllowedTargets =
45-
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::Fn)]);
57+
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::Fn), Warn(Target::Crate), Warn(Target::ForeignMod),
58+
Warn(Target::Crate),
59+
Warn(Target::Mod),
60+
Warn(Target::Struct),
61+
Warn(Target::Enum),
62+
Warn(Target::Union),
63+
Warn(Target::TyAlias),
64+
Warn(Target::Impl { of_trait: false }),
65+
Warn(Target::Impl { of_trait: true }),]);
4666
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
4767

4868
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_hir::{MethodKind, Target};
33
use rustc_span::{Span, Symbol, sym};
44

55
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6-
use crate::context::MaybeWarn::Allow;
6+
use crate::context::MaybeWarn::{Allow, Warn};
77
use crate::context::{AllowedTargets, Stage};
88
pub(crate) struct AsPtrParser;
99
impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
@@ -42,7 +42,17 @@ pub(crate) struct AutomaticallyDerivedParser;
4242
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4343
const PATH: &[Symbol] = &[sym::automatically_derived];
4444
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
45-
const ALLOWED_TARGETS: AllowedTargets =
46-
AllowedTargets::AllowList(&[Allow(Target::Impl { of_trait: true })]);
45+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
46+
Allow(Target::Impl { of_trait: true }),
47+
Warn(Target::Fn),
48+
Warn(Target::Struct),
49+
Warn(Target::Enum),
50+
Warn(Target::Struct),
51+
Warn(Target::Union),
52+
Warn(Target::TyAlias),
53+
Warn(Target::Impl { of_trait: false }),
54+
Warn(Target::Trait),
55+
Warn(Target::Mod),
56+
]);
4757
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
4858
}

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ pub(crate) struct MacroEscapeParser;
1414
impl<S: Stage> NoArgsAttributeParser<S> for MacroEscapeParser {
1515
const PATH: &[Symbol] = &[sym::macro_escape];
1616
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
17-
const ALLOWED_TARGETS: AllowedTargets =
18-
AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
17+
const ALLOWED_TARGETS: AllowedTargets = MACRO_USE_ALLOWED_TARGETS;
1918
const CREATE: fn(Span) -> AttributeKind = AttributeKind::MacroEscape;
2019
}
2120

@@ -35,6 +34,19 @@ pub(crate) struct MacroUseParser {
3534
}
3635

3736
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ...");
37+
const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
38+
Allow(Target::Mod),
39+
Allow(Target::ExternCrate),
40+
Allow(Target::Crate),
41+
Warn(Target::Fn),
42+
Warn(Target::Struct),
43+
Warn(Target::Enum),
44+
Warn(Target::Struct),
45+
Warn(Target::Union),
46+
Warn(Target::TyAlias),
47+
Warn(Target::Impl { of_trait: false }),
48+
Warn(Target::Impl { of_trait: true }),
49+
]);
3850

3951
impl<S: Stage> AttributeParser<S> for MacroUseParser {
4052
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
@@ -111,8 +123,7 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
111123
}
112124
},
113125
)];
114-
const ALLOWED_TARGETS: AllowedTargets =
115-
AllowedTargets::AllowList(&[Allow(Target::Mod), Allow(Target::ExternCrate)]);
126+
const ALLOWED_TARGETS: AllowedTargets = MACRO_USE_ALLOWED_TARGETS;
116127

117128
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
118129
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::{MethodKind, Target};
55
use rustc_span::{Symbol, sym};
66

77
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
8-
use crate::context::MaybeWarn::Allow;
8+
use crate::context::MaybeWarn::{Allow, Warn};
99
use crate::context::{AcceptContext, AllowedTargets, Stage};
1010
use crate::parser::ArgParser;
1111
use crate::session_diagnostics;
@@ -24,6 +24,11 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
2424
Allow(Target::Method(MethodKind::Inherent)),
2525
Allow(Target::ForeignFn),
2626
Allow(Target::Trait),
27+
Warn(Target::Crate),
28+
Warn(Target::Mod),
29+
Warn(Target::TyAlias),
30+
Warn(Target::Impl { of_trait: false }),
31+
Warn(Target::Impl { of_trait: true }),
2732
]);
2833
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
2934

compiler/rustc_attr_parsing/src/attributes/no_implicit_prelude.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ use rustc_hir::attrs::AttributeKind;
33
use rustc_span::{Span, sym};
44

55
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6-
use crate::context::MaybeWarn::Allow;
6+
use crate::context::MaybeWarn::{Allow, Warn};
77
use crate::context::{AllowedTargets, Stage};
88
pub(crate) struct NoImplicitPreludeParser;
99

1010
impl<S: Stage> NoArgsAttributeParser<S> for NoImplicitPreludeParser {
1111
const PATH: &[rustc_span::Symbol] = &[sym::no_implicit_prelude];
1212
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
13-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
13+
const ALLOWED_TARGETS: AllowedTargets =
14+
AllowedTargets::AllowList(&[Allow(Target::Crate), Warn(Target::Mod), Warn(Target::Struct),
15+
Warn(Target::Enum),
16+
Warn(Target::Union),
17+
Warn(Target::TyAlias), Warn(Target::Fn), Warn(Target::Impl {of_trait: false}), Warn(Target::Impl {of_trait: true})]);
1418
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoImplicitPrelude;
1519
}

compiler/rustc_attr_parsing/src/attributes/path.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_hir::attrs::AttributeKind;
44
use rustc_span::{Symbol, sym};
55

66
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7-
use crate::context::MaybeWarn::Allow;
7+
use crate::context::MaybeWarn::{Allow, Warn};
88
use crate::context::{AcceptContext, AllowedTargets, Stage};
99
use crate::parser::ArgParser;
1010
pub(crate) struct PathParser;
@@ -13,7 +13,16 @@ impl<S: Stage> SingleAttributeParser<S> for PathParser {
1313
const PATH: &[Symbol] = &[sym::path];
1414
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1515
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Mod)]);
16+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
17+
Allow(Target::Mod),
18+
Warn(Target::Fn),
19+
Warn(Target::Struct),
20+
Warn(Target::Enum),
21+
Warn(Target::Union),
22+
Warn(Target::TyAlias),
23+
Warn(Target::Impl { of_trait: false }),
24+
Warn(Target::Impl { of_trait: true }),
25+
]);
1726
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file");
1827

1928
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,24 @@ use thin_vec::ThinVec;
77
use crate::attributes::{
88
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
99
};
10-
use crate::context::MaybeWarn::Allow;
10+
use crate::context::MaybeWarn::{Allow, Warn};
1111
use crate::context::{AcceptContext, AllowedTargets, Stage};
1212
use crate::parser::ArgParser;
1313
pub(crate) struct ProcMacroParser;
1414
impl<S: Stage> NoArgsAttributeParser<S> for ProcMacroParser {
1515
const PATH: &[Symbol] = &[sym::proc_macro];
1616
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
17-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
17+
const ALLOWED_TARGETS: AllowedTargets =
18+
AllowedTargets::AllowList(&[Allow(Target::Fn), Warn(Target::Crate)]);
1819
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ProcMacro;
1920
}
2021

2122
pub(crate) struct ProcMacroAttributeParser;
2223
impl<S: Stage> NoArgsAttributeParser<S> for ProcMacroAttributeParser {
2324
const PATH: &[Symbol] = &[sym::proc_macro_attribute];
2425
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
25-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
26+
const ALLOWED_TARGETS: AllowedTargets =
27+
AllowedTargets::AllowList(&[Allow(Target::Fn), Warn(Target::Crate)]);
2628
const CREATE: fn(Span) -> AttributeKind = AttributeKind::ProcMacroAttribute;
2729
}
2830

@@ -31,7 +33,8 @@ impl<S: Stage> SingleAttributeParser<S> for ProcMacroDeriveParser {
3133
const PATH: &[Symbol] = &[sym::proc_macro_derive];
3234
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
3335
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
34-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
36+
const ALLOWED_TARGETS: AllowedTargets =
37+
AllowedTargets::AllowList(&[Allow(Target::Fn), Warn(Target::Crate)]);
3538
const TEMPLATE: AttributeTemplate =
3639
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)");
3740

0 commit comments

Comments
 (0)