Skip to content

Commit ce50e42

Browse files
committed
Use the span of the attribute for the error message
1 parent d24a106 commit ce50e42

File tree

2 files changed

+84
-44
lines changed

2 files changed

+84
-44
lines changed

clippy_lints/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,11 +632,11 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
632632
if attr.check_name(sym!(cfg));
633633
if let Some(list) = attr.meta_item_list();
634634
let mismatched = find_mismatched_target_os(&list);
635-
if let Some((_, span)) = mismatched.iter().peekable().peek();
635+
if !mismatched.is_empty();
636636
then {
637637
let mess = "operating system used in target family position";
638638

639-
span_lint_and_then(cx, MISMATCHED_TARGET_OS, *span, &mess, |diag| {
639+
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, &mess, |diag| {
640640
// Avoid showing the unix suggestion multiple times in case
641641
// we have more than one mismatch for unix-like systems
642642
let mut unix_suggested = false;

tests/ui/mismatched_target_os.stderr

Lines changed: 82 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,201 @@
11
error: operating system used in target family position
2-
--> $DIR/mismatched_target_os.rs:8:7
2+
--> $DIR/mismatched_target_os.rs:8:1
33
|
44
LL | #[cfg(linux)]
5-
| ^^^^^ help: try: `target_os = "linux"`
5+
| ^^^^^^-----^^
6+
| |
7+
| help: try: `target_os = "linux"`
68
|
79
= note: `-D clippy::mismatched-target-os` implied by `-D warnings`
810
= help: Did you mean `unix`?
911

1012
error: operating system used in target family position
11-
--> $DIR/mismatched_target_os.rs:11:7
13+
--> $DIR/mismatched_target_os.rs:11:1
1214
|
1315
LL | #[cfg(freebsd)]
14-
| ^^^^^^^ help: try: `target_os = "freebsd"`
16+
| ^^^^^^-------^^
17+
| |
18+
| help: try: `target_os = "freebsd"`
1519
|
1620
= help: Did you mean `unix`?
1721

1822
error: operating system used in target family position
19-
--> $DIR/mismatched_target_os.rs:14:7
23+
--> $DIR/mismatched_target_os.rs:14:1
2024
|
2125
LL | #[cfg(dragonfly)]
22-
| ^^^^^^^^^ help: try: `target_os = "dragonfly"`
26+
| ^^^^^^---------^^
27+
| |
28+
| help: try: `target_os = "dragonfly"`
2329
|
2430
= help: Did you mean `unix`?
2531

2632
error: operating system used in target family position
27-
--> $DIR/mismatched_target_os.rs:17:7
33+
--> $DIR/mismatched_target_os.rs:17:1
2834
|
2935
LL | #[cfg(openbsd)]
30-
| ^^^^^^^ help: try: `target_os = "openbsd"`
36+
| ^^^^^^-------^^
37+
| |
38+
| help: try: `target_os = "openbsd"`
3139
|
3240
= help: Did you mean `unix`?
3341

3442
error: operating system used in target family position
35-
--> $DIR/mismatched_target_os.rs:20:7
43+
--> $DIR/mismatched_target_os.rs:20:1
3644
|
3745
LL | #[cfg(netbsd)]
38-
| ^^^^^^ help: try: `target_os = "netbsd"`
46+
| ^^^^^^------^^
47+
| |
48+
| help: try: `target_os = "netbsd"`
3949
|
4050
= help: Did you mean `unix`?
4151

4252
error: operating system used in target family position
43-
--> $DIR/mismatched_target_os.rs:23:7
53+
--> $DIR/mismatched_target_os.rs:23:1
4454
|
4555
LL | #[cfg(macos)]
46-
| ^^^^^ help: try: `target_os = "macos"`
56+
| ^^^^^^-----^^
57+
| |
58+
| help: try: `target_os = "macos"`
4759
|
4860
= help: Did you mean `unix`?
4961

5062
error: operating system used in target family position
51-
--> $DIR/mismatched_target_os.rs:26:7
63+
--> $DIR/mismatched_target_os.rs:26:1
5264
|
5365
LL | #[cfg(ios)]
54-
| ^^^ help: try: `target_os = "ios"`
66+
| ^^^^^^---^^
67+
| |
68+
| help: try: `target_os = "ios"`
5569
|
5670
= help: Did you mean `unix`?
5771

5872
error: operating system used in target family position
59-
--> $DIR/mismatched_target_os.rs:29:7
73+
--> $DIR/mismatched_target_os.rs:29:1
6074
|
6175
LL | #[cfg(android)]
62-
| ^^^^^^^ help: try: `target_os = "android"`
76+
| ^^^^^^-------^^
77+
| |
78+
| help: try: `target_os = "android"`
6379
|
6480
= help: Did you mean `unix`?
6581

6682
error: operating system used in target family position
67-
--> $DIR/mismatched_target_os.rs:32:7
83+
--> $DIR/mismatched_target_os.rs:32:1
6884
|
6985
LL | #[cfg(emscripten)]
70-
| ^^^^^^^^^^ help: try: `target_os = "emscripten"`
86+
| ^^^^^^----------^^
87+
| |
88+
| help: try: `target_os = "emscripten"`
7189
|
7290
= help: Did you mean `unix`?
7391

7492
error: operating system used in target family position
75-
--> $DIR/mismatched_target_os.rs:35:7
93+
--> $DIR/mismatched_target_os.rs:35:1
7694
|
7795
LL | #[cfg(fuchsia)]
78-
| ^^^^^^^ help: try: `target_os = "fuchsia"`
96+
| ^^^^^^-------^^
97+
| |
98+
| help: try: `target_os = "fuchsia"`
7999
|
80100
= help: Did you mean `unix`?
81101

82102
error: operating system used in target family position
83-
--> $DIR/mismatched_target_os.rs:38:7
103+
--> $DIR/mismatched_target_os.rs:38:1
84104
|
85105
LL | #[cfg(haiku)]
86-
| ^^^^^ help: try: `target_os = "haiku"`
106+
| ^^^^^^-----^^
107+
| |
108+
| help: try: `target_os = "haiku"`
87109
|
88110
= help: Did you mean `unix`?
89111

90112
error: operating system used in target family position
91-
--> $DIR/mismatched_target_os.rs:41:7
113+
--> $DIR/mismatched_target_os.rs:41:1
92114
|
93115
LL | #[cfg(illumos)]
94-
| ^^^^^^^ help: try: `target_os = "illumos"`
116+
| ^^^^^^-------^^
117+
| |
118+
| help: try: `target_os = "illumos"`
95119
|
96120
= help: Did you mean `unix`?
97121

98122
error: operating system used in target family position
99-
--> $DIR/mismatched_target_os.rs:44:7
123+
--> $DIR/mismatched_target_os.rs:44:1
100124
|
101125
LL | #[cfg(l4re)]
102-
| ^^^^ help: try: `target_os = "l4re"`
126+
| ^^^^^^----^^
127+
| |
128+
| help: try: `target_os = "l4re"`
103129
|
104130
= help: Did you mean `unix`?
105131

106132
error: operating system used in target family position
107-
--> $DIR/mismatched_target_os.rs:47:7
133+
--> $DIR/mismatched_target_os.rs:47:1
108134
|
109135
LL | #[cfg(redox)]
110-
| ^^^^^ help: try: `target_os = "redox"`
136+
| ^^^^^^-----^^
137+
| |
138+
| help: try: `target_os = "redox"`
111139
|
112140
= help: Did you mean `unix`?
113141

114142
error: operating system used in target family position
115-
--> $DIR/mismatched_target_os.rs:50:7
143+
--> $DIR/mismatched_target_os.rs:50:1
116144
|
117145
LL | #[cfg(solaris)]
118-
| ^^^^^^^ help: try: `target_os = "solaris"`
146+
| ^^^^^^-------^^
147+
| |
148+
| help: try: `target_os = "solaris"`
119149
|
120150
= help: Did you mean `unix`?
121151

122152
error: operating system used in target family position
123-
--> $DIR/mismatched_target_os.rs:53:7
153+
--> $DIR/mismatched_target_os.rs:53:1
124154
|
125155
LL | #[cfg(vxworks)]
126-
| ^^^^^^^ help: try: `target_os = "vxworks"`
156+
| ^^^^^^-------^^
157+
| |
158+
| help: try: `target_os = "vxworks"`
127159
|
128160
= help: Did you mean `unix`?
129161

130162
error: operating system used in target family position
131-
--> $DIR/mismatched_target_os.rs:58:7
163+
--> $DIR/mismatched_target_os.rs:58:1
132164
|
133165
LL | #[cfg(cloudabi)]
134-
| ^^^^^^^^ help: try: `target_os = "cloudabi"`
166+
| ^^^^^^--------^^
167+
| |
168+
| help: try: `target_os = "cloudabi"`
135169

136170
error: operating system used in target family position
137-
--> $DIR/mismatched_target_os.rs:61:7
171+
--> $DIR/mismatched_target_os.rs:61:1
138172
|
139173
LL | #[cfg(hermit)]
140-
| ^^^^^^ help: try: `target_os = "hermit"`
174+
| ^^^^^^------^^
175+
| |
176+
| help: try: `target_os = "hermit"`
141177

142178
error: operating system used in target family position
143-
--> $DIR/mismatched_target_os.rs:64:7
179+
--> $DIR/mismatched_target_os.rs:64:1
144180
|
145181
LL | #[cfg(wasi)]
146-
| ^^^^ help: try: `target_os = "wasi"`
182+
| ^^^^^^----^^
183+
| |
184+
| help: try: `target_os = "wasi"`
147185

148186
error: operating system used in target family position
149-
--> $DIR/mismatched_target_os.rs:67:7
187+
--> $DIR/mismatched_target_os.rs:67:1
150188
|
151189
LL | #[cfg(none)]
152-
| ^^^^ help: try: `target_os = "none"`
190+
| ^^^^^^----^^
191+
| |
192+
| help: try: `target_os = "none"`
153193

154194
error: operating system used in target family position
155-
--> $DIR/mismatched_target_os.rs:71:28
195+
--> $DIR/mismatched_target_os.rs:71:1
156196
|
157197
LL | #[cfg(all(not(any(windows, linux)), freebsd))]
158-
| ^^^^^
198+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
159199
|
160200
= help: Did you mean `unix`?
161201
help: try

0 commit comments

Comments
 (0)