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

non_lifetime_binders falsely recognizes (and rejects) trait as lifetime #119067

Closed
LastExceed opened this issue Dec 18, 2023 · 2 comments · Fixed by #119154
Closed

non_lifetime_binders falsely recognizes (and rejects) trait as lifetime #119067

LastExceed opened this issue Dec 18, 2023 · 2 comments · Fixed by #119154
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-non_lifetime_binders `#![feature(non_lifetime_binders)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@LastExceed
Copy link
Contributor

LastExceed commented Dec 18, 2023

minimal repro:

#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

trait MyTrait1 {}

trait MyTrait2
    where for <T: MyTrait1> ():
{
    
}

output:

error: lifetime bounds cannot be used in this context
 --> src/lib.rs:7:19
  |
7 |     where for <T: MyTrait1> ():
  |                   ^^^^^^^^

use case:

[playground]
weird example, i know. its difficult to construct a proper example that isn't overly complex

workaround:

add the bound to all call sites that require it (e.g. add where Human: Consume<Food> to foo() in the above example)

rustc:

1.76.0-nightly (2023-12-17 6a62871)

@LastExceed LastExceed added the C-bug Category: This is a bug. label Dec 18, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 18, 2023
@fmease fmease added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-non_lifetime_binders `#![feature(non_lifetime_binders)]` and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 18, 2023
@fmease
Copy link
Member

fmease commented Dec 18, 2023

Right, this is a diagnostic bug and a current limitation of non_lifetime_binders.

Obviously, we should say bounds cannot be used in this context instead (dropping the word lifetime). The diagnostic has simply never been updated after for<T> became syntactically valid and still assumes that for<'a: 'b> is the only possible way for a user to sneak in a higher-ranked bound.
Note to ppl interested in fixing this: Please add a regression test for the following code, too:

#![feature(closure_lifetime_binder)]
fn main() { let _ = for<T: Trait> || {}; }

Secondly, higher-ranked bounds aren't supported yet. There's a draft PR, namely #115362, which is blocked on a performance run.

@surechen
Copy link
Contributor

@rustbot claim

surechen added a commit to surechen/rust that referenced this issue Dec 20, 2023
surechen added a commit to surechen/rust that referenced this issue Dec 20, 2023
surechen added a commit to surechen/rust that referenced this issue Dec 21, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 21, 2023
Simple modification of `non_lifetime_binders`'s diagnostic information to adapt to type binders

fixes rust-lang#119067

Replace diagnostic information "lifetime bounds cannot be used in this context" to "bounds cannot be used in this context".

```rust
#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

trait Trait {}

trait Trait2
    where for <T: Trait> ():{}
//~^ ERROR bounds cannot be used in this context
```
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 21, 2023
Rollup merge of rust-lang#119154 - surechen:fix_119067, r=fmease

Simple modification of `non_lifetime_binders`'s diagnostic information to adapt to type binders

fixes rust-lang#119067

Replace diagnostic information "lifetime bounds cannot be used in this context" to "bounds cannot be used in this context".

```rust
#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

trait Trait {}

trait Trait2
    where for <T: Trait> ():{}
//~^ ERROR bounds cannot be used in this context
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints F-non_lifetime_binders `#![feature(non_lifetime_binders)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants