Skip to content

Type alias impl trait resolves to different concrete types #113619

Closed
@mikialex

Description

@mikialex

I tried this code:

#![feature(type_alias_impl_trait)]

trait Test {}

struct A;

impl Test for A {}

struct B<T> {
  inner: T,
}

impl<T: Test> Test for B<T> {}

type TestImpl = impl Test;
fn test() -> TestImpl {
  A
}

fn make_option() -> Option<TestImpl> {
  Some(test())
}

fn make_option2() -> Option<TestImpl> {
  let inner = make_option().unwrap();

  B { inner }.into()
}

I expected to see this happen: compile error that said the make_option2 return type is wrong.

Instead, this happened: compiled without error

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (37998ab50 2023-06-11)
binary: rustc
commit-hash: 37998ab508d5d9fa0d465d7b535dc673087dda8f
commit-date: 2023-06-11
host: x86_64-pc-windows-msvc
release: 1.72.0-nightly
LLVM version: 16.0.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemC-bugCategory: This is a bug.F-type_alias_impl_trait`#[feature(type_alias_impl_trait)]`I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions