`obligations_for_self_ty` leaks placeholders
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
trait Foo<'a> {}
fn needs_foo<T>(_: T)
where
for<'a> Wrap<T>: Foo<'a>,
{}
struct Wrap<T>(T);
impl<'a, T> Foo<'a> for Wrap<T> where T: Fn(&'a i32) {}
fn main() {
needs_foo(|x| println!("{x}"));
}
During typeck, the signature of |x| println!("{x}") gets inferred to fn(&'!a i32) where '!a is a placeholder which is not nameable by the closure. This is unsound as in "it breaks a core invariant of the type system". As all regions are erased after hir typeck and rechecked during mir borrowck it should not cause any "allows for UB at runtime" unsoundness.
This is still something we should fix, ideally by "pulling down" the inference variables of the closure signature into the root universe when deducing it. The same issue exists for all uses of obligations_for_self_ty.
This may cause some ICEs in the future if we improve our validation of type system invariants in the future.
cc @rust-lang/types
edit: for now this is actually not too different from how higher ranked relate works in general. However, the same issue exists with feature(non_lifetime_binders) and we want to more eagerly handle these placeholder constraints in the future to handle where-bounds on binders
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating obligations_for_self_ty in the compiler and reproduce the closure example during type checking. Trace how the closure signature is inferred under the higher-ranked bound; done means the resulting signature does not expose an unnameable placeholder while preserving the expected type-system invariants.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100