Skip to content

Error code E0116 causes high volume of incorrect compiler errors #125814

Closed

Description

@anthonydandrea

Hello! When an E0116 is present in a codebase, it causes a very large slew of other unrelated and incorrect errors to get printed to the terminal. Even though it's a beginner Rust mistake, this is extremely hard to diagnose in any codebase.

Possible solutions might be:

  1. If E0116 is found, just print that, and skip printing any other errors (preferred)

  2. If E0116 is found, print it at the very end (not preferable, as there may be hundreds of errors which print first)

Code

fn main() {
    let x = "hello";
    x.split(" ");
}

impl Vec<usize> {}

Meta

rustc --version --verbose:

rustc 1.78.0 (9b00956e5 2024-04-29) (built from a source tarball)
binary: rustc
commit-hash: 9b00956e56009bab2aa15d7bff10916599e3d6d6
commit-date: 2024-04-29
host: x86_64-unknown-linux-gnu
release: 1.78.0
LLVM version: 18.1.2

Error output

   Compiling playground v0.0.1 (/playground)
error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
 --> src/main.rs:6:1
  |
6 | impl Vec<usize> {}
  | ^^^^^^^^^^^^^^^ impl for type defined outside of crate.
  |
  = note: define and implement a trait or new type instead

error[E0599]: no method named `split` found for reference `&str` in the current scope
 --> src/main.rs:3:7
  |
3 |     x.split(" ");
  |       ^^^^^ method not found in `&str`

Some errors have detailed explanations: E0116, E0599.
For more information about an error, try `rustc --explain E0116`.
error: could not compile `playground` (bin "playground") due to 2 previous errors
Backtrace

<backtrace>

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 31, 2024
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 31, 2024
  3. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
    and removed
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    C-bugCategory: This is a bug.
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on May 31, 2024
  4. workingjubilee commented on Jun 1, 2024

    @workingjubilee
    Member

    ...huh, the impl Vec<usize> causes a failure to find .split on str...

  5. estebank commented on Jun 21, 2024

    @estebank
    Contributor

    This happens because the query crate_inherent_impls returns a Result<&'tcx CrateInherentImpls, ErrorGuaranteed>, which means that when calling that query, if there's any error being propagated, we don't actually get the inherent impls. The options are to modify the existing query to never forward the errors (which would break the query caching mechanism, I believe) or add a second query that always succeeds, as a fallback to the fallible query so that we can get as many of the inherent impls as possible for the later resolutions.

  6. anthonydandrea commented on Jun 21, 2024

    @anthonydandrea
    Author

    I've never contributed to Rust OSS but if this may be first-time-contributor friendly, I'd be happy to give it a go. Any pointers of where to try changes beyond crate_inherent_impls would be appreciated!

  7. estebank commented on Jun 21, 2024

    @estebank
    Contributor

    @anthonydandrea the most esoteric thing you'll have to deal with is the query system, as there's a function crate_inherent_impls with a corresponding query crate_inherent_impls which is a way of encoding the contract of the "providers", so that you can define whether calls should get memoized/cached on-disk. Because we want errors to be properly tracked, you'd have to add a new query that always succeeds that isn't cached, that only gets called if the other query call fails. You probably can put that logic behind a method in TyCtxt which deals with the fall back and then call that new method from everywhere the query gets called today.

  8. estebank commented on Dec 3, 2024

    @estebank
    Contributor

    Current output is doing what was originally requested:

    error[E0116]: cannot define inherent `impl` for a type outside of the crate where the type is defined
     --> src/main.rs:6:1
      |
    6 | impl Vec<usize> {}
      | ^^^^^^^^^^^^^^^ impl for type defined outside of crate
      |
      = note: define and implement a trait or new type instead
    
  9. added
    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    and removed
    D-confusingDiagnostics: Confusing error or lint that should be reworked.
    D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
    on Dec 3, 2024
  10. kei519 commented on Dec 4, 2024

    @kei519
    Contributor

    I want to try this, but like what tests should I add?

  11. estebank commented on Dec 4, 2024

    @estebank
    Contributor

    @kei519 it would be adding a file with

    fn main() {
        let x = "hello";
        x.split(" ");
    }
    
    impl Vec<usize> {} //~ ERROR E0116

    in a tests/ui/ sub-directory (need to find an appropriate place), and then run ./x.py test tests/ui --bless to create an .stderr file. Be aware that the first compile will take a while, depending on your hardware, so make some tea :)

  12. kei519 commented on Dec 5, 2024

    @kei519
    Contributor

    Thank you! I'll try.

    @rustbot claim

  13. added a commit that references this issue on Dec 5, 2024
  14. added a commit that references this issue on Dec 5, 2024
  15. Aditya-PS-05 commented on Jan 9, 2025

    @Aditya-PS-05
    Contributor

    @anthonydandrea , can you assign me this issue? I would love to solve it.

  16. workingjubilee commented on Jan 9, 2025

    @workingjubilee
    Member

    Resolved by #133890

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsE-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions