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

Stand-in lifetime names for printing HRTs doesn’t avoid name collisions. #101280

Closed
steffahn opened this issue Sep 1, 2022 · 1 comment · Fixed by #101996
Closed

Stand-in lifetime names for printing HRTs doesn’t avoid name collisions. #101280

steffahn opened this issue Sep 1, 2022 · 1 comment · Fixed by #101996
Assignees
Labels
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.

Comments

@steffahn
Copy link
Member

steffahn commented Sep 1, 2022

E.g.

use std::cell::Cell;

fn f<'a>(f: fn(Cell<(&'a i32, &i32)>)) -> for<'l> fn(Cell<(&'l i32, &'l i32)>) {
    f
}

chooses the lifetime name “'r” for the fn-pointer type of the argument f and prints

error[E0308]: mismatched types
 --> src/lib.rs:4:5
  |
3 | fn f<'a>(f: fn(Cell<(&'a i32, &i32)>)) -> for<'l> fn(Cell<(&'l i32, &'l i32)>) {
  |                                           ------------------------------------ expected `for<'l> fn(Cell<(&'l i32, &'l i32)>)` because of return type
4 |     f
  |     ^ one type is more general than the other
  |
  = note: expected fn pointer `for<'l> fn(Cell<(&'l i32, &'l i32)>)`
             found fn pointer `for<'r> fn(Cell<(&'a i32, &'r i32)>)`

For more information about this error, try `rustc --explain E0308`.

However, rewriting the code into

use std::cell::Cell;
type Ty = for<'r> fn(Cell<(&'r i32, &'r i32)>);
fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
    f
}

does not currently make the compiler reconsider the choice of “'r” in the lifetime name, resulting in an unhelpful error message

error[E0308]: mismatched types
 --> src/lib.rs:4:5
  |
3 | fn f<'r>(f: fn(Cell<(&'r i32, &i32)>)) -> Ty {
  |                                           -- expected `for<'r> fn(Cell<(&'r i32, &'r i32)>)` because of return type
4 |     f
  |     ^ one type is more general than the other
  |
  = note: expected fn pointer `for<'r> fn(Cell<(&'r i32, &'r i32)>)`
             found fn pointer `for<'r> fn(Cell<(&'r i32, &'r i32)>)`
@steffahn steffahn 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. labels Sep 1, 2022
@b-naber
Copy link
Contributor

b-naber commented Sep 2, 2022

@rustbot claim

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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants