Skip to content

Commit b2bf163

Browse files
committed
Auto merge of #43726 - zackmdavis:extended_information_summer_block_party, r=GuillaumeGomez
E05XX odyssey chipping away at the surface exposed by #43709 r? @GuillaumeGomez
2 parents c2de81f + 116bf07 commit b2bf163

File tree

3 files changed

+92
-5
lines changed

3 files changed

+92
-5
lines changed

src/librustc_passes/diagnostics.rs

+34-1
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,45 @@ To fix this, add a label specifying which loop is being broken out of:
223223
```
224224
'foo: while break 'foo {}
225225
```
226+
"##,
227+
228+
E0571: r##"
229+
A `break` statement with an argument appeared in a non-`loop` loop.
230+
231+
Example of erroneous code:
232+
233+
```compile_fail,E0571
234+
# let mut i = 1;
235+
# fn satisfied(n: usize) -> bool { n % 23 == 0 }
236+
let result = while true {
237+
if satisfied(i) {
238+
break 2*i; // error: `break` with value from a `while` loop
239+
}
240+
i += 1;
241+
};
242+
```
243+
244+
The `break` statement can take an argument (which will be the value of the loop
245+
expression if the `break` statement is executed) in `loop` loops, but not
246+
`for`, `while`, or `while let` loops.
247+
248+
Make sure `break value;` statements only occur in `loop` loops:
249+
250+
```
251+
# let mut i = 1;
252+
# fn satisfied(n: usize) -> bool { n % 23 == 0 }
253+
let result = loop { // ok!
254+
if satisfied(i) {
255+
break 2*i;
256+
}
257+
i += 1;
258+
};
259+
```
226260
"##
227261
}
228262

229263
register_diagnostics! {
230264
E0226, // only a single explicit lifetime bound is permitted
231265
E0472, // asm! is unsupported on this target
232266
E0561, // patterns aren't allowed in function pointer types
233-
E0571, // `break` with a value in a non-`loop`-loop
234267
}

src/libsyntax/diagnostic_list.rs

+57-3
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,63 @@ For more information about the cfg attribute, read:
162162
https://doc.rust-lang.org/reference.html#conditional-compilation
163163
"##,
164164

165+
E0552: r##"
166+
A unrecognized representation attribute was used.
167+
168+
Erroneous code example:
169+
170+
```compile_fail,E0552
171+
#[repr(D)] // error: unrecognized representation hint
172+
struct MyStruct {
173+
my_field: usize
174+
}
175+
```
176+
177+
You can use a `repr` attribute to tell the compiler how you want a struct or
178+
enum to be laid out in memory.
179+
180+
Make sure you're using one of the supported options:
181+
182+
```
183+
#[repr(C)] // ok!
184+
struct MyStruct {
185+
my_field: usize
186+
}
187+
```
188+
189+
For more information about specifying representations, see the ["Alternative
190+
Representations" section] of the Rustonomicon.
191+
192+
["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html
193+
"##,
194+
195+
E0554: r##"
196+
Feature attributes are only allowed on the nightly release channel. Stable or
197+
beta compilers will not comply.
198+
199+
Example of erroneous code (on a stable compiler):
200+
201+
```ignore (depends on release channel)
202+
#![feature(non_ascii_idents)] // error: #![feature] may not be used on the
203+
// stable release channel
204+
```
205+
206+
If you need the feature, make sure to use a nightly release of the compiler
207+
(but be warned that the feature may be removed or altered in the future).
208+
"##,
209+
210+
E0557: r##"
211+
A feature attribute named a feature that has been removed.
212+
213+
Erroneous code example:
214+
215+
```compile_fail,E0557
216+
#![feature(managed_boxes)] // error: feature has been removed
217+
```
218+
219+
Delete the offending feature attribute.
220+
"##,
221+
165222
E0558: r##"
166223
The `export_name` attribute was malformed.
167224
@@ -300,11 +357,8 @@ register_diagnostics! {
300357
E0549, // rustc_deprecated attribute must be paired with either stable or unstable attribute
301358
E0550, // multiple deprecated attributes
302359
E0551, // incorrect meta item
303-
E0552, // unrecognized representation hint
304-
E0554, // #[feature] may not be used on the [] release channel
305360
E0555, // malformed feature attribute, expected #![feature(...)]
306361
E0556, // malformed feature, expected just one word
307-
E0557, // feature has been removed
308362
E0584, // file for module `..` found at both .. and ..
309363
E0589, // invalid `repr(align)` attribute
310364
}

src/libsyntax/feature_gate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ fn maybe_stage_features(span_handler: &Handler, krate: &ast::Crate,
16021602
if attr.check_name("feature") {
16031603
let release_channel = option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)");
16041604
span_err!(span_handler, attr.span, E0554,
1605-
"#[feature] may not be used on the {} release channel",
1605+
"#![feature] may not be used on the {} release channel",
16061606
release_channel);
16071607
}
16081608
}

0 commit comments

Comments
 (0)