Skip to content

Commit 4d7abdf

Browse files
wip
1 parent 30df403 commit 4d7abdf

File tree

10 files changed

+113
-528
lines changed

10 files changed

+113
-528
lines changed

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir::{MethodKind, Target};
66
use rustc_span::{Span, Symbol, sym};
77

88
use super::{CombineAttributeParser, ConvertFn};
9-
use crate::context::MaybeWarn::Allow;
9+
use crate::context::MaybeWarn::{Allow, Warn};
1010
use crate::context::{AcceptContext, AllowedTargets, Stage};
1111
use crate::parser::ArgParser;
1212
use crate::session_diagnostics;
@@ -19,7 +19,9 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1919
|items, span| AttributeKind::AllowInternalUnstable(items, span);
2020
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
2121
Allow(Target::MacroDef),
22-
Allow(Target::Fn), //TODO if proc macro
22+
Allow(Target::Fn),
23+
Warn(Target::Field),
24+
Warn(Target::Arm),
2325
]);
2426
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
2527

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
7272
Warn(Target::TyAlias),
7373
Warn(Target::Impl { of_trait: false }),
7474
Warn(Target::Impl { of_trait: true }),
75+
Warn(Target::Field),
76+
Warn(Target::Arm),
77+
Warn(Target::MacroDef),
7578
]);
7679
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Cold;
7780
}
@@ -135,6 +138,9 @@ impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
135138
Allow(Target::Fn),
136139
Allow(Target::Method(MethodKind::Inherent)),
137140
Allow(Target::Method(MethodKind::Trait { body: true })),
141+
Warn(Target::Field),
142+
Warn(Target::Arm),
143+
Warn(Target::MacroDef),
138144
]);
139145
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
140146

@@ -450,5 +456,9 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
450456
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
451457
Allow(Target::Fn),
452458
Allow(Target::Method(MethodKind::Inherent)),
459+
Warn(Target::Statement),
460+
Warn(Target::Field),
461+
Warn(Target::Arm),
462+
Warn(Target::MacroDef),
453463
]);
454464
}

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,24 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
4949
Allow(Target::Static),
5050
Allow(Target::MacroDef),
5151
Allow(Target::Method(MethodKind::Inherent)),
52+
Allow(Target::Method(MethodKind::Trait { body: false })),
5253
Allow(Target::TyAlias),
5354
Allow(Target::Use),
5455
Allow(Target::ForeignFn),
5556
Allow(Target::Field),
5657
Allow(Target::Trait),
5758
Allow(Target::AssocTy),
59+
Allow(Target::AssocConst),
5860
Allow(Target::Variant),
5961
Warn(Target::Expression),
6062
Warn(Target::Impl { of_trait: false }),
6163
Warn(Target::Impl { of_trait: true }),
62-
Warn(Target::Crate)
64+
Warn(Target::Crate),
65+
Warn(Target::Param),
66+
Warn(Target::Closure),
67+
Warn(Target::Expression),
68+
Warn(Target::Statement),
69+
Warn(Target::Arm),
6370
]);
6471
const TEMPLATE: AttributeTemplate = template!(
6572
Word,

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,20 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
5353
const PATH: &[Symbol] = &[sym::link_section];
5454
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
5555
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
56-
const ALLOWED_TARGETS: AllowedTargets =
57-
AllowedTargets::AllowList(&[Allow(Target::Static), Allow(Target::Fn), Warn(Target::Crate), Warn(Target::ForeignMod),
58-
Warn(Target::Crate),
59-
Warn(Target::Mod),
60-
Warn(Target::Struct),
61-
Warn(Target::Enum),
62-
Warn(Target::Union),
63-
Warn(Target::TyAlias),
64-
Warn(Target::Impl { of_trait: false }),
65-
Warn(Target::Impl { of_trait: true }),]);
56+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
57+
Allow(Target::Static),
58+
Allow(Target::Fn),
59+
Warn(Target::Crate),
60+
Warn(Target::ForeignMod),
61+
Warn(Target::Crate),
62+
Warn(Target::Mod),
63+
Warn(Target::Struct),
64+
Warn(Target::Enum),
65+
Warn(Target::Union),
66+
Warn(Target::TyAlias),
67+
Warn(Target::Impl { of_trait: false }),
68+
Warn(Target::Impl { of_trait: true }),
69+
]);
6670
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
6771

