rust-lang / rust-lang/rust

debug ice: `E0423` suggests assoc fns inside macro_rules

Open
#118,784 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics A-suggestion-diagnostics C-bug I-ICE requires-debug-assertions S-bug-has-test T-compiler
Dominant language
Rust
Stars
119k
Forks
16.2k
PR merge metrics
PR metrics pending

Description

Code
use std::collections::HashMap;

macro_rules! all_sync_send {
    ($ctor:expr, $($iter:expr),+) => ({
        $(
            let mut x = $ctor;
            is_sync(x.$iter());
            let mut y = $ctor;
            is_send(y.$iter());
        )+
    })
}

fn main() {
    all_sync_send!(HashMap, HashMap);
}

Meta

rustc --version --verbose:

f967532a47eb728ada44473a5c4c2eca1a45fe30
Error output

This is the offending suggestion

error[E0423]: expected function, tuple struct or tuple variant, found struct `HashMap`
   --> C066.rs:9:23
    |
9   |             is_send(y.$iter());
    |                       ^^^^^^^
...
15  |     all_sync_send!(HashMap, HashMap);
    |     -------------------------------- in this macro invocation
    |
   ::: /home/matthias/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/collections/hash/map.rs:213:1
    |
213 | pub struct HashMap<K, V, S = RandomState> {
    | ----------------------------------------- `HashMap` defined here
    |
    = note: this error originates in the macro `all_sync_send` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you might have meant to use an associated function to build this type
    |
9   |             is_send(y.$iter()::new());
    |                              ~~~~~~~
9   |             is_send(y.$iter()::with_capacity(_));
    |                              ~~~~~~~~~~~~~~~~~~
9   |             is_send(y.$iter()::with_hasher(_));
    |                              ~~~~~~~~~~~~~~~~
9   |             is_send(y.$iter()::with_capacity_and_hasher(_, _));
    |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
help: consider using the `Default` trait
    |
9   |             is_send(y.$iter() as std::default::Default>::default()<HashMap);
    |                             + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

especially this is_send(y.$iter() as std::default::Default>::default()<HashMap); looks very weird

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust reproducer in the issue and compare the diagnostic produced by the referenced nightly compiler. Trace the diagnostic suggestions for the macro_rules invocation, then verify that the completed fix no longer emits the malformed associated-function or Default-trait suggestions shown here.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.