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

Incorrect syntax when suggesting the use of Fn* traits as supertraits #118225

Open
xmh0511 opened this issue Nov 24, 2023 · 2 comments · Fixed by #118268
Open

Incorrect syntax when suggesting the use of Fn* traits as supertraits #118225

xmh0511 opened this issue Nov 24, 2023 · 2 comments · Fixed by #118268
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@xmh0511
Copy link

xmh0511 commented Nov 24, 2023

Code

`
Box<dyn Fn(Vec<AstValueExpr>)->AstValueExpr + Clone>
`

Current output

The diagnosis suggests writing this code:
only auto traits can be used as additional traits in a trait object
consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: Fn<(Vec<AstValueExpr>)>+ Clone {}`

Desired output

However, the use of `Fn*` series traits should be used as `Fn(Vec<AstValueExpr>)`, that is, the correct suggestion should be `trait NewTrait: Fn(Vec<AstValueExpr>)->AstValueExpr + Clone{}`

Rationale and extra context

740b75e08f494fe8171bd7b920361a47

Other cases

No response

Anything else?

No response

@xmh0511 xmh0511 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 Nov 24, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 24, 2023
@clubby789
Copy link
Contributor

A copy-pastable example:

pub fn a() -> Box<dyn Fn(u8) + Clone> {
    todo!()
}

suggests
trait NewTrait: Fn<(u8,)> + Clone {}
The code to print the trait path doesn't account for the Fn* trait syntax sugar

@clubby789 clubby789 added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Nov 24, 2023
@clubby789 clubby789 changed the title A wrong suggestion to use Fn* as supertrait Incorrect syntax when suggesting the use of Fn* traits as supertrait s Nov 24, 2023
@clubby789 clubby789 changed the title Incorrect syntax when suggesting the use of Fn* traits as supertrait s Incorrect syntax when suggesting the use of Fn* traits as supertraits Nov 24, 2023
@compiler-errors compiler-errors self-assigned this Nov 24, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 29, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 29, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 5, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 5, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 5, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
compiler-errors added a commit to compiler-errors/rust that referenced this issue Dec 5, 2023
…tebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 6, 2023
Rollup merge of rust-lang#118268 - compiler-errors:pretty-print, r=estebank

Pretty print `Fn<(..., ...)>` trait refs with parentheses (almost) always

It's almost always better, at least in diagnostics, to print `Fn(i32, u32)` instead of `Fn<(i32, u32)>`.

Related to but doesn't fix rust-lang#118225. That needs a separate fix.
@compiler-errors
Copy link
Member

Oops, this shouldn't have closed

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 D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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.

4 participants