Skip to content

Commit d935f8f

Browse files
wip
1 parent 4d7abdf commit d935f8f

File tree

7 files changed

+73
-632
lines changed

7 files changed

+73
-632
lines changed

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
288288
Allow(Target::ForeignFn),
289289
Allow(Target::Closure),
290290
Warn(Target::MacroDef),
291+
Warn(Target::Arm),
292+
Warn(Target::Field),
291293
]);
292294
const CREATE: fn(Span) -> AttributeKind = AttributeKind::TrackCaller;
293295
}
@@ -296,24 +298,12 @@ pub(crate) struct NoMangleParser;
296298
impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
297299
const PATH: &[Symbol] = &[sym::no_mangle];
298300
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
299-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
301+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
300302
Allow(Target::Fn),
301303
Allow(Target::Static),
302304
Allow(Target::Method(MethodKind::Inherent)),
303305
Allow(Target::Method(MethodKind::Trait { body: true })),
304306
Allow(Target::Method(MethodKind::Trait { body: false })),
305-
Warn(Target::Struct),
306-
Warn(Target::Enum),
307-
Warn(Target::Union),
308-
Warn(Target::TyAlias),
309-
Warn(Target::Impl { of_trait: false }),
310-
Warn(Target::Impl { of_trait: true }),
311-
Warn(Target::Trait),
312-
Warn(Target::Mod),
313-
Warn(Target::Const),
314-
Warn(Target::Statement),
315-
Warn(Target::ForeignFn),
316-
Warn(Target::ForeignStatic),
317307
]);
318308
const CREATE: fn(Span) -> AttributeKind = AttributeKind::NoMangle;
319309
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_span::{Span, Symbol, sym};
77
use crate::attributes::{
88
AttributeOrder, NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
99
};
10-
use crate::context::MaybeWarn::{Allow, Warn};
10+
use crate::context::MaybeWarn::Allow;
1111
use crate::context::{AcceptContext, AllowedTargets, Stage, parse_single_integer};
1212
use crate::parser::ArgParser;
1313
use crate::session_diagnostics::{LinkOrdinalOutOfRange, NullOnLinkSection};
@@ -17,19 +17,9 @@ impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
1717
const PATH: &[Symbol] = &[sym::link_name];
1818
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
1919
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
20-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
20+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
2121
Allow(Target::ForeignFn),
2222
Allow(Target::ForeignStatic),
23-
Warn(Target::ForeignMod),
24-
Warn(Target::Crate),
25-
Warn(Target::Fn),
26-
Warn(Target::Mod),
27-
Warn(Target::Struct),
28-
Warn(Target::Enum),
29-
Warn(Target::Union),
30-
Warn(Target::TyAlias),
31-
Warn(Target::Impl { of_trait: false }),
32-
Warn(Target::Impl { of_trait: true }),
3323
]);
3424
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
3525

@@ -53,20 +43,8 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
5343
const PATH: &[Symbol] = &[sym::link_section];
5444
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
5545
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
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-
]);
46+
const ALLOWED_TARGETS: AllowedTargets =
47+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Static), Allow(Target::Fn)]);
7048
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
7149

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

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

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

88
use crate::attributes::{AcceptMapping, AttributeParser, NoArgsAttributeParser, OnDuplicate};
9-
use crate::context::MaybeWarn::{Allow, Warn};
9+
use crate::context::MaybeWarn::Allow;
1010
use crate::context::{AcceptContext, AllowedTargets, FinalizeContext, Stage};
1111
use crate::parser::ArgParser;
1212
use crate::session_diagnostics;
@@ -34,19 +34,10 @@ pub(crate) struct MacroUseParser {
3434
}
3535

3636
const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ...");
37-
const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
37+
const MACRO_USE_ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
3838
Allow(Target::Mod),
3939
Allow(Target::ExternCrate),
4040
Allow(Target::Crate),
41-
Warn(Target::Fn),
42-
Warn(Target::Struct),
43-
Warn(Target::Enum),
44-
Warn(Target::Struct),
45-
Warn(Target::Union),
46-
Warn(Target::TyAlias),
47-
Warn(Target::Impl { of_trait: false }),
48-
Warn(Target::Impl { of_trait: true }),
49-
Warn(Target::Use),
5041
]);
5142

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

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,20 +648,24 @@ impl ShouldEmit {
648648
pub(crate) enum AllowedTargets {
649649
AllowAll,
650650
AllowList(&'static [MaybeWarn]),
651+
AllowListWarnRest(&'static [MaybeWarn]),
651652
}
652653

653654
impl AllowedTargets {
654655
pub(crate) fn is_allowed(&self, target: Target) -> bool {
655656
match self {
656657
AllowedTargets::AllowAll => true,
657-
AllowedTargets::AllowList(list) => list.contains(&Allow(target)),
658+
AllowedTargets::AllowList(list) | AllowedTargets::AllowListWarnRest(list) => {
659+
list.contains(&Allow(target))
660+
}
658661
}
659662
}
660663

661664
pub(crate) fn is_warn(&self, target: Target) -> bool {
662665
match self {
663666
AllowedTargets::AllowAll => false,
664667
AllowedTargets::AllowList(list) => list.contains(&Warn(target)),
668+
AllowedTargets::AllowListWarnRest(list) => !list.contains(&Allow(target)),
665669
}
666670
}
667671
}

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,6 @@ passes_coroutine_on_non_closure =
7474
attribute should be applied to closures
7575
.label = not a closure
7676
77-
passes_coverage_attribute_not_allowed =
78-
coverage attribute not allowed here
79-
.not_fn_impl_mod = not a function, impl block, or module
80-
.no_body = function has no body
81-
.help = coverage attribute can be applied to a function (with body), impl block, or module
82-
8377
passes_dead_codes =
8478
{ $multiple ->
8579
*[true] multiple {$descr}s are
@@ -282,12 +276,6 @@ passes_feature_previously_declared =
282276
passes_feature_stable_twice =
283277
feature `{$feature}` is declared stable since {$since}, but was previously declared stable since {$prev_since}
284278
285-
passes_ffi_const_invalid_target =
286-
`#[ffi_const]` may only be used on foreign functions
287-
288-
passes_ffi_pure_invalid_target =
289-
`#[ffi_pure]` may only be used on foreign functions
290-
291279
passes_has_incoherent_inherent_impl =
292280
`rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits
293281
.label = only adts, extern types and traits are supported
@@ -386,21 +374,6 @@ passes_link =
386374
.warn = {-passes_previously_accepted}
387375
.label = not an `extern` block
388376
389-
passes_link_name =
390-
attribute should be applied to a foreign function or static
391-
.warn = {-passes_previously_accepted}
392-
.label = not a foreign function or static
393-
.help = try `#[link(name = "{$value}")]` instead
394-
395-
passes_link_ordinal =
396-
attribute should be applied to a foreign function or static
397-
.label = not a foreign function or static
398-
399-
passes_link_section =
400-
attribute should be applied to a function or static
401-
.warn = {-passes_previously_accepted}
402-
.label = not a function or static
403-
404377
passes_linkage =
405378
attribute should be applied to a function or static
406379
.label = not a function definition or static
@@ -416,9 +389,6 @@ passes_macro_export_on_decl_macro =
416389
`#[macro_export]` has no effect on declarative macro definitions
417390
.note = declarative macros follow the same exporting rules as regular items
418391
419-
passes_macro_use =
420-
`#[{$name}]` only has an effect on `extern crate` and modules
421-
422392
passes_may_dangle =
423393
`#[may_dangle]` must be applied to a lifetime or type generic parameter in `Drop` impl
424394
@@ -477,18 +447,6 @@ passes_no_main_function =
477447
.teach_note = If you don't know the basics of Rust, you can go look to the Rust Book to get started: https://doc.rust-lang.org/book/
478448
.non_function_main = non-function item at `crate::main` is found
479449
480-
passes_no_mangle =
481-
attribute should be applied to a free function, impl method or static
482-
.warn = {-passes_previously_accepted}
483-
.label = not a free function, impl method or static
484-
485-
passes_no_mangle_foreign =
486-
`#[no_mangle]` has no effect on a foreign {$foreign_item_kind}
487-
.warn = {-passes_previously_accepted}
488-
.label = foreign {$foreign_item_kind}
489-
.note = symbol names in extern blocks are not mangled
490-
.suggestion = remove this attribute
491-
492450
passes_no_sanitize =
493451
`#[no_sanitize({$attr_str})]` should be applied to {$accepted_kind}
494452
.label = not {$accepted_kind}
@@ -528,10 +486,6 @@ passes_parent_info =
528486
*[other] {$descr}s
529487
} in this {$parent_descr}
530488
531-
passes_pass_by_value =
532-
`pass_by_value` attribute should be applied to a struct, enum or type alias
533-
.label = is not a struct, enum or type alias
534-
535489
passes_proc_macro_bad_sig = {$kind} has incorrect signature
536490
537491
passes_remove_fields =
@@ -571,10 +525,6 @@ passes_rustc_force_inline_coro =
571525
attribute cannot be applied to a `async`, `gen` or `async gen` function
572526
.label = `async`, `gen` or `async gen` function
573527
574-
passes_rustc_layout_scalar_valid_range_not_struct =
575-
attribute should be applied to a struct
576-
.label = not a struct
577-
578528
passes_rustc_legacy_const_generics_index =
579529
#[rustc_legacy_const_generics] must have one index for each generic parameter
580530
.label = generic parameters
@@ -608,14 +558,6 @@ passes_rustc_pub_transparent =
608558
attribute should be applied to `#[repr(transparent)]` types
609559
.label = not a `#[repr(transparent)]` type
610560
611-
passes_rustc_std_internal_symbol =
612-
attribute should be applied to functions or statics
613-
.label = not a function or static
614-
615-
passes_rustc_unstable_feature_bound =
616-
attribute should be applied to `impl` or free function outside of any `impl` or trait
617-
.label = not an `impl` or free function
618-
619561
passes_should_be_applied_to_fn =
620562
attribute should be applied to a function definition
621563
.label = {$on_crate ->
@@ -757,11 +699,6 @@ passes_unused_variable_try_prefix = unused variable: `{$name}`
757699
.label = unused variable
758700
.suggestion = if this is intentional, prefix it with an underscore
759701
760-
761-
passes_used_static =
762-
attribute must be applied to a `static` variable
763-
.label = but this is a {$target}
764-
765702
passes_useless_assignment =
766703
useless assignment of {$is_field_assign ->
767704
[true] field

0 commit comments

Comments
 (0)