Use smaller span for adjustments on block expressions

This commit is contained in:
Matthew Jasper 2018-08-25 12:13:28 +01:00
parent a9fe312b98
commit 9309e2ef07
12 changed files with 81 additions and 95 deletions

View File

@ -78,7 +78,7 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
mut expr: Expr<'tcx>, mut expr: Expr<'tcx>,
adjustment: &Adjustment<'tcx>) adjustment: &Adjustment<'tcx>)
-> Expr<'tcx> { -> Expr<'tcx> {
let Expr { temp_lifetime, span, .. } = expr; let Expr { temp_lifetime, mut span, .. } = expr;
let kind = match adjustment.kind { let kind = match adjustment.kind {
Adjust::ReifyFnPointer => { Adjust::ReifyFnPointer => {
ExprKind::ReifyFnPointer { source: expr.to_ref() } ExprKind::ReifyFnPointer { source: expr.to_ref() }
@ -96,6 +96,25 @@ fn apply_adjustment<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
ExprKind::Cast { source: expr.to_ref() } ExprKind::Cast { source: expr.to_ref() }
} }
Adjust::Deref(None) => { Adjust::Deref(None) => {
// Adjust the span from the block, to the last expression of the
// block. This is a better span when returning a mutable reference
// with too short a lifetime. The error message will use the span
// from the assignment to the return place, which should only point
// at the returned value, not the entire function body.
//
// fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 {
// x
// // ^ error message points at this expression.
// }
//
// We don't need to do this adjustment in the next match arm since
// deref coercions always start with a built-in deref.
if let ExprKind::Block { body } = expr.kind {
if let Some(ref last_expr) = body.expr {
span = last_expr.span;
expr.span = span;
}
}
ExprKind::Deref { arg: expr.to_ref() } ExprKind::Deref { arg: expr.to_ref() }
} }
Adjust::Deref(Some(deref)) => { Adjust::Deref(Some(deref)) => {

View File

@ -15,6 +15,5 @@ static mut S: usize = 3;
const C2: &'static mut usize = unsafe { &mut S }; const C2: &'static mut usize = unsafe { &mut S };
//~^ ERROR: constants cannot refer to statics //~^ ERROR: constants cannot refer to statics
//~| ERROR: references in constants may only refer to immutable values //~| ERROR: references in constants may only refer to immutable values
//~| ERROR: references in constants may only refer to immutable values
fn main() {} fn main() {}

View File

@ -16,13 +16,7 @@ error[E0017]: references in constants may only refer to immutable values
LL | const C2: &'static mut usize = unsafe { &mut S }; LL | const C2: &'static mut usize = unsafe { &mut S };
| ^^^^^^ constants require immutable values | ^^^^^^ constants require immutable values
error[E0017]: references in constants may only refer to immutable values error: aborting due to 3 previous errors
--> $DIR/issue-17718-const-bad-values.rs:15:32
|
LL | const C2: &'static mut usize = unsafe { &mut S };
| ^^^^^^^^^^^^^^^^^ constants require immutable values
error: aborting due to 4 previous errors
Some errors occurred: E0013, E0017. Some errors occurred: E0013, E0017.
For more information about an error, try `rustc --explain E0013`. For more information about an error, try `rustc --explain E0013`.

View File

@ -12,16 +12,13 @@ LL | }
error[E0597]: `z` does not live long enough (Mir) error[E0597]: `z` does not live long enough (Mir)
--> $DIR/issue-46471-1.rs:16:9 --> $DIR/issue-46471-1.rs:16:9
| |
LL | let y = { LL | &mut z
| _____________- | ^^^^^^
LL | | let mut z = 0; | |
LL | | &mut z | borrowed value does not live long enough
| | ^^^^^^ borrowed value does not live long enough | borrow later used here
LL | | }; LL | };
| | - | - `z` dropped here while still borrowed
| | |
| |_____`z` dropped here while still borrowed
| borrow later used here
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View File

@ -5,17 +5,14 @@ LL | match self.0 { ref mut x => x } //~ ERROR mismatched types
| ^ | ^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/match-ref-mut-invariance.rs:19:49 --> $DIR/match-ref-mut-invariance.rs:20:9
| |
LL | impl<'b> S<'b> { LL | impl<'b> S<'b> {
| -- lifetime `'b` defined here | -- lifetime `'b` defined here
LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 { LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
| ____________--___________________________________^ | -- lifetime `'a` defined here
| | | LL | match self.0 { ref mut x => x } //~ ERROR mismatched types
| | lifetime `'a` defined here | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'b`
LL | | match self.0 { ref mut x => x } //~ ERROR mismatched types
LL | | }
| |_____^ returning this value requires that `'a` must outlive `'b`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,18 +5,15 @@ LL | x //~ ERROR mismatched types
| ^ | ^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/match-ref-mut-let-invariance.rs:19:49 --> $DIR/match-ref-mut-let-invariance.rs:21:9
| |
LL | impl<'b> S<'b> { LL | impl<'b> S<'b> {
| -- lifetime `'b` defined here | -- lifetime `'b` defined here
LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 { LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
| ____________--___________________________________^ | -- lifetime `'a` defined here
| | | LL | let ref mut x = self.0;
| | lifetime `'a` defined here LL | x //~ ERROR mismatched types
LL | | let ref mut x = self.0; | ^ returning this value requires that `'a` must outlive `'b`
LL | | x //~ ERROR mismatched types
LL | | }
| |_____^ returning this value requires that `'a` must outlive `'b`
error: aborting due to previous error error: aborting due to previous error

View File

@ -15,9 +15,9 @@
use std::fmt::Debug; use std::fmt::Debug;
fn bar<'a>(x: &'a u32) -> &'static dyn Debug { fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
//~^ ERROR unsatisfied lifetime constraints
x x
//~^ WARNING not reporting region error due to nll //~^ ERROR unsatisfied lifetime constraints
//~| WARNING not reporting region error due to nll
} }
fn main() {} fn main() {}

View File

@ -1,21 +1,16 @@
warning: not reporting region error due to nll warning: not reporting region error due to nll
--> $DIR/mir_check_cast_unsize.rs:19:5 --> $DIR/mir_check_cast_unsize.rs:18:5
| |
LL | x LL | x
| ^ | ^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/mir_check_cast_unsize.rs:17:46 --> $DIR/mir_check_cast_unsize.rs:18:5
| |
LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug { LL | fn bar<'a>(x: &'a u32) -> &'static dyn Debug {
| ________--____________________________________^ | -- lifetime `'a` defined here
| | | LL | x
| | lifetime `'a` defined here | ^ returning this value requires that `'a` must outlive `'static`
LL | | //~^ ERROR unsatisfied lifetime constraints
LL | | x
LL | | //~^ WARNING not reporting region error due to nll
LL | | }
| |_^ returning this value requires that `'a` must outlive `'static`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,20 +5,15 @@ LL | ss
| ^^ | ^^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/object-lifetime-default-elision.rs:64:53 --> $DIR/object-lifetime-default-elision.rs:81:5
| |
LL | fn load3<'a,'b>(ss: &'a SomeTrait) -> &'b SomeTrait { LL | fn load3<'a,'b>(ss: &'a SomeTrait) -> &'b SomeTrait {
| __________--_--______________________________________^ | -- -- lifetime `'b` defined here
| | | | | |
| | | lifetime `'b` defined here | lifetime `'a` defined here
| | lifetime `'a` defined here ...
LL | | // Under old rules, the fully elaborated types of input/output were: LL | ss
LL | | // | ^^ returning this value requires that `'a` must outlive `'b`
LL | | // for<'a,'b,'c>fn(&'a (SomeTrait+'c)) -> &'b (SomeTrait+'a)
... |
LL | | //~| ERROR cannot infer
LL | | }
| |_^ returning this value requires that `'a` must outlive `'b`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,16 +5,14 @@ LL | &mut ***p //~ ERROR 14:5: 14:14: lifetime mismatch [E0623]
| ^^^^^^^^^ | ^^^^^^^^^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/regions-reborrow-from-shorter-mut-ref-mut-ref.rs:13:85 --> $DIR/regions-reborrow-from-shorter-mut-ref-mut-ref.rs:14:5
| |
LL | fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut isize) -> &'b mut isize { LL | fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut isize) -> &'b mut isize {
| ______________________--__--_________________________________________________________^ | -- -- lifetime `'b` defined here
| | | | | |
| | | lifetime `'b` defined here | lifetime `'a` defined here
| | lifetime `'a` defined here LL | &mut ***p //~ ERROR 14:5: 14:14: lifetime mismatch [E0623]
LL | | &mut ***p //~ ERROR 14:5: 14:14: lifetime mismatch [E0623] | ^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
LL | | }
| |_^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
error: aborting due to previous error error: aborting due to previous error

View File

@ -5,16 +5,14 @@ LL | &mut **p //~ ERROR 16:5: 16:13: lifetime mismatch [E0623]
| ^^^^^^^^ | ^^^^^^^^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/regions-reborrow-from-shorter-mut-ref.rs:15:73 --> $DIR/regions-reborrow-from-shorter-mut-ref.rs:16:5
| |
LL | fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize { LL | fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize {
| ______________________--__--_____________________________________________^ | -- -- lifetime `'b` defined here
| | | | | |
| | | lifetime `'b` defined here | lifetime `'a` defined here
| | lifetime `'a` defined here LL | &mut **p //~ ERROR 16:5: 16:13: lifetime mismatch [E0623]
LL | | &mut **p //~ ERROR 16:5: 16:13: lifetime mismatch [E0623] | ^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
LL | | }
| |_^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
error: aborting due to previous error error: aborting due to previous error

View File

@ -11,18 +11,15 @@ LL | x //~ ERROR mismatched types
| ^ | ^
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/regions-trait-object-subtyping.rs:23:51 --> $DIR/regions-trait-object-subtyping.rs:25:5
| |
LL | fn foo3<'a,'b>(x: &'a mut Dummy) -> &'b mut Dummy { LL | fn foo3<'a,'b>(x: &'a mut Dummy) -> &'b mut Dummy {
| _________--_--_____________________________________^ | -- -- lifetime `'b` defined here
| | | | | |
| | | lifetime `'b` defined here | lifetime `'a` defined here
| | lifetime `'a` defined here LL | // Without knowing 'a:'b, we can't coerce
LL | | // Without knowing 'a:'b, we can't coerce LL | x //~ ERROR lifetime bound not satisfied
LL | | x //~ ERROR lifetime bound not satisfied | ^ returning this value requires that `'a` must outlive `'b`
LL | | //~^ ERROR cannot infer an appropriate lifetime
LL | | }
| |_^ returning this value requires that `'a` must outlive `'b`
error: unsatisfied lifetime constraints error: unsatisfied lifetime constraints
--> $DIR/regions-trait-object-subtyping.rs:32:5 --> $DIR/regions-trait-object-subtyping.rs:32:5