Skip to content

Commit 097ad4b

Browse files
authored
Rollup merge of #143659 - GrigorenkoPV:attributes/inner-outer, r=jdonszelmann
Use "Innermost" & "Outermost" terminology for `AttributeOrder` Follow-up to #143603. https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/527768926 Also remove some outdated comments. cc `@jdonszelmann`
2 parents f587784 + e391578 commit 097ad4b

File tree

12 files changed

+29
-42
lines changed

12 files changed

+29
-42
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub(crate) struct OptimizeParser;
1515

1616
impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
1717
const PATH: &[Symbol] = &[sym::optimize];
18-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
18+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1919
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
2020
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
2121

@@ -56,7 +56,7 @@ pub(crate) struct ExportNameParser;
5656

5757
impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
5858
const PATH: &[rustc_span::Symbol] = &[sym::export_name];
59-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
59+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
6060
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
6161
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
6262

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn get<S: Stage>(
3636

3737
impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
3838
const PATH: &[Symbol] = &[sym::deprecated];
39-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
39+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4040
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4141
const TEMPLATE: AttributeTemplate = template!(
4242
Word,

compiler/rustc_attr_parsing/src/attributes/dummy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::parser::ArgParser;
99
pub(crate) struct DummyParser;
1010
impl<S: Stage> SingleAttributeParser<S> for DummyParser {
1111
const PATH: &[Symbol] = &[sym::rustc_dummy];
12-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
12+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1313
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
1414
const TEMPLATE: AttributeTemplate = template!(Word); // Anything, really
1515

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) struct InlineParser;
1616

1717
impl<S: Stage> SingleAttributeParser<S> for InlineParser {
1818
const PATH: &'static [Symbol] = &[sym::inline];
19-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
19+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
2020
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
2121
const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never");
2222

@@ -57,7 +57,7 @@ pub(crate) struct RustcForceInlineParser;
5757

5858
impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
5959
const PATH: &'static [Symbol] = &[sym::rustc_force_inline];
60-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
60+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
6161
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
6262
const TEMPLATE: AttributeTemplate = template!(Word, List: "reason", NameValueStr: "reason");
6363

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) struct LinkNameParser;
1414

1515
impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
1616
const PATH: &[Symbol] = &[sym::link_name];
17-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
17+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1818
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
1919
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
2020

@@ -36,7 +36,7 @@ pub(crate) struct LinkSectionParser;
3636

3737
impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
3838
const PATH: &[Symbol] = &[sym::link_section];
39-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
39+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4040
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
4141
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
4242

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -140,15 +140,15 @@ impl<T: SingleAttributeParser<S>, S: Stage> AttributeParser<S> for Single<T, S>
140140
if let Some(pa) = T::convert(cx, args) {
141141
match T::ATTRIBUTE_ORDER {
142142
// keep the first and report immediately. ignore this attribute
143-
AttributeOrder::KeepFirst => {
143+
AttributeOrder::KeepInnermost => {
144144
if let Some((_, unused)) = group.1 {
145145
T::ON_DUPLICATE.exec::<T>(cx, cx.attr_span, unused);
146146
return;
147147
}
148148
}
149149
// keep the new one and warn about the previous,
150150
// then replace
151-
AttributeOrder::KeepLast => {
151+
AttributeOrder::KeepOutermost => {
152152
if let Some((_, used)) = group.1 {
153153
T::ON_DUPLICATE.exec::<T>(cx, used, cx.attr_span);
154154
}
@@ -165,9 +165,6 @@ impl<T: SingleAttributeParser<S>, S: Stage> AttributeParser<S> for Single<T, S>
165165
}
166166
}
167167

168-
// FIXME(jdonszelmann): logic is implemented but the attribute parsers needing
169-
// them will be merged in another PR
170-
#[allow(unused)]
171168
pub(crate) enum OnDuplicate<S: Stage> {
172169
/// Give a default warning
173170
Warn,
@@ -213,39 +210,29 @@ impl<S: Stage> OnDuplicate<S> {
213210
}
214211
}
215212
}
216-
//
217-
// FIXME(jdonszelmann): logic is implemented but the attribute parsers needing
218-
// them will be merged in another PR
219-
#[allow(unused)]
213+
220214
pub(crate) enum AttributeOrder {
221-
/// Duplicates after the first attribute will be an error. I.e. only keep the lowest attribute.
215+
/// Duplicates after the innermost instance of the attribute will be an error/warning.
216+
/// Only keep the lowest attribute.
222217
///
223-
/// Attributes are processed from bottom to top, so this raises an error on all the attributes
218+
/// Attributes are processed from bottom to top, so this raises a warning/error on all the attributes
224219
/// further above the lowest one:
225220
/// ```
226221
/// #[stable(since="1.0")] //~ WARNING duplicated attribute
227222
/// #[stable(since="2.0")]
228223
/// ```
229-
///
230-
/// This should be used where duplicates would be ignored, but carry extra
231-
/// meaning that could cause confusion. For example, `#[stable(since="1.0")]
232-
/// #[stable(since="2.0")]`, which version should be used for `stable`?
233-
KeepFirst,
224+
KeepInnermost,
234225

235-
/// Duplicates preceding the last instance of the attribute will be a
236-
/// warning, with a note that this will be an error in the future.
226+
/// Duplicates before the outermost instance of the attribute will be an error/warning.
227+
/// Only keep the highest attribute.
237228
///
238-
/// Attributes are processed from bottom to top, so this raises a warning on all the attributes
239-
/// below the higher one:
229+
/// Attributes are processed from bottom to top, so this raises a warning/error on all the attributes
230+
/// below the highest one:
240231
/// ```
241232
/// #[path="foo.rs"]
242233
/// #[path="bar.rs"] //~ WARNING duplicated attribute
243234
/// ```
244-
///
245-
/// This is the same as `FutureWarnFollowing`, except the last attribute is
246-
/// the one that is "used". Ideally these can eventually migrate to
247-
/// `ErrorPreceding`.
248-
KeepLast,
235+
KeepOutermost,
249236
}
250237

251238
/// An even simpler version of [`SingleAttributeParser`]:
@@ -271,7 +258,7 @@ impl<T: NoArgsAttributeParser<S>, S: Stage> Default for WithoutArgs<T, S> {
271258

272259
impl<T: NoArgsAttributeParser<S>, S: Stage> SingleAttributeParser<S> for WithoutArgs<T, S> {
273260
const PATH: &[Symbol] = T::PATH;
274-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
261+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
275262
const ON_DUPLICATE: OnDuplicate<S> = T::ON_DUPLICATE;
276263
const TEMPLATE: AttributeTemplate = template!(Word);
277264

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub(crate) struct MustUseParser;
1212

1313
impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
1414
const PATH: &[Symbol] = &[sym::must_use];
15-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
15+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1616
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
1717
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
1818

compiler/rustc_attr_parsing/src/attributes/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub(crate) struct PathParser;
1010

1111
impl<S: Stage> SingleAttributeParser<S> for PathParser {
1212
const PATH: &[Symbol] = &[sym::path];
13-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
13+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1414
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
1515
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file");
1616

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) struct RustcLayoutScalarValidRangeStart;
1111

1212
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart {
1313
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_start];
14-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1515
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1616
const TEMPLATE: AttributeTemplate = template!(List: "start");
1717

@@ -25,7 +25,7 @@ pub(crate) struct RustcLayoutScalarValidRangeEnd;
2525

2626
impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd {
2727
const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_end];
28-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
28+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
2929
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
3030
const TEMPLATE: AttributeTemplate = template!(List: "end");
3131

@@ -62,7 +62,7 @@ pub(crate) struct RustcObjectLifetimeDefaultParser;
6262

6363
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {
6464
const PATH: &[rustc_span::Symbol] = &[sym::rustc_object_lifetime_default];
65-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
65+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
6666
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
6767
const TEMPLATE: AttributeTemplate = template!(Word);
6868

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub(crate) struct IgnoreParser;
1111

1212
impl<S: Stage> SingleAttributeParser<S> for IgnoreParser {
1313
const PATH: &[Symbol] = &[sym::ignore];
14-
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1515
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
1616
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
1717

0 commit comments

Comments
 (0)