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

Unconstrained lifetimes permitted in assoc. type as long as they are in a projection #29861

Closed
nikomatsakis opened this Issue Nov 16, 2015 · 4 comments

Comments

Projects
None yet
4 participants
@nikomatsakis
Copy link
Contributor

nikomatsakis commented Nov 16, 2015

This makes things unsound. Here is an example from @eddyb:

pub trait MakeRef<'a> {
    type Ref;
}
impl<'a, T: 'a> MakeRef<'a> for T {
    type Ref = &'a T;
}

pub trait MakeRef2 {
    type Ref2;
}
impl<'a, T> MakeRef2 for T {
    type Ref2 = <T as MakeRef<'a>>::Ref;
}

fn foo() -> <String as MakeRef2>::Ref2 { &String::from("foo") }

fn main() {
    println!("{}", foo());
}

This should be prohibited by https://github.com/rust-lang/rfcs/blob/master/text/0447-no-unused-impl-parameters.md, but it seems there is some bug.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor Author

nikomatsakis commented Nov 16, 2015

triage: P-high

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Nov 16, 2015

cc @james-darkfox (who tripped on this and #29859 in his lense crate)

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Nov 18, 2015

This is just stupid. I made ctp::parameters_for_type return the set of parameters that are constrained by a type, but we are also interested in the basis of parameters that determine a type, and I missed that that logic also uses the method. I will issue a patch.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Nov 18, 2015

I really should try to stop having my bugfixes having bugs.

arielb1 added a commit to arielb1/rust that referenced this issue Nov 19, 2015

constrained_type_params: make projections depend on their trait-ref
As this is a soundness fix, it is a [breaking-change].

Fixes rust-lang#29861.

bors added a commit that referenced this issue Nov 24, 2015

@bors bors closed this in #29934 Nov 24, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.