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

Rustc says method doesn't exist instead of hinting at unsatisfied trait bounds #71505

Open
Kixunil opened this issue Apr 24, 2020 · 3 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Kixunil
Copy link
Contributor

Kixunil commented Apr 24, 2020

As described in #67642 (comment) when one attempts to call a triat method with unsatisfied bounds, the message says the method doesn't exist instead of explaining that the bounds weren't satisfied.

I tried this code:

use std::collections::HashMap;

struct Foo;

fn main() {
    let a: HashMap<Foo, String> = HashMap::default();
    let mut b: HashMap<Foo, String> = HashMap::default();
    b.extend(a);
}

I expected to see this happen: Rustc message saying that Eq and Hash aren't satisfied.

Instead, this happened: Rustc says that extend doesn't exist.

Meta

The bug is in nightly

Tested on the playground:

 1.44.0-nightly (2020-04-22 b2e36e6c2d229126b59e)
@Kixunil Kixunil added the C-bug Category: This is a bug. label Apr 24, 2020
@jonas-schievink jonas-schievink 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 24, 2020
@estebank estebank added the D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. label Apr 24, 2020
@estebank
Copy link
Contributor

estebank commented Aug 3, 2023

Current output:

error[E0599]: no method named `extend` found for struct `HashMap` in the current scope
 --> src/main.rs:8:7
  |
8 |     b.extend(a);
  |       ^^^^^^ method not found in `HashMap<Foo, String>`

@estebank
Copy link
Contributor

estebank commented Mar 7, 2025

This was an attempt at exploring what is needed to track this information correctly.

@lcnr / @compiler-errors (question about trait solver): I noticed that we currently don't track the elaborated obligations' failures beyond the signal EvaluatedToErr. Would it make sense to make that a signaling error that collects all the predicates that failed, in order to be able to present information on E0599 when only some of the trait bounds failed for a method that otherwise should be present?

@lcnr
Copy link
Contributor

lcnr commented Mar 10, 2025

I am hesitant about this. How does your desired behavior differ from the behavior of using a fullfillment context/ObligationCtxt? I think we should not report errors for failures when using evaluation but instead get a FulfillmentError.

If you prove Vec<T>: Clone via a fulfillment context you already get an error talking about T: Clone.

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 C-bug Category: This is a bug. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants