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

Don't suggest dereferencing on &dyn T where T is a trait #115569

Closed
typesanitizer opened this issue Sep 5, 2023 · 0 comments · Fixed by #115629
Closed

Don't suggest dereferencing on &dyn T where T is a trait #115569

typesanitizer opened this issue Sep 5, 2023 · 0 comments · Fixed by #115629
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

@typesanitizer
Copy link

Code

fn use_iterator<I>(itr: I) where I: IntoIterator<Item = i32> {}

fn pass_iterator<I>(i: &dyn IntoIterator<Item = i32, IntoIter = I>)
where I: Iterator<Item = i32> {
    use_iterator(i);
}


### Current output

```Shell
error[E0277]: `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator
 --> src/main.rs:5:18
  |
5 |     use_iterator(i);
  |     ------------ ^ `&dyn IntoIterator<IntoIter = I, Item = i32>` is not an iterator
  |     |
  |     required by a bound introduced by this call
  |
  = help: the trait `Iterator` is not implemented for `&dyn IntoIterator<IntoIter = I, Item = i32>`
  = note: required for `&dyn IntoIterator<IntoIter = I, Item = i32>` to implement `IntoIterator`
note: required by a bound in `use_iterator`
 --> src/main.rs:1:37
  |
1 | fn use_iterator<I>(itr: I) where I: IntoIterator<Item = i32> {}
  |                                     ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `use_iterator`
help: consider dereferencing here
  |
5 |     use_iterator(*i);
  |                  +


### Desired output

```Shell
I'm not 100% sure, but I can't think of any situation under which `*` on `&dyn` is actually sensible given that `&dyn` is dynamically sized. So that suggestion should at least be removed.

Rationale and extra context

No response

Other cases

No response

Anything else?

Playground link: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=84f3066368cc498af5c078514f84525a

@typesanitizer typesanitizer 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 5, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 5, 2023
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 7, 2023
… r=oli-obk

Don't suggest dereferencing to unsized type

Rudimentary check that the self type is Sized. I don't really like any of this diagnostics code -- it's really messy and also really prone to false positives and negatives, but oh well.

Fixes rust-lang#115569
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 7, 2023
… r=oli-obk

Don't suggest dereferencing to unsized type

Rudimentary check that the self type is Sized. I don't really like any of this diagnostics code -- it's really messy and also really prone to false positives and negatives, but oh well.

Fixes rust-lang#115569
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 7, 2023
… r=oli-obk

Don't suggest dereferencing to unsized type

Rudimentary check that the self type is Sized. I don't really like any of this diagnostics code -- it's really messy and also really prone to false positives and negatives, but oh well.

Fixes rust-lang#115569
@bors bors closed this as completed in 38adedc Sep 8, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Sep 8, 2023
Rollup merge of rust-lang#115629 - compiler-errors:sugg-deref-unsize, r=oli-obk

Don't suggest dereferencing to unsized type

Rudimentary check that the self type is Sized. I don't really like any of this diagnostics code -- it's really messy and also really prone to false positives and negatives, but oh well.

Fixes rust-lang#115569
@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 8, 2023
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.

3 participants