Skip to content

Commit 35363d5

Browse files
committed
Update exisgting instruction_set error handling
1 parent f68063d commit 35363d5

File tree

6 files changed

+39
-50
lines changed

6 files changed

+39
-50
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+2-30
Original file line numberDiff line numberDiff line change
@@ -380,38 +380,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
380380
unreachable!()
381381
}
382382
}
383-
_ => {
384-
struct_span_code_err!(
385-
tcx.dcx(),
386-
attr.span,
387-
E0779,
388-
"invalid instruction set specified",
389-
)
390-
.emit();
391-
None
392-
}
383+
_ => None,
393384
}
394385
}
395-
[] => {
396-
struct_span_code_err!(
397-
tcx.dcx(),
398-
attr.span,
399-
E0778,
400-
"`#[instruction_set]` requires an argument"
401-
)
402-
.emit();
403-
None
404-
}
405-
_ => {
406-
struct_span_code_err!(
407-
tcx.dcx(),
408-
attr.span,
409-
E0779,
410-
"cannot specify more than one instruction set"
411-
)
412-
.emit();
413-
None
414-
}
386+
_ => None,
415387
})
416388
}
417389
sym::repr => {

compiler/rustc_passes/messages.ftl

+8-4
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ passes_coroutine_on_non_closure =
112112
attribute should be applied to closures
113113
.label = not a closure
114114
115-
passes_invalid_instruction_set =
116-
`[instruction_set]` attribute argument should be valid
117-
.label = `[instruction_set]` containes invalid argument
118-
119115
passes_coverage_not_fn_or_closure =
120116
attribute should be applied to a function definition or closure
121117
.label = not a function or closure
@@ -312,6 +308,10 @@ passes_duplicate_lang_item_crate_depends =
312308
passes_empty_confusables =
313309
expected at least one confusable name
314310
311+
passes_empty_instruction_set =
312+
`[instruction_set]` requires an argument
313+
.label = `[instruction_set]` requires an argument
314+
315315
passes_export_name =
316316
attribute should be applied to a free function, impl method or static
317317
.label = not a free function, impl method or static
@@ -401,6 +401,10 @@ passes_invalid_attr_at_crate_level =
401401
passes_invalid_attr_at_crate_level_item =
402402
the inner attribute doesn't annotate this {$kind}
403403
404+
passes_invalid_instruction_set =
405+
`[instruction_set]` attribute argument should be valid
406+
.label = `[instruction_set]` containes invalid argument
407+
404408
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
405409
406410
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments

compiler/rustc_passes/src/check_attr.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7+
use std::cell::Cell;
8+
use std::collections::hash_map::Entry;
9+
10+
use rustc_ast::token::TokenKind;
11+
use rustc_ast::tokenstream::TokenTree;
712
use rustc_ast::{
813
AttrKind, AttrStyle, Attribute, LitKind, MetaItemInner, MetaItemKind, MetaItemLit, ast,
914
token::TokenKind, tokenstream::TokenTree, AttrKind, AttrStyle, Attribute, LitKind,
@@ -38,8 +43,6 @@ use rustc_target::spec::abi::Abi;
3843
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3944
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
4045
use rustc_trait_selection::traits::ObligationCtxt;
41-
use std::cell::Cell;
42-
use std::collections::hash_map::Entry;
4346
use tracing::debug;
4447

4548
use crate::{errors, fluent_generated as fluent};
@@ -2389,7 +2392,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23892392
// Valid item for `instruction_set()` is:
23902393
// - arm::a32
23912394
// - arm::t32
2392-
let valid_attribute = match (tokens.next(), tokens.next(), tokens.next()) {
2395+
match (tokens.next(), tokens.next(), tokens.next()) {
23932396
(
23942397
Some(TokenTree::Token(first_token, _)),
23952398
Some(TokenTree::Token(second_token, _)),
@@ -2398,18 +2401,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23982401
(Some(first_ident), TokenKind::PathSep, Some(third_ident))
23992402
if first_ident.0.name == sym::arm =>
24002403
{
2401-
third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32
2404+
if third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32 {
2405+
return;
2406+
} else {
2407+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2408+
}
2409+
}
2410+
_ => {
2411+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
24022412
}
2403-
_ => false,
24042413
},
2405-
_ => false,
2414+
(None, None, None) => {
2415+
self.dcx().emit_err(errors::EmptyInstructionSet { span: attr.span });
2416+
}
2417+
_ => {
2418+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2419+
}
24062420
};
2407-
2408-
if !valid_attribute {
2409-
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2410-
} else {
2411-
return;
2412-
}
24132421
}
24142422
}
24152423
}

compiler/rustc_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,13 @@ pub struct InvalidInstructionSet {
696696
pub span: Span,
697697
}
698698

699+
#[derive(Diagnostic)]
700+
#[diag(passes_empty_instruction_set)]
701+
pub struct EmptyInstructionSet {
702+
#[primary_span]
703+
pub span: Span,
704+
}
705+
699706
#[derive(Diagnostic)]
700707
#[diag(passes_empty_confusables)]
701708
pub(crate) struct EmptyConfusables {

tests/ui/error-codes/E0778.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
error[E0778]: `#[instruction_set]` requires an argument
1+
error: `[instruction_set]` requires an argument
22
--> $DIR/E0778.rs:1:1
33
|
44
LL | #[instruction_set()]
55
| ^^^^^^^^^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

9-
For more information about this error, try `rustc --explain E0778`.

tests/ui/error-codes/E0779.stderr

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
error[E0779]: invalid instruction set specified
1+
error: `[instruction_set]` attribute argument should be valid
22
--> $DIR/E0779.rs:1:1
33
|
44
LL | #[instruction_set(arm::magic)]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

77
error: aborting due to 1 previous error
88

9-
For more information about this error, try `rustc --explain E0779`.

0 commit comments

Comments
 (0)