Skip to content

Commit 5a4a758

Browse files
wip
1 parent ce66f6f commit 5a4a758

File tree

15 files changed

+83
-157
lines changed

15 files changed

+83
-157
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
6868
Allow(Target::Method(MethodKind::Inherent)),
6969
Allow(Target::Method(MethodKind::Trait { body: false })),
7070
Allow(Target::Method(MethodKind::Trait { body: true })),
71+
Allow(Target::Method(MethodKind::TraitImpl)),
7172
]);
7273
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
7374

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
2323
Allow(Target::Fn),
2424
Allow(Target::Closure),
2525
Allow(Target::Method(MethodKind::Trait { body: true })),
26+
Allow(Target::Method(MethodKind::TraitImpl)),
2627
Allow(Target::Method(MethodKind::Inherent)),
2728
]);
2829
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
@@ -60,6 +61,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
6061
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
6162
Allow(Target::Fn),
6263
Allow(Target::Method(MethodKind::Trait { body: true })),
64+
Allow(Target::Method(MethodKind::TraitImpl)),
6365
Allow(Target::Method(MethodKind::Trait { body: false })),
6466
Allow(Target::Method(MethodKind::Inherent)),
6567
Allow(Target::ForeignFn),
@@ -78,6 +80,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
7880
Allow(Target::Fn),
7981
Allow(Target::Closure),
8082
Allow(Target::Method(MethodKind::Trait { body: true })),
83+
Allow(Target::Method(MethodKind::TraitImpl)),
8184
Allow(Target::Method(MethodKind::Inherent)),
8285
Allow(Target::Impl { of_trait: true }),
8386
Allow(Target::Impl { of_trait: false }),
@@ -127,6 +130,7 @@ impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
127130
Allow(Target::Fn),
128131
Allow(Target::Method(MethodKind::Inherent)),
129132
Allow(Target::Method(MethodKind::Trait { body: true })),
133+
Allow(Target::Method(MethodKind::TraitImpl)),
130134
Warn(Target::Field),
131135
Warn(Target::Arm),
132136
Warn(Target::MacroDef),
@@ -176,6 +180,7 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
176180
Allow(Target::Fn),
177181
Allow(Target::Method(MethodKind::Inherent)),
178182
Allow(Target::Method(MethodKind::Trait { body: true })),
183+
Allow(Target::Method(MethodKind::TraitImpl)),
179184
]);
180185

