From ee43e6d6c9c298c22c106a221ca962818f6a0b56 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 10 Jan 2018 17:12:23 +0000 Subject: [PATCH 1/3] Added test for #46983 --- src/test/ui/issue-46983.rs | 18 ++++++++++++++++++ src/test/ui/issue-46983.stderr | 10 ++++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/test/ui/issue-46983.rs create mode 100644 src/test/ui/issue-46983.stderr diff --git a/src/test/ui/issue-46983.rs b/src/test/ui/issue-46983.rs new file mode 100644 index 00000000000..ebbd474b1c2 --- /dev/null +++ b/src/test/ui/issue-46983.rs @@ -0,0 +1,18 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(nll)] + +fn foo(x: &u32) -> &'static u32 { + &*x + //~^ ERROR explicit lifetime required in the type of `x` [E0621] +} + +fn main() {} diff --git a/src/test/ui/issue-46983.stderr b/src/test/ui/issue-46983.stderr new file mode 100644 index 00000000000..ac8417a7a24 --- /dev/null +++ b/src/test/ui/issue-46983.stderr @@ -0,0 +1,10 @@ +error[E0621]: explicit lifetime required in the type of `x` + --> $DIR/issue-46983.rs:14:5 + | +13 | fn foo(x: &u32) -> &'static u32 { + | - consider changing the type of `x` to `&'static u32` +14 | &*x + | ^^^ lifetime `'static` required + +error: aborting due to previous error + From cad7b4f450e6584c4067c7a0947812625065d693 Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 10 Jan 2018 17:13:07 +0000 Subject: [PATCH 2/3] Fixes #46983. Fixes bad error message when converting anonymous lifetime to `'static` --- .../nice_region_error/named_anon_conflict.rs | 13 +++++++++++++ .../infer/error_reporting/nice_region_error/util.rs | 12 ------------ 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs index 9d0ddfd4be0..5617c772385 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/named_anon_conflict.rs @@ -118,4 +118,17 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { .emit(); return Some(ErrorReported); } + + // This method returns whether the given Region is Named + pub(super) fn is_named_region(&self, region: ty::Region<'tcx>) -> bool { + match *region { + ty::ReStatic => true, + ty::ReFree(ref free_region) => match free_region.bound_region { + ty::BrNamed(..) => true, + _ => false, + }, + ty::ReEarlyBound(_) => true, + _ => false, + } + } } diff --git a/src/librustc/infer/error_reporting/nice_region_error/util.rs b/src/librustc/infer/error_reporting/nice_region_error/util.rs index f8b6f7d0afa..8aadec64554 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/util.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/util.rs @@ -198,16 +198,4 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { } false } - - // This method returns whether the given Region is Named - pub(super) fn is_named_region(&self, region: Region<'tcx>) -> bool { - match *region { - ty::ReFree(ref free_region) => match free_region.bound_region { - ty::BrNamed(..) => true, - _ => false, - }, - ty::ReEarlyBound(_) => true, - _ => false, - } - } } From 1aa454e1e65cbd47d60849f274debe96226b1a5a Mon Sep 17 00:00:00 2001 From: David Wood Date: Wed, 10 Jan 2018 18:00:50 +0000 Subject: [PATCH 3/3] Updated other tests affected by change. --- .../closure-bounds-static-cant-capture-borrowed.rs | 2 +- .../impl-trait/must_outlive_least_region_or_bound.rs | 2 +- src/test/compile-fail/issue-16922.rs | 2 +- .../object-lifetime-default-from-box-error.rs | 2 +- .../compile-fail/region-object-lifetime-in-coercion.rs | 6 +++--- src/test/compile-fail/regions-proc-bound-capture.rs | 2 +- src/test/compile-fail/regions-static-bound.rs | 8 ++++---- .../region-lbr-anon-does-not-outlive-static.rs | 2 +- .../region-lbr-anon-does-not-outlive-static.stderr | 6 ++++-- src/test/ui/nll/guarantor-issue-46974.rs | 2 +- src/test/ui/nll/guarantor-issue-46974.stderr | 9 ++++++--- 11 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs index 513a17e2ef2..1ffba68263a 100644 --- a/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs +++ b/src/test/compile-fail/closure-bounds-static-cant-capture-borrowed.rs @@ -13,7 +13,7 @@ fn bar(blk: F) where F: FnOnce() + 'static { fn foo(x: &()) { bar(|| { - //~^ ERROR does not fulfill + //~^ ERROR explicit lifetime required in the type of `x` [E0621] let _ = x; }) } diff --git a/src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs b/src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs index 837160bc2fc..0eb99ca0fc3 100644 --- a/src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs +++ b/src/test/compile-fail/impl-trait/must_outlive_least_region_or_bound.rs @@ -13,7 +13,7 @@ use std::fmt::Debug; fn elided(x: &i32) -> impl Copy { x } -//~^ ERROR cannot infer an appropriate lifetime +//~^ ERROR explicit lifetime required in the type of `x` [E0621] fn explicit<'a>(x: &'a i32) -> impl Copy { x } //~^ ERROR cannot infer an appropriate lifetime diff --git a/src/test/compile-fail/issue-16922.rs b/src/test/compile-fail/issue-16922.rs index b525d5f64fc..1768c834cb3 100644 --- a/src/test/compile-fail/issue-16922.rs +++ b/src/test/compile-fail/issue-16922.rs @@ -12,7 +12,7 @@ use std::any::Any; fn foo(value: &T) -> Box { Box::new(value) as Box - //~^ ERROR: cannot infer an appropriate lifetime + //~^ ERROR explicit lifetime required in the type of `value` [E0621] } fn main() { diff --git a/src/test/compile-fail/object-lifetime-default-from-box-error.rs b/src/test/compile-fail/object-lifetime-default-from-box-error.rs index c50f425b2c0..b253612bc32 100644 --- a/src/test/compile-fail/object-lifetime-default-from-box-error.rs +++ b/src/test/compile-fail/object-lifetime-default-from-box-error.rs @@ -25,7 +25,7 @@ fn load(ss: &mut SomeStruct) -> Box { // `Box` defaults to a `'static` bound, so this return // is illegal. - ss.r //~ ERROR cannot infer an appropriate lifetime + ss.r //~ ERROR explicit lifetime required in the type of `ss` [E0621] } fn store(ss: &mut SomeStruct, b: Box) { diff --git a/src/test/compile-fail/region-object-lifetime-in-coercion.rs b/src/test/compile-fail/region-object-lifetime-in-coercion.rs index 687b2c344a3..5bf397ab383 100644 --- a/src/test/compile-fail/region-object-lifetime-in-coercion.rs +++ b/src/test/compile-fail/region-object-lifetime-in-coercion.rs @@ -16,20 +16,20 @@ impl<'a> Foo for &'a [u8] {} fn a(v: &[u8]) -> Box { let x: Box = Box::new(v); - //~^ ERROR cannot infer an appropriate lifetime due to conflicting + //~^ ERROR explicit lifetime required in the type of `v` [E0621] x } fn b(v: &[u8]) -> Box { Box::new(v) - //~^ ERROR cannot infer an appropriate lifetime due to conflicting + //~^ ERROR explicit lifetime required in the type of `v` [E0621] } fn c(v: &[u8]) -> Box { // same as previous case due to RFC 599 Box::new(v) - //~^ ERROR cannot infer an appropriate lifetime due to conflicting + //~^ ERROR explicit lifetime required in the type of `v` [E0621] } fn d<'a,'b>(v: &'a [u8]) -> Box { diff --git a/src/test/compile-fail/regions-proc-bound-capture.rs b/src/test/compile-fail/regions-proc-bound-capture.rs index 17fd55b031b..dd7b2bf9635 100644 --- a/src/test/compile-fail/regions-proc-bound-capture.rs +++ b/src/test/compile-fail/regions-proc-bound-capture.rs @@ -16,7 +16,7 @@ fn borrowed_proc<'a>(x: &'a isize) -> Box(isize) + 'a> { fn static_proc(x: &isize) -> Box(isize) + 'static> { // This is illegal, because the region bound on `proc` is 'static. - Box::new(move|| { *x }) //~ ERROR cannot infer an appropriate lifetime + Box::new(move|| { *x }) //~ ERROR explicit lifetime required in the type of `x` [E0621] } fn main() { } diff --git a/src/test/compile-fail/regions-static-bound.rs b/src/test/compile-fail/regions-static-bound.rs index a217cc9ebfa..13f93090fbb 100644 --- a/src/test/compile-fail/regions-static-bound.rs +++ b/src/test/compile-fail/regions-static-bound.rs @@ -22,12 +22,12 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { } fn error(u: &(), v: &()) { - static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime + static_id(&u); //[ll]~ ERROR explicit lifetime required in the type of `u` [E0621] //[nll]~^ WARNING not reporting region error due to -Znll - //[nll]~| ERROR free region `` does not outlive free region `'static` - static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime + //[nll]~| ERROR explicit lifetime required in the type of `u` [E0621] + static_id_indirect(&v); //[ll]~ ERROR explicit lifetime required in the type of `v` [E0621] //[nll]~^ WARNING not reporting region error due to -Znll - //[nll]~| ERROR free region `` does not outlive free region `'static` + //[nll]~| ERROR explicit lifetime required in the type of `v` [E0621] } fn main() {} diff --git a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.rs b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.rs index 3f56dfe5af4..ac21fe25bd1 100644 --- a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.rs +++ b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.rs @@ -18,7 +18,7 @@ fn foo(x: &u32) -> &'static u32 { &*x //~^ WARN not reporting region error due to -Znll - //~| ERROR does not outlive free region + //~| ERROR explicit lifetime required in the type of `x` } fn main() { } diff --git a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr index 6648e38e7de..2a1122cbda7 100644 --- a/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr +++ b/src/test/ui/nll/closure-requirements/region-lbr-anon-does-not-outlive-static.stderr @@ -4,11 +4,13 @@ warning: not reporting region error due to -Znll 19 | &*x | ^^^ -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` +error[E0621]: explicit lifetime required in the type of `x` --> $DIR/region-lbr-anon-does-not-outlive-static.rs:19:5 | +18 | fn foo(x: &u32) -> &'static u32 { + | - consider changing the type of `x` to `&ReStatic u32` 19 | &*x - | ^^^ + | ^^^ lifetime `ReStatic` required error: aborting due to previous error diff --git a/src/test/ui/nll/guarantor-issue-46974.rs b/src/test/ui/nll/guarantor-issue-46974.rs index 57ecddb80ab..09ce42ce1b5 100644 --- a/src/test/ui/nll/guarantor-issue-46974.rs +++ b/src/test/ui/nll/guarantor-issue-46974.rs @@ -22,7 +22,7 @@ fn foo(s: &mut (i32,)) -> i32 { fn bar(s: &Box<(i32,)>) -> &'static i32 { // FIXME(#46983): error message should be better - &s.0 //~ ERROR free region `` does not outlive free region `'static` + &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621] } fn main() { diff --git a/src/test/ui/nll/guarantor-issue-46974.stderr b/src/test/ui/nll/guarantor-issue-46974.stderr index 68cc87ef407..4f0bd88f988 100644 --- a/src/test/ui/nll/guarantor-issue-46974.stderr +++ b/src/test/ui/nll/guarantor-issue-46974.stderr @@ -7,11 +7,14 @@ error[E0506]: cannot assign to `*s` because it is borrowed 19 | *s = (2,); //~ ERROR cannot assign to `*s` | ^^^^^^^^^ assignment to borrowed `*s` occurs here -error: free region `` does not outlive free region `'static` +error[E0621]: explicit lifetime required in the type of `s` --> $DIR/guarantor-issue-46974.rs:25:5 | -25 | &s.0 //~ ERROR free region `` does not outlive free region `'static` - | ^^^^ +23 | fn bar(s: &Box<(i32,)>) -> &'static i32 { + | - consider changing the type of `s` to `&'static std::boxed::Box<(i32,)>` +24 | // FIXME(#46983): error message should be better +25 | &s.0 //~ ERROR explicit lifetime required in the type of `s` [E0621] + | ^^^^ lifetime `'static` required error: aborting due to 2 previous errors