Skip to content

Commit 85510ef

Browse files
committed
Update exisgting instruction_set error handling
1 parent e9cae2b commit 85510ef

File tree

6 files changed

+41
-44
lines changed

6 files changed

+41
-44
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+12-30
Original file line numberDiff line numberDiff line change
@@ -397,38 +397,20 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
397397
unreachable!()
398398
}
399399
}
400-
_ => {
401-
struct_span_code_err!(
402-
tcx.dcx(),
403-
attr.span,
404-
E0779,
405-
"invalid instruction set specified",
406-
)
407-
.emit();
408-
None
409-
}
400+
_ => None,
401+
// _ => {
402+
// struct_span_code_err!(
403+
// tcx.dcx(),
404+
// attr.span,
405+
// E0779,
406+
// "invalid instruction set specified",
407+
// )
408+
// .emit();
409+
// None
410+
// }
410411
}
411412
}
412-
[] => {
413-
struct_span_code_err!(
414-
tcx.dcx(),
415-
attr.span,
416-
E0778,
417-
"`#[instruction_set]` requires an argument"
418-
)
419-
.emit();
420-
None
421-
}
422-
_ => {
423-
struct_span_code_err!(
424-
tcx.dcx(),
425-
attr.span,
426-
E0779,
427-
"cannot specify more than one instruction set"
428-
)
429-
.emit();
430-
None
431-
}
413+
_ => None,
432414
})
433415
}
434416
sym::repr => {

compiler/rustc_passes/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ passes_invalid_instruction_set =
108108
`[instruction_set]` attribute argument should be valid
109109
.label = `[instruction_set]` containes invalid argument
110110
111+
passes_empty_instruction_set =
112+
`[instruction_set]` requires an argument
113+
.label = `[instruction_set]` requires an argument
114+
111115
passes_coverage_not_fn_or_closure =
112116
attribute should be applied to a function definition or closure
113117
.label = not a function or closure

compiler/rustc_passes/src/check_attr.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23522352
}
23532353
}
23542354

2355+
// TODO: empty
23552356
fn check_instruction_set(&self, attr: &Attribute, _item: Option<ItemLike<'_>>) {
23562357
if let AttrKind::Normal(ref p) = attr.kind {
23572358
let inner_tokens = p.item.args.inner_tokens();
@@ -2360,7 +2361,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23602361
// Valid item for `instruction_set()` is:
23612362
// - arm::a32
23622363
// - arm::t32
2363-
let valid_attribute = match (tokens.next(), tokens.next(), tokens.next()) {
2364+
match (tokens.next(), tokens.next(), tokens.next()) {
23642365
(
23652366
Some(TokenTree::Token(first_token, _)),
23662367
Some(TokenTree::Token(second_token, _)),
@@ -2369,18 +2370,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23692370
(Some(first_ident), TokenKind::PathSep, Some(third_ident))
23702371
if first_ident.0.name == sym::arm =>
23712372
{
2372-
third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32
2373+
if third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32 {
2374+
return;
2375+
} else {
2376+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2377+
}
2378+
}
2379+
_ => {
2380+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
23732381
}
2374-
_ => false,
23752382
},
2376-
_ => false,
2383+
(None, None, None) => {
2384+
self.dcx().emit_err(errors::EmptyInstructionSet { span: attr.span });
2385+
}
2386+
_ => {
2387+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2388+
}
23772389
};
2378-
2379-
if !valid_attribute {
2380-
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2381-
} else {
2382-
return;
2383-
}
23842390
}
23852391
}
23862392
}

compiler/rustc_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ pub struct InvalidInstructionSet {
650650
pub span: Span,
651651
}
652652

653+
#[derive(Diagnostic)]
654+
#[diag(passes_empty_instruction_set)]
655+
pub struct EmptyInstructionSet {
656+
#[primary_span]
657+
pub span: Span,
658+
}
659+
653660
#[derive(Diagnostic)]
654661
#[diag(passes_empty_confusables)]
655662
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)