diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-22 22:50:10 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2018-10-26 23:47:52 +0200 |
| commit | 740e8a3f37f224927269bf7b205b16142d91bf0f (patch) | |
| tree | 94b10bf3171886d3c26522085a0af10967231177 /src/test/ui/nll | |
| parent | b569caf267c595d2c2988941fb39f4718cadfdcc (diff) | |
| download | rust-740e8a3f37f224927269bf7b205b16142d91bf0f.tar.gz rust-740e8a3f37f224927269bf7b205b16142d91bf0f.zip | |
Add the actual chain of projections to `UserTypeProjection`.
Update the existing NLL `patterns.rs` test accordingly. includes changes addressing review feedback: * Added example to docs for `UserTypeProjections` illustrating how we build up multiple projections when descending into a pattern with type ascriptions. * Adapted niko's suggested docs for `UserTypeProjection`. * Factored out `projection_ty` from more general `projection_ty_core` (as a drive-by, made its callback an `FnMut`, as I discovered later that I need that). * Add note to docs that `PlaceTy.field_ty(..)` does not normalize its result. * Normalize as we project out `field_ty`.
Diffstat (limited to 'src/test/ui/nll')
| -rw-r--r-- | src/test/ui/nll/user-annotations/patterns.rs | 32 | ||||
| -rw-r--r-- | src/test/ui/nll/user-annotations/patterns.stderr | 31 |
2 files changed, 46 insertions, 17 deletions
diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs index e3bac513fa8..643231b39b4 100644 --- a/src/test/ui/nll/user-annotations/patterns.rs +++ b/src/test/ui/nll/user-annotations/patterns.rs @@ -9,11 +9,11 @@ fn variable_no_initializer() { } fn tuple_no_initializer() { - // FIXME(#47187): We are not propagating ascribed type through tuples. + let x = 22; let (y, z): (&'static u32, &'static u32); - y = &x; + y = &x; //~ ERROR } fn ref_with_ascribed_static_type() -> u32 { @@ -34,11 +34,11 @@ fn ref_with_ascribed_any_type() -> u32 { struct Single<T> { value: T } fn struct_no_initializer() { - // FIXME(#47187): We are not propagating ascribed type through patterns. + let x = 22; let Single { value: y }: Single<&'static u32>; - y = &x; + y = &x; //~ ERROR } fn variable_with_initializer() { @@ -91,26 +91,26 @@ fn struct_double_field_underscore_with_initializer() { } fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 { - // The error in this test is inconsistency with - // `static_to_a_to_static_through_tuple`, but "feels right" to - // me. It occurs because we special case the single binding case - // and force the type of `y` to be `&'a u32`, even though the - // right-hand side has type `&'static u32`. + + + + + let y: &'a u32 = &22; y //~ ERROR } fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { - // FIXME(#47187): The fact that this type-checks is perhaps surprising. - // What happens is that the right-hand side is constrained to have - // type `&'a u32`, which is possible, because it has type - // `&'static u32`. The variable `y` is then forced to have type - // `&'static u32`, but it is constrained only by the right-hand - // side, not the ascribed type, and hence it passes. + + + + + + let (y, _z): (&'a u32, u32) = (&22, 44); - y + y //~ ERROR } fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr index 0c50b98ee27..58b708fcb1b 100644 --- a/src/test/ui/nll/user-annotations/patterns.stderr +++ b/src/test/ui/nll/user-annotations/patterns.stderr @@ -9,6 +9,16 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:16:9 + | +LL | let (y, z): (&'static u32, &'static u32); + | ---------------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; //~ ERROR + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:22:13 | LL | let y = &x; //~ ERROR @@ -20,6 +30,16 @@ LL | } | - `x` dropped here while still borrowed error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:41:9 + | +LL | let Single { value: y }: Single<&'static u32>; + | -------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; //~ ERROR + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough --> $DIR/patterns.rs:46:27 | LL | let y: &'static u32 = &x; //~ ERROR @@ -128,6 +148,15 @@ LL | y //~ ERROR | ^ returning this value requires that `'a` must outlive `'static` error: unsatisfied lifetime constraints + --> $DIR/patterns.rs:113:5 + | +LL | fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y //~ ERROR + | ^ returning this value requires that `'a` must outlive `'static` + +error: unsatisfied lifetime constraints --> $DIR/patterns.rs:117:18 | LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { @@ -135,7 +164,7 @@ LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` -error: aborting due to 14 previous errors +error: aborting due to 17 previous errors Some errors occurred: E0597, E0716. For more information about an error, try `rustc --explain E0597`. |