6872
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {

compiler/rustc_attr_parsing/src/attributes/no_implicit_prelude.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,16 @@ pub(crate) struct NoImplicitPreludeParser;
1010
impl<S: Stage> NoArgsAttributeParser<S> for NoImplicitPreludeParser {
1111
const PATH: &[rustc_span::Symbol] = &[sym::no_implicit_prelude];
1212
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
13-
const ALLOWED_TARGETS: AllowedTargets =
14-
AllowedTargets::AllowList(&[Allow(Target::Crate), Warn(Target::Mod), Warn(Target::Struct),
15-
Warn(Target::Enum),
16-
Warn(Target::Union),
17-
Warn(Target::TyAlias), Warn(Target::Fn), Warn(Target::Impl {of_trait: false}), Warn(Target::Impl {of_trait: true})]);
13+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
14+
Allow(Target::Crate),
15+
Warn(Target::Mod),
16+
Warn(Target::Struct),
17+
Warn(Target::Enum),
18+
Warn(Target::Union),
19+
Warn(Target::TyAlias),
20+
Warn(Target::Fn),
21+
Warn(Target::Impl { of_trait: false }),
22+
Warn(Target::Impl { of_trait: true }),
23+
]);
1824
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoImplicitPrelude;
1925
}

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,9 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
326326
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
327327
Allow(Target::Fn),
328328
Allow(Target::Method(MethodKind::Inherent)),
329+
Allow(Target::Method(MethodKind::Trait { body: true })),
330+
Allow(Target::ForeignFn),
331+
// TODO special error for struct,enum,union
329332
]);
330333

