Skip to content

Commit

Permalink
Also use smaller spans for unsize adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjasper committed Aug 27, 2018
1 parent 9309e2e commit 7f7fada
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 89 deletions.
7 changes: 7 additions & 0 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
ExprKind::Use { source: cast_expr.to_ref() }
}
Adjust::Unsize => {
// See the above comment for Adjust::Deref
if let ExprKind::Block { body } = expr.kind {
if let Some(ref last_expr) = body.expr {
span = last_expr.span;
expr.span = span;
}
}
ExprKind::Unsize { source: expr.to_ref() }
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,13 @@ LL | ss.r = b; //~ ERROR 41:12: 41:13: explicit lifetime required in the typ
| ^

error[E0621]: explicit lifetime required in the type of `ss`
--> $DIR/object-lifetime-default-from-box-error.rs:24:48
--> $DIR/object-lifetime-default-from-box-error.rs:28:5
|
LL | fn load(ss: &mut SomeStruct) -> Box<SomeTrait> {
| _____________---------------____________________^
| | |
| | help: add explicit lifetime `'static` to the type of `ss`: `&mut SomeStruct<'static>`
LL | | // `Box<SomeTrait>` defaults to a `'static` bound, so this return
LL | | // is illegal.
LL | |
LL | | ss.r //~ ERROR explicit lifetime required in the type of `ss` [E0621]
LL | | }
| |_^ lifetime `'static` required
LL | fn load(ss: &mut SomeStruct) -> Box<SomeTrait> {
| --------------- help: add explicit lifetime `'static` to the type of `ss`: `&mut SomeStruct<'static>`
...
LL | ss.r //~ ERROR explicit lifetime required in the type of `ss` [E0621]
| ^^^^ lifetime `'static` required

error[E0507]: cannot move out of borrowed content
--> $DIR/object-lifetime-default-from-box-error.rs:28:5
Expand Down
48 changes: 18 additions & 30 deletions src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,31 @@ LL | let x: Box<Foo + 'static> = Box::new(v);
| ^^^^^^^^^^^ lifetime `'static` required

error[E0621]: explicit lifetime required in the type of `v`
--> $DIR/region-object-lifetime-in-coercion.rs:23:38
--> $DIR/region-object-lifetime-in-coercion.rs:24:5
|
LL | fn b(v: &[u8]) -> Box<Foo + 'static> {
| _________-----________________________^
| | |
| | help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
LL | | Box::new(v)
LL | | //~^ ERROR explicit lifetime required in the type of `v` [E0621]
LL | | }
| |_^ lifetime `'static` required
LL | fn b(v: &[u8]) -> Box<Foo + 'static> {
| ----- help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
LL | Box::new(v)
| ^^^^^^^^^^^ lifetime `'static` required

error[E0621]: explicit lifetime required in the type of `v`
--> $DIR/region-object-lifetime-in-coercion.rs:28:28
--> $DIR/region-object-lifetime-in-coercion.rs:31:5
|
LL | fn c(v: &[u8]) -> Box<Foo> {
| _________-----______________^
| | |
| | help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
LL | | // same as previous case due to RFC 599
LL | |
LL | | Box::new(v)
LL | | //~^ ERROR explicit lifetime required in the type of `v` [E0621]
LL | | }
| |_^ lifetime `'static` required
LL | fn c(v: &[u8]) -> Box<Foo> {
| ----- help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
...
LL | Box::new(v)
| ^^^^^^^^^^^ lifetime `'static` required

error: unsatisfied lifetime constraints
--> $DIR/region-object-lifetime-in-coercion.rs:35:41
--> $DIR/region-object-lifetime-in-coercion.rs:36:5
|
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
| ______--_--______________________________^
| | | |
| | | lifetime `'b` defined here
| | lifetime `'a` defined here
LL | | Box::new(v)
LL | | //~^ ERROR cannot infer an appropriate lifetime due to conflicting
LL | | }
| |_^ returning this value requires that `'a` must outlive `'b`
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | Box::new(v)
| ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'b`

error: aborting due to 4 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ LL | box B(&*v) as Box<X> //~ ERROR cannot infer
| ^^^

error: unsatisfied lifetime constraints
--> $DIR/regions-close-object-into-object-2.rs:19:57
--> $DIR/regions-close-object-into-object-2.rs:20:5
|
LL | fn g<'a, T: 'static>(v: Box<A<T>+'a>) -> Box<X+'static> {
| ______--_________________________________________________^
| | |
| | lifetime `'a` defined here
LL | | box B(&*v) as Box<X> //~ ERROR cannot infer
LL | | }
| |_^ returning this value requires that `'a` must outlive `'static`
LL | fn g<'a, T: 'static>(v: Box<A<T>+'a>) -> Box<X+'static> {
| -- lifetime `'a` defined here
LL | box B(&*v) as Box<X> //~ ERROR cannot infer
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`

error[E0597]: `*v` does not live long enough
--> $DIR/regions-close-object-into-object-2.rs:20:11
Expand Down
19 changes: 8 additions & 11 deletions src/test/ui/regions/regions-close-object-into-object-4.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,6 @@ warning: not reporting region error due to nll
LL | box B(&*v) as Box<X> //~ ERROR cannot infer
| ^^^^^^^^^^

error: unsatisfied lifetime constraints
--> $DIR/regions-close-object-into-object-4.rs:19:51
|
LL | fn i<'a, T, U>(v: Box<A<U>+'a>) -> Box<X+'static> {
| ______--___________________________________________^
| | |
| | lifetime `'a` defined here
LL | | box B(&*v) as Box<X> //~ ERROR cannot infer
LL | | }
| |_^ returning this value requires that `'a` must outlive `'static`

error[E0310]: the parameter type `U` may not live long enough
--> $DIR/regions-close-object-into-object-4.rs:20:5
|
Expand All @@ -47,6 +36,14 @@ LL | box B(&*v) as Box<X> //~ ERROR cannot infer
|
= help: consider adding an explicit lifetime bound `U: 'static`...

error: unsatisfied lifetime constraints
--> $DIR/regions-close-object-into-object-4.rs:20:5
|
LL | fn i<'a, T, U>(v: Box<A<U>+'a>) -> Box<X+'static> {
| -- lifetime `'a` defined here
LL | box B(&*v) as Box<X> //~ ERROR cannot infer
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`

error[E0310]: the parameter type `U` may not live long enough
--> $DIR/regions-close-object-into-object-4.rs:20:9
|
Expand Down
15 changes: 6 additions & 9 deletions src/test/ui/regions/regions-proc-bound-capture.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ LL | Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the typ
| ^^^^^^^^^^^^^

error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/regions-proc-bound-capture.rs:17:62
--> $DIR/regions-proc-bound-capture.rs:19:5
|
LL | fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> {
| ___________________------_____________________________________^
| | |
| | help: add explicit lifetime `'static` to the type of `x`: `&'static isize`
LL | | // This is illegal, because the region bound on `proc` is 'static.
LL | | Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the type of `x` [E0621]
LL | | }
| |_^ lifetime `'static` required
LL | fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> {
| ------ help: add explicit lifetime `'static` to the type of `x`: `&'static isize`
LL | // This is illegal, because the region bound on `proc` is 'static.
LL | Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the type of `x` [E0621]
| ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'static` required

error: aborting due to previous error

Expand Down
17 changes: 6 additions & 11 deletions src/test/ui/span/regions-close-over-type-parameter-2.nll.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
error[E0597]: `tmp0` does not live long enough
--> $DIR/regions-close-over-type-parameter-2.rs:33:20
|
LL | let _ = {
| _____________-
LL | | let tmp0 = 3;
LL | | let tmp1 = &tmp0;
| | ^^^^^ borrowed value does not live long enough
LL | | repeater3(tmp1)
LL | | };
| | -
| | |
| |_____`tmp0` dropped here while still borrowed
| borrow later used here
LL | let tmp1 = &tmp0;
| ^^^^^ borrowed value does not live long enough
LL | repeater3(tmp1)
| --------------- borrow later used here
LL | };
| - `tmp0` dropped here while still borrowed

error: aborting due to previous error

Expand Down
15 changes: 6 additions & 9 deletions src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^^^^^^^^^^^^^^^^^^^

error: unsatisfied lifetime constraints
--> $DIR/dyn-trait-underscore.rs:16:52
--> $DIR/dyn-trait-underscore.rs:18:5
|
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| ________________-___________________________________^
| | |
| | let's call the lifetime of this reference `'1`
LL | | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
LL | | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
LL | | }
| |_^ returning this value requires that `'1` must outlive `'static`
LL | fn a<T>(items: &[T]) -> Box<dyn Iterator<Item=&T>> {
| - let's call the lifetime of this reference `'1`
LL | // ^^^^^^^^^^^^^^^^^^^^^ bound *here* defaults to `'static`
LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
| ^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'static`

error: aborting due to previous error

0 comments on commit 7f7fada

Please sign in to comment.