Skip to content

Commit 4f24b61

Browse files
authored
Rollup merge of #147445 - jdonszelmann:sort-targets, r=JonathanBrouwer
sort attribute targets for more consistent error messages In this PR I noticed that we don't sort attribute targets, so a rather trivial change to the source changed the ordering in an error message even though its meaning stayed the same. See: #147418 (comment) I think sorting might be a good thing to do in general. I also prefer it when reading error messages. Quite a few tests changed, but not in meaning, only sorting order obviously. r? `@jieyouxu`
2 parents 27b3881 + 1dbe831 commit 4f24b61

21 files changed

+114
-110
lines changed

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,20 @@ pub(crate) fn allowed_targets_applied(
198198
filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets);
199199
filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets);
200200

201+
let mut target_strings: Vec<_> = added_fake_targets
202+
.iter()
203+
.copied()
204+
.chain(allowed_targets.iter().map(|t| t.plural_name()))
205+
.map(|i| i.to_string())
206+
.collect();
207+
208+
// ensure a consistent order
209+
target_strings.sort();
210+
201211
// If there is now only 1 target left, show that as the only possible target
202-
(
203-
added_fake_targets
204-
.iter()
205-
.copied()
206-
.chain(allowed_targets.iter().map(|t| t.plural_name()))
207-
.map(|i| i.to_string())
208-
.collect(),
209-
allowed_targets.len() + added_fake_targets.len() == 1,
210-
)
212+
let only_target = target_strings.len() == 1;
213+
214+
(target_strings, only_target)
211215
}
212216