331334
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {

compiler/rustc_hir/src/target.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ impl Target {
241241
}
242242

243243
pub fn from_expr(expr: &ast::Expr) -> Self {
244-
if let ast::ExprKind::Closure(..) | ast::ExprKind::Gen(..) = expr.kind { Self::Closure } else { Self::Expression }
244+
if let ast::ExprKind::Closure(..) | ast::ExprKind::Gen(..) = expr.kind {
245+
Self::Closure
246+
} else {
247+
Self::Expression
248+
}
245249
}
246250

247251
pub fn name(self) -> &'static str {

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,6 @@ passes_abi_ne =
1313
passes_abi_of =
1414
fn_abi_of({$fn_name}) = {$fn_abi}
1515
16-
passes_align_attr_application =
17-
`#[rustc_align(...)]` should be applied to a function item
18-
.label = not a function item
19-
20-
passes_align_on_fields =
21-
attribute should be applied to a function or method
22-
.warn = {-passes_previously_accepted}
23-
24-
passes_align_should_be_repr_align =
25-
`#[rustc_align(...)]` is not supported on {$item} items
26-
.suggestion = use `#[repr(align(...))]` instead
27-
28-
passes_allow_incoherent_impl =
29-
`rustc_allow_incoherent_impl` attribute should be applied to impl items
30-
.label = the only currently supported targets are inherent methods
31-
32-
passes_allow_internal_unstable =
33-
attribute should be applied to a macro
34-
.label = not a macro
35-
3616
passes_attr_application_enum =
3717
attribute should be applied to an enum
3818
.label = not an enum
@@ -78,18 +58,10 @@ passes_change_fields_to_be_of_unit_type =
7858
*[other] fields
7959
}
8060
81-
passes_cold =
82-
{passes_should_be_applied_to_fn}
83-
.warn = {-passes_previously_accepted}
84-
.label = {passes_should_be_applied_to_fn.label}
85-
8661
passes_collapse_debuginfo =
8762
`collapse_debuginfo` attribute should be applied to macro definitions
8863
.label = not a macro definition
8964
90-
passes_confusables = attribute should be applied to an inherent method
91-
.label = not an inherent method
92-
9365
passes_const_continue_attr =
9466
`#[const_continue]` should be applied to a break expression
9567
.label = not a break expression
@@ -129,9 +101,6 @@ passes_debug_visualizer_placement =
129101
passes_debug_visualizer_unreadable =
130102
couldn't read {$file}: {$error}
131103
132-
passes_deprecated =
133-
attribute is ignored here
134-
135104
passes_deprecated_annotation_has_no_effect =
136105
this `#[deprecated]` annotation has no effect
137106
.suggestion = remove the unnecessary deprecation attribute
@@ -304,10 +273,6 @@ passes_duplicate_lang_item_crate_depends =
304273
passes_enum_variant_same_name =
305274
it is impossible to refer to the {$dead_descr} `{$dead_name}` because it is shadowed by this enum variant with the same name
306275
307-
passes_export_name =
308-
attribute should be applied to a free function, impl method or static
309-
.label = not a free function, impl method or static
310-
311276
passes_extern_main =
312277
the `main` function cannot be declared in an `extern` block
313278
@@ -327,11 +292,6 @@ passes_has_incoherent_inherent_impl =
327292
`rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits
328293
.label = only adts, extern types and traits are supported
329294
330-
passes_ignored_attr =
331-
`#[{$sym}]` is ignored on struct fields and match arms
332-
.warn = {-passes_previously_accepted}
333-
.note = {-passes_see_issue(issue: "80564")}
334-
335295
passes_ignored_attr_with_macro =
336296
`#[{$sym}]` is ignored on struct fields, match arms and macro defs
337297
.warn = {-passes_previously_accepted}
@@ -373,22 +333,10 @@ passes_incorrect_target =
373333
passes_ineffective_unstable_impl = an `#[unstable]` annotation here has no effect
374334
.note = see issue #55436 <https://github.com/rust-lang/rust/issues/55436> for more information
375335
376-
passes_inline_ignored_constants =
377-
`#[inline]` is ignored on constants
378-
.warn = {-passes_previously_accepted}
379-
.note = {-passes_see_issue(issue: "65833")}
380-
381336
passes_inline_ignored_for_exported =
382337
`#[inline]` is ignored on externally exported functions
383338
.help = externally exported functions are functions with `#[no_mangle]`, `#[export_name]`, or `#[linkage]`
384339
385-
passes_inline_ignored_function_prototype =
386-
`#[inline]` is ignored on function prototypes
387-
388-
passes_inline_not_fn_or_closure =
389-
attribute should be applied to function or closure
390-
.label = not a function or closure
391-
392340
passes_inner_crate_level_attr =
393341
crate-level attribute should be in the root module
394342
@@ -565,10 +513,6 @@ passes_only_has_effect_on =
565513
*[unspecified] (unspecified--this is a compiler bug)
566514
}
567515
568-
passes_optimize_invalid_target =
569-
attribute applied to an invalid target
570-
.label = invalid target
571-
572516
passes_outer_crate_level_attr =
573517
crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
574518
@@ -687,16 +631,8 @@ passes_should_be_applied_to_trait =
687631
attribute should be applied to a trait
688632
.label = not a trait
689633
690-
passes_stability_promotable =
691-
attribute cannot be applied to an expression
692-
693634
passes_string_interpolation_only_works = string interpolation only works in `format!` invocations
694635
695-
passes_target_feature_on_statement =
696-
{passes_should_be_applied_to_fn}
697-
.warn = {-passes_previously_accepted}
698-
.label = {passes_should_be_applied_to_fn.label}
699-
700636
passes_trait_impl_const_stability_mismatch = const stability on the impl does not match the const stability on the trait
701637
passes_trait_impl_const_stability_mismatch_impl_stable = this impl is (implicitly) stable...
702638
passes_trait_impl_const_stability_mismatch_impl_unstable = this impl is unstable...

0 commit comments

Comments
 (0)