Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type parameter defaults are not checked correctly #26633

Closed
Tobba opened this issue Jun 28, 2015 · 7 comments
Closed

Type parameter defaults are not checked correctly #26633

Tobba opened this issue Jun 28, 2015 · 7 comments
Labels
A-type-system Area: Type system T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@Tobba
Copy link
Contributor

Tobba commented Jun 28, 2015

This typechecks:

pub trait Foo {
    fn foo<E=<Self as Bar>::A>(_: E) { }
}

pub trait Bar {
    type A;
}

fn main() { }

Which doesn't really make a lot of sense and seems like it could be a backwards compatibility footgun.

@eddyb eddyb added the A-type-system Area: Type system label Jun 28, 2015
@jroesch
Copy link
Member

jroesch commented Jun 28, 2015

Can you clarify what you are expecting here? this looks fine to me. You are allowed to declare that default and it will be manifested at a call site to Foo::foo.

@eddyb
Copy link
Member

eddyb commented Jun 28, 2015

@jroesch the default depends on Self: Bar but that is implicit (due to a use of <Self as Bar> projection).
I am not sure that is actually a problem, as it will get type-checked at call sites (not in that specific form, though, not yet. would need defaults to be used in inference for that default to be instantiated).

@jroesch
Copy link
Member

jroesch commented Jun 28, 2015

@eddyb yeah that was my point, currently we don't check implied constraints like that in most places. You can do similar things in trait declarations but will receive a type error at a call site. Thought I agree that we should try to improve the error reporting. I would like to do some work in this area after we finish the current set of internal refactors.

@steveklabnik
Copy link
Member

Triage: so is this a problem or not?

@eddyb
Copy link
Member

eddyb commented Jan 3, 2017

cc @rust-lang/lang I am a bit worried about this.

EDIT: Currently the example hits #36887 in playpen on stable (1.14).
There might still be a way to construct a problematic example.

@Mark-Simulacrum
Copy link
Member

@rust-lang/lang didn't comment on this; I'm going to nominate.

@Mark-Simulacrum Mark-Simulacrum added I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels May 19, 2017
@nikomatsakis
Copy link
Contributor

I believe we intentionally deprecated this with #36887 -- we can probably just close this issue, in my opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants