Skip to content

normalization may result in unconstrained regions #15

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

Open
lcnr opened this issue Jan 30, 2025 · 2 comments
Open

normalization may result in unconstrained regions #15

lcnr opened this issue Jan 30, 2025 · 2 comments

Comments

@lcnr
Copy link
Owner

lcnr commented Jan 30, 2025

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn unconstrained_lt<T: for<'a> Trait<'a>>(x: <T as Super>::SAssoc) {}

The function argument of unconstrained_lt normalizes to <T as Trait<'unconstrained>>::TAssoc

@lcnr
Copy link
Owner Author

lcnr commented Jan 30, 2025

Because proving alias-outlives bounds checks for equality between regions, this results in the undesirable errors:

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a>>(x: &'arg <T as Super>::SAssoc) {
    test::<'arg, <T as Super>::SAssoc>();
}

normalizing "through" the alias with unconstrained regions does compile:

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a, TAssoc = T>>(x: &'arg <T as Super>::SAssoc) {
    test::<'arg, <T as Super>::SAssoc>();
}

@lcnr
Copy link
Owner Author

lcnr commented Jan 30, 2025

via alias-bound instead

trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

trait AliasBound {
    type WithBound: for<'a> Trait<'a>;
}

fn unconstrained_lt<T: AliasBound>(x: <T::WithBound as Super>::SAssoc) {}

bors added a commit to rust-lang-ci/rust that referenced this issue Jan 30, 2025
… r=<try>

elaborate: avoid projections with unconstrained bound regions

Should only do this for where-bounds and item bounds. Gonna rewrite later I think.

This means we'll no longer need to support unconstrained regions in implied bounds, see lcnr/random-rust-snippets#15. This fixes
```rust
trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a>>(x: &'arg <T as Super>::SAssoc) {
    test::<'arg, <T as Super>::SAssoc>();
}
```
but breaks
```rust
trait Super {
    type SAssoc;
}
trait Trait<'a>: Super<SAssoc = <Self as Trait<'a>>::TAssoc> {
    type TAssoc;
}

fn test<'a, T: 'a>() {}

fn unconstrained_lt<'arg, T: for<'a> Trait<'a, TAssoc = usize>>(x: <T as Super>::SAssoc) -> usize {
    x
}
```

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant