Skip to content

Commit 442e5c4

Browse files
committed
Update exisgting instruction_set error handling
1 parent c33bab5 commit 442e5c4

File tree

6 files changed

+39
-50
lines changed

6 files changed

+39
-50
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 30 deletions
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

Lines changed: 8 additions & 4 deletions
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
@@ -315,6 +311,10 @@ passes_duplicate_lang_item_crate_depends =
315311
passes_empty_confusables =
316312
expected at least one confusable name
317313
314+
passes_empty_instruction_set =
315+
`[instruction_set]` requires an argument
316+
.label = `[instruction_set]` requires an argument
317+
318318
passes_export_name =
319319
attribute should be applied to a free function, impl method or static
320320
.label = not a free function, impl method or static
@@ -404,6 +404,10 @@ passes_invalid_attr_at_crate_level =
404404
passes_invalid_attr_at_crate_level_item =
405405
the inner attribute doesn't annotate this {$kind}
406406
407+
passes_invalid_instruction_set =
408+
`[instruction_set]` attribute argument should be valid
409+
.label = `[instruction_set]` containes invalid argument
410+
407411
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
408412
409413
passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments

compiler/rustc_passes/src/check_attr.rs

Lines changed: 20 additions & 12 deletions
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};
@@ -2412,7 +2415,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24122415
// Valid item for `instruction_set()` is:
24132416
// - arm::a32
24142417
// - arm::t32
2415-
let valid_attribute = match (tokens.next(), tokens.next(), tokens.next()) {
2418+
match (tokens.next(), tokens.next(), tokens.next()) {
24162419
(
24172420
Some(TokenTree::Token(first_token, _)),
24182421
Some(TokenTree::Token(second_token, _)),
@@ -2421,18 +2424,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
24212424
(Some(first_ident), TokenKind::PathSep, Some(third_ident))
24222425
if first_ident.0.name == sym::arm =>
24232426
{
2424-
third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32
2427+
if third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32 {
2428+
return;
2429+
} else {
2430+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2431+
}
2432+
}
2433+
_ => {
2434+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
24252435
}
2426-
_ => false,
24272436
},
2428-
_ => false,
2437+
(None, None, None) => {
2438+
self.dcx().emit_err(errors::EmptyInstructionSet { span: attr.span });
2439+
}
2440+
_ => {
2441+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2442+
}
24292443
};
2430-
2431-
if !valid_attribute {
2432-
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2433-
} else {
2434-
return;
2435-
}
24362444
}
24372445
}
24382446
}

compiler/rustc_passes/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,13 @@ pub struct InvalidInstructionSet {
703703
pub span: Span,
704704
}
705705

706+
#[derive(Diagnostic)]
707+
#[diag(passes_empty_instruction_set)]
708+
pub struct EmptyInstructionSet {
709+
#[primary_span]
710+
pub span: Span,
711+
}
712+
706713
#[derive(Diagnostic)]
707714
#[diag(passes_empty_confusables)]
708715
pub(crate) struct EmptyConfusables {

tests/ui/error-codes/E0778.stderr

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 2 deletions
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)