Skip to content

Commit 0ad15fd

Browse files
authored
Rollup merge of rust-lang#145238 - estebank:attr-overhaul, r=jdonszelmann
Tweak invalid builtin attribute output - Add link to reference/docs when possible - More accurate suggestions by supporting multiple alternative suggestions ``` error: malformed `crate_type` attribute input --> $DIR/crate-type-macro-call.rs:1:1 | LL | #![crate_type = foo!()] | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> help: the following are the possible correct uses | LL - #![crate_type = foo!()] LL + #![crate_type = "bin"] | LL - #![crate_type = foo!()] LL + #![crate_type = "cdylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "dylib"] | LL - #![crate_type = foo!()] LL + #![crate_type = "lib"] | = and 4 other candidates ```
2 parents 07c6471 + 928dd11 commit 0ad15fd

File tree

84 files changed

+1276
-391
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+1276
-391
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ attr_parsing_unknown_version_literal =
132132
attr_parsing_unrecognized_repr_hint =
133133
unrecognized representation hint
134134
.help = valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
135+
.note = for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations>
135136
136137
attr_parsing_unstable_cfg_target_compact =
137138
compact `cfg(target(..))` is experimental and subject to change

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1515
type Item = (Symbol, Span);
1616
const CONVERT: ConvertFn<Self::Item> =
1717
|items, span| AttributeKind::AllowInternalUnstable(items, span);
18-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
18+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
1919

2020
fn extend<'c>(
2121
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -32,7 +32,7 @@ impl<S: Stage> CombineAttributeParser<S> for UnstableFeatureBoundParser {
3232
const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound];
3333
type Item = (Symbol, Span);
3434
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items);
35-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
35+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
3636

3737
fn extend<'c>(
3838
cx: &'c mut AcceptContext<'_, '_, S>,
@@ -53,7 +53,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
5353
type Item = Symbol;
5454
const CONVERT: ConvertFn<Self::Item> =
5555
|items, first_span| AttributeKind::AllowConstFnUnstable(items, first_span);
56-
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
56+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]);
5757

5858
fn extend<'c>(
5959
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ use crate::{
1616
CfgMatchesLintEmitter, fluent_generated, parse_version, session_diagnostics, try_gate_cfg,
1717
};
1818

19-
pub const CFG_TEMPLATE: AttributeTemplate = template!(List: "predicate");
19+
pub const CFG_TEMPLATE: AttributeTemplate = template!(
20+
List: &["predicate"],
21+
"https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute"
22+
);
2023

2124
pub fn parse_cfg_attr<'c, S: Stage>(
2225
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
1717
const PATH: &[Symbol] = &[sym::optimize];
1818
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1919
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
20-
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
20+
const TEMPLATE: AttributeTemplate = template!(List: &["size", "speed", "none"]);
2121

2222
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2323
let Some(list) = args.list() else {
@@ -253,7 +253,7 @@ pub(crate) struct UsedParser {
253253
impl<S: Stage> AttributeParser<S> for UsedParser {
254254
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
255255
&[sym::used],
256-
template!(Word, List: "compiler|linker"),
256+
template!(Word, List: &["compiler", "linker"]),
257257
|group: &mut Self, cx, args| {
258258
let used_by = match args {
259259
ArgParser::NoArgs => UsedBy::Linker,
@@ -327,7 +327,7 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
327327
type Item = (Symbol, Span);
328328
const PATH: &[Symbol] = &[sym::target_feature];
329329
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature(items, span);
330-
const TEMPLATE: AttributeTemplate = template!(List: "enable = \"feat1, feat2\"");
330+
const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]);
331331

332332
fn extend<'c>(
333333
cx: &'c mut AcceptContext<'_, '_, S>,

compiler/rustc_attr_parsing/src/attributes/confusables.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub(crate) struct ConfusablesParser {
1616
impl<S: Stage> AttributeParser<S> for ConfusablesParser {
1717
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
1818
&[sym::rustc_confusables],
19-
template!(List: r#""name1", "name2", ..."#),
19+
template!(List: &[r#""name1", "name2", ..."#]),
2020
|this, cx, args| {
2121
let Some(list) = args.list() else {
2222
cx.expected_list(cx.attr_span);

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
4040
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
4141
const TEMPLATE: AttributeTemplate = template!(
4242
Word,
43-
List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#,
43+
List: &[r#"since = "version""#, r#"note = "reason""#, r#"since = "version", note = "reason""#],
4444
NameValueStr: "reason"
4545
);
4646

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
1818
const PATH: &'static [Symbol] = &[sym::inline];
1919
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
2020
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
21-
const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never");
21+
const TEMPLATE: AttributeTemplate = template!(
22+
Word,
23+
List: &["always", "never"],
24+
"https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute"
25+
);
2226

2327
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2428
match args {
@@ -59,7 +63,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser {
5963
const PATH: &'static [Symbol] = &[sym::rustc_force_inline];
6064
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
6165
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
62-
const TEMPLATE: AttributeTemplate = template!(Word, List: "reason", NameValueStr: "reason");
66+
const TEMPLATE: AttributeTemplate = template!(Word, List: &["reason"], NameValueStr: "reason");
6367

6468
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
6569
let reason = match args {

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
1616
const PATH: &[Symbol] = &[sym::link_name];
1717
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1818
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
19-
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
19+
const TEMPLATE: AttributeTemplate = template!(
20+
NameValueStr: "name",
21+
"https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute"
22+
);
2023

2124
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
2225
let Some(nv) = args.name_value() else {
@@ -38,7 +41,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
3841
const PATH: &[Symbol] = &[sym::link_section];
3942
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4043
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
41-
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
44+
const TEMPLATE: AttributeTemplate = template!(
45+
NameValueStr: "name",
46+
"https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"
47+
);
4248

4349
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
4450
let Some(nv) = args.name_value() else {
@@ -94,7 +100,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser {
94100
const PATH: &[Symbol] = &[sym::link_ordinal];
95101
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
96102
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
97-
const TEMPLATE: AttributeTemplate = template!(List: "ordinal");
103+
const TEMPLATE: AttributeTemplate = template!(
104+
List: &["ordinal"],
105+
"https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute"
106+
);
98107

99108
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
100109
let ordinal = parse_single_integer(cx, args)?;

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ pub(crate) struct MacroUseParser {
3131
first_span: Option<Span>,
3232
}
3333

34-
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ...");
34+
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(
35+
Word, List: &["name1, name2, ..."],
36+
"https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute"
37+
);
3538

3639
impl<S: Stage> AttributeParser<S> for MacroUseParser {
3740
const ATTRIBUTES: AcceptMapping<Self, S> = &[(

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
1414
const PATH: &[Symbol] = &[sym::must_use];
1515
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1616
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
17-
const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason");
17+
const TEMPLATE: AttributeTemplate = template!(
18+
Word, NameValueStr: "reason",
19+
"https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"
20+
);
1821

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

0 commit comments

Comments
 (0)