Skip to content

Commit b59e743

Browse files
committed
Mark windows_subsytem and no_builtins as crate-only attributes.
These attributes are only checked at the crate root, so they should have a warning if they are used anywhere else.
1 parent 59d4bae commit b59e743

File tree

3 files changed

+123
-39
lines changed

3 files changed

+123
-39
lines changed

compiler/rustc_feature/src/builtin_attrs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
352352

353353
// Runtime
354354
ungated!(
355-
windows_subsystem, Normal,
355+
windows_subsystem, CrateLevel,
356356
template!(NameValueStr: "windows|console"), FutureWarnFollowing
357357
),
358358
ungated!(panic_handler, Normal, template!(Word), WarnFollowing), // RFC 2070
359359

360360
// Code generation:
361361
ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing),
362362
ungated!(cold, Normal, template!(Word), WarnFollowing),
363-
ungated!(no_builtins, Normal, template!(Word), WarnFollowing),
363+
ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing),
364364
ungated!(target_feature, Normal, template!(List: r#"enable = "name""#), DuplicatesOk),
365365
ungated!(track_caller, Normal, template!(Word), WarnFollowing),
366366
gated!(

src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.rs

+12
Original file line numberDiff line numberDiff line change
@@ -611,16 +611,22 @@ mod must_use {
611611
}
612612

613613
#[windows_subsystem = "windows"]
614+
//~^ WARN crate-level attribute should be an inner attribute
614615
mod windows_subsystem {
615616
mod inner { #![windows_subsystem="windows"] }
617+
//~^ WARN crate-level attribute should be in the root module
616618

617619
#[windows_subsystem = "windows"] fn f() { }
620+
//~^ WARN crate-level attribute should be an inner attribute
618621

619622
#[windows_subsystem = "windows"] struct S;
623+
//~^ WARN crate-level attribute should be an inner attribute
620624

621625
#[windows_subsystem = "windows"] type T = S;
626+
//~^ WARN crate-level attribute should be an inner attribute
622627

623628
#[windows_subsystem = "windows"] impl S { }
629+
//~^ WARN crate-level attribute should be an inner attribute
624630
}
625631

626632
// BROKEN USES OF CRATE-LEVEL BUILT-IN ATTRIBUTES
@@ -703,16 +709,22 @@ mod no_main_1 {
703709
}
704710

705711
#[no_builtins]
712+
//~^ WARN crate-level attribute should be an inner attribute
706713
mod no_builtins {
707714
mod inner { #![no_builtins] }
715+
//~^ WARN crate-level attribute should be in the root module
708716

709717
#[no_builtins] fn f() { }
718+
//~^ WARN crate-level attribute should be an inner attribute
710719

711720
#[no_builtins] struct S;
721+
//~^ WARN crate-level attribute should be an inner attribute
712722

713723
#[no_builtins] type T = S;
724+
//~^ WARN crate-level attribute should be an inner attribute
714725

715726
#[no_builtins] impl S { }
727+
//~^ WARN crate-level attribute should be an inner attribute
716728
}
717729

718730
#[recursion_limit="0200"]

src/test/ui/feature-gates/issue-43106-gating-of-builtin-attrs.stderr

+109-37
Original file line numberDiff line numberDiff line change
@@ -328,37 +328,49 @@ LL | | }
328328
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
329329

330330
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
331-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:628:1
331+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:613:1
332+
|
333+
LL | #[windows_subsystem = "windows"]
334+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
335+
336+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
337+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:634:1
332338
|
333339
LL | #[crate_name = "0900"]
334340
| ^^^^^^^^^^^^^^^^^^^^^^
335341

336342
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
337-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:647:1
343+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:653:1
338344
|
339345
LL | #[crate_type = "0800"]
340346
| ^^^^^^^^^^^^^^^^^^^^^^
341347

342348
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
343-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:666:1
349+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:672:1
344350
|
345351
LL | #[feature(x0600)]
346352
| ^^^^^^^^^^^^^^^^^
347353

348354
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
349-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:686:1
355+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:1
350356
|
351357
LL | #[no_main]
352358
| ^^^^^^^^^^
353359

354360
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
355-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:718:1
361+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:711:1
362+
|
363+
LL | #[no_builtins]
364+
| ^^^^^^^^^^^^^^
365+
366+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
367+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:730:1
356368
|
357369
LL | #[recursion_limit="0200"]
358370
| ^^^^^^^^^^^^^^^^^^^^^^^^^
359371

360372
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
361-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:737:1
373+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:749:1
362374
|
363375
LL | #[type_length_limit="0100"]
364376
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -880,181 +892,241 @@ LL | #[link()] impl S { }
880892
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
881893

882894
warning: crate-level attribute should be in the root module
883-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:631:17
895+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:616:17
896+
|
897+
LL | mod inner { #![windows_subsystem="windows"] }
898+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
899+
900+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
901+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:619:5
902+
|
903+
LL | #[windows_subsystem = "windows"] fn f() { }
904+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
905+
906+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
907+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:622:5
908+
|
909+
LL | #[windows_subsystem = "windows"] struct S;
910+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
911+
912+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
913+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:625:5
914+
|
915+
LL | #[windows_subsystem = "windows"] type T = S;
916+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
917+
918+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
919+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:628:5
920+
|
921+
LL | #[windows_subsystem = "windows"] impl S { }
922+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
923+
924+
warning: crate-level attribute should be in the root module
925+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:637:17
884926
|
885927
LL | mod inner { #![crate_name="0900"] }
886928
| ^^^^^^^^^^^^^^^^^^^^^
887929

888930
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
889-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:634:5
931+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:640:5
890932
|
891933
LL | #[crate_name = "0900"] fn f() { }
892934
| ^^^^^^^^^^^^^^^^^^^^^^
893935

894936
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
895-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:637:5
937+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:643:5
896938
|
897939
LL | #[crate_name = "0900"] struct S;
898940
| ^^^^^^^^^^^^^^^^^^^^^^
899941

900942
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
901-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:640:5
943+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:646:5
902944
|
903945
LL | #[crate_name = "0900"] type T = S;
904946
| ^^^^^^^^^^^^^^^^^^^^^^
905947

906948
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
907-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:643:5
949+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:649:5
908950
|
909951
LL | #[crate_name = "0900"] impl S { }
910952
| ^^^^^^^^^^^^^^^^^^^^^^
911953

912954
warning: crate-level attribute should be in the root module
913-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:650:17
955+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:656:17
914956
|
915957
LL | mod inner { #![crate_type="0800"] }
916958
| ^^^^^^^^^^^^^^^^^^^^^
917959

918960
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
919-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:653:5
961+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:659:5
920962
|
921963
LL | #[crate_type = "0800"] fn f() { }
922964
| ^^^^^^^^^^^^^^^^^^^^^^
923965

924966
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
925-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:656:5
967+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:662:5
926968
|
927969
LL | #[crate_type = "0800"] struct S;
928970
| ^^^^^^^^^^^^^^^^^^^^^^
929971

930972
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
931-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:659:5
973+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:665:5
932974
|
933975
LL | #[crate_type = "0800"] type T = S;
934976
| ^^^^^^^^^^^^^^^^^^^^^^
935977

936978
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
937-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:662:5
979+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:668:5
938980
|
939981
LL | #[crate_type = "0800"] impl S { }
940982
| ^^^^^^^^^^^^^^^^^^^^^^
941983

942984
warning: crate-level attribute should be in the root module
943-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:669:17
985+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:675:17
944986
|
945987
LL | mod inner { #![feature(x0600)] }
946988
| ^^^^^^^^^^^^^^^^^^
947989

948990
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
949-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:672:5
991+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:678:5
950992
|
951993
LL | #[feature(x0600)] fn f() { }
952994
| ^^^^^^^^^^^^^^^^^
953995

954996
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
955-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:675:5
997+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:681:5
956998
|
957999
LL | #[feature(x0600)] struct S;
9581000
| ^^^^^^^^^^^^^^^^^
9591001

9601002
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
961-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:678:5
1003+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:684:5
9621004
|
9631005
LL | #[feature(x0600)] type T = S;
9641006
| ^^^^^^^^^^^^^^^^^
9651007

9661008
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
967-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:681:5
1009+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:687:5
9681010
|
9691011
LL | #[feature(x0600)] impl S { }
9701012
| ^^^^^^^^^^^^^^^^^
9711013

9721014
warning: crate-level attribute should be in the root module
973-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:689:17
1015+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:695:17
9741016
|
9751017
LL | mod inner { #![no_main] }
9761018
| ^^^^^^^^^^^
9771019

9781020
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
979-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:692:5
1021+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:698:5
9801022
|
9811023
LL | #[no_main] fn f() { }
9821024
| ^^^^^^^^^^
9831025

9841026
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
985-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:695:5
1027+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:701:5
9861028
|
9871029
LL | #[no_main] struct S;
9881030
| ^^^^^^^^^^
9891031

9901032
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
991-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:698:5
1033+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:704:5
9921034
|
9931035
LL | #[no_main] type T = S;
9941036
| ^^^^^^^^^^
9951037

9961038
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
997-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:701:5
1039+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:707:5
9981040
|
9991041
LL | #[no_main] impl S { }
10001042
| ^^^^^^^^^^
10011043

10021044
warning: crate-level attribute should be in the root module
1003-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:721:17
1045+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:714:17
1046+
|
1047+
LL | mod inner { #![no_builtins] }
1048+
| ^^^^^^^^^^^^^^^
1049+
1050+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1051+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:717:5
1052+
|
1053+
LL | #[no_builtins] fn f() { }
1054+
| ^^^^^^^^^^^^^^
1055+
1056+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1057+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:720:5
1058+
|
1059+
LL | #[no_builtins] struct S;
1060+
| ^^^^^^^^^^^^^^
1061+
1062+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1063+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:723:5
1064+
|
1065+
LL | #[no_builtins] type T = S;
1066+
| ^^^^^^^^^^^^^^
1067+
1068+
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1069+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:726:5
1070+
|
1071+
LL | #[no_builtins] impl S { }
1072+
| ^^^^^^^^^^^^^^
1073+
1074+
warning: crate-level attribute should be in the root module
1075+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:733:17
10041076
|
10051077
LL | mod inner { #![recursion_limit="0200"] }
10061078
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
10071079

10081080
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1009-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:724:5
1081+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:736:5
10101082
|
10111083
LL | #[recursion_limit="0200"] fn f() { }
10121084
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10131085

10141086
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1015-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:727:5
1087+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:739:5
10161088
|
10171089
LL | #[recursion_limit="0200"] struct S;
10181090
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10191091

10201092
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1021-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:730:5
1093+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:742:5
10221094
|
10231095
LL | #[recursion_limit="0200"] type T = S;
10241096
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10251097

10261098
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1027-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:733:5
1099+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:745:5
10281100
|
10291101
LL | #[recursion_limit="0200"] impl S { }
10301102
| ^^^^^^^^^^^^^^^^^^^^^^^^^
10311103

10321104
warning: crate-level attribute should be in the root module
1033-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:740:17
1105+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:752:17
10341106
|
10351107
LL | mod inner { #![type_length_limit="0100"] }
10361108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10371109

10381110
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1039-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:743:5
1111+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:755:5
10401112
|
10411113
LL | #[type_length_limit="0100"] fn f() { }
10421114
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10431115

10441116
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1045-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:746:5
1117+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:758:5
10461118
|
10471119
LL | #[type_length_limit="0100"] struct S;
10481120
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10491121

10501122
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1051-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:749:5
1123+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:761:5
10521124
|
10531125
LL | #[type_length_limit="0100"] type T = S;
10541126
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10551127

10561128
warning: crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
1057-
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:752:5
1129+
--> $DIR/issue-43106-gating-of-builtin-attrs.rs:764:5
10581130
|
10591131
LL | #[type_length_limit="0100"] impl S { }
10601132
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -1067,5 +1139,5 @@ LL | #![feature(rust1)]
10671139
|
10681140
= note: `#[warn(stable_features)]` on by default
10691141

1070-
warning: 155 warnings emitted
1142+
warning: 167 warnings emitted
10711143

0 commit comments

Comments
 (0)