Skip to content

Diagnostic when a trait is not in scope no longer tells you to add a use, instead tells you to box the receiver. #84272

Closed
@5225225

Description

@5225225

Given the following code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=057c1715bd0bea7866420e59e5a070f1

// Not including std::hash::Hasher, which is why the build fails
use std::hash::BuildHasher;

fn next_u64() -> u64 {
    let bh = std::collections::hash_map::RandomState::new();
    let h = bh.build_hasher();
    h.finish()
}

fn main() {}

The current (nightly) output is:

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `finish` found for struct `DefaultHasher` in the current scope
   --> src/main.rs:7:7
    |
7   |     h.finish()
    |       ^^^^^^ method not found in `DefaultHasher`
    |
help: consider wrapping the receiver expression with the appropriate type
    |
7   |     Box::new(h).finish()
    |     ^^^^^^^^^ ^
help: consider wrapping the receiver expression with the appropriate type
    |
7   |     Box::new(&mut h).finish()
    |     ^^^^^^^^^^^^^  ^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

On stable, there was a line telling you which trait you need to import in order to call the function.

   Compiling playground v0.0.1 (/playground)
error[E0599]: no method named `finish` found for struct `DefaultHasher` in the current scope
   --> src/main.rs:7:7
    |
7   |     h.finish()
    |       ^^^^^^ method not found in `DefaultHasher`
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
2   | use std::hash::Hasher;
    |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
error: could not compile `playground`

To learn more, run the command again with --verbose.

Also, boxing the object here isn't helpful, so it shouldn't be suggested.

Bisected this, and I'm assuming that the relevant issue is #83667, but I'm not sure how I would verify that.


searched nightlies: from nightly-2021-03-30 to nightly-2021-03-31
regressed nightly: nightly-2021-03-31
searched commits: from 48691ea to 74874a6
regressed commit: 16156fb

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --test-dir=. --start=2021-03-30 --end=2021-03-31 --preserve --script=./test.sh 

(where test.sh is

#!/bin/bash

cargo check 2>&1 | grep "std::hash::Hasher"

)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsP-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions