Skip to content

Commit c894630

Browse files
Rollup merge of rust-lang#108444 - Ezrashaw:add-test+docs-for-e0476, r=GuillaumeGomez
docs/test: add UI test and docs for `E0476` Final undocumented error code. Not entirely sure about wording in the docs. Part of rust-lang#61137. r? `@compiler-errors` cc `@compiler-errors`
2 parents ec85ac5 + 3b51e9f commit c894630

File tree

6 files changed

+68
-3
lines changed

6 files changed

+68
-3
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ E0466: include_str!("./error_codes/E0466.md"),
253253
E0468: include_str!("./error_codes/E0468.md"),
254254
E0469: include_str!("./error_codes/E0469.md"),
255255
E0472: include_str!("./error_codes/E0472.md"),
256+
E0476: include_str!("./error_codes/E0476.md"),
256257
E0477: include_str!("./error_codes/E0477.md"),
257258
E0478: include_str!("./error_codes/E0478.md"),
258259
E0482: include_str!("./error_codes/E0482.md"),
@@ -611,7 +612,6 @@ E0793: include_str!("./error_codes/E0793.md"),
611612
// E0473, // dereference of reference outside its lifetime
612613
// E0474, // captured variable `..` does not outlive the enclosing closure
613614
// E0475, // index of slice outside its lifetime
614-
E0476, // lifetime of the source pointer does not outlive lifetime bound...
615615
// E0479, // the type `..` (provided as the value of a type parameter) is...
616616
// E0480, // lifetime of method receiver does not outlive the method call
617617
// E0481, // lifetime of function argument does not outlive the function call
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The coerced type does not outlive the value being coerced to.
2+
3+
Example of erroneous code:
4+
5+
```compile_fail,E0476
6+
#![feature(coerce_unsized)]
7+
#![feature(unsize)]
8+
9+
use std::marker::Unsize;
10+
use std::ops::CoerceUnsized;
11+
12+
// error: lifetime of the source pointer does not outlive lifetime bound of the
13+
// object type
14+
impl<'a, 'b, T, S> CoerceUnsized<&'a T> for &'b S where S: Unsize<T> {}
15+
```
16+
17+
During a coercion, the "source pointer" (the coerced type) did not outlive the
18+
"object type" (value being coerced to). In the above example, `'b` is not a
19+
subtype of `'a`. This error can currently only be encountered with the unstable
20+
`CoerceUnsized` trait which allows custom coercions of unsized types behind a
21+
smart pointer to be implemented.

src/tools/error_index_generator/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ macro_rules! register_diagnostics {
2222
pub fn error_codes() -> Vec<(&'static str, Option<&'static str>)> {
2323
let mut errors: Vec<(&str, Option<&str>)> = vec![
2424
$((stringify!($error_code), Some($message)),)+
25-
$((stringify!($undocumented), None),)+
25+
$((stringify!($undocumented), None),)*
2626
];
2727
errors.sort();
2828
errors

src/tools/tidy/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E06
3131

3232
// Error codes that don't yet have a UI test. This list will eventually be removed.
3333
const IGNORE_UI_TEST_CHECK: &[&str] =
34-
&["E0461", "E0465", "E0476", "E0514", "E0554", "E0640", "E0717", "E0729"];
34+
&["E0461", "E0465", "E0514", "E0554", "E0640", "E0717", "E0729"];
3535

3636
macro_rules! verbose_print {
3737
($verbose:expr, $($fmt:tt)*) => {

tests/ui/error-codes/E0476.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(coerce_unsized)]
2+
#![feature(unsize)]
3+
4+
use std::marker::Unsize;
5+
use std::ops::CoerceUnsized;
6+
7+
struct Wrapper<T>(T);
8+
9+
impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
10+
//~^ ERROR lifetime of the source pointer does not outlive lifetime bound of the object type [E0476]
11+
//~^^ ERROR E0119
12+
13+
fn main() {}

tests/ui/error-codes/E0476.stderr

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
error[E0119]: conflicting implementations of trait `CoerceUnsized<&Wrapper<_>>` for type `&Wrapper<_>`
2+
--> $DIR/E0476.rs:9:1
3+
|
4+
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: conflicting implementation in crate `core`:
8+
- impl<'a, 'b, T, U> CoerceUnsized<&'a U> for &'b T
9+
where 'b: 'a, T: Unsize<U>, T: ?Sized, U: ?Sized;
10+
11+
error[E0476]: lifetime of the source pointer does not outlive lifetime bound of the object type
12+
--> $DIR/E0476.rs:9:1
13+
|
14+
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
|
17+
note: object type is valid for the lifetime `'a` as defined here
18+
--> $DIR/E0476.rs:9:6
19+
|
20+
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
21+
| ^^
22+
note: source pointer is only valid for the lifetime `'b` as defined here
23+
--> $DIR/E0476.rs:9:10
24+
|
25+
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {}
26+
| ^^
27+
28+
error: aborting due to 2 previous errors
29+
30+
Some errors have detailed explanations: E0119, E0476.
31+
For more information about an error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)