Skip to content

quickfix inserts where clause for tuple structs in wrong place and causes errors #10923

Closed
@coderedart

Description

@coderedart

I am newbie, so i will repeat when i learnt on rust official discord while debugging this issue.
Reproduce error:

  1. add derive_more and halfbrown as dependencies.

  2. create a tuple struct with halfbrown::HashMap as its only field.

  3. derive IntoIterator using derive_more with the #[derive(IntoIterator)]

  4. vscode/RA complain that the macro needs trait bounds of IntoIterator for the inner field.

  5. suggest the quickfix to put a where class specifying the requirement. I click on quickfix
    into

  6. quickfix introduces the where clause between the struct name and the parenthesis which declare the fields, which introduces a whole new class of errors
    after

the full errors that cargo check gives me:

error: proc-macro derive panicked
 --> src/main.rs:7:10
  |
7 | #[derive(IntoIterator)]
  |          ^^^^^^^^^^^^
  |
  = help: message: derive(IntoIterator) only works when forwarding to a single field. Try putting #[into_iterator] or #[into_iterator(ignore)] on the fields in the struct

error[E0658]: parenthetical notation is only stable when used with `Fn`-family traits
 --> src/main.rs:8:72
  |
8 | pub struct UOMap<K: std::hash::Hash,V> where halfbrown::HashMap<K, V>: std::iter::IntoIterator(HashMap<K, V>);
  |                                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #29625 <https://github.com/rust-lang/rust/issues/29625> for more information

error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied
   --> src/main.rs:8:83
    |
8   | pub struct UOMap<K: std::hash::Hash,V> where halfbrown::HashMap<K, V>: std::iter::IntoIterator(HashMap<K, V>);
    |                                                                                   ^^^^^^^^^^^^--------------- help: remove these parenthetical generics
    |                                                                                   |
    |                                                                                   expected 0 generic arguments
    |
note: trait defined here, with 0 generic parameters
   --> /home/red/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/collect.rs:204:11
    |
204 | pub trait IntoIterator {
    |           ^^^^^^^^^^^^

error[E0220]: associated type `Output` not found for `IntoIterator`
 --> src/main.rs:8:83
  |
8 | pub struct UOMap<K: std::hash::Hash,V> where halfbrown::HashMap<K, V>: std::iter::IntoIterator(HashMap<K, V>);
  |                                                                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `Output` not found

Some errors have detailed explanations: E0107, E0220, E0658.
For more information about an error, try `rustc --explain E0107`.

The Fix:
changing
pub struct UOMap<K: std::hash::Hash,V> where halfbrown::HashMap<K, V>: std::iter::IntoIterator(HashMap<K, V>);
to
pub struct UOMap<K: std::hash::Hash,V>(HashMap<K, V>) where halfbrown::HashMap<K, V>: std::iter::IntoIterator;
basically, insert the where clause AFTER the closing parenthesis. from what i was told on the discord, where clause needs to come just before the first {, but idk how it will be dealt with in regards to tuple struct.

rust-analyzer version: rust-analyzer version: d9b2291 2021-11-29 stable

rustc version: rustc 1.57.0 (f1edd0429 2021-11-29)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions