Skip to content

Commit c0ead89

Browse files
wip
1 parent 9ad2305 commit c0ead89

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
281281
Allow(Target::Method(MethodKind::Trait { body: false })),
282282
Allow(Target::ForeignFn),
283283
Allow(Target::Closure),
284+
Warn(Target::MacroDef),
284285
]);
285286
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
286287
}
@@ -303,6 +304,10 @@ impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
303304
Warn(Target::Impl { of_trait: true }),
304305
Warn(Target::Trait),
305306
Warn(Target::Mod),
307+
Warn(Target::Const),
308+
Warn(Target::Statement),
309+
Warn(Target::ForeignFn),
310+
Warn(Target::ForeignStatic),
306311
]);
307312
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
308313
}

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5959
Warn(Target::Expression),
6060
Warn(Target::Impl { of_trait: false }),
6161
Warn(Target::Impl { of_trait: true }),
62+
Warn(Target::Crate)
6263
]);
6364
const TEMPLATE: AttributeTemplate = template!(
6465
Word,

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
4646
Warn(Target::TyAlias),
4747
Warn(Target::Impl { of_trait: false }),
4848
Warn(Target::Impl { of_trait: true }),
49+
Warn(Target::Use),
4950
]);
5051

5152
impl<S: Stage> AttributeParser<S> for MacroUseParser {

compiler/rustc_attr_parsing/src/attributes/must_use.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser {
2424
Allow(Target::Method(MethodKind::Inherent)),
2525
Allow(Target::ForeignFn),
2626
Allow(Target::Trait),
27+
Warn(Target::Method(MethodKind::Trait { body: true })),
2728
Warn(Target::Crate),
2829
Warn(Target::Mod),
2930
Warn(Target::TyAlias),

compiler/rustc_hir/src/target.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ pub enum Target {
6363
// Used for attributes
6464
MacroCall,
6565
Crate,
66+
Delegation,
6667
}
6768

6869
impl Display for Target {
@@ -106,7 +107,8 @@ impl Target {
106107
| Target::ExprField
107108
| Target::MacroCall
108109
| Target::Crate
109-
| Target::WherePredicate => false,
110+
| Target::WherePredicate
111+
| Target::Delegation => false,
110112
}
111113
}
112114

@@ -233,12 +235,13 @@ impl Target {
233235
MethodKind::Inherent
234236
}),
235237
AssocItemKind::Type(_) => Target::AssocTy,
238+
AssocItemKind::Delegation(_) => Target::Delegation,
236239
_ => unreachable!(),
237240
}
238241
}
239242

240243
pub fn from_expr(expr: &ast::Expr) -> Self {
241-
if let ast::ExprKind::Closure(..) = expr.kind { Self::Closure } else { Self::Expression }
244+
if let ast::ExprKind::Closure(..) | ast::ExprKind::Gen(..) = expr.kind { Self::Closure } else { Self::Expression }
242245
}
243246

244247
pub fn name(self) -> &'static str {
@@ -287,6 +290,7 @@ impl Target {
287290
Target::WherePredicate => "where predicate",
288291
Target::MacroCall => "macro call",
289292
Target::Crate => "crate",
293+
Target::Delegation => "delegation",
290294
}
291295
}
292296
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10571057
| Target::PatField
10581058
| Target::ExprField
10591059
| Target::Crate
1060-
| Target::MacroCall => None,
1060+
| Target::MacroCall
1061+
| Target::Delegation => None,
10611062
} {
10621063
tcx.dcx().emit_err(errors::DocAliasBadLocation { span, attr_str, location });
10631064
return;
@@ -2329,7 +2330,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
23292330
| Target::ExprField
23302331
| Target::WherePredicate
23312332
| Target::Crate
2332-
| Target::MacroCall => {
2333+
| Target::MacroCall
2334+
| Target::Delegation => {
23332335
self.tcx.dcx().emit_err(errors::RustcUnstableFeatureBound { attr_span, span });
23342336
}
23352337
}

0 commit comments

Comments
 (0)