213217
fn filter_targets(

tests/ui/asm/naked-invalid-attr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error: `#[naked]` attribute cannot be used on foreign functions
1818
LL | #[unsafe(naked)]
1919
| ^^^^^^^^^^^^^^^^
2020
|
21-
= help: `#[naked]` can be applied to methods and functions
21+
= help: `#[naked]` can be applied to functions and methods
2222

2323
error: `#[naked]` attribute cannot be used on structs
2424
--> $DIR/naked-invalid-attr.rs:13:1
@@ -50,7 +50,7 @@ error: `#[naked]` attribute cannot be used on closures
5050
LL | #[unsafe(naked)]
5151
| ^^^^^^^^^^^^^^^^
5252
|
53-
= help: `#[naked]` can be applied to methods and functions
53+
= help: `#[naked]` can be applied to functions and methods
5454

5555
error[E0736]: attribute incompatible with `#[unsafe(naked)]`
5656
--> $DIR/naked-invalid-attr.rs:56:3

tests/ui/attributes/attr-on-mac-call.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | #[deprecated]
5555
| ^^^^^^^^^^^^^
5656
|
5757
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
58-
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
58+
= help: `#[deprecated]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, unions, and use statements
5959

6060
warning: `#[inline]` attribute cannot be used on macro calls
6161
--> $DIR/attr-on-mac-call.rs:24:5
@@ -136,7 +136,7 @@ LL | #[deprecated]
136136
| ^^^^^^^^^^^^^
137137
|
138138
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
139-
= help: `#[deprecated]` can be applied to functions, data types, modules, unions, constants, statics, macro defs, type aliases, use statements, foreign statics, struct fields, traits, associated types, associated consts, enum variants, inherent impl blocks, and crates
139+
= help: `#[deprecated]` can be applied to associated consts, associated types, constants, crates, data types, enum variants, foreign statics, functions, inherent impl blocks, macro defs, modules, statics, struct fields, traits, type aliases, unions, and use statements
140140

141141
warning: `#[automatically_derived]` attribute cannot be used on macro calls
142142
--> $DIR/attr-on-mac-call.rs:51:5
@@ -154,7 +154,7 @@ LL | #[macro_use]
154154
| ^^^^^^^^^^^^
155155
|
156156
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
157-
= help: `#[macro_use]` can be applied to modules, extern crates, and crates
157+
= help: `#[macro_use]` can be applied to crates, extern crates, and modules
158158

159159
warning: `#[must_use]` attribute cannot be used on macro calls
160160
--> $DIR/attr-on-mac-call.rs:57:5
@@ -163,7 +163,7 @@ LL | #[must_use]
163163
| ^^^^^^^^^^^
164164
|
165165
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
166-
= help: `#[must_use]` can be applied to functions, data types, unions, and traits
166+
= help: `#[must_use]` can be applied to data types, functions, traits, and unions
167167

168168
warning: `#[no_implicit_prelude]` attribute cannot be used on macro calls
169169
--> $DIR/attr-on-mac-call.rs:60:5
@@ -172,7 +172,7 @@ LL | #[no_implicit_prelude]
172172
| ^^^^^^^^^^^^^^^^^^^^^^
173173
|
174174
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
175-
= help: `#[no_implicit_prelude]` can be applied to modules and crates
175+
= help: `#[no_implicit_prelude]` can be applied to crates and modules
176176

177177
warning: `#[path]` attribute cannot be used on macro calls
178178
--> $DIR/attr-on-mac-call.rs:63:5

tests/ui/attributes/linkage.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,47 @@ error: `#[linkage]` attribute cannot be used on type aliases
44
LL | #[linkage = "weak"]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= help: `#[linkage]` can be applied to functions, statics, and foreign statics
7+
= help: `#[linkage]` can be applied to foreign statics, functions, and statics
88

99
error: `#[linkage]` attribute cannot be used on modules
1010
--> $DIR/linkage.rs:9:1
1111
|
1212
LL | #[linkage = "weak"]
1313
| ^^^^^^^^^^^^^^^^^^^
1414
|
15-
= help: `#[linkage]` can be applied to functions, statics, and foreign statics
15+
= help: `#[linkage]` can be applied to foreign statics, functions, and statics
1616

1717
error: `#[linkage]` attribute cannot be used on structs
1818
--> $DIR/linkage.rs:12:1
1919
|
2020
LL | #[linkage = "weak"]
2121
| ^^^^^^^^^^^^^^^^^^^
2222
|
23-
= help: `#[linkage]` can be applied to functions, statics, and foreign statics
23+
= help: `#[linkage]` can be applied to foreign statics, functions, and statics
2424

2525
error: `#[linkage]` attribute cannot be used on inherent impl blocks
2626
--> $DIR/linkage.rs:15:1
2727
|
2828
LL | #[linkage = "weak"]
2929
| ^^^^^^^^^^^^^^^^^^^
3030
|
31-
= help: `#[linkage]` can be applied to functions, statics, and foreign statics
31+
= help: `#[linkage]` can be applied to foreign statics, functions, and statics
3232

3333
error: `#[linkage]` attribute cannot be used on expressions
3434
--> $DIR/linkage.rs:23:5
3535
|
3636
LL | #[linkage = "weak"]
3737
| ^^^^^^^^^^^^^^^^^^^
3838
|
39-
= help: `#[linkage]` can be applied to functions, statics, and foreign statics
39+
= help: `#[linkage]` can be applied to foreign statics, functions, and statics
4040

4141
error: `#[linkage]` attribute cannot be used on closures
4242
--> $DIR/linkage.rs:39:13
4343
|
4444
LL | let _ = #[linkage = "weak"]
4545
| ^^^^^^^^^^^^^^^^^^^
4646
|
47-
= help: `#[linkage]` can be applied to methods, functions, statics, foreign statics, and foreign functions
47+
= help: `#[linkage]` can be applied to foreign functions, foreign statics, functions, methods, and statics
4848

4949
error: aborting due to 6 previous errors
5050

tests/ui/attributes/malformed-static-align.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ error: `#[rustc_align_static]` attribute cannot be used on structs
2525
LL | #[rustc_align_static(16)]
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2727
|
28-
= help: `#[rustc_align_static]` can be applied to statics and foreign statics
28+
= help: `#[rustc_align_static]` can be applied to foreign statics and statics
2929

3030
error: `#[repr(align(...))]` is not supported on statics
3131
--> $DIR/malformed-static-align.rs:13:8

tests/ui/coverage-attr/allowed-positions.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,135 +14,135 @@ error: `#[coverage]` attribute cannot be used on type aliases
1414
LL | #[coverage(off)]
1515
| ^^^^^^^^^^^^^^^^
1616
|
17-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
17+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
1818

1919
error: `#[coverage]` attribute cannot be used on traits
2020
--> $DIR/allowed-positions.rs:17:1
2121
|
2222
LL | #[coverage(off)]
2323
| ^^^^^^^^^^^^^^^^
2424
|
25-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
25+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
2626

2727
error: `#[coverage]` attribute cannot be used on associated consts
2828
--> $DIR/allowed-positions.rs:19:5
2929
|
3030
LL | #[coverage(off)]
3131
| ^^^^^^^^^^^^^^^^
3232
|
33-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
33+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
3434

3535
error: `#[coverage]` attribute cannot be used on associated types
3636
--> $DIR/allowed-positions.rs:22:5
3737
|
3838
LL | #[coverage(off)]
3939
| ^^^^^^^^^^^^^^^^
4040
|
41-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
41+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
4242

4343
error: `#[coverage]` attribute cannot be used on required trait methods
4444
--> $DIR/allowed-positions.rs:25:5
4545
|
4646
LL | #[coverage(off)]
4747
| ^^^^^^^^^^^^^^^^
4848
|
49-
= help: `#[coverage]` can be applied to impl blocks, functions, closures, provided trait methods, trait methods in impl blocks, inherent methods, modules, and crates
49+
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks
5050

5151
error: `#[coverage]` attribute cannot be used on required trait methods
5252
--> $DIR/allowed-positions.rs:31:5
5353
|
5454
LL | #[coverage(off)]
5555
| ^^^^^^^^^^^^^^^^
5656
|
57-
= help: `#[coverage]` can be applied to impl blocks, functions, closures, provided trait methods, trait methods in impl blocks, inherent methods, modules, and crates
57+
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, inherent methods, modules, provided trait methods, and trait methods in impl blocks
5858

5959
error: `#[coverage]` attribute cannot be used on associated types
6060
--> $DIR/allowed-positions.rs:39:5
6161
|
6262
LL | #[coverage(off)]
6363
| ^^^^^^^^^^^^^^^^
6464
|
65-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
65+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
6666

6767
error: `#[coverage]` attribute cannot be used on associated types
6868
--> $DIR/allowed-positions.rs:56:5
6969
|
7070
LL | #[coverage(off)]
7171
| ^^^^^^^^^^^^^^^^
7272
|
73-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
73+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
7474

7575
error: `#[coverage]` attribute cannot be used on structs
7676
--> $DIR/allowed-positions.rs:61:1
7777
|
7878
LL | #[coverage(off)]
7979
| ^^^^^^^^^^^^^^^^
8080
|
81-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
81+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
8282

8383
error: `#[coverage]` attribute cannot be used on struct fields
8484
--> $DIR/allowed-positions.rs:63:5
8585
|
8686
LL | #[coverage(off)]
8787
| ^^^^^^^^^^^^^^^^
8888
|
89-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
89+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
9090

9191
error: `#[coverage]` attribute cannot be used on foreign statics
9292
--> $DIR/allowed-positions.rs:76:5
9393
|
9494
LL | #[coverage(off)]
9595
| ^^^^^^^^^^^^^^^^
9696
|
97-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
97+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
9898

9999
error: `#[coverage]` attribute cannot be used on foreign types
100100
--> $DIR/allowed-positions.rs:79:5
101101
|
102102
LL | #[coverage(off)]
103103
| ^^^^^^^^^^^^^^^^
104104
|
105-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
105+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
106106

107107
error: `#[coverage]` attribute cannot be used on foreign functions
108108
--> $DIR/allowed-positions.rs:82:5
109109
|
110110
LL | #[coverage(off)]
111111
| ^^^^^^^^^^^^^^^^
112112
|
113-
= help: `#[coverage]` can be applied to methods, impl blocks, functions, closures, modules, and crates
113+
= help: `#[coverage]` can be applied to closures, crates, functions, impl blocks, methods, and modules
114114

115115
error: `#[coverage]` attribute cannot be used on statements
116116
--> $DIR/allowed-positions.rs:88:5
117117
|
118118
LL | #[coverage(off)]
119119
| ^^^^^^^^^^^^^^^^
120120
|
121-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
121+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
122122

123123
error: `#[coverage]` attribute cannot be used on statements
124124
--> $DIR/allowed-positions.rs:94:5
125125
|
126126
LL | #[coverage(off)]
127127
| ^^^^^^^^^^^^^^^^
128128
|
129-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
129+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
130130

131131
error: `#[coverage]` attribute cannot be used on match arms
132132
--> $DIR/allowed-positions.rs:110:9
133133
|
134134
LL | #[coverage(off)]
135135
| ^^^^^^^^^^^^^^^^
136136
|
137-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
137+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
138138

139139
error: `#[coverage]` attribute cannot be used on expressions
140140
--> $DIR/allowed-positions.rs:114:5
141141
|
142142
LL | #[coverage(off)]
143143
| ^^^^^^^^^^^^^^^^
144144
|
145-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
145+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
146146

147147
error: aborting due to 18 previous errors
148148

tests/ui/coverage-attr/name-value.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ error: `#[coverage]` attribute cannot be used on structs
4949
LL | #[coverage = "off"]
5050
| ^^^^^^^^^^^^^^^^^^^
5151
|
52-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
52+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
5353

5454
error[E0539]: malformed `coverage` attribute input
5555
--> $DIR/name-value.rs:26:1
@@ -87,7 +87,7 @@ error: `#[coverage]` attribute cannot be used on associated consts
8787
LL | #[coverage = "off"]
8888
| ^^^^^^^^^^^^^^^^^^^
8989
|
90-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
90+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
9191

9292
error[E0539]: malformed `coverage` attribute input
9393
--> $DIR/name-value.rs:35:1
@@ -110,7 +110,7 @@ error: `#[coverage]` attribute cannot be used on traits
110110
LL | #[coverage = "off"]
111111
| ^^^^^^^^^^^^^^^^^^^
112112
|
113-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
113+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
114114

115115
error[E0539]: malformed `coverage` attribute input
116116
--> $DIR/name-value.rs:39:5
@@ -133,7 +133,7 @@ error: `#[coverage]` attribute cannot be used on associated consts
133133
LL | #[coverage = "off"]
134134
| ^^^^^^^^^^^^^^^^^^^
135135
|
136-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
136+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
137137

138138
error[E0539]: malformed `coverage` attribute input
139139
--> $DIR/name-value.rs:44:5
@@ -156,7 +156,7 @@ error: `#[coverage]` attribute cannot be used on associated types
156156
LL | #[coverage = "off"]
157157
| ^^^^^^^^^^^^^^^^^^^
158158
|
159-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
159+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
160160

161161
error[E0539]: malformed `coverage` attribute input
162162
--> $DIR/name-value.rs:50:1
@@ -194,7 +194,7 @@ error: `#[coverage]` attribute cannot be used on associated consts
194194
LL | #[coverage = "off"]
195195
| ^^^^^^^^^^^^^^^^^^^
196196
|
197-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
197+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
198198

199199
error[E0539]: malformed `coverage` attribute input
200200
--> $DIR/name-value.rs:58:5
@@ -217,7 +217,7 @@ error: `#[coverage]` attribute cannot be used on associated types
217217
LL | #[coverage = "off"]
218218
| ^^^^^^^^^^^^^^^^^^^
219219
|
220-
= help: `#[coverage]` can be applied to functions, impl blocks, modules, and crates
220+
= help: `#[coverage]` can be applied to crates, functions, impl blocks, and modules
221221

222222
error[E0539]: malformed `coverage` attribute input
223223
--> $DIR/name-value.rs:64:1

0 commit comments

Comments
 (0)