181186
fn finalize(self, cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
@@ -273,6 +278,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
273278
Allow(Target::Fn),
274279
Allow(Target::Method(MethodKind::Inherent)),
275280
Allow(Target::Method(MethodKind::Trait { body: true })),
281+
Allow(Target::Method(MethodKind::TraitImpl)),
276282
Allow(Target::Method(MethodKind::Trait { body: false })),
277283
Allow(Target::ForeignFn),
278284
Allow(Target::Closure),
@@ -291,8 +297,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
291297
Allow(Target::Fn),
292298
Allow(Target::Static),
293299
Allow(Target::Method(MethodKind::Inherent)),
294-
Allow(Target::Method(MethodKind::Trait { body: true })),
295-
Allow(Target::Method(MethodKind::Trait { body: false })),
300+
Allow(Target::Method(MethodKind::TraitImpl)),
296301
]);
297302
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
298303
}
@@ -436,6 +441,7 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
436441
Allow(Target::Fn),
437442
Allow(Target::Method(MethodKind::Inherent)),
438443
Allow(Target::Method(MethodKind::Trait { body: true })),
444+
Allow(Target::Method(MethodKind::TraitImpl)),
439445
Warn(Target::Statement),
440446
Warn(Target::Field),
441447
Warn(Target::Arm),

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5858
Allow(Target::AssocTy),
5959
Allow(Target::AssocConst),
6060
Allow(Target::Variant),
61+
Allow(Target::Impl { of_trait: false }), //TODO what does that even do?
6162
Error(Target::WherePredicate),
6263
]);
6364
const TEMPLATE: AttributeTemplate = template!(

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
2323
Allow(Target::Fn),
2424
Allow(Target::Method(MethodKind::Inherent)),
2525
Allow(Target::Method(MethodKind::Trait { body: true })),
26+
Allow(Target::Method(MethodKind::TraitImpl)),
2627
Allow(Target::Closure),
2728
Warn(Target::Method(MethodKind::Trait { body: false })),
2829
Warn(Target::ForeignFn),

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 4 additions & 13 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, Warn};
6+
use crate::context::MaybeWarn::Allow;
77
use crate::context::{AllowedTargets, Stage};
88
pub(crate) struct AsPtrParser;
99
impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
@@ -14,6 +14,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
1414
Allow(Target::Method(MethodKind::Inherent)),
1515
Allow(Target::Method(MethodKind::Trait { body: false })),
1616
Allow(Target::Method(MethodKind::Trait { body: true })),
17+
Allow(Target::Method(MethodKind::TraitImpl)),
1718
]);
1819
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AsPtr;
1920
}
@@ -46,17 +47,7 @@ pub(crate) struct AutomaticallyDerivedParser;
4647
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4748
const PATH: &[Symbol] = &[sym::automatically_derived];
4849
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
49-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
50-
Allow(Target::Impl { of_trait: true }),
51-
Warn(Target::Fn),
52-
Warn(Target::Struct),
53-
Warn(Target::Enum),
54-
Warn(Target::Struct),
55-
Warn(Target::Union),
56-
Warn(Target::TyAlias),
57-
Warn(Target::Impl { of_trait: false }),
58-
Warn(Target::Trait),
59-
Warn(Target::Mod),
60-
]);
50+
const ALLOWED_TARGETS: AllowedTargets =
51+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Impl { of_trait: true })]);
6152
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
6253
}

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
2121
Allow(Target::Struct),
2222
Allow(Target::Union),
2323
Allow(Target::Method(MethodKind::Trait { body: false })),
24-
Allow(Target::Method(MethodKind::Trait { body: true })), // Sometimes not allowed, see check_attr
24+
Allow(Target::Method(MethodKind::Trait { body: true })),
25+
Allow(Target::Method(MethodKind::TraitImpl)), // Sometimes not allowed, see check_attr
2526
Allow(Target::Method(MethodKind::Inherent)),
2627
Allow(Target::ForeignFn),
2728
Allow(Target::Trait),

compiler/rustc_attr_parsing/src/attributes/no_implicit_prelude.rs

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

55
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
6-
use crate::context::MaybeWarn::{Allow, Warn};
6+
use crate::context::MaybeWarn::Allow;
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(&[
14-
Allow(Target::Crate),
15-
Warn(Target::Mod),
16-
Warn(Target::Struct),
17-
Warn(Target::Enum),
18-
Warn(Target::Union),
19-
Warn(Target::TyAlias),
20-
Warn(Target::Fn),
21-
Warn(Target::Impl { of_trait: false }),
22-
Warn(Target::Impl { of_trait: true }),
23-
]);
13+
const ALLOWED_TARGETS: AllowedTargets =
14+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod), Allow(Target::Crate)]);
2415
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoImplicitPrelude;
2516
}

compiler/rustc_attr_parsing/src/attributes/path.rs

Lines changed: 3 additions & 11 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, Warn};
7+
use crate::context::MaybeWarn::Allow;
88
use crate::context::{AcceptContext, AllowedTargets, Stage};
99
use crate::parser::ArgParser;
1010
pub(crate) struct PathParser;
@@ -13,16 +13,8 @@ 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(&[
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-
]);
16+
const ALLOWED_TARGETS: AllowedTargets =
17+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod)]);
2618
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file");
2719

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

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ impl<S: Stage> SingleAttributeParser<S> for ProcMacroDeriveParser {
3333
const PATH: &[Symbol] = &[sym::proc_macro_derive];
3434
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
3535
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
36-
const ALLOWED_TARGETS: AllowedTargets =
37-
AllowedTargets::AllowList(&[Allow(Target::Fn), Warn(Target::Crate)]);
36+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn)]);
3837
const TEMPLATE: AttributeTemplate =
3938
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)");
4039

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
324324
Allow(Target::Fn),
325325
Allow(Target::Method(MethodKind::Inherent)),
326326
Allow(Target::Method(MethodKind::Trait { body: true })),
327+
Allow(Target::Method(MethodKind::TraitImpl)),
327328
Allow(Target::Method(MethodKind::Trait { body: false })),
328329
Allow(Target::ForeignFn),
329330
// TODO special error for struct,enum,union

0 commit comments

Comments
 (0)