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

Type alias impl trait types do not check bounds apply to concrete type #73035

Closed
matthewjasper opened this issue Jun 5, 2020 · 5 comments
Closed
Assignees
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthewjasper
Copy link
Contributor

The following code runs and prints random values:

#![feature(type_alias_impl_trait)]

type X<'a> = impl Into<&'static str> + From<&'a str>;

fn f<'a: 'static>(t: &'a str) -> X<'a> {
    t
}

fn extend_lt<'a>(o: &'a str) -> &'static str {
    X::<'_>::from(o).into()
}

fn main() {
    let r =
    {
        let s = "abcdef".to_string();
        extend_lt(&s)
    };
    println!("{}", r);
}
ICE using the same issue
#![feature(type_alias_impl_trait)]

type X<T> = impl Clone;

fn f<T: Clone>(t: T) -> X<T> {
    t
}

fn g<T>(o : Option<X<T>>) -> Option<X<T>> {
    o.clone()
}

fn main() {
    g(None::<X<&mut ()>>);
}
@matthewjasper matthewjasper added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` requires-nightly This issue requires a nightly compiler in some way. labels Jun 5, 2020
@matthewjasper matthewjasper changed the title Type alias impl trait types do check bounds apply to concrete type Type alias impl trait types do not check bounds apply to concrete type Jun 5, 2020
@Elinvynia Elinvynia added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 9, 2020
@LeSeulArtichaut LeSeulArtichaut removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 9, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jun 17, 2020
@matthewjasper matthewjasper self-assigned this Jun 18, 2020
@ghost
Copy link

ghost commented Jun 29, 2020

Just a curious bystander: the provided example no longer prints random values (rustc 1.46.0-nightly (2f517ce6f 2020-06-28)). Was this fixed?

@matthewjasper
Copy link
Contributor Author

The first example is UB so it may be target/optimization level dependent. This will be fixed once the ICE is gone.

@WorldSEnder
Copy link

For my understanding: the point is that values for X<'a> are only infered under the additional assumption 'a: 'static (from the signature of f), not for general 'a, so rust should complain about that before it allows you to use it as X::<'_>, correct?

bors added a commit to rust-lang-ci/rust that referenced this issue Oct 6, 2020
…nikomatsakis

Separate projection bounds and predicates

Follow up to rust-lang#72788.

- Rename `projection_predicates` to `item_bounds`
- Separate bounds on associated types (the things after the `:` in `type X: ...`) and opaque types (the things after `impl`)  from predicates.
- Projection candidates now have the correct nested obligations
- Trait object candidates now check that the associated types on the trait object satisfy their bounds as nested obligations
- Type alias impl trait types are now checked (rust-lang#73035)
- `feature(generic_associated_types)` no longer changes how we handle bounds (rust-lang#73816)

Opening for a perf and crater runs.

r? `@nikomatsakis`
@Aaron1011
Copy link
Member

Both of the examples in this issue now error with #73905 merged

@Aaron1011 Aaron1011 added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Oct 6, 2020
@matthewjasper
Copy link
Contributor Author

matthewjasper commented Oct 6, 2020

This is tested in src/test/ui/type-alias-impl-trait/bounds-are-checked.rs already.

Ideally we would not allow f as a defining use because it overconstrains 'a, but it's hard to specify exactly what that means because not all of the (generic) parameters of the function have to be (generic) arguments of the opaque type.

@matthewjasper matthewjasper removed the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` glacier ICE tracked in rust-lang/glacier. requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

No branches or pull requests

6 participants