Skip to content

Commit fd19773

Browse files
committed
Auto merge of rust-lang#134627 - estebank:issue-133252, r=jackh726
Avoid ICE in borrowck Provide a fallback in `best_blame_constraint` when `find_constraint_paths_between_regions` doesn't have a result. This code is due a rework to avoid the letf-over `unwrap()`, but avoids the ICE caused by the repro. Fix rust-lang#133252.
2 parents 480eec0 + 70fe5a1 commit fd19773

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1950,8 +1950,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
19501950
target_test: impl Fn(RegionVid) -> bool,
19511951
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
19521952
// Find all paths
1953-
let (path, target_region) =
1954-
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
1953+
let (path, target_region) = self
1954+
.find_constraint_paths_between_regions(from_region, target_test)
1955+
.or_else(|| {
1956+
self.find_constraint_paths_between_regions(from_region, |r| {
1957+
self.cannot_name_placeholder(from_region, r)
1958+
})
1959+
})
1960+
.unwrap();
19551961
debug!(
19561962
"path={:#?}",
19571963
path.iter()

Diff for: tests/crashes/133252.rs renamed to tests/ui/borrowck/implementation-not-general-enough-ice-133252.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ known-bug: #133252
1+
// Regression test for borrowck ICE #133252
22
//@ edition:2021
33
use std::future::Future;
44

@@ -7,6 +7,8 @@ fn ice() -> impl Future<Output = &'static dyn Owned> {
77
async {
88
let not_static = 0;
99
force_send(async_load(&not_static));
10+
//~^ ERROR implementation of `LoadQuery` is not general enough
11+
//~| ERROR `not_static` does not live long enough
1012
loop {}
1113
}
1214
}
@@ -41,3 +43,5 @@ impl Future for SimpleFuture {
4143
loop {}
4244
}
4345
}
46+
47+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error: implementation of `LoadQuery` is not general enough
2+
--> $DIR/implementation-not-general-enough-ice-133252.rs:9:9
3+
|
4+
LL | force_send(async_load(&not_static));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `LoadQuery` is not general enough
6+
|
7+
= note: `LoadQuery<'0>` would have to be implemented for the type `&u8`, for any lifetime `'0`...
8+
= note: ...but `LoadQuery<'1>` is actually implemented for the type `&'1 u8`, for some specific lifetime `'1`
9+
10+
error[E0597]: `not_static` does not live long enough
11+
--> $DIR/implementation-not-general-enough-ice-133252.rs:9:31
12+
|
13+
LL | async {
14+
| - return type of async block is &(dyn Owned + '1)
15+
LL | let not_static = 0;
16+
| ---------- binding `not_static` declared here
17+
LL | force_send(async_load(&not_static));
18+
| -----------^^^^^^^^^^^-
19+
| | |
20+
| | borrowed value does not live long enough
21+
| argument requires that `not_static` is borrowed for `'1`
22+
...
23+
LL | }
24+
| - `not_static` dropped here while still borrowed
25+
|
26+
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
27+
--> $DIR/implementation-not-general-enough-ice-133252.rs:16:18
28+
|
29+
LL | fn force_send<T: Send>(_: T) {}
30+
| ^^^^
31+
32+
error: aborting due to 2 previous errors
33+
34+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)