Rollup merge of #126405 - He1pa:translate_builtin_macro_diag, r=davidtwco
Migrate some rustc_builtin_macros to SessionDiagnostic <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> --> Part of https://github.com/rust-lang/rust/issues/100717. pick up abandoned pr: #101935 `@rustbot` label +A-translation
This commit is contained in:
commit
b16a711191
@ -17,6 +17,9 @@ builtin_macros_asm_expected_other = expected operand, {$is_global_asm ->
|
|||||||
*[false] clobber_abi, options
|
*[false] clobber_abi, options
|
||||||
}, or additional template string
|
}, or additional template string
|
||||||
|
|
||||||
|
builtin_macros_asm_expected_string_literal = expected string literal
|
||||||
|
.label = not a string literal
|
||||||
|
|
||||||
builtin_macros_asm_explicit_register_name = explicit register arguments cannot have names
|
builtin_macros_asm_explicit_register_name = explicit register arguments cannot have names
|
||||||
|
|
||||||
builtin_macros_asm_mayunwind = asm labels are not allowed with the `may_unwind` option
|
builtin_macros_asm_mayunwind = asm labels are not allowed with the `may_unwind` option
|
||||||
@ -25,6 +28,8 @@ builtin_macros_asm_modifier_invalid = asm template modifier must be a single cha
|
|||||||
|
|
||||||
builtin_macros_asm_mutually_exclusive = the `{$opt1}` and `{$opt2}` options are mutually exclusive
|
builtin_macros_asm_mutually_exclusive = the `{$opt1}` and `{$opt2}` options are mutually exclusive
|
||||||
|
|
||||||
|
builtin_macros_asm_no_matched_argument_name = there is no argument named `{$name}`
|
||||||
|
|
||||||
builtin_macros_asm_noreturn = asm outputs are not allowed with the `noreturn` option
|
builtin_macros_asm_noreturn = asm outputs are not allowed with the `noreturn` option
|
||||||
|
|
||||||
builtin_macros_asm_opt_already_provided = the `{$symbol}` option was already provided
|
builtin_macros_asm_opt_already_provided = the `{$symbol}` option was already provided
|
||||||
@ -228,10 +233,16 @@ builtin_macros_only_one_argument = {$name} takes 1 argument
|
|||||||
|
|
||||||
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
|
||||||
|
|
||||||
|
builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions = the `#[{$path}]` attribute may only be used on bare functions
|
||||||
|
|
||||||
|
builtin_macros_proc_macro_attribute_only_usable_with_crate_type = the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type
|
||||||
|
|
||||||
builtin_macros_requires_cfg_pattern =
|
builtin_macros_requires_cfg_pattern =
|
||||||
macro requires a cfg-pattern as an argument
|
macro requires a cfg-pattern as an argument
|
||||||
.label = cfg-pattern required
|
.label = cfg-pattern required
|
||||||
|
|
||||||
|
builtin_macros_source_uitls_expected_item = expected item, found `{$token}`
|
||||||
|
|
||||||
builtin_macros_takes_no_arguments = {$name} takes no arguments
|
builtin_macros_takes_no_arguments = {$name} takes no arguments
|
||||||
|
|
||||||
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
|
builtin_macros_test_bad_fn = {$kind} functions cannot be used for tests
|
||||||
|
@ -390,9 +390,7 @@ fn parse_clobber_abi<'a>(p: &mut Parser<'a>, args: &mut AsmArgs) -> PResult<'a,
|
|||||||
}
|
}
|
||||||
Err(opt_lit) => {
|
Err(opt_lit) => {
|
||||||
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
|
let span = opt_lit.map_or(p.token.span, |lit| lit.span);
|
||||||
let mut err = p.dcx().struct_span_err(span, "expected string literal");
|
return Err(p.dcx().create_err(errors::AsmExpectedStringLiteral { span }));
|
||||||
err.span_label(span, "not a string literal");
|
|
||||||
return Err(err);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -639,14 +637,13 @@ fn expand_preparsed_asm(
|
|||||||
match args.named_args.get(&Symbol::intern(name)) {
|
match args.named_args.get(&Symbol::intern(name)) {
|
||||||
Some(&idx) => Some(idx),
|
Some(&idx) => Some(idx),
|
||||||
None => {
|
None => {
|
||||||
let msg = format!("there is no argument named `{name}`");
|
|
||||||
let span = arg.position_span;
|
let span = arg.position_span;
|
||||||
ecx.dcx()
|
ecx.dcx()
|
||||||
.struct_span_err(
|
.create_err(errors::AsmNoMatchedArgumentName {
|
||||||
template_span
|
name: name.to_owned(),
|
||||||
|
span: template_span
|
||||||
.from_inner(InnerSpan::new(span.start, span.end)),
|
.from_inner(InnerSpan::new(span.start, span.end)),
|
||||||
msg,
|
})
|
||||||
)
|
|
||||||
.emit();
|
.emit();
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -728,6 +728,14 @@ pub(crate) struct AsmExpectedComma {
|
|||||||
pub(crate) span: Span,
|
pub(crate) span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_asm_expected_string_literal)]
|
||||||
|
pub(crate) struct AsmExpectedStringLiteral {
|
||||||
|
#[primary_span]
|
||||||
|
#[label]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(builtin_macros_asm_underscore_input)]
|
#[diag(builtin_macros_asm_underscore_input)]
|
||||||
pub(crate) struct AsmUnderscoreInput {
|
pub(crate) struct AsmUnderscoreInput {
|
||||||
@ -781,6 +789,14 @@ pub(crate) struct AsmNoReturn {
|
|||||||
pub(crate) outputs_sp: Vec<Span>,
|
pub(crate) outputs_sp: Vec<Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_asm_no_matched_argument_name)]
|
||||||
|
pub(crate) struct AsmNoMatchedArgumentName {
|
||||||
|
pub(crate) name: String,
|
||||||
|
#[primary_span]
|
||||||
|
pub(crate) span: Span,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(builtin_macros_asm_mayunwind)]
|
#[diag(builtin_macros_asm_mayunwind)]
|
||||||
pub(crate) struct AsmMayUnwind {
|
pub(crate) struct AsmMayUnwind {
|
||||||
@ -872,3 +888,27 @@ pub(crate) struct TakesNoArguments<'a> {
|
|||||||
pub span: Span,
|
pub span: Span,
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions)]
|
||||||
|
pub(crate) struct AttributeOnlyBeUsedOnBareFunctions<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub path: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_proc_macro_attribute_only_usable_with_crate_type)]
|
||||||
|
pub(crate) struct AttributeOnlyUsableWithCrateType<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub path: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(builtin_macros_source_uitls_expected_item)]
|
||||||
|
pub(crate) struct ExpectedItem<'a> {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub token: &'a str,
|
||||||
|
}
|
||||||
|
@ -214,12 +214,12 @@ fn visit_item(&mut self, item: &'a ast::Item) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !is_fn {
|
if !is_fn {
|
||||||
let msg = format!(
|
self.dcx
|
||||||
"the `#[{}]` attribute may only be used on bare functions",
|
.create_err(errors::AttributeOnlyBeUsedOnBareFunctions {
|
||||||
pprust::path_to_string(&attr.get_normal_item().path),
|
span: attr.span,
|
||||||
);
|
path: &pprust::path_to_string(&attr.get_normal_item().path),
|
||||||
|
})
|
||||||
self.dcx.span_err(attr.span, msg);
|
.emit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,12 +228,12 @@ fn visit_item(&mut self, item: &'a ast::Item) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !self.is_proc_macro_crate {
|
if !self.is_proc_macro_crate {
|
||||||
let msg = format!(
|
self.dcx
|
||||||
"the `#[{}]` attribute is only usable with crates of the `proc-macro` crate type",
|
.create_err(errors::AttributeOnlyUsableWithCrateType {
|
||||||
pprust::path_to_string(&attr.get_normal_item().path),
|
span: attr.span,
|
||||||
);
|
path: &pprust::path_to_string(&attr.get_normal_item().path),
|
||||||
|
})
|
||||||
self.dcx.span_err(attr.span, msg);
|
.emit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use crate::errors;
|
||||||
use crate::util::{
|
use crate::util::{
|
||||||
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
|
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
|
||||||
};
|
};
|
||||||
@ -165,9 +166,13 @@ fn make_expr(mut self: Box<ExpandInclude<'a>>) -> Option<P<ast::Expr>> {
|
|||||||
Ok(Some(item)) => ret.push(item),
|
Ok(Some(item)) => ret.push(item),
|
||||||
Ok(None) => {
|
Ok(None) => {
|
||||||
if self.p.token != token::Eof {
|
if self.p.token != token::Eof {
|
||||||
let token = pprust::token_to_string(&self.p.token);
|
self.p
|
||||||
let msg = format!("expected item, found `{token}`");
|
.dcx()
|
||||||
self.p.dcx().span_err(self.p.token.span, msg);
|
.create_err(errors::ExpectedItem {
|
||||||
|
span: self.p.token.span,
|
||||||
|
token: &pprust::token_to_string(&self.p.token),
|
||||||
|
})
|
||||||
|
.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user