Skip to content

Commit 80872ec

Browse files
wip
1 parent c535b85 commit 80872ec

File tree

10 files changed

+66
-99
lines changed

10 files changed

+66
-99
lines changed

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::{Span, Symbol, sym};
55

66
use super::util::parse_version;
77
use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
8-
use crate::context::MaybeWarn::{Allow};
8+
use crate::context::MaybeWarn::{Allow, Error};
99
use crate::context::{AcceptContext, AllowedTargets, Stage};
1010
use crate::parser::ArgParser;
1111
use crate::session_diagnostics;
@@ -58,6 +58,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5858
Allow(Target::AssocTy),
5959
Allow(Target::AssocConst),
6060
Allow(Target::Variant),
61+
Error(Target::WherePredicate)
6162
]);
6263
const TEMPLATE: AttributeTemplate = template!(
6364
Word,

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_span::{Span, Symbol, sym};
66
use thin_vec::ThinVec;
77

88
use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
9-
use crate::context::MaybeWarn::Allow;
9+
use crate::context::MaybeWarn::{Allow, Error};
1010
use crate::context::{AcceptContext, AllowedTargets, FinalizeContext, Stage};
1111
use crate::parser::ArgParser;
1212
use crate::session_diagnostics;
@@ -38,6 +38,7 @@ const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnR
3838
Allow(Target::Mod),
3939
Allow(Target::ExternCrate),
4040
Allow(Target::Crate),
41+
Error(Target::WherePredicate),
4142
]);
4243

4344
impl<S: Stage> AttributeParser<S> for MacroUseParser {

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::Trait { body: false })),
327328
Allow(Target::ForeignFn),
328329
// TODO special error for struct,enum,union
329330
]);

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use crate::attributes::traits::{
5959
};
6060
use crate::attributes::transparency::TransparencyParser;
6161
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
62-
use crate::context::MaybeWarn::{Allow, Warn};
62+
use crate::context::MaybeWarn::{Allow, Error, Warn};
6363
use crate::parser::{ArgParser, MetaItemParser, PathParser};
6464
use crate::session_diagnostics::{AttributeParseError, AttributeParseErrorReason, UnknownMetaItem};
6565

