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

Lifetime in trait method declaration affects RFC 1214 checks #27987

Open
eefriedman opened this Issue Aug 24, 2015 · 7 comments

Comments

Projects
None yet
6 participants
@eefriedman
Copy link
Contributor

eefriedman commented Aug 24, 2015

trait Test {
    fn f<'a>(&self) where PartialEq<i32> : std::fmt::Display {}
}
trait Test2 {
    fn f<'a>(&self) where (PartialEq<i32> + 'a) : std::fmt::Display {}
}
fn main() {
}

Currently, Test1 triggers an "error", but Test2 doesn't. I would expect them to be treated the same way.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Aug 24, 2015

this is because middle::traits::normalize_param_env both

  • registers all predicates as obligations
  • adds all non-global predicates (these that don't contain lifetimes or type-variables) to the param-env where-clauses list

for this reason, predicates that contain lifetimes or type parameters can be used to satisfy themselves, while global predicates don't enter the where-clause list, and therefore correctly cause a warning. This is only an RFC1214 error because you did it in a trait method.

Type-less predicates being allowed in trait/impl methods can indeed cause ICEs:

pub struct S;
impl S {
    pub fn f<'a>(&self, f: &'a f32) where u32: PartialEq<&'a f32> {
        4==f;
    }
}
fn main() {}
@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Sep 3, 2015

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Sep 4, 2015

This has to do w/ the early- vs late-bound lifetime distinction. I'd like to ease and remove that distinction, but it'll take more effort to get there.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Sep 4, 2015

@nikomatsakis

No it doesn't. Nothing changes if you force 'a to be early-bound - e.g. by adding &'a (): Sized. This is just an consequence of the global-predicate-ignoring restriction.

@eefriedman was surprised by the distinction in #28046 though.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Sep 4, 2015

@arielb1 ah I see, yes, I stand corrected.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jul 25, 2017

  1. @arielb1 's example no longer ICEs.
  2. Test2 now compiles, Test does not.

I don't know what this means regarding the bug.

@arielb1

This comment has been minimized.

Copy link
Contributor

arielb1 commented Jul 27, 2017

The ICE was fixed by me in #42797, the "global predicate" thing is still present.

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.