Skip to content

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

Closed

Description

@matthewjasper

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 ()>>);
}

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    C-bugCategory: This is a bug.
    requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.
    on Jun 5, 2020
  2. 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[/+] on Jun 5, 2020
  3. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 9, 2020
  4. removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Jun 9, 2020
  5. matthewjasper commented on Jun 29, 2020

    @matthewjasper
    ContributorAuthor

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

  6. 3 remaining items

  7. WorldSEnder commented on Oct 3, 2020

    @WorldSEnder

    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?

  8. Aaron1011 commented on Oct 6, 2020

    @Aaron1011
    Contributor

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

  9. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    and removed
    I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    on Oct 6, 2020
  10. matthewjasper commented on Oct 6, 2020

    @matthewjasper
    ContributorAuthor

    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.

  11. removed
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Oct 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions