Skip to content

Commit b800c30

Browse files
committed
Auto merge of #117466 - compiler-errors:alias-bound, r=aliemjay
Don't check for alias bounds in liveness when aliases have escaping bound vars I actually have no idea how we *should* be treating aliases with escaping bound vars here... but the simplest behavior is just doing what we used to do before. r? aliemjay Fixes #117455
2 parents 62270fb + 4d5d763 commit b800c30

File tree

4 files changed

+64
-1
lines changed

4 files changed

+64
-1
lines changed

compiler/rustc_infer/src/infer/outlives/for_liveness.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
1+
use rustc_middle::ty::{
2+
self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
3+
};
24

35
use std::ops::ControlFlow;
46

@@ -49,6 +51,12 @@ where
4951
return ControlFlow::Continue(());
5052
}
5153

54+
// FIXME: Don't consider alias bounds on types that have escaping bound
55+
// vars. See #117455.
56+
if ty.has_escaping_bound_vars() {
57+
return ty.super_visit_with(self);
58+
}
59+
5260
match ty.kind() {
5361
// We can prove that an alias is live two ways:
5462
// 1. All the components are live.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Trait {
2+
type Gat<'a: 'b, 'b: 'c, 'c>: 'c;
3+
}
4+
5+
fn get_func<'a, T: Trait>(_: &'a str) -> fn(T::Gat<'a, '_, 'static>) {
6+
loop {}
7+
}
8+
9+
fn test<T: Trait>() {
10+
let func = get_func::<T>(&String::new()); //~ ERROR temporary value dropped
11+
drop(func);
12+
}
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0716]: temporary value dropped while borrowed
2+
--> $DIR/escaping-bounds-2.rs:10:31
3+
|
4+
LL | let func = get_func::<T>(&String::new());
5+
| ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
6+
| |
7+
| creates a temporary value which is freed while still in use
8+
LL | drop(func);
9+
| ---- borrow later used here
10+
|
11+
help: consider using a `let` binding to create a longer lived value
12+
|
13+
LL ~ let binding = String::new();
14+
LL ~ let func = get_func::<T>(&binding);
15+
|
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0716`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
3+
// Ensure that we don't ICE when an alias that has escaping bound vars is
4+
// required to be live. This is because the code that allows us to deduce an
5+
// appropriate outlives bound for a given alias type (in this test, a
6+
// projection) does not handle aliases with escaping bound vars.
7+
// See <https://github.com/rust-lang/rust/issues/117455>.
8+
9+
trait Foo {
10+
type Assoc<'a, 'b>: 'static;
11+
}
12+
13+
struct MentionsLifetimeAndType<'a, T>(&'a (), T);
14+
15+
fn foo<'a, 'b, T: Foo>(_: <T as Foo>::Assoc<'a, 'b>) {}
16+
17+
fn test<'b, T: Foo>() {
18+
let y: MentionsLifetimeAndType<'_, for<'a> fn(<T as Foo>::Assoc<'a, 'b>)> =
19+
MentionsLifetimeAndType(&(), foo);
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)