Skip to content

Commit 1da1a39

Browse files
Remove UnknownMetaItem error
1 parent 25a6fca commit 1da1a39

File tree

13 files changed

+44
-67
lines changed

13 files changed

+44
-67
lines changed

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,6 @@ attr_parsing_stability_outside_std = stability attributes may not be used outsid
213213
attr_parsing_suffixed_literal_in_attribute = suffixed literals are not allowed in attributes
214214
.help = instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
215215
216-
attr_parsing_unknown_meta_item =
217-
unknown meta item '{$item}'
218-
.label = expected one of {$expected}
219-
220216
attr_parsing_unknown_version_literal =
221217
unknown version literal format, assuming it refers to a future version
222218

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,12 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
110110
Some(get(cx, name, param.span(), param.args(), &suggestion)?);
111111
}
112112
_ => {
113-
cx.unknown_key(
113+
cx.expected_specific_argument(
114114
param.span(),
115-
param.path().to_string(),
116115
if features.deprecated_suggestion() {
117-
&["since", "note", "suggestion"]
116+
&[sym::since, sym::note, sym::suggestion]
118117
} else {
119-
&["since", "note"]
118+
&[sym::since, sym::note]
120119
},
121120
);
122121
return None;

compiler/rustc_attr_parsing/src/attributes/prototype.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ impl<S: Stage> SingleAttributeParser<S> for CustomMirParser {
4646
extract_value(cx, sym::dialect, arg, meta_item.span(), &mut dialect, &mut failed);
4747
} else if let Some(arg) = meta_item.word_is(sym::phase) {
4848
extract_value(cx, sym::phase, arg, meta_item.span(), &mut phase, &mut failed);
49-
} else if let Some(word) = meta_item.path().word() {
50-
let word = word.to_string();
51-
cx.unknown_key(meta_item.span(), word, &["dialect", "phase"]);
49+
} else if let Some(..) = meta_item.path().word() {
50+
cx.expected_specific_argument(meta_item.span(), &[sym::dialect, sym::phase]);
5251
failed = true;
5352
} else {
5453
cx.expected_name_value(meta_item.span(), None);

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,7 @@ pub(crate) fn parse_stability<S: Stage>(
315315
insert_value_into_option_or_error(cx, &param, &mut since, word.unwrap())?
316316
}
317317
_ => {
318-
cx.emit_err(session_diagnostics::UnknownMetaItem {
319-
span: param_span,
320-
item: param.path().to_string(),
321-
expected: &["feature", "since"],
322-
});
318+
cx.expected_specific_argument(param_span, &[sym::feature, sym::since]);
323319
return None;
324320
}
325321
}
@@ -426,11 +422,17 @@ pub(crate) fn parse_unstability<S: Stage>(
426422
insert_value_into_option_or_error(cx, &param, &mut old_name, word.unwrap())?
427423
}
428424
_ => {
429-
cx.emit_err(session_diagnostics::UnknownMetaItem {
430-
span: param.span(),
431-
item: param.path().to_string(),
432-
expected: &["feature", "reason", "issue", "soft", "implied_by", "old_name"],
433-
});
425+
cx.expected_specific_argument(
426+
param.span(),
427+
&[
428+
sym::feature,
429+
sym::reason,
430+
sym::issue,
431+
sym::soft,
432+
sym::implied_by,
433+
sym::old_name,
434+
],
435+
);
434436
return None;
435437
}
436438
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use crate::attributes::transparency::TransparencyParser;
7777
use crate::attributes::{AttributeParser as _, Combine, Single, WithoutArgs};
7878
use crate::parser::{ArgParser, RefPathParser};
7979
use crate::session_diagnostics::{
80-
AttributeParseError, AttributeParseErrorReason, ParsedDescription, UnknownMetaItem,
80+
AttributeParseError, AttributeParseErrorReason, ParsedDescription,
8181
};
8282
use crate::target_checking::AllowedTargets;
8383

@@ -425,15 +425,6 @@ impl<'f, 'sess: 'f, S: Stage> SharedContext<'f, 'sess, S> {
425425
}
426426

427427
impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
428-
pub(crate) fn unknown_key(
429-
&self,
430-
span: Span,
431-
found: String,
432-
options: &[&'static str],
433-
) -> ErrorGuaranteed {
434-
self.emit_err(UnknownMetaItem { span, item: found, expected: options })
435-
}
436-
437428
fn emit_parse_error(
438429
&self,
439430
span: Span,

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,26 +64,6 @@ pub(crate) struct DocAttributeNotAttribute {
6464
pub attribute: Symbol,
6565
}
6666

67-
/// Error code: E0541
68-
pub(crate) struct UnknownMetaItem<'a> {
69-
pub span: Span,
70-
pub item: String,
71-
pub expected: &'a [&'a str],
72-
}
73-
74-
// Manual implementation to be able to format `expected` items correctly.
75-
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnknownMetaItem<'_> {
76-
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
77-
let expected = self.expected.iter().map(|name| format!("`{name}`")).collect::<Vec<_>>();
78-
Diag::new(dcx, level, fluent::attr_parsing_unknown_meta_item)
79-
.with_span(self.span)
80-
.with_code(E0541)
81-
.with_arg("item", self.item)
82-
.with_arg("expected", expected.join(", "))
83-
.with_span_label(self.span, fluent::attr_parsing_label)
84-
}
85-
}
86-
8767
#[derive(Diagnostic)]
8868
#[diag(attr_parsing_missing_since, code = E0542)]
8969
pub(crate) struct MissingSince {

compiler/rustc_error_codes/src/error_codes/E0541.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
An unknown meta item was used.
24

35
Erroneous code example:
46

5-
```compile_fail,E0541
7+
```compile_fail (no longer emitted)
68
#[deprecated(
79
since="1.0.0",
810
// error: unknown meta item

tests/ui/deprecation/deprecation-sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// Various checks that deprecation attributes are used correctly
44

55
mod bogus_attribute_types_1 {
6-
#[deprecated(since = "a", note = "a", reason)] //~ ERROR unknown meta item 'reason'
6+
#[deprecated(since = "a", note = "a", reason)] //~ ERROR malformed `deprecated` attribute input [E0539]
77
fn f1() { }
88

99
#[deprecated(since = "a", note)] //~ ERROR malformed `deprecated` attribute input [E0539]

tests/ui/deprecation/deprecation-sanity.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
error[E0541]: unknown meta item 'reason'
2-
--> $DIR/deprecation-sanity.rs:6:43
1+
error[E0539]: malformed `deprecated` attribute input
2+
--> $DIR/deprecation-sanity.rs:6:5
33
|
44
LL | #[deprecated(since = "a", note = "a", reason)]
5-
| ^^^^^^ expected one of `since`, `note`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^
6+
| |
7+
| valid arguments are `since` or `note`
68

79
error[E0539]: malformed `deprecated` attribute input
810
--> $DIR/deprecation-sanity.rs:9:5
@@ -86,5 +88,5 @@ LL | #[deprecated = "hello"]
8688

8789
error: aborting due to 10 previous errors
8890

89-
Some errors have detailed explanations: E0538, E0539, E0541, E0565.
91+
Some errors have detailed explanations: E0538, E0539, E0565.
9092
For more information about an error, try `rustc --explain E0538`.

tests/ui/stability-attribute/stability-attribute-sanity-2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#[stable(feature = "a", feature = "b", since = "1.0.0")] //~ ERROR malformed `stable` attribute input [E0538]
88
fn f1() { }
99

10-
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR unknown meta item 'sinse'
10+
#[stable(feature = "a", sinse = "1.0.0")] //~ ERROR malformed `stable` attribute input [E0539]
1111
fn f2() { }
1212

1313
#[unstable(feature = "a", issue = "no")]

0 commit comments

Comments
 (0)