Skip to content

Commit 63fb71a

Browse files
Rework illformed attribute check for unparsed attributes
Signed-off-by: Jonathan Brouwer <[email protected]>
1 parent 81af9d4 commit 63fb71a

31 files changed

+739
-509
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3275,7 +3275,6 @@ dependencies = [
32753275
"rustc_feature",
32763276
"rustc_fluent_macro",
32773277
"rustc_macros",
3278-
"rustc_parse",
32793278
"rustc_session",
32803279
"rustc_span",
32813280
"rustc_target",
@@ -3321,6 +3320,7 @@ dependencies = [
33213320
"rustc_hir",
33223321
"rustc_lexer",
33233322
"rustc_macros",
3323+
"rustc_parse",
33243324
"rustc_session",
33253325
"rustc_span",
33263326
"thin-vec",

compiler/rustc_ast_passes/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ rustc_errors = { path = "../rustc_errors" }
1515
rustc_feature = { path = "../rustc_feature" }
1616
rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1717
rustc_macros = { path = "../rustc_macros" }
18-
rustc_parse = { path = "../rustc_parse" }
1918
rustc_session = { path = "../rustc_session" }
2019
rustc_span = { path = "../rustc_span" }
2120
rustc_target = { path = "../rustc_target" }

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ use rustc_ast_pretty::pprust::{self, State};
2929
use rustc_data_structures::fx::FxIndexMap;
3030
use rustc_errors::DiagCtxtHandle;
3131
use rustc_feature::Features;
32-
use rustc_parse::validate_attr;
3332
use rustc_session::Session;
3433
use rustc_session::lint::builtin::{
3534
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
@@ -928,10 +927,6 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
928927
}
929928

930929
impl<'a> Visitor<'a> for AstValidator<'a> {
931-
fn visit_attribute(&mut self, attr: &Attribute) {
932-
validate_attr::check_attr(&self.sess.psess, attr, self.lint_node_id);
933-
}
934-
935930
fn visit_ty(&mut self, ty: &'a Ty) {
936931
self.visit_ty_common(ty);
937932
self.walk_ty(ty)

compiler/rustc_attr_data_structures/src/lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ pub enum AttributeLintKind {
1313
UnusedDuplicate { this: Span, other: Span, warning: bool },
1414
IllFormedAttributeInput { suggestions: Vec<String> },
1515
EmptyAttribute { first_span: Span },
16+
UnsafeAttrOutsideUnsafe { attribute_name_span: Span, sugg_spans: (Span, Span) },
1617
}

compiler/rustc_attr_parsing/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rustc_fluent_macro = { path = "../rustc_fluent_macro" }
1515
rustc_hir = { path = "../rustc_hir" }
1616
rustc_lexer = { path = "../rustc_lexer" }
1717
rustc_macros = { path = "../rustc_macros" }
18+
rustc_parse = { path = "../rustc_parse" }
1819
rustc_session = { path = "../rustc_session" }
1920
rustc_span = { path = "../rustc_span" }
2021
thin-vec = "0.2.12"

compiler/rustc_attr_parsing/messages.ftl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,12 @@ attr_parsing_unused_multiple =
161161
162162
-attr_parsing_previously_accepted =
163163
this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
164+
165+
attr_parsing_unsafe_attr_outside_unsafe = unsafe attribute used without unsafe
166+
.label = usage of unsafe attribute
167+
attr_parsing_unsafe_attr_outside_unsafe_suggestion = wrap the attribute in `unsafe(...)`
168+
169+
attr_parsing_invalid_attr_unsafe = `{$name}` is not an unsafe attribute
170+
.label = this is not an unsafe attribute
171+
.suggestion = remove the `unsafe(...)`
172+
.note = extraneous unsafe is not allowed in attributes

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,12 @@ pub(crate) fn parse_stability<S: Stage>(
247247
let mut feature = None;
248248
let mut since = None;
249249

250-
for param in args.list()?.mixed() {
250+
let ArgParser::List(list) = args else {
251+
cx.expected_list(cx.attr_span);
252+
return None;
253+
};
254+
255+
for param in list.mixed() {
251256
let param_span = param.span();
252257
let Some(param) = param.meta_item() else {
253258
cx.emit_err(session_diagnostics::UnsupportedLiteral {
@@ -322,7 +327,13 @@ pub(crate) fn parse_unstability<S: Stage>(
322327
let mut is_soft = false;
323328
let mut implied_by = None;
324329
let mut old_name = None;
325-
for param in args.list()?.mixed() {
330+
331+
let ArgParser::List(list) = args else {
332+
cx.expected_list(cx.attr_span);
333+
return None;
334+
};
335+
336+
for param in list.mixed() {
326337
let Some(param) = param.meta_item() else {
327338
cx.emit_err(session_diagnostics::UnsupportedLiteral {
328339
span: param.span(),

0 commit comments

Comments
 (0)