Skip to content

Confusing impl Trait limitation #104526

Closed
Closed
@c410-f3r

Description

@c410-f3r

For some reason, impl Trait is allowed in a type's first mention but not in a where clause.

use core::ops::Add;

// Allowed
fn foo<T: Add<Output = impl Default>>(t: T) {}
fn bar<T: AsRef<impl Default>>(t: T) {}

// Not allowed
fn another_foo<T>(t: T)
where
    T: Add<Output = impl Default>,
{
}
fn another_bar<T>(t: T)
where
    T: AsRef<impl Default>,
{
}

Besides, the error message isn't very helpful.

`impl Trait` only allowed in function and inherent method return types, not in *****bound***** (which bound?)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-confusingDiagnostics: Confusing error or lint that should be reworked.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions