Skip to content

poor diagnostics when type-alias-impl-trait appears in impl #96569

Closed
@aliemjay

Description

@aliemjay

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=38b4af731292bf171e1011d9e54abd70

A type alias with at least one lifetime or type parameter:

#![feature(type_alias_impl_trait)]

type Ty<T> = impl Sized;
fn defining<T>(s: T) -> Ty<T> { s }

trait Tr {}
impl<T> Tr for Ty<T> {}

The current output is:

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> src/lib.rs:7:6
  |
7 | impl<T> Tr for Ty<T> {}
  |      ^ unconstrained type parameter

Ideally the output should look like when the type alias has no lifetime of type paramters:

error: cannot implement trait on type alias impl trait
 --> src/lib.rs:7:13
  |
7 | impl<T> Tr for Ty<T> {}
  |               ^^^^^^
  |
note: type alias impl trait defined here
 --> src/lib.rs:3:14
  |
3 | type Ty<T> = impl Sized;
  |              ^^^^^^^^^^

These diagnostics where introduced in #95973. cc @oli-obk.

@rustbot label T-compiler F-type_alias_impl_trait

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.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.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions