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

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 opened this issue Apr 17, 2021 · 4 comments · Fixed by #84499
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@5225225
Copy link
Contributor

5225225 commented Apr 17, 2021

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"

)

@5225225 5225225 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 Apr 17, 2021
@jyn514
Copy link
Member

jyn514 commented Apr 17, 2021

cc @estebank

@jyn514 jyn514 added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Apr 17, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Apr 17, 2021
@estebank
Copy link
Contributor

estebank commented Apr 18, 2021

Removing this early return would likely give you the suggestion, but given the current state of the code, I'm not sure we can give the "always correct" suggestion.

@Stupremee
Copy link
Member

Assigning P-high as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@Stupremee Stupremee added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Apr 19, 2021
@estebank
Copy link
Contributor

I have a fix for this in #84499.

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 P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

5 participants