Skip to content

Commit 8ff449d

Browse files
committed
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

Lines changed: 13 additions & 0 deletions
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 18 additions & 0 deletions
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() {}

0 commit comments

Comments
 (0)