Skip to content

Commit

Permalink
Bless test fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Aug 17, 2024
1 parent eae5b5c commit 84044cd
Show file tree
Hide file tree
Showing 30 changed files with 124 additions and 186 deletions.
22 changes: 4 additions & 18 deletions compiler/rustc_trait_selection/src/error_reporting/infer/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol};
use rustc_type_ir::Upcast as _;

use super::nice_region_error::find_anon_type;
use super::{nice_region_error, ObligationCauseAsDiagArg};
use crate::error_reporting::infer::ObligationCauseExt as _;
use super::ObligationCauseAsDiagArg;
use crate::error_reporting::infer::ObligationCauseExt;
use crate::error_reporting::TypeErrCtxt;
use crate::errors::{
self, note_and_explain, FulfillReqLifetime, LfBoundNotSatisfied, OutlivesBound,
Expand Down Expand Up @@ -1212,22 +1212,8 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
hidden_region,
"",
);
if let Some(reg_info) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
if infcx.tcx.features().precise_capturing {
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
} else {
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
nice_region_error::suggest_new_region_bound(
tcx,
&mut err,
fn_returns,
hidden_region.to_string(),
None,
format!("captures `{hidden_region}`"),
None,
Some(reg_info.def_id),
)
}
if let Some(_) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
}
}
ty::RePlaceholder(_) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ LL | | (a, b)
LL | | }
| |_^
|
help: to declare that `impl Trait<'a>` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
| ++++
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + use<'a, 'b> {
| +++++++++++++

error: aborting due to 2 previous errors

Expand Down
5 changes: 5 additions & 0 deletions tests/ui/borrowck/alias-liveness/opaque-type-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static {
| hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here
LL | bar(s)
| ^^^^^^
|
help: add a `use<...>` bound to explicitly capture `'a`
|
LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static + use<'a> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ LL | fn a(&self) -> impl Iterator {
LL | self.0.iter_mut()
| ^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn a(&self) -> impl Iterator + '_ {
| ++++
LL | fn a(&self) -> impl Iterator + use<'_> {
| +++++++++

error: aborting due to 3 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn foo(x: &Vec<i32>) -> impl Sized {
LL | x
| ^
|
help: to declare that `impl Sized` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn foo(x: &Vec<i32>) -> impl Sized + '_ {
| ++++
LL | fn foo(x: &Vec<i32>) -> impl Sized + use<'_> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a {
LL | step1::<'a, 'b>()
| ^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Sized + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + 'b {
| ++++
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + use<'a, 'b> {
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error: aborting due to 1 previous error

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/impl-trait/hidden-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error[E0700]: hidden type for `impl Swap + 'a` captures lifetime that does not appear in bounds
--> $DIR/hidden-lifetimes.rs:46:5
Expand All @@ -23,10 +23,10 @@ LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl S
LL | x
| ^
|
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
| ++++
LL | fn hide_rc_refcell<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + use<'a, 'b, T> {
| ++++++++++++++++

error: aborting due to 2 previous errors

Expand Down
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

use std::future::Future;
use std::pin::Pin;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0700]: hidden type for `impl Future<Output = i32>` captures lifetime that does not appear in bounds
--> $DIR/cannot-capture-intersection.rs:24:9
--> $DIR/cannot-capture-intersection.rs:22:9
|
LL | fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32> {
| ------------------------- opaque type defined here
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/impl-trait/must_outlive_least_region_or_bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ LL | fn elided(x: &i32) -> impl Copy { x }
| | opaque type defined here
| hidden type `&i32` captures the anonymous lifetime defined here
|
help: to declare that `impl Copy` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
| ++++
LL | fn elided(x: &i32) -> impl Copy + use<'_> { x }
| +++++++++

error[E0700]: hidden type for `impl Copy` captures lifetime that does not appear in bounds
--> $DIR/must_outlive_least_region_or_bound.rs:6:44
Expand All @@ -21,10 +21,10 @@ LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x }
| | opaque type defined here
| hidden type `&'a i32` captures the lifetime `'a` as defined here
|
help: to declare that `impl Copy` captures `'a`, you can add an explicit `'a` lifetime bound
help: add a `use<...>` bound to explicitly capture `'a`
|
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x }
| ++++
LL | fn explicit<'a>(x: &'a i32) -> impl Copy + use<'a> { x }
| +++++++++

error: lifetime may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:9:46
Expand Down Expand Up @@ -108,10 +108,10 @@ LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32
LL | move |_| println!("{}", y)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Fn(&'a u32)` captures `'b`, you can add an explicit `'b` lifetime bound
help: add a `use<...>` bound to explicitly capture `'b`
|
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + 'b {
| ++++
LL | fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) + use<'a, 'b> {
| +++++++++++++

error[E0310]: the parameter type `T` may not live long enough
--> $DIR/must_outlive_least_region_or_bound.rs:47:5
Expand Down
10 changes: 3 additions & 7 deletions tests/ui/impl-trait/nested-return-type4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized
LL | async move { let _s = s; }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Future<Output = impl Sized>` captures `'s`, you can add an explicit `'s` lifetime bound
help: add a `use<...>` bound to explicitly capture `'s`
|
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + 's {
| ++++
help: to declare that `impl Sized` captures `'s`, you can add an explicit `'s` lifetime bound
|
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized + 's> {
| ++++
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + use<'s> {
| +++++++++

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(precise_capturing)]

fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
//~^ HELP add `'a` to the `use<...>` bound
x
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:5:5
--> $DIR/hidden-type-suggestion.rs:3:5
|
LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
| -- -------------------- opaque type defined here
Expand All @@ -15,7 +15,7 @@ LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b, 'a> {
| ++++

error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:11:5
--> $DIR/hidden-type-suggestion.rs:9:5
|
LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<T> {
| -- ------------------- opaque type defined here
Expand All @@ -31,7 +31,7 @@ LL | fn param<'a, T>(x: &'a ()) -> impl Sized + use<'a, T> {
| +++

error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:17:5
--> $DIR/hidden-type-suggestion.rs:15:5
|
LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<> {
| -- ------------------ opaque type defined here
Expand All @@ -47,7 +47,7 @@ LL | fn empty<'a>(x: &'a ()) -> impl Sized + use<'a> {
| ++

error[E0700]: hidden type for `impl Captures<'captured>` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:26:5
--> $DIR/hidden-type-suggestion.rs:24:5
|
LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captures<'captured> {
| -- ------------------------ opaque type defined here
Expand All @@ -63,7 +63,7 @@ LL | fn missing<'a, 'captured, 'not_captured, Captured>(x: &'a ()) -> impl Captu
| ++++++++++++++++++++++++++++++

error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:32:5
--> $DIR/hidden-type-suggestion.rs:30:5
|
LL | fn no_params_yet(_: impl Sized, y: &()) -> impl Sized {
| --- ---------- opaque type defined here
Expand All @@ -74,7 +74,7 @@ LL | y
| ^
|
note: you could use a `use<...>` bound to explicitly capture `'_`, but argument-position `impl Trait`s are not nameable
--> $DIR/hidden-type-suggestion.rs:30:21
--> $DIR/hidden-type-suggestion.rs:28:21
|
LL | fn no_params_yet(_: impl Sized, y: &()) -> impl Sized {
| ^^^^^^^^^^
Expand All @@ -84,7 +84,7 @@ LL | fn no_params_yet<T: Sized>(_: T, y: &()) -> impl Sized + use<'_, T> {
| ++++++++++ ~ ++++++++++++

error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
--> $DIR/hidden-type-suggestion.rs:38:5
--> $DIR/hidden-type-suggestion.rs:36:5
|
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
| -- ---------- opaque type defined here
Expand All @@ -95,7 +95,7 @@ LL | y
| ^
|
note: you could use a `use<...>` bound to explicitly capture `'a`, but argument-position `impl Trait`s are not nameable
--> $DIR/hidden-type-suggestion.rs:36:29
--> $DIR/hidden-type-suggestion.rs:34:29
|
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
| ^^^^^^^^^^
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/impl-trait/region-escape-via-bound.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
LL | x
| ^
|
help: to declare that `impl Trait<'y>` captures `'x`, you can add an explicit `'x` lifetime bound
help: add a `use<...>` bound to explicitly capture `'x`
|
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + 'x
| ++++
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + use<'y, 'x>
| +++++++++++++

error: aborting due to 1 previous error

Expand Down
12 changes: 6 additions & 6 deletions tests/ui/impl-trait/static-return-lifetime-infered.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Iterator<Item = u32>` captures `'_`, you can add an explicit `'_` lifetime bound
help: add a `use<...>` bound to explicitly capture `'_`
|
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
| ++++
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + use<'_> {
| +++++++++

error[E0700]: hidden type for `impl Iterator<Item = u32>` captures lifetime that does not appear in bounds
--> $DIR/static-return-lifetime-infered.rs:11:9
Expand All @@ -23,10 +23,10 @@ LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> {
LL | self.x.iter().map(|a| a.0)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: to declare that `impl Iterator<Item = u32>` captures `'a`, you can add an explicit `'a` lifetime bound
help: add a `use<...>` bound to explicitly capture `'a`
|
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + 'a {
| ++++
LL | fn iter_values<'a>(&'a self) -> impl Iterator<Item=u32> + use<'a> {
| +++++++++

error: aborting due to 2 previous errors

Expand Down
26 changes: 0 additions & 26 deletions tests/ui/lifetimes/issue-105227.fixed

This file was deleted.

16 changes: 8 additions & 8 deletions tests/ui/lifetimes/issue-105227.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
// Regression test for issue #105227.

//@ run-rustfix
#![allow(warnings)]
// FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes

#![allow(unused)]

fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> {
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
//~^ HELP add a `use<...>` bound
v.0.chars().chain(v.1.chars())
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
}

fn chars1(v0 : & str, v1 : &str) -> impl Iterator<Item = char> {
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
//~^ HELP add a `use<...>` bound
v0.chars().chain(v1.chars())
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
}

fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) ->
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can use the named lifetime parameter `'b`
(impl Iterator<Item = char>, &'b str)
{
fn chars2<'b>(v0 : &str, v1 : &'_ str, v2 : &'b str) -> (impl Iterator<Item = char>, &'b str) {
//~^ HELP add a `use<...>` bound
(v0.chars().chain(v1.chars()), v2)
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bound
}
Expand Down
Loading

0 comments on commit 84044cd

Please sign in to comment.