Skip to content

Commit 92fbd2c

Browse files
committed
Update exisgting instruction_set error handling
1 parent e9cae2b commit 92fbd2c

File tree

6 files changed

+40
-52
lines changed

6 files changed

+40
-52
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -397,38 +397,10 @@ 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,
410401
}
411402
}
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-
}
403+
_ => None,
432404
})
433405
}
434406
sym::repr => {

compiler/rustc_passes/messages.ftl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ passes_coroutine_on_non_closure =
104104
attribute should be applied to closures
105105
.label = not a closure
106106
107-
passes_invalid_instruction_set =
108-
`[instruction_set]` attribute argument should be valid
109-
.label = `[instruction_set]` containes invalid argument
110-
111107
passes_coverage_not_fn_or_closure =
112108
attribute should be applied to a function definition or closure
113109
.label = not a function or closure
@@ -288,6 +284,10 @@ passes_duplicate_lang_item_crate_depends =
288284
passes_empty_confusables =
289285
expected at least one confusable name
290286
287+
passes_empty_instruction_set =
288+
`[instruction_set]` requires an argument
289+
.label = `[instruction_set]` requires an argument
290+
291291
passes_export_name =
292292
attribute should be applied to a free function, impl method or static
293293
.label = not a free function, impl method or static
@@ -377,6 +377,10 @@ passes_invalid_attr_at_crate_level =
377377
passes_invalid_attr_at_crate_level_item =
378378
the inner attribute doesn't annotate this {$kind}
379379
380+
passes_invalid_instruction_set =
381+
`[instruction_set]` attribute argument should be valid
382+
.label = `[instruction_set]` containes invalid argument
383+
380384
passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument
381385
382386
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: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@
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::{
8-
ast, token::TokenKind, tokenstream::TokenTree, AttrKind, AttrStyle, Attribute, LitKind,
9-
MetaItemKind, MetaItemLit, NestedMetaItem,
13+
ast, AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem,
1014
};
1115
use rustc_data_structures::fx::FxHashMap;
1216
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
@@ -36,8 +40,6 @@ use rustc_target::spec::abi::Abi;
3640
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
3741
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
3842
use rustc_trait_selection::traits::ObligationCtxt;
39-
use std::cell::Cell;
40-
use std::collections::hash_map::Entry;
4143
use tracing::debug;
4244

4345
use crate::{errors, fluent_generated as fluent};
@@ -2360,7 +2362,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23602362
// Valid item for `instruction_set()` is:
23612363
// - arm::a32
23622364
// - arm::t32
2363-
let valid_attribute = match (tokens.next(), tokens.next(), tokens.next()) {
2365+
match (tokens.next(), tokens.next(), tokens.next()) {
23642366
(
23652367
Some(TokenTree::Token(first_token, _)),
23662368
Some(TokenTree::Token(second_token, _)),
@@ -2369,18 +2371,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23692371
(Some(first_ident), TokenKind::PathSep, Some(third_ident))
23702372
if first_ident.0.name == sym::arm =>
23712373
{
2372-
third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32
2374+
if third_ident.0.name == sym::a32 || third_ident.0.name == sym::t32 {
2375+
return;
2376+
} else {
2377+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2378+
}
2379+
}
2380+
_ => {
2381+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
23732382
}
2374-
_ => false,
23752383
},
2376-
_ => false,
2384+
(None, None, None) => {
2385+
self.dcx().emit_err(errors::EmptyInstructionSet { span: attr.span });
2386+
}
2387+
_ => {
2388+
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2389+
}
23772390
};
2378-
2379-
if !valid_attribute {
2380-
self.dcx().emit_err(errors::InvalidInstructionSet { span: attr.span });
2381-
} else {
2382-
return;
2383-
}
23842391
}
23852392
}
23862393
}

compiler/rustc_passes/src/errors.rs

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

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)