Skip to content

Warn for type parameter defaults on impl blocks #31543

Closed
@bluss

Description

@bluss

If I understand correctly, type parameter defaults have no effect in the block impl<T = default> Foo<T> { }.

Just like in PR #30724, this should have a warning and then an error.

Example (playground)

use std::marker::PhantomData;

struct Foo<T> {
    x: PhantomData<T>,
}

impl<T = i32> Foo<T> {
    pub fn new() -> Self {
        Foo { x: PhantomData }
    }
}

fn main() {
    let x = Foo::new();  // error: unable to infer enough type information about `_`
}

cc @nikomatsakis

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language 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