forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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``
- Loading branch information
Showing
6 changed files
with
68 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The coerced type does not outlive the value being coerced to. | ||
|
||
Example of erroneous code: | ||
|
||
```compile_fail,E0476 | ||
#![feature(coerce_unsized)] | ||
#![feature(unsize)] | ||
use std::marker::Unsize; | ||
use std::ops::CoerceUnsized; | ||
// error: lifetime of the source pointer does not outlive lifetime bound of the | ||
// object type | ||
impl<'a, 'b, T, S> CoerceUnsized<&'a T> for &'b S where S: Unsize<T> {} | ||
``` | ||
|
||
During a coercion, the "source pointer" (the coerced type) did not outlive the | ||
"object type" (value being coerced to). In the above example, `'b` is not a | ||
subtype of `'a`. This error can currently only be encountered with the unstable | ||
`CoerceUnsized` trait which allows custom coercions of unsized types behind a | ||
smart pointer to be implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![feature(coerce_unsized)] | ||
#![feature(unsize)] | ||
|
||
use std::marker::Unsize; | ||
use std::ops::CoerceUnsized; | ||
|
||
struct Wrapper<T>(T); | ||
|
||
impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {} | ||
//~^ ERROR lifetime of the source pointer does not outlive lifetime bound of the object type [E0476] | ||
//~^^ ERROR E0119 | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
error[E0119]: conflicting implementations of trait `CoerceUnsized<&Wrapper<_>>` for type `&Wrapper<_>` | ||
--> $DIR/E0476.rs:9:1 | ||
| | ||
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: conflicting implementation in crate `core`: | ||
- impl<'a, 'b, T, U> CoerceUnsized<&'a U> for &'b T | ||
where 'b: 'a, T: Unsize<U>, T: ?Sized, U: ?Sized; | ||
|
||
error[E0476]: lifetime of the source pointer does not outlive lifetime bound of the object type | ||
--> $DIR/E0476.rs:9:1 | ||
| | ||
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: object type is valid for the lifetime `'a` as defined here | ||
--> $DIR/E0476.rs:9:6 | ||
| | ||
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {} | ||
| ^^ | ||
note: source pointer is only valid for the lifetime `'b` as defined here | ||
--> $DIR/E0476.rs:9:10 | ||
| | ||
LL | impl<'a, 'b, T, S> CoerceUnsized<&'a Wrapper<T>> for &'b Wrapper<S> where S: Unsize<T> {} | ||
| ^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0119, E0476. | ||
For more information about an error, try `rustc --explain E0119`. |