Skip to content

Commit f309805

Browse files
wip
1 parent 5a4a758 commit f309805

File tree

7 files changed

+20
-22
lines changed

7 files changed

+20
-22
lines changed

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 6 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, Error};
77
use crate::context::{AllowedTargets, Stage};
88
pub(crate) struct AsPtrParser;
99
impl<S: Stage> NoArgsAttributeParser<S> for AsPtrParser {
@@ -47,7 +47,10 @@ pub(crate) struct AutomaticallyDerivedParser;
4747
impl<S: Stage> NoArgsAttributeParser<S> for AutomaticallyDerivedParser {
4848
const PATH: &[Symbol] = &[sym::automatically_derived];
4949
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
50-
const ALLOWED_TARGETS: AllowedTargets =
51-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Impl { of_trait: true })]);
50+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
51+
Allow(Target::Impl { of_trait: true }),
52+
Error(Target::Crate),
53+
Error(Target::WherePredicate),
54+
]);
5255
const CREATE: fn(Span) -> AttributeKind = AttributeKind::AutomaticallyDerived;
5356
}

compiler/rustc_attr_parsing/src/attributes/path.rs

Lines changed: 2 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, Error};
88
use crate::context::{AcceptContext, AllowedTargets, Stage};
99
use crate::parser::ArgParser;
1010
pub(crate) struct PathParser;
@@ -14,7 +14,7 @@ impl<S: Stage> SingleAttributeParser<S> for PathParser {
1414
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1515
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
1616
const ALLOWED_TARGETS: AllowedTargets =
17-
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod)]);
17+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Mod), Error(Target::Crate)]);
1818
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file");
1919

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

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ 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 = AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn)]);
36+
const ALLOWED_TARGETS: AllowedTargets =
37+
AllowedTargets::AllowList(&[Allow(Target::Fn), Warn(Target::Crate)]);
3738
const TEMPLATE: AttributeTemplate =
3839
template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)");
3940

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::lints::AttributeLintKind;
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, Error};
99
use crate::context::{AcceptContext, AllowedTargets, Stage};
1010
use crate::parser::ArgParser;
1111
pub(crate) struct IgnoreParser;
@@ -14,7 +14,8 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
1414
const PATH: &[Symbol] = &[sym::ignore];
1515
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1616
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
17-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn)]);
17+
const ALLOWED_TARGETS: AllowedTargets =
18+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn), Error(Target::WherePredicate)]);
1819
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
1920

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

tests/ui/lint/unused/unused-attr-macro-rules.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
error: this attribute is not allowed on this target
2-
--> $DIR/unused-attr-macro-rules.rs:8:3
3-
|
4-
LL | #[path="foo"]
5-
| ^^^^^^^^^^
6-
71
error: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
82
--> $DIR/unused-attr-macro-rules.rs:9:1
93
|
@@ -22,5 +16,11 @@ error: this attribute is not allowed on this target
2216
LL | #[macro_use]
2317
| ^^^^^^^^^
2418

19+
error: this attribute is not allowed on this target
20+
--> $DIR/unused-attr-macro-rules.rs:8:3
21+
|
22+
LL | #[path="foo"]
23+
| ^^^^^^^^^^
24+
2525
error: aborting due to 3 previous errors
2626

tests/ui/resolve/path-attr-in-const-block.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ fn main() {
66
#![path = foo!()]
77
//~^ ERROR: cannot find macro `foo` in this scope
88
//~| ERROR malformed `path` attribute input
9-
//~| ERROR this attribute is not allowed on this target
109
}
1110
}

tests/ui/resolve/path-attr-in-const-block.stderr

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,6 @@ LL | #![path = foo!()]
1313
| | expected a string literal here
1414
| help: must be of the form: `#[path = "file"]`
1515

16-
error: this attribute is not allowed on this target
17-
--> $DIR/path-attr-in-const-block.rs:6:12
18-
|
19-
LL | #![path = foo!()]
20-
| ^^^^^^^^^^^^^
21-
22-
error: aborting due to 3 previous errors
16+
error: aborting due to 2 previous errors
2317

2418
For more information about this error, try `rustc --explain E0539`.

0 commit comments

Comments
 (0)