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

Closed
eefriedman opened this issue Aug 24, 2015 · 9 comments
Closed

Lifetime in trait method declaration affects RFC 1214 checks #27987

eefriedman opened this issue Aug 24, 2015 · 9 comments
Labels
A-lifetimes Area: Lifetimes / regions A-traits Area: Trait system C-bug Category: This is a bug. P-low Low priority T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@eefriedman
Copy link
Contributor

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
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
Copy link
Member

/cc @rust-lang/lang

@steveklabnik steveklabnik added A-lang A-lifetimes Area: Lifetimes / regions A-traits Area: Trait system labels Sep 3, 2015
@nikomatsakis
Copy link
Contributor

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
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
Copy link
Contributor

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

bltavares added a commit to bltavares/glacier that referenced this issue May 30, 2016
@brson brson added T-lang Relevant to the language team, which will review and decide on the PR/issue. P-low Low priority labels Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 22, 2017
@steveklabnik
Copy link
Member

  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
Copy link
Contributor

arielb1 commented Jul 27, 2017

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

@Enselic
Copy link
Member

Enselic commented Sep 21, 2023

Triage: This has been marked P-low for 6 years, and during that time has had no updates at all. Note in particular the lack of "duplicate of" or "I also have this problem" comments. It seems very unlikely this issue will ever get fixed. Rather than keeping this open forever, let's close it as "won't fix".

@Enselic Enselic closed this as not planned Won't fix, can't repro, duplicate, stale Sep 21, 2023
@oli-obk oli-obk added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Sep 22, 2023
@oli-obk
Copy link
Contributor

oli-obk commented Sep 22, 2023

Both function pass with #![feature(trivial_bounds)] (as suggested by the diagnostic). So linking to #48214 which is the tracking issue for that feature.

I don't think we need this issue specifically to track such behaviour

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-traits Area: Trait system C-bug Category: This is a bug. P-low Low priority T-lang Relevant to the language team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants