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

Error code E0794 for late-bound lifetime parameter error. #107416

Merged
merged 1 commit into from
Mar 18, 2023

Conversation

czzrr
Copy link
Contributor

@czzrr czzrr commented Jan 28, 2023

This PR addresses #80618.

@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2023

r? @WaffleLapkin

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 28, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 28, 2023

Some changes occurred in diagnostic error codes

cc @GuillaumeGomez

Copy link
Contributor

@eggyal eggyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small suggestions that, I think, make the explanation even clearer.

A lifetime parameter of a function definition is called *late-bound* if it both:

1. appears in an argument type
2. does not appear in a where clause
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to talk about not appearing in "a generic type constraint" rather than in "a where clause", as the 'a lifetime parameters in both fn<'a, T: Trait<'a>>(t: T) and fn<'a>(t: impl Trait<'a>) are early bound without there being any where clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point!

Comment on lines 8 to 10
function of a concrete type by substituting concrete types for
generic ones, you cannot specify a late-bound lifetime, because such lifetime
parameters are resolved at the function's call site(s).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function of a concrete type by substituting concrete types for
generic ones, you cannot specify a late-bound lifetime, because such lifetime
parameters are resolved at the function's call site(s).
concrete instance of the generic function, you cannot specify any of
its late-bound lifetime parameters, because they are not resolved until
each call site(s).

```

Lifetime parameters that are not late-bound are called *early-bound*.
The confusion might stem from the fact that late-bound and early-bound
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The confusion might stem from the fact that late-bound and early-bound
Confusion may arise from the fact that late-bound and early-bound

In the definition of `bar`, the lifetime parameter `'a` is late-bound, while
`'b` is early-bound. This is reflected in the type annotation for `bar_fn`,
where `'a` is universally quantified and `'b` is substituted by a specific
lifetime.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
lifetime.
lifetime. It is not possible to explicitly specify early-bound lifetime
parameters when late-bound parameters are present, although the types
that are constrained by early-bound parameters can be specified (as in the
example above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this what you mean? https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=c30a35a698a82969827f8260139c0f9d
It is possible in the sense that it just generates a warning, but warns about it being an error in the future.

Copy link
Contributor

@eggyal eggyal Jan 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, only just saw your comment (the trials and tribulations of GitHub mobile!). Yes, _bar_fn2 in your playground is what I meant—a number of the tests output the error message "cannot specify lifetime arguments explicitly if late bound lifetime parameters are present", but I didn't appreciate they were only warnings (which compiletest denies/upgrades to errors); I think it'd still be helpful to make some reference to it?

That _bar_fn3 in your playground compiles is completely consistent with your existing explanation: no attempt was made to (erroneously) specify concrete lifetimes for late-bound parameters in a function reference, nor was the function reference cast to a pointer that would require explicit universal quantification; lifetime parameter 'b is early-bound to the lifetime parameter of the second argument, whatever that ends up happening to be—it is existentially, not universally, quantified.

@rust-log-analyzer

This comment has been minimized.

@eggyal
Copy link
Contributor

eggyal commented Jan 29, 2023

I think it's a shame to have lost the bar_fn example that you originally had, which showed a function with both late and early-bound lifetime parameters, as it helped both to illustrate the difference and to show how early-bound parameters can be, erm, early bound.

@czzrr
Copy link
Contributor Author

czzrr commented Jan 29, 2023

@eggyal I agree, but I was unsure whether it fit the error code template while not being too lengthy.
Should I add it back? @GuillaumeGomez

@bors
Copy link
Contributor

bors commented Feb 1, 2023

☔ The latest upstream changes (presumably #102513) made this pull request unmergeable. Please resolve the merge conflicts.

@czzrr czzrr changed the title Error code E0793 for late-bound lifetime parameter error. Error code E0794 for late-bound lifetime parameter error. Feb 2, 2023
@WaffleLapkin
Copy link
Member

r? @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

Looks good to me and it's ok to add it back even if it's lengthy.

@bors
Copy link
Contributor

bors commented Feb 26, 2023

☔ The latest upstream changes (presumably #108488) made this pull request unmergeable. Please resolve the merge conflicts.

@czzrr
Copy link
Contributor Author

czzrr commented Mar 17, 2023

Bump. Is anything more needed? @GuillaumeGomez @WaffleLapkin

@GuillaumeGomez
Copy link
Member

No nothing. Sorry, completely forgot about it. Thanks for working on this!

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Mar 17, 2023

📌 Commit 75563cd has been approved by GuillaumeGomez

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 17, 2023
Error code E0794 for late-bound lifetime parameter error.

This PR addresses [rust-lang#80618](rust-lang#80618).
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 18, 2023
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#107416 (Error code E0794 for late-bound lifetime parameter error.)
 - rust-lang#108772 (Speed up tidy quite a lot)
 - rust-lang#109193 (Add revisions for -Zlower-impl-trait-in-trait-to-assoc-ty fixed tests)
 - rust-lang#109234 (Tweak implementation of overflow checking assertions)
 - rust-lang#109238 (Fix generics mismatch errors for RPITITs on -Zlower-impl-trait-in-trait-to-assoc-ty)
 - rust-lang#109283 (rustdoc: reduce allocations in `visibility_to_src_with_space`)
 - rust-lang#109287 (Use `size_of_val` instead of manual calculation)
 - rust-lang#109288 (Stabilise `unix_socket_abstract`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9599f3c into rust-lang:master Mar 18, 2023
@rustbot rustbot added this to the 1.70.0 milestone Mar 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants