mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-22 04:27:33 +00:00
Rollup merge of #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 https://github.com/rust-lang/rust/issues/61137. r? ```@compiler-errors``` cc ```@compiler-errors```
This commit is contained in:
commit
65eecc6b59
@ -253,6 +253,7 @@ E0466: include_str!("./error_codes/E0466.md"),
|
|||||||
E0468: include_str!("./error_codes/E0468.md"),
|
E0468: include_str!("./error_codes/E0468.md"),
|
||||||
E0469: include_str!("./error_codes/E0469.md"),
|
E0469: include_str!("./error_codes/E0469.md"),
|
||||||
E0472: include_str!("./error_codes/E0472.md"),
|
E0472: include_str!("./error_codes/E0472.md"),
|
||||||
|
E0476: include_str!("./error_codes/E0476.md"),
|
||||||
E0477: include_str!("./error_codes/E0477.md"),
|
E0477: include_str!("./error_codes/E0477.md"),
|
||||||
E0478: include_str!("./error_codes/E0478.md"),
|
E0478: include_str!("./error_codes/E0478.md"),
|
||||||
E0482: include_str!("./error_codes/E0482.md"),
|
E0482: include_str!("./error_codes/E0482.md"),
|
||||||
@ -611,7 +612,6 @@ E0793: include_str!("./error_codes/E0793.md"),
|
|||||||
// E0473, // dereference of reference outside its lifetime
|
// E0473, // dereference of reference outside its lifetime
|
||||||
// E0474, // captured variable `..` does not outlive the enclosing closure
|
// E0474, // captured variable `..` does not outlive the enclosing closure
|
||||||
// E0475, // index of slice outside its lifetime
|
// E0475, // index of slice outside its lifetime
|
||||||
E0476, // lifetime of the source pointer does not outlive lifetime bound...
|
|
||||||
// E0479, // the type `..` (provided as the value of a type parameter) is...
|
// E0479, // the type `..` (provided as the value of a type parameter) is...
|
||||||
// E0480, // lifetime of method receiver does not outlive the method call
|
// E0480, // lifetime of method receiver does not outlive the method call
|
||||||
// E0481, // lifetime of function argument does not outlive the function call
|
// E0481, // lifetime of function argument does not outlive the function call
|
||||||
|
21
compiler/rustc_error_codes/src/error_codes/E0476.md
Normal file
21
compiler/rustc_error_codes/src/error_codes/E0476.md
Normal file
@ -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.
|
@ -22,7 +22,7 @@ macro_rules! register_diagnostics {
|
|||||||
pub fn error_codes() -> Vec<(&'static str, Option<&'static str>)> {
|
pub fn error_codes() -> Vec<(&'static str, Option<&'static str>)> {
|
||||||
let mut errors: Vec<(&str, Option<&str>)> = vec![
|
let mut errors: Vec<(&str, Option<&str>)> = vec![
|
||||||
$((stringify!($error_code), Some($message)),)+
|
$((stringify!($error_code), Some($message)),)+
|
||||||
$((stringify!($undocumented), None),)+
|
$((stringify!($undocumented), None),)*
|
||||||
];
|
];
|
||||||
errors.sort();
|
errors.sort();
|
||||||
errors
|
errors
|
||||||
|
@ -31,7 +31,7 @@ const IGNORE_DOCTEST_CHECK: &[&str] = &["E0464", "E0570", "E0601", "E0602", "E06
|
|||||||
|
|
||||||
// Error codes that don't yet have a UI test. This list will eventually be removed.
|
// Error codes that don't yet have a UI test. This list will eventually be removed.
|
||||||
const IGNORE_UI_TEST_CHECK: &[&str] =
|
const IGNORE_UI_TEST_CHECK: &[&str] =
|
||||||
&["E0461", "E0465", "E0476", "E0514", "E0554", "E0640", "E0717", "E0729"];
|
&["E0461", "E0465", "E0514", "E0554", "E0640", "E0717", "E0729"];
|
||||||
|
|
||||||
macro_rules! verbose_print {
|
macro_rules! verbose_print {
|
||||||
($verbose:expr, $($fmt:tt)*) => {
|
($verbose:expr, $($fmt:tt)*) => {
|
||||||
|
13
tests/ui/error-codes/E0476.rs
Normal file
13
tests/ui/error-codes/E0476.rs
Normal file
@ -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() {}
|
31
tests/ui/error-codes/E0476.stderr
Normal file
31
tests/ui/error-codes/E0476.stderr
Normal file
@ -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`.
|
Loading…
Reference in New Issue
Block a user