Skip to content

Commit a095e61

Browse files
Merge InvalidTarget and InvalidTargetLint diagnostics
1 parent 4f84d9f commit a095e61

3 files changed

Lines changed: 10 additions & 25 deletions

File tree

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,6 @@ pub(crate) struct EmptyAttributeList {
132132
pub valid_without_list: bool,
133133
}
134134

135-
#[derive(Diagnostic)]
136-
#[diag("`#[{$name}]` attribute cannot be used on {$target}")]
137-
#[warning(
138-
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
139-
)]
140-
#[help("`#[{$name}]` can {$only}be applied to {$applied}")]
141-
pub(crate) struct InvalidTargetLint {
142-
pub name: String,
143-
pub target: &'static str,
144-
pub applied: DiagArgValue,
145-
pub only: &'static str,
146-
#[suggestion(
147-
"remove the attribute",
148-
code = "",
149-
applicability = "machine-applicable",
150-
style = "tool-only"
151-
)]
152-
pub attr_span: Span,
153-
}
154-
155135
#[derive(Diagnostic)]
156136
#[diag(
157137
"{$is_used_as_inner ->

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ pub(crate) struct InvalidTarget {
353353
pub target: &'static str,
354354
pub applied: DiagArgValue,
355355
pub only: &'static str,
356+
#[warning(
357+
"this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!"
358+
)]
359+
pub previously_accepted: bool,
356360
}
357361

358362
#[derive(Diagnostic)]

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use rustc_span::{BytePos, FileName, RemapPathScopeComponents, Span, Symbol, sym}
99

1010
use crate::context::AcceptContext;
1111
use crate::errors::{
12-
InvalidAttrAtCrateLevel, InvalidTargetLint, ItemFollowingInnerAttr,
13-
UnsupportedAttributesInWhere,
12+
InvalidAttrAtCrateLevel, ItemFollowingInnerAttr, UnsupportedAttributesInWhere,
1413
};
1514
use crate::session_diagnostics::InvalidTarget;
1615
use crate::target_checking::Policy::Allow;
@@ -150,14 +149,15 @@ impl<'sess> AttributeParser<'sess> {
150149
cx.emit_lint_with_sess(
151150
lint,
152151
move |dcx, level, _| {
153-
InvalidTargetLint {
154-
name: name.to_string(),
152+
InvalidTarget {
153+
name,
155154
target: target.plural_name(),
156155
only: if only { "only " } else { "" },
157156
applied: DiagArgValue::StrListSepByAnd(
158157
applied.iter().map(|i| Cow::Owned(i.to_string())).collect(),
159158
),
160-
attr_span,
159+
span: attr_span,
160+
previously_accepted: true,
161161
}
162162
.into_diag(dcx, level)
163163
},
@@ -177,6 +177,7 @@ impl<'sess> AttributeParser<'sess> {
177177
applied: DiagArgValue::StrListSepByAnd(
178178
applied.into_iter().map(Cow::Owned).collect(),
179179
),
180+
previously_accepted: false,
180181
});
181182
}
182183
}

0 commit comments

Comments
 (0)