Skip to content

Commit 7f7fada

Browse files
committed
Also use smaller spans for unsize adjustments
1 parent 9309e2e commit 7f7fada

8 files changed

+62
-89
lines changed

src/librustc_mir/hair/cx/expr.rs

+7
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,13 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
199199
ExprKind::Use { source: cast_expr.to_ref() }
200200
}
201201
Adjust::Unsize => {
202+
// See the above comment for Adjust::Deref
203+
if let ExprKind::Block { body } = expr.kind {
204+
if let Some(ref last_expr) = body.expr {
205+
span = last_expr.span;
206+
expr.span = span;
207+
}
208+
}
202209
ExprKind::Unsize { source: expr.to_ref() }
203210
}
204211
};

src/test/ui/object-lifetime/object-lifetime-default-from-box-error.nll.stderr

+6-11
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,13 @@ LL | ss.r = b; //~ ERROR 41:12: 41:13: explicit lifetime required in the typ
1111
| ^
1212

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

2722
error[E0507]: cannot move out of borrowed content
2823
--> $DIR/object-lifetime-default-from-box-error.rs:28:5

src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr

+18-30
Original file line numberDiff line numberDiff line change
@@ -31,43 +31,31 @@ LL | let x: Box<Foo + 'static> = Box::new(v);
3131
| ^^^^^^^^^^^ lifetime `'static` required
3232

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

4541
error[E0621]: explicit lifetime required in the type of `v`
46-
--> $DIR/region-object-lifetime-in-coercion.rs:28:28
42+
--> $DIR/region-object-lifetime-in-coercion.rs:31:5
4743
|
48-
LL | fn c(v: &[u8]) -> Box<Foo> {
49-
| _________-----______________^
50-
| | |
51-
| | help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
52-
LL | | // same as previous case due to RFC 599
53-
LL | |
54-
LL | | Box::new(v)
55-
LL | | //~^ ERROR explicit lifetime required in the type of `v` [E0621]
56-
LL | | }
57-
| |_^ lifetime `'static` required
44+
LL | fn c(v: &[u8]) -> Box<Foo> {
45+
| ----- help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
46+
...
47+
LL | Box::new(v)
48+
| ^^^^^^^^^^^ lifetime `'static` required
5849

5950
error: unsatisfied lifetime constraints
60-
--> $DIR/region-object-lifetime-in-coercion.rs:35:41
51+
--> $DIR/region-object-lifetime-in-coercion.rs:36:5
6152
|
62-
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
63-
| ______--_--______________________________^
64-
| | | |
65-
| | | lifetime `'b` defined here
66-
| | lifetime `'a` defined here
67-
LL | | Box::new(v)
68-
LL | | //~^ ERROR cannot infer an appropriate lifetime due to conflicting
69-
LL | | }
70-
| |_^ returning this value requires that `'a` must outlive `'b`
53+
LL | fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {
54+
| -- -- lifetime `'b` defined here
55+
| |
56+
| lifetime `'a` defined here
57+
LL | Box::new(v)
58+
| ^^^^^^^^^^^ returning this value requires that `'a` must outlive `'b`
7159

7260
error: aborting due to 4 previous errors
7361

src/test/ui/regions/regions-close-object-into-object-2.nll.stderr

+5-8
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ LL | box B(&*v) as Box<X> //~ ERROR cannot infer
55
| ^^^
66

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

1815
error[E0597]: `*v` does not live long enough
1916
--> $DIR/regions-close-object-into-object-2.rs:20:11

src/test/ui/regions/regions-close-object-into-object-4.nll.stderr

+8-11
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,6 @@ warning: not reporting region error due to nll
2828
LL | box B(&*v) as Box<X> //~ ERROR cannot infer
2929
| ^^^^^^^^^^
3030

31-
error: unsatisfied lifetime constraints
32-
--> $DIR/regions-close-object-into-object-4.rs:19:51
33-
|
34-
LL | fn i<'a, T, U>(v: Box<A<U>+'a>) -> Box<X+'static> {
35-
| ______--___________________________________________^
36-
| | |
37-
| | lifetime `'a` defined here
38-
LL | | box B(&*v) as Box<X> //~ ERROR cannot infer
39-
LL | | }
40-
| |_^ returning this value requires that `'a` must outlive `'static`
41-
4231
error[E0310]: the parameter type `U` may not live long enough
4332
--> $DIR/regions-close-object-into-object-4.rs:20:5
4433
|
@@ -47,6 +36,14 @@ LL | box B(&*v) as Box<X> //~ ERROR cannot infer
4736
|
4837
= help: consider adding an explicit lifetime bound `U: 'static`...
4938

39+
error: unsatisfied lifetime constraints
40+
--> $DIR/regions-close-object-into-object-4.rs:20:5
41+
|
42+
LL | fn i<'a, T, U>(v: Box<A<U>+'a>) -> Box<X+'static> {
43+
| -- lifetime `'a` defined here
44+
LL | box B(&*v) as Box<X> //~ ERROR cannot infer
45+
| ^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
46+
5047
error[E0310]: the parameter type `U` may not live long enough
5148
--> $DIR/regions-close-object-into-object-4.rs:20:9
5249
|

src/test/ui/regions/regions-proc-bound-capture.nll.stderr

+6-9
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ LL | Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the typ
55
| ^^^^^^^^^^^^^
66

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

1916
error: aborting due to previous error
2017

src/test/ui/span/regions-close-over-type-parameter-2.nll.stderr

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
error[E0597]: `tmp0` does not live long enough
22
--> $DIR/regions-close-over-type-parameter-2.rs:33:20
33
|
4-
LL | let _ = {
5-
| _____________-
6-
LL | | let tmp0 = 3;
7-
LL | | let tmp1 = &tmp0;
8-
| | ^^^^^ borrowed value does not live long enough
9-
LL | | repeater3(tmp1)
10-
LL | | };
11-
| | -
12-
| | |
13-
| |_____`tmp0` dropped here while still borrowed
14-
| borrow later used here
4+
LL | let tmp1 = &tmp0;
5+
| ^^^^^ borrowed value does not live long enough
6+
LL | repeater3(tmp1)
7+
| --------------- borrow later used here
8+
LL | };
9+
| - `tmp0` dropped here while still borrowed
1510

1611
error: aborting due to previous error
1712

src/test/ui/underscore-lifetime/dyn-trait-underscore.nll.stderr

+6-9
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@ LL | Box::new(items.iter()) //~ ERROR cannot infer an appropriate lifetime
2323
| ^^^^^^^^^^^^^^^^^^^^^^
2424

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

3734
error: aborting due to previous error
3835

0 commit comments

Comments
 (0)