@@ -673,6 +673,8 @@ impl AllowedTargets {
673673
AllowedTargets::AllowListWarnRest(list) => {
674674
if list.contains(&Allow(target)) {
675675
AllowedResult::Allowed
676+
} else if list.contains(&Error(target)) {
677+
AllowedResult::Error
676678
} else {
677679
AllowedResult::Warn
678680
}
@@ -685,6 +687,7 @@ impl AllowedTargets {
685687
pub(crate) enum MaybeWarn {
686688
Allow(Target),
687689
Warn(Target),
690+
Error(Target)
688691
}
689692

690693
/// Context created once, for example as part of the ast lowering

compiler/rustc_hir/src/hir.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,13 @@ impl Attribute {
12331233
_ => None,
12341234
}
12351235
}
1236+
1237+
pub fn is_parsed_attr(&self) -> bool {
1238+
match self {
1239+
Attribute::Parsed(_) => true,
1240+
Attribute::Unparsed(_) => false,
1241+
}
1242+
}
12361243
}
12371244

12381245
impl AttributeExt for Attribute {
@@ -1304,12 +1311,6 @@ impl AttributeExt for Attribute {
13041311
Attribute::Unparsed(u) => u.span,
13051312
// FIXME: should not be needed anymore when all attrs are parsed
13061313
Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
1307-
Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
1308-
Attribute::Parsed(AttributeKind::MacroUse { span, .. }) => *span,
1309-
Attribute::Parsed(AttributeKind::MayDangle(span)) => *span,
1310-
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span,
1311-
Attribute::Parsed(AttributeKind::ShouldPanic { span, .. }) => *span,
1312-
Attribute::Parsed(AttributeKind::AutomaticallyDerived(span)) => *span,
13131314
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
13141315
}
13151316
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,7 @@ impl<'tcx> Visitor<'tcx> for CheckAttrVisitor<'tcx> {
21822182
.hir_attrs(where_predicate.hir_id)
21832183
.iter()
21842184
.filter(|attr| !ATTRS_ALLOWED.iter().any(|&sym| attr.has_name(sym)))
2185+
.filter(|attr| !attr.is_parsed_attr())
21852186
.map(|attr| attr.span())
21862187
.collect::<Vec<_>>();
21872188
if !spans.is_empty() {

tests/ui/feature-gates/issue-43106-gating-of-proc_macro_derive.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
2-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:21:5
2+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:16:5
33
|
44
LL | #[proc_macro_derive(Test)] fn f() { }
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: this attribute is not allowed on this target
8-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:10:3
8+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:5:3
99
|
1010
LL | #[proc_macro_derive(Test)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: this attribute is not allowed on this target
14-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:13:20
14+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:8:20
1515
|
1616
LL | mod inner { #![proc_macro_derive(Test)] }
1717
| ^^^^^^^^^^^^^^^^^^^^^^^
1818

1919
error: this attribute is not allowed on this target
20-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:18:20
20+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:13:20
2121
|
2222
LL | mod inner { #![proc_macro_derive(Test)] }
2323
| ^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error: this attribute is not allowed on this target
26-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:24:7
26+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:19:7
2727
|
2828
LL | #[proc_macro_derive(Test)] struct S;
2929
| ^^^^^^^^^^^^^^^^^^^^^^^
3030

3131
error: this attribute is not allowed on this target
32-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:27:7
32+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:22:7
3333
|
3434
LL | #[proc_macro_derive(Test)] type T = S;
3535
| ^^^^^^^^^^^^^^^^^^^^^^^
3636

3737
error: this attribute is not allowed on this target
38-
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:30:7
38+
--> $DIR/issue-43106-gating-of-proc_macro_derive.rs:25:7
3939
|
4040
LL | #[proc_macro_derive(Test)] impl S { }
4141
| ^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/ffi-attrs/ffi_pure.stderr

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,23 @@ help: wrap the attribute in `unsafe(...)`
99
LL | #[unsafe(ffi_pure)]
1010
| +++++++ +
1111

12-
error[E0755]: this attribute is not allowed on this target
13-
--> $DIR/ffi_pure.rs:4:1
12+
error: this attribute is not allowed on this target
13+
--> $DIR/ffi_pure.rs:4:10
1414
|
1515
LL | #[unsafe(ffi_pure)]
16-
| ^^^^^^^^^^^^^^^^^^^
16+
| ^^^^^^^^
1717

18-
error[E0755]: this attribute is not allowed on this target
19-
--> $DIR/ffi_pure.rs:7:1
18+
error: this attribute is not allowed on this target
19+
--> $DIR/ffi_pure.rs:7:10
2020
|
2121
LL | #[unsafe(ffi_pure)]
22-
| ^^^^^^^^^^^^^^^^^^^
22+
| ^^^^^^^^
2323

24-
error[E0755]: this attribute is not allowed on this target
25-
--> $DIR/ffi_pure.rs:13:5
24+
error: this attribute is not allowed on this target
25+
--> $DIR/ffi_pure.rs:13:14
2626
|
2727
LL | #[unsafe(ffi_pure)]
28-
| ^^^^^^^^^^^^^^^^^^^
28+
| ^^^^^^^^
2929

3030
error: aborting due to 4 previous errors
3131

32-
For more information about this error, try `rustc --explain E0755`.

tests/ui/where-clauses/unsupported_attribute.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ fn foo<'a, T>()
1313
where
1414
#[doc = "doc"] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
1515
#[doc = "doc"] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
16-
#[ignore] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
17-
#[ignore] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
16+
#[ignore] T: Trait, //~ ERROR this attribute is not allowed on this target
17+
#[ignore] 'a: 'static, //~ ERROR this attribute is not allowed on this target
1818
#[should_panic] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
1919
#[should_panic] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
20-
#[macro_use] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
21-
#[macro_use] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
20+
#[macro_use] T: Trait, //~ ERROR this attribute is not allowed on this target
21+
#[macro_use] 'a: 'static, //~ ERROR this attribute is not allowed on this target
2222
#[allow(unused)] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
2323
#[allow(unused)] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
24-
#[deprecated] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
25-
#[deprecated] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
26-
#[automatically_derived] T: Trait, //~ ERROR most attributes are not supported in `where` clauses
27-
#[automatically_derived] 'a: 'static, //~ ERROR most attributes are not supported in `where` clauses
24+
#[deprecated] T: Trait, //~ ERROR this attribute is not allowed on this target
25+
#[deprecated] 'a: 'static, //~ ERROR this attribute is not allowed on this target
26+
#[automatically_derived] T: Trait, //~ ERROR this attribute is not allowed on this target
27+
#[automatically_derived] 'a: 'static, //~ ERROR this attribute is not allowed on this target
2828
#[derive(Clone)] T: Trait,
2929
//~^ ERROR most attributes are not supported in `where` clauses
3030
//~| ERROR expected non-macro attribute, found attribute macro `derive`

tests/ui/where-clauses/unsupported_attribute.stderr

Lines changed: 25 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,30 @@ error: this attribute is not allowed on this target
2222
LL | #[ignore] 'a: 'static,
2323
| ^^^^^^
2424

25+
error: this attribute is not allowed on this target
26+
--> $DIR/unsupported_attribute.rs:20:7
27+
|
28+
LL | #[macro_use] T: Trait,
29+
| ^^^^^^^^^
30+
31+
error: this attribute is not allowed on this target
32+
--> $DIR/unsupported_attribute.rs:21:7
33+
|
34+
LL | #[macro_use] 'a: 'static,
35+
| ^^^^^^^^^
36+
37+
error: this attribute is not allowed on this target
38+
--> $DIR/unsupported_attribute.rs:24:7
39+
|
40+
LL | #[deprecated] T: Trait,
41+
| ^^^^^^^^^^
42+
43+
error: this attribute is not allowed on this target
44+
--> $DIR/unsupported_attribute.rs:25:7
45+
|
46+
LL | #[deprecated] 'a: 'static,
47+
| ^^^^^^^^^^
48+
2549
error: this attribute is not allowed on this target
2650
--> $DIR/unsupported_attribute.rs:26:7
2751
|
@@ -50,22 +74,6 @@ LL | #[doc = "doc"] 'a: 'static,
5074
|
5175
= help: only `#[cfg]` and `#[cfg_attr]` are supported
5276

53-
error: most attributes are not supported in `where` clauses
54-
--> $DIR/unsupported_attribute.rs:16:5
55-
|
56-
LL | #[ignore] T: Trait,
57-
| ^^^^^^^^^
58-
|
59-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
60-
61-
error: most attributes are not supported in `where` clauses
62-
--> $DIR/unsupported_attribute.rs:17:5
63-
|
64-
LL | #[ignore] 'a: 'static,
65-
| ^^^^^^^^^
66-
|
67-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
68-
6977
error: most attributes are not supported in `where` clauses
7078
--> $DIR/unsupported_attribute.rs:18:5
7179
|
@@ -82,22 +90,6 @@ LL | #[should_panic] 'a: 'static,
8290
|
8391
= help: only `#[cfg]` and `#[cfg_attr]` are supported
8492

85-
error: most attributes are not supported in `where` clauses
86-
--> $DIR/unsupported_attribute.rs:20:5
87-
|
88-
LL | #[macro_use] T: Trait,
89-
| ^^^^^^^^^^^^
90-
|
91-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
92-
93-
error: most attributes are not supported in `where` clauses
94-
--> $DIR/unsupported_attribute.rs:21:5
95-
|
96-
LL | #[macro_use] 'a: 'static,
97-
| ^^^^^^^^^^^^
98-
|
99-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
100-
10193
error: most attributes are not supported in `where` clauses
10294
--> $DIR/unsupported_attribute.rs:22:5
10395
|
@@ -114,38 +106,6 @@ LL | #[allow(unused)] 'a: 'static,
114106
|
115107
= help: only `#[cfg]` and `#[cfg_attr]` are supported
116108

117-
error: most attributes are not supported in `where` clauses
118-
--> $DIR/unsupported_attribute.rs:24:5
119-
|
120-
LL | #[deprecated] T: Trait,
121-
| ^^^^^^^^^^^^^
122-
|
123-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
124-
125-
error: most attributes are not supported in `where` clauses
126-
--> $DIR/unsupported_attribute.rs:25:5
127-
|
128-
LL | #[deprecated] 'a: 'static,
129-
| ^^^^^^^^^^^^^
130-
|
131-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
132-
133-
error: most attributes are not supported in `where` clauses
134-
--> $DIR/unsupported_attribute.rs:26:5
135-
|
136-
LL | #[automatically_derived] T: Trait,
137-
| ^^^^^^^^^^^^^^^^^^^^^^^^
138-
|
139-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
140-
141-
error: most attributes are not supported in `where` clauses
142-
--> $DIR/unsupported_attribute.rs:27:5
143-
|
144-
LL | #[automatically_derived] 'a: 'static,
145-
| ^^^^^^^^^^^^^^^^^^^^^^^^
146-
|
147-
= help: only `#[cfg]` and `#[cfg_attr]` are supported
148-
149109
error: most attributes are not supported in `where` clauses
150110
--> $DIR/unsupported_attribute.rs:28:5
151111
|
@@ -178,5 +138,5 @@ LL | #[rustfmt::skip] 'a: 'static,
178138
|
179139
= help: only `#[cfg]` and `#[cfg_attr]` are supported
180140

181-
error: aborting due to 24 previous errors
141+
error: aborting due to 20 previous errors
182142

0 commit comments

Comments
 (0)