Skip to content

Account for impl Trait { when impl Trait for Type { was intended #131273

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

estebank
Copy link
Contributor

@estebank estebank commented Oct 4, 2024

On editions where bare traits are never allowed, detect if the user has written impl Trait with no type, silence any dyn-compatibility errors, and provide a structured suggestion for the potentially missing type:

error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/missing-for-type-in-impl.rs:8:6
   |
LL | impl Foo<i64> {
   |      ^^^^^^^^
   |
help: add `dyn` keyword before this trait
   |
LL | impl dyn Foo<i64> {
   |      +++
help: you might have intended to implement this trait for a given type
   |
LL | impl Foo<i64> for /* Type */ {
   |               ++++++++++++++

CC #131051.

On editions where bare traits are never allowed, detect if the user has
written `impl Trait` with no type, silence any dyn-compatibility errors,
and provide a structured suggestion for the potentially missing type:

```
error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/missing-for-type-in-impl.rs:8:6
   |
LL | impl Foo<i64> {
   |      ^^^^^^^^
   |
help: add `dyn` keyword before this trait
   |
LL | impl dyn Foo<i64> {
   |      +++
help: you might have intended to implement this trait for a given type
   |
LL | impl Foo<i64> for /* Type */ {
   |               ++++++++++++++
```
@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Oct 4, 2024
@rustbot
Copy link
Collaborator

rustbot commented Oct 4, 2024

HIR ty lowering was modified

cc @fmease

@compiler-errors
Copy link
Member

r=me when green

@compiler-errors
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Oct 5, 2024

📌 Commit e057c43 has been approved by compiler-errors

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 Oct 5, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#129517 (Compute array length from type for unconditional panic lint. )
 - rust-lang#130367 (Check elaborated projections from dyn don't mention unconstrained late bound lifetimes)
 - rust-lang#130403 (Stabilize `const_slice_from_raw_parts_mut`)
 - rust-lang#130633 (Add support for reborrowing pinned method receivers)
 - rust-lang#131105 (update `Literal`'s intro)
 - rust-lang#131194 (Fix needless_lifetimes in stable_mir)
 - rust-lang#131260 (rustdoc: cleaner errors on disambiguator/namespace mismatches)
 - rust-lang#131267 (Stabilize `BufRead::skip_until`)
 - rust-lang#131273 (Account for `impl Trait {` when `impl Trait for Type {` was intended)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 08689af into rust-lang:master Oct 5, 2024
6 checks passed
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
Rollup merge of rust-lang#131273 - estebank:issue-131051, r=compiler-errors

Account for `impl Trait {` when `impl Trait for Type {` was intended

On editions where bare traits are never allowed, detect if the user has written `impl Trait` with no type, silence any dyn-compatibility errors, and provide a structured suggestion for the potentially missing type:

```
error[E0782]: trait objects must include the `dyn` keyword
  --> $DIR/missing-for-type-in-impl.rs:8:6
   |
LL | impl Foo<i64> {
   |      ^^^^^^^^
   |
help: add `dyn` keyword before this trait
   |
LL | impl dyn Foo<i64> {
   |      +++
help: you might have intended to implement this trait for a given type
   |
LL | impl Foo<i64> for /* Type */ {
   |               ++++++++++++++
```

CC rust-lang#131051.
@rustbot rustbot added this to the 1.83.0 milestone Oct 5, 2024
# for free to join this conversation on GitHub. Already have an account? # 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.

5 participants