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

Lint bare traits in AstConv. #89090

Merged
merged 6 commits into from
Dec 18, 2021
Merged

Lint bare traits in AstConv. #89090

merged 6 commits into from
Dec 18, 2021

Conversation

cjgillot
Copy link
Contributor

Removing the lint from lowering allows to:

  • make lowering querification easier;
  • have the lint implementation in only one place.

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2021
--> $DIR/bad-assoc-ty.rs:33:10
|
LL | type H = Fn(u8) -> (u8)::Output;
| ^^^^^^ help: use `dyn`: `<dyn Fn(u8)>`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one makes me uncomfortable, but I could not find how to fix it. Suggestions?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is outright incorrect, right? The whole type is <dyn Fn(u8) -> (u8)::Output>, if I'm reading this correctly. I think we can special case Fn traits in this format by looking at the poly_trait_ref.

It's also interesting that the error below is already making some suggestions, so it might make sense to only emit this one if E0233 isn't (but this might not be needed in this PR).

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

The reasoning behind the change makes sense, but I am concerned at some of the places we are silencing these errors, particularly in binding types (let x: &Trait = todo!() isn't being linted anymore).

self_ty.span,
|lint| {
let mut db = lint.build(msg);
db.span_suggestion(self_ty.span, "use `dyn`", sugg, app);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this a multipart_suggestion? We previously only highlighted the change to add dyn in most cases, now we underline the whole type, which is fine, but the more targeted spans aid in understanding what the change is supposed to be. Making that change requires instead of dealing with a string for the suggestion to deal with a vec of changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't really understand what kind of output you would like to see.

--> $DIR/bad-assoc-ty.rs:33:10
|
LL | type H = Fn(u8) -> (u8)::Output;
| ^^^^^^ help: use `dyn`: `<dyn Fn(u8)>`
Copy link
Contributor

Choose a reason for hiding this comment

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

This is outright incorrect, right? The whole type is <dyn Fn(u8) -> (u8)::Output>, if I'm reading this correctly. I think we can special case Fn traits in this format by looking at the poly_trait_ref.

It's also interesting that the error below is already making some suggestions, so it might make sense to only emit this one if E0233 isn't (but this might not be needed in this PR).

Comment on lines 10 to 11
//~^ ERROR trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition
Copy link
Contributor

Choose a reason for hiding this comment

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

These shouldn't go away, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The type checker skips looking at bodies if there is an error while checking signatures. As a consequence, no error is emitted on the locals because there is some on the parameter types.

@petrochenkov
Copy link
Contributor

I am concerned at some of the places we are silencing these errors, particularly in binding types

On 2021 edition bare traits are a hard error, so we must always report them regardless of their positions.
The 2021 edition error should ideally be moved to resolve (#83213 (comment)), it's simpler and more reliable to report it that way.

@bors

This comment has been minimized.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 8, 2021
@rust-log-analyzer

This comment has been minimized.

@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@cjgillot cjgillot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 17, 2021
@bors
Copy link
Contributor

bors commented Oct 18, 2021

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

@bors
Copy link
Contributor

bors commented Nov 14, 2021

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

@rust-log-analyzer

This comment has been minimized.

@bors

This comment has been minimized.

@cjgillot
Copy link
Contributor Author

@estebank, I introduced the multipart suggestions. Do you still have unresolved remarks on this PR?

@jackh726
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Dec 18, 2021

📌 Commit 6fcbc3a has been approved by jackh726

@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 Dec 18, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 18, 2021
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#87901 (Fix suggestion of additional `pub` when using `pub pub fn ...`)
 - rust-lang#89090 (Lint bare traits in AstConv.)
 - rust-lang#91818 (Show the unused type for `unused_results` lint)
 - rust-lang#91910 (miri: lift restriction on extern types being the only field in a struct)
 - rust-lang#91928 (Constify (most) `Option` methods)
 - rust-lang#91975 (Move generator check earlier in inlining.)
 - rust-lang#92016 (builtin_macros: allow external consumers for AsmArgs parsing)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7a626cf into rust-lang:master Dec 18, 2021
@rustbot rustbot added this to the 1.59.0 milestone Dec 18, 2021
@cjgillot cjgillot deleted the bare-dyn branch December 18, 2021 11:03
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.

9 participants