Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ICE in borrowck #134627

Merged
merged 1 commit into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1945,8 +1945,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
target_test: impl Fn(RegionVid) -> bool,
) -> (BlameConstraint<'tcx>, Vec<ExtraConstraintInfo>) {
// Find all paths
let (path, target_region) =
self.find_constraint_paths_between_regions(from_region, target_test).unwrap();
let (path, target_region) = self
.find_constraint_paths_between_regions(from_region, target_test)
.or_else(|| {
self.find_constraint_paths_between_regions(from_region, |r| {
self.cannot_name_placeholder(from_region, r)
})
})
.unwrap();
debug!(
"path={:#?}",
path.iter()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//@ known-bug: #133252
// Regression test for borrowck ICE #133252
//@ edition:2021
use std::future::Future;

Expand All @@ -7,6 +7,8 @@ fn ice() -> impl Future<Output = &'static dyn Owned> {
async {
let not_static = 0;
force_send(async_load(&not_static));
//~^ ERROR implementation of `LoadQuery` is not general enough
//~| ERROR `not_static` does not live long enough
loop {}
}
}
Expand Down Expand Up @@ -41,3 +43,5 @@ impl Future for SimpleFuture {
loop {}
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: implementation of `LoadQuery` is not general enough
--> $DIR/implementation-not-general-enough-ice-133252.rs:9:9
|
LL | force_send(async_load(&not_static));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `LoadQuery` is not general enough
|
= note: `LoadQuery<'0>` would have to be implemented for the type `&u8`, for any lifetime `'0`...
= note: ...but `LoadQuery<'1>` is actually implemented for the type `&'1 u8`, for some specific lifetime `'1`

error[E0597]: `not_static` does not live long enough
--> $DIR/implementation-not-general-enough-ice-133252.rs:9:31
|
LL | async {
| - return type of async block is &(dyn Owned + '1)
LL | let not_static = 0;
| ---------- binding `not_static` declared here
LL | force_send(async_load(&not_static));
| -----------^^^^^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `not_static` is borrowed for `'1`
...
LL | }
| - `not_static` dropped here while still borrowed
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/implementation-not-general-enough-ice-133252.rs:16:18
|
LL | fn force_send<T: Send>(_: T) {}
| ^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0597`.
Loading