Skip to content

Commit 84044cd

Browse files
Bless test fallout
1 parent eae5b5c commit 84044cd

30 files changed

+124
-186
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/region.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ use rustc_span::{BytePos, ErrorGuaranteed, Span, Symbol};
1717
use rustc_type_ir::Upcast as _;
1818

1919
use super::nice_region_error::find_anon_type;
20-
use super::{nice_region_error, ObligationCauseAsDiagArg};
21-
use crate::error_reporting::infer::ObligationCauseExt as _;
20+
use super::ObligationCauseAsDiagArg;
21+
use crate::error_reporting::infer::ObligationCauseExt;
2222
use crate::error_reporting::TypeErrCtxt;
2323
use crate::errors::{
2424
self, note_and_explain, FulfillReqLifetime, LfBoundNotSatisfied, OutlivesBound,
@@ -1212,22 +1212,8 @@ pub fn unexpected_hidden_region_diagnostic<'a, 'tcx>(
12121212
hidden_region,
12131213
"",
12141214
);
1215-
if let Some(reg_info) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
1216-
if infcx.tcx.features().precise_capturing {
1217-
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
1218-
} else {
1219-
let fn_returns = tcx.return_type_impl_or_dyn_traits(reg_info.def_id);
1220-
nice_region_error::suggest_new_region_bound(
1221-
tcx,
1222-
&mut err,
1223-
fn_returns,
1224-
hidden_region.to_string(),
1225-
None,
1226-
format!("captures `{hidden_region}`"),
1227-
None,
1228-
Some(reg_info.def_id),
1229-
)
1230-
}
1215+
if let Some(_) = tcx.is_suitable_region(generic_param_scope, hidden_region) {
1216+
suggest_precise_capturing(tcx, opaque_ty_key.def_id, hidden_region, &mut err);
12311217
}
12321218
}
12331219
ty::RePlaceholder(_) => {

tests/ui/async-await/multiple-lifetimes/ret-impl-trait-one.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ LL | | (a, b)
2626
LL | | }
2727
| |_^
2828
|
29-
help: to declare that `impl Trait<'a>` captures `'b`, you can add an explicit `'b` lifetime bound
29+
help: add a `use<...>` bound to explicitly capture `'b`
3030
|
31-
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b {
32-
| ++++
31+
LL | async fn async_ret_impl_trait1<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + use<'a, 'b> {
32+
| +++++++++++++
3333

3434
error: aborting due to 2 previous errors
3535

tests/ui/borrowck/alias-liveness/opaque-type-param.stderr

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static {
77
| hidden type `impl Trait + 'static` captures the lifetime `'a` as defined here
88
LL | bar(s)
99
| ^^^^^^
10+
|
11+
help: add a `use<...>` bound to explicitly capture `'a`
12+
|
13+
LL | fn foo<'a>(s: &'a str) -> impl Trait + 'static + use<'a> {
14+
| +++++++++
1015

1116
error: aborting due to 1 previous error
1217

tests/ui/const-generics/generic_const_exprs/issue-109141.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ LL | fn a(&self) -> impl Iterator {
3030
LL | self.0.iter_mut()
3131
| ^^^^^^^^^^^^^^^^^
3232
|
33-
help: to declare that `impl Iterator` captures `'_`, you can add an explicit `'_` lifetime bound
33+
help: add a `use<...>` bound to explicitly capture `'_`
3434
|
35-
LL | fn a(&self) -> impl Iterator + '_ {
36-
| ++++
35+
LL | fn a(&self) -> impl Iterator + use<'_> {
36+
| +++++++++
3737

3838
error: aborting due to 3 previous errors
3939

tests/ui/feature-gates/feature-gate-lifetime-capture-rules-2024.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn foo(x: &Vec<i32>) -> impl Sized {
88
LL | x
99
| ^
1010
|
11-
help: to declare that `impl Sized` captures `'_`, you can add an explicit `'_` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'_`
1212
|
13-
LL | fn foo(x: &Vec<i32>) -> impl Sized + '_ {
14-
| ++++
13+
LL | fn foo(x: &Vec<i32>) -> impl Sized + use<'_> {
14+
| +++++++++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/impl-trait/alias-liveness/rpit-hidden-erased-unsoundness.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a {
88
LL | step1::<'a, 'b>()
99
| ^^^^^^^^^^^^^^^^^
1010
|
11-
help: to declare that `impl Sized + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'b`
1212
|
13-
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + 'b {
14-
| ++++
13+
LL | fn step2<'a, 'b: 'a>() -> impl Sized + 'a + use<'a, 'b> {
14+
| +++++++++++++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/impl-trait/alias-liveness/rpit-hide-lifetime-for-swap.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a {
88
LL | x
99
| ^
1010
|
11-
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'b`
1212
|
13-
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + 'b {
14-
| ++++
13+
LL | fn hide<'a, 'b: 'a, T: 'static>(x: Rc<RefCell<&'b T>>) -> impl Swap + 'a + use<'a, 'b, T> {
14+
| ++++++++++++++++
1515

1616
error: aborting due to 1 previous error
1717

tests/ui/impl-trait/hidden-lifetimes.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
88
LL | x
99
| ^
1010
|
11-
help: to declare that `impl Swap + 'a` captures `'b`, you can add an explicit `'b` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'b`
1212
|
13-
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + 'b {
14-
| ++++
13+
LL | fn hide_ref<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a + use<'a, 'b, T> {
14+
| ++++++++++++++++
1515

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

3131
error: aborting due to 2 previous errors
3232

tests/ui/impl-trait/in-trait/cannot-capture-intersection.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(precise_capturing)]
2-
31
use std::future::Future;
42
use std::pin::Pin;
53

tests/ui/impl-trait/in-trait/cannot-capture-intersection.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0700]: hidden type for `impl Future<Output = i32>` captures lifetime that does not appear in bounds
2-
--> $DIR/cannot-capture-intersection.rs:24:9
2+
--> $DIR/cannot-capture-intersection.rs:22:9
33
|
44
LL | fn foo<'a, 'b>(&'a self, x: &'b i32) -> impl Future<Output = i32> {
55
| ------------------------- opaque type defined here

tests/ui/impl-trait/must_outlive_least_region_or_bound.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ LL | fn elided(x: &i32) -> impl Copy { x }
77
| | opaque type defined here
88
| hidden type `&i32` captures the anonymous lifetime defined here
99
|
10-
help: to declare that `impl Copy` captures `'_`, you can add an explicit `'_` lifetime bound
10+
help: add a `use<...>` bound to explicitly capture `'_`
1111
|
12-
LL | fn elided(x: &i32) -> impl Copy + '_ { x }
13-
| ++++
12+
LL | fn elided(x: &i32) -> impl Copy + use<'_> { x }
13+
| +++++++++
1414

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

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

116116
error[E0310]: the parameter type `T` may not live long enough
117117
--> $DIR/must_outlive_least_region_or_bound.rs:47:5

tests/ui/impl-trait/nested-return-type4.stderr

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,10 @@ LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized
88
LL | async move { let _s = s; }
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1010
|
11-
help: to declare that `impl Future<Output = impl Sized>` captures `'s`, you can add an explicit `'s` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'s`
1212
|
13-
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + 's {
14-
| ++++
15-
help: to declare that `impl Sized` captures `'s`, you can add an explicit `'s` lifetime bound
16-
|
17-
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized + 's> {
18-
| ++++
13+
LL | fn test<'s: 's>(s: &'s str) -> impl std::future::Future<Output = impl Sized> + use<'s> {
14+
| +++++++++
1915

2016
error: aborting due to 1 previous error
2117

tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(precise_capturing)]
2-
31
fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
42
//~^ HELP add `'a` to the `use<...>` bound
53
x

tests/ui/impl-trait/precise-capturing/hidden-type-suggestion.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
2-
--> $DIR/hidden-type-suggestion.rs:5:5
2+
--> $DIR/hidden-type-suggestion.rs:3:5
33
|
44
LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b> {
55
| -- -------------------- opaque type defined here
@@ -15,7 +15,7 @@ LL | fn lifetime<'a, 'b>(x: &'a ()) -> impl Sized + use<'b, 'a> {
1515
| ++++
1616

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

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

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

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

8686
error[E0700]: hidden type for `impl Sized` captures lifetime that does not appear in bounds
87-
--> $DIR/hidden-type-suggestion.rs:38:5
87+
--> $DIR/hidden-type-suggestion.rs:36:5
8888
|
8989
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
9090
| -- ---------- opaque type defined here
@@ -95,7 +95,7 @@ LL | y
9595
| ^
9696
|
9797
note: you could use a `use<...>` bound to explicitly capture `'a`, but argument-position `impl Trait`s are not nameable
98-
--> $DIR/hidden-type-suggestion.rs:36:29
98+
--> $DIR/hidden-type-suggestion.rs:34:29
9999
|
100100
LL | fn yes_params_yet<'a, T>(_: impl Sized, y: &'a ()) -> impl Sized {
101101
| ^^^^^^^^^^

tests/ui/impl-trait/region-escape-via-bound.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y>
99
LL | x
1010
| ^
1111
|
12-
help: to declare that `impl Trait<'y>` captures `'x`, you can add an explicit `'x` lifetime bound
12+
help: add a `use<...>` bound to explicitly capture `'x`
1313
|
14-
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + 'x
15-
| ++++
14+
LL | fn foo<'x, 'y>(x: Cell<&'x u32>) -> impl Trait<'y> + use<'y, 'x>
15+
| +++++++++++++
1616

1717
error: aborting due to 1 previous error
1818

tests/ui/impl-trait/static-return-lifetime-infered.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> {
88
LL | self.x.iter().map(|a| a.0)
99
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1010
|
11-
help: to declare that `impl Iterator<Item = u32>` captures `'_`, you can add an explicit `'_` lifetime bound
11+
help: add a `use<...>` bound to explicitly capture `'_`
1212
|
13-
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + '_ {
14-
| ++++
13+
LL | fn iter_values_anon(&self) -> impl Iterator<Item=u32> + use<'_> {
14+
| +++++++++
1515

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

3131
error: aborting due to 2 previous errors
3232

tests/ui/lifetimes/issue-105227.fixed

-26
This file was deleted.

tests/ui/lifetimes/issue-105227.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
// Regression test for issue #105227.
22

3-
//@ run-rustfix
4-
#![allow(warnings)]
3+
// FIXME(precise_capturing): Add rustfix here after dealing w/ elided lifetimes
4+
5+
#![allow(unused)]
6+
57
fn chars0(v :(& str, &str)) -> impl Iterator<Item = char> {
6-
//~^ HELP to declare that `impl Iterator<Item = char>` captures `'_`, you can introduce a named lifetime parameter `'a`
8+
//~^ HELP add a `use<...>` bound
79
v.0.chars().chain(v.1.chars())
810
//~^ ERROR hidden type for `impl Iterator<Item = char>` captures lifetime that does not appear in bounds
911
}
1012

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

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

0 commit comments

Comments
 (0)