convert strings to symbols in attr diagnostics
This commit is contained in:
parent
f5703d5dd3
commit
f6ac728aad
10 changed files with 36 additions and 31 deletions
|
|
@ -35,7 +35,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
|
|||
Some(sym::speed) => OptimizeAttr::Speed,
|
||||
Some(sym::none) => OptimizeAttr::DoNotOptimize,
|
||||
_ => {
|
||||
cx.expected_specific_argument(single.span(), vec!["size", "speed", "none"]);
|
||||
cx.expected_specific_argument(single.span(), &[sym::size, sym::speed, sym::none]);
|
||||
OptimizeAttr::Default
|
||||
}
|
||||
};
|
||||
|
|
@ -82,7 +82,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
|
|||
|
||||
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
|
||||
let Some(args) = args.list() else {
|
||||
cx.expected_specific_argument_and_list(cx.attr_span, vec!["on", "off"]);
|
||||
cx.expected_specific_argument_and_list(cx.attr_span, &[sym::on, sym::off]);
|
||||
return None;
|
||||
};
|
||||
|
||||
|
|
@ -91,7 +91,8 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
|
|||
return None;
|
||||
};
|
||||
|
||||
let fail_incorrect_argument = |span| cx.expected_specific_argument(span, vec!["on", "off"]);
|
||||
let fail_incorrect_argument =
|
||||
|span| cx.expected_specific_argument(span, &[sym::on, sym::off]);
|
||||
|
||||
let Some(arg) = arg.meta_item() else {
|
||||
fail_incorrect_argument(args.span);
|
||||
|
|
@ -343,7 +344,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
|
|||
UsedBy::Linker
|
||||
}
|
||||
_ => {
|
||||
cx.expected_specific_argument(l.span(), vec!["compiler", "linker"]);
|
||||
cx.expected_specific_argument(l.span(), &[sym::compiler, sym::linker]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
|
|||
Some(AttributeKind::Inline(InlineAttr::Never, cx.attr_span))
|
||||
}
|
||||
_ => {
|
||||
cx.expected_specific_argument(l.span(), vec!["always", "never"]);
|
||||
cx.expected_specific_argument(l.span(), &[sym::always, sym::never]);
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -206,16 +206,16 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
|
|||
_ => {
|
||||
cx.expected_specific_argument(
|
||||
name_value.value_span,
|
||||
vec![
|
||||
"available_externally",
|
||||
"common",
|
||||
"extern_weak",
|
||||
"external",
|
||||
"internal",
|
||||
"linkonce",
|
||||
"linkonce_odr",
|
||||
"weak",
|
||||
"weak_odr",
|
||||
&[
|
||||
sym::available_externally,
|
||||
sym::common,
|
||||
sym::extern_weak,
|
||||
sym::external,
|
||||
sym::internal,
|
||||
sym::linkonce,
|
||||
sym::linkonce_odr,
|
||||
sym::weak,
|
||||
sym::weak_odr,
|
||||
],
|
||||
);
|
||||
return None;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ fn parse_derive_like<S: Stage>(
|
|||
return None;
|
||||
};
|
||||
if !attr_list.path().word_is(sym::attributes) {
|
||||
cx.expected_specific_argument(attrs.span(), vec!["attributes"]);
|
||||
cx.expected_specific_argument(attrs.span(), &[sym::attributes]);
|
||||
return None;
|
||||
}
|
||||
let Some(attr_list) = attr_list.args().list() else {
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ fn parse_dialect<S: Stage>(
|
|||
sym::runtime => MirDialect::Runtime,
|
||||
|
||||
_ => {
|
||||
cx.expected_specific_argument(span, vec!["analysis", "built", "runtime"]);
|
||||
cx.expected_specific_argument(span, &[sym::analysis, sym::built, sym::runtime]);
|
||||
*failed = true;
|
||||
return None;
|
||||
}
|
||||
|
|
@ -131,7 +131,7 @@ fn parse_phase<S: Stage>(
|
|||
sym::optimized => MirPhase::Optimized,
|
||||
|
||||
_ => {
|
||||
cx.expected_specific_argument(span, vec!["initial", "post-cleanup", "optimized"]);
|
||||
cx.expected_specific_argument(span, &[sym::initial, sym::post_cleanup, sym::optimized]);
|
||||
*failed = true;
|
||||
return None;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,7 +81,7 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
|
|||
return None;
|
||||
};
|
||||
if !single.path().word_is(sym::expected) {
|
||||
cx.expected_specific_argument_strings(list.span, vec!["expected"]);
|
||||
cx.expected_specific_argument_strings(list.span, &[sym::expected]);
|
||||
return None;
|
||||
}
|
||||
let Some(nv) = single.args().name_value() else {
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ impl<S: Stage> SingleAttributeParser<S> for SkipDuringMethodDispatchParser {
|
|||
Some(key @ sym::array) => (key, &mut array),
|
||||
Some(key @ sym::boxed_slice) => (key, &mut boxed_slice),
|
||||
_ => {
|
||||
cx.expected_specific_argument(path.span(), vec!["array", "boxed_slice"]);
|
||||
cx.expected_specific_argument(path.span(), &[sym::array, sym::boxed_slice]);
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ impl<S: Stage> SingleAttributeParser<S> for TransparencyParser {
|
|||
Some(_) => {
|
||||
cx.expected_specific_argument_strings(
|
||||
nv.value_span,
|
||||
vec!["transparent", "semitransparent", "opaque"],
|
||||
&[sym::transparent, sym::semitransparent, sym::opaque],
|
||||
);
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -502,10 +502,11 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
|
|||
})
|
||||
}
|
||||
|
||||
/// produces an error along the lines of `expected one of [foo, meow]`
|
||||
pub(crate) fn expected_specific_argument(
|
||||
&self,
|
||||
span: Span,
|
||||
possibilities: Vec<&'static str>,
|
||||
possibilities: &[Symbol],
|
||||
) -> ErrorGuaranteed {
|
||||
self.emit_err(AttributeParseError {
|
||||
span,
|
||||
|
|
@ -521,10 +522,12 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
|
|||
})
|
||||
}
|
||||
|
||||
/// produces an error along the lines of `expected one of [foo, meow] as an argument`.
|
||||
/// i.e. slightly different wording to [`expected_specific_argument`](Self::expected_specific_argument).
|
||||
pub(crate) fn expected_specific_argument_and_list(
|
||||
&self,
|
||||
span: Span,
|
||||
possibilities: Vec<&'static str>,
|
||||
possibilities: &[Symbol],
|
||||
) -> ErrorGuaranteed {
|
||||
self.emit_err(AttributeParseError {
|
||||
span,
|
||||
|
|
@ -540,10 +543,11 @@ impl<'f, 'sess: 'f, S: Stage> AcceptContext<'f, 'sess, S> {
|
|||
})
|
||||
}
|
||||
|
||||
/// produces an error along the lines of `expected one of ["foo", "meow"]`
|
||||
pub(crate) fn expected_specific_argument_strings(
|
||||
&self,
|
||||
span: Span,
|
||||
possibilities: Vec<&'static str>,
|
||||
possibilities: &[Symbol],
|
||||
) -> ErrorGuaranteed {
|
||||
self.emit_err(AttributeParseError {
|
||||
span,
|
||||
|
|
|
|||
|
|
@ -558,7 +558,7 @@ pub(crate) struct LinkOrdinalOutOfRange {
|
|||
pub ordinal: u128,
|
||||
}
|
||||
|
||||
pub(crate) enum AttributeParseErrorReason {
|
||||
pub(crate) enum AttributeParseErrorReason<'a> {
|
||||
ExpectedNoArgs,
|
||||
ExpectedStringLiteral {
|
||||
byte_string: Option<Span>,
|
||||
|
|
@ -571,7 +571,7 @@ pub(crate) enum AttributeParseErrorReason {
|
|||
ExpectedNameValue(Option<Symbol>),
|
||||
DuplicateKey(Symbol),
|
||||
ExpectedSpecificArgument {
|
||||
possibilities: Vec<&'static str>,
|
||||
possibilities: &'a [Symbol],
|
||||
strings: bool,
|
||||
/// Should we tell the user to write a list when they didn't?
|
||||
list: bool,
|
||||
|
|
@ -579,16 +579,16 @@ pub(crate) enum AttributeParseErrorReason {
|
|||
ExpectedIdentifier,
|
||||
}
|
||||
|
||||
pub(crate) struct AttributeParseError {
|
||||
pub(crate) struct AttributeParseError<'a> {
|
||||
pub(crate) span: Span,
|
||||
pub(crate) attr_span: Span,
|
||||
pub(crate) attr_style: AttrStyle,
|
||||
pub(crate) template: AttributeTemplate,
|
||||
pub(crate) attribute: AttrPath,
|
||||
pub(crate) reason: AttributeParseErrorReason,
|
||||
pub(crate) reason: AttributeParseErrorReason<'a>,
|
||||
}
|
||||
|
||||
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
|
||||
impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError<'_> {
|
||||
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
|
||||
let name = self.attribute.to_string();
|
||||
|
||||
|
|
@ -657,7 +657,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
|
|||
list: false,
|
||||
} => {
|
||||
let quote = if strings { '"' } else { '`' };
|
||||
match possibilities.as_slice() {
|
||||
match possibilities {
|
||||
&[] => {}
|
||||
&[x] => {
|
||||
diag.span_label(
|
||||
|
|
@ -687,7 +687,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError {
|
|||
list: true,
|
||||
} => {
|
||||
let quote = if strings { '"' } else { '`' };
|
||||
match possibilities.as_slice() {
|
||||
match possibilities {
|
||||
&[] => {}
|
||||
&[x] => {
|
||||
diag.span_label(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue