Skip to content

Commit 8ff449d

Browse files
committedJan 15, 2018
Auto merge of #47329 - davidtwco:issue-46983, r=nikomatsakis
NLL: bad error message when converting anonymous lifetime to `'static` Fixes #46983. r? @nikomatsakis
2 parents bb345a0 + 1aa454e commit 8ff449d

15 files changed

+65
-31
lines changed
 

‎src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+13
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,17 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
118118
.emit();
119119
return Some(ErrorReported);
120120
}
121+
122+
// This method returns whether the given Region is Named
123+
pub(super) fn is_named_region(&self, region: ty::Region<'tcx>) -> bool {
124+
match *region {
125+
ty::ReStatic => true,
126+
ty::ReFree(ref free_region) => match free_region.bound_region {
127+
ty::BrNamed(..) => true,
128+
_ => false,
129+
},
130+
ty::ReEarlyBound(_) => true,
131+
_ => false,
132+
}
133+
}
121134
}

‎src/librustc/infer/error_reporting/nice_region_error/util.rs

-12
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,4 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> {
198198
}
199199
false
200200
}
201-
202-
// This method returns whether the given Region is Named
203-
pub(super) fn is_named_region(&self, region: Region<'tcx>) -> bool {
204-
match *region {
205-
ty::ReFree(ref free_region) => match free_region.bound_region {
206-
ty::BrNamed(..) => true,
207-
_ => false,
208-
},
209-
ty::ReEarlyBound(_) => true,
210-
_ => false,
211-
}
212-
}
213201
}

‎src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn bar<F>(blk: F) where F: FnOnce() + 'static {
1313

1414
fn foo(x: &()) {
1515
bar(|| {
16-
//~^ ERROR does not fulfill
16+
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
1717
let _ = x;
1818
})
1919
}

‎src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use std::fmt::Debug;
1414

1515
fn elided(x: &i32) -> impl Copy { x }
16-
//~^ ERROR cannot infer an appropriate lifetime
16+
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
1717

1818
fn explicit<'a>(x: &'a i32) -> impl Copy { x }
1919
//~^ ERROR cannot infer an appropriate lifetime

‎src/test/compile-fail/issue-16922.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::any::Any;
1212

1313
fn foo<T: Any>(value: &T) -> Box<Any> {
1414
Box::new(value) as Box<Any>
15-
//~^ ERROR: cannot infer an appropriate lifetime
15+
//~^ ERROR explicit lifetime required in the type of `value` [E0621]
1616
}
1717

1818
fn main() {

‎src/test/compile-fail/object-lifetime-default-from-box-error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn load(ss: &mut SomeStruct) -> Box<SomeTrait> {
2525
// `Box<SomeTrait>` defaults to a `'static` bound, so this return
2626
// is illegal.
2727

28-
ss.r //~ ERROR cannot infer an appropriate lifetime
28+
ss.r //~ ERROR explicit lifetime required in the type of `ss` [E0621]
2929
}
3030

3131
fn store(ss: &mut SomeStruct, b: Box<SomeTrait>) {

‎src/test/compile-fail/region-object-lifetime-in-coercion.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ impl<'a> Foo for &'a [u8] {}
1616

1717
fn a(v: &[u8]) -> Box<Foo + 'static> {
1818
let x: Box<Foo + 'static> = Box::new(v);
19-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
19+
//~^ ERROR explicit lifetime required in the type of `v` [E0621]
2020
x
2121
}
2222

2323
fn b(v: &[u8]) -> Box<Foo + 'static> {
2424
Box::new(v)
25-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
25+
//~^ ERROR explicit lifetime required in the type of `v` [E0621]
2626
}
2727

2828
fn c(v: &[u8]) -> Box<Foo> {
2929
// same as previous case due to RFC 599
3030

3131
Box::new(v)
32-
//~^ ERROR cannot infer an appropriate lifetime due to conflicting
32+
//~^ ERROR explicit lifetime required in the type of `v` [E0621]
3333
}
3434

3535
fn d<'a,'b>(v: &'a [u8]) -> Box<Foo+'b> {

‎src/test/compile-fail/regions-proc-bound-capture.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn borrowed_proc<'a>(x: &'a isize) -> Box<FnMut()->(isize) + 'a> {
1616

1717
fn static_proc(x: &isize) -> Box<FnMut()->(isize) + 'static> {
1818
// This is illegal, because the region bound on `proc` is 'static.
19-
Box::new(move|| { *x }) //~ ERROR cannot infer an appropriate lifetime
19+
Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the type of `x` [E0621]
2020
}
2121

2222
fn main() { }

‎src/test/compile-fail/regions-static-bound.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
2222
}
2323

2424
fn error(u: &(), v: &()) {
25-
static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime
25+
static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621]
2626
//[nll]~^ WARNING not reporting region error due to -Znll
27-
//[nll]~| ERROR free region `` does not outlive free region `'static`
28-
static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime
27+
//[nll]~| ERROR explicit lifetime required in the type of `u` [E0621]
28+
static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621]
2929
//[nll]~^ WARNING not reporting region error due to -Znll
30-
//[nll]~| ERROR free region `` does not outlive free region `'static`
30+
//[nll]~| ERROR explicit lifetime required in the type of `v` [E0621]
3131
}
3232

3333
fn main() {}

‎src/test/ui/issue-46983.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(nll)]
12+
13+
fn foo(x: &u32) -> &'static u32 {
14+
&*x
15+
//~^ ERROR explicit lifetime required in the type of `x` [E0621]
16+
}
17+
18+
fn main() {}

‎src/test/ui/issue-46983.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0621]: explicit lifetime required in the type of `x`
2+
--> $DIR/issue-46983.rs:14:5
3+
|
4+
13 | fn foo(x: &u32) -> &'static u32 {
5+
| - consider changing the type of `x` to `&'static u32`
6+
14 | &*x
7+
| ^^^ lifetime `'static` required
8+
9+
error: aborting due to previous error
10+

‎src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
fn foo(x: &u32) -> &'static u32 {
1919
&*x
2020
//~^ WARN not reporting region error due to -Znll
21-
//~| ERROR does not outlive free region
21+
//~| ERROR explicit lifetime required in the type of `x`
2222
}
2323

2424
fn main() { }

‎src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ warning: not reporting region error due to -Znll
44
19 | &*x
55
| ^^^
66

7-
error: free region `ReFree(DefId(0/0:3 ~ region_lbr_anon_does_not_outlive_static[317d]::foo[0]), BrAnon(0))` does not outlive free region `ReStatic`
7+
error[E0621]: explicit lifetime required in the type of `x`
88
--> $DIR/region-lbr-anon-does-not-outlive-static.rs:19:5
99
|
10+
18 | fn foo(x: &u32) -> &'static u32 {
11+
| - consider changing the type of `x` to `&ReStatic u32`
1012
19 | &*x
11-
| ^^^
13+
| ^^^ lifetime `ReStatic` required
1214

1315
error: aborting due to previous error
1416

‎src/test/ui/nll/guarantor-issue-46974.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn foo(s: &mut (i32,)) -> i32 {
2222

2323
fn bar(s: &Box<(i32,)>) -> &'static i32 {
2424
// FIXME(#46983): error message should be better
25-
&s.0 //~ ERROR free region `` does not outlive free region `'static`
25+
&s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621]
2626
}
2727

2828
fn main() {

‎src/test/ui/nll/guarantor-issue-46974.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ error[E0506]: cannot assign to `*s` because it is borrowed
77
19 | *s = (2,); //~ ERROR cannot assign to `*s`
88
| ^^^^^^^^^ assignment to borrowed `*s` occurs here
99

10-
error: free region `` does not outlive free region `'static`
10+
error[E0621]: explicit lifetime required in the type of `s`
1111
--> $DIR/guarantor-issue-46974.rs:25:5
1212
|
13-
25 | &s.0 //~ ERROR free region `` does not outlive free region `'static`
14-
| ^^^^
13+
23 | fn bar(s: &Box<(i32,)>) -> &'static i32 {
14+
| - consider changing the type of `s` to `&'static std::boxed::Box<(i32,)>`
15+
24 | // FIXME(#46983): error message should be better
16+
25 | &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621]
17+
| ^^^^ lifetime `'static` required
1518

1619
error: aborting due to 2 previous errors
1720

0 commit comments

Comments
 (0)
Please sign in to comment.