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

ICE: assertion failed (left == right) in astconv.rs #38504

Closed
Nashenas88 opened this issue Dec 20, 2016 · 1 comment · Fixed by #38154
Closed

ICE: assertion failed (left == right) in astconv.rs #38504

Nashenas88 opened this issue Dec 20, 2016 · 1 comment · Fixed by #38154

Comments

@Nashenas88
Copy link
Contributor

The following code:

struct NotTrait { } // <--- Struct instead of trait

fn do_something() {
    let x: <NotImportant as NotTrait>::test = test;
    //                      ^ This and ^ this together are the problem
}

Produces the following error only on nightly. Stable and beta fail compilation without an ICE.

$ RUST_BACKTRACE=1 cargo build --verbose
   Compiling compiler_error v0.1.0 (file:///home/pfaria/compiler_error)
     Running `rustc --crate-name compiler_error src/lib.rs --crate-type lib -g -C metadata=8b5a0bdfc8a3f707 -C extra-filename=-8b5a0bdfc8a3f707 --out-dir /home/pfaria/compiler_error/target/debug/deps --emit=dep-info,link -L dependency=/home/pfaria/compiler_error/target/debug/deps`
error[E0404]: `NotTrait` is not a trait
 --> src/lib.rs:4:29
  |
4 |     let x: <NotImportant as NotTrait>::test = test;
  |                             ^^^^^^^^^^^^^^^ expected trait, found struct

error[E0412]: type name `NotImportant` is undefined or not in scope
 --> src/lib.rs:4:13
  |
4 |     let x: <NotImportant as NotTrait>::test = test;
  |             ^^^^^^^^^^^^ undefined or not in scope
  |
  = help: no candidates by the name of `NotImportant` found in your project; maybe you misspelled the name or forgot to import an external crate?

error[E0425]: unresolved name `test`
 --> src/lib.rs:4:47
  |
4 |     let x: <NotImportant as NotTrait>::test = test;
  |                                               ^^^^ unresolved name

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'assertion failed: `(left == right)` (left: `Some([type error])`, right: `None`)', /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1451
stack backtrace:
   1:     0x7f27b5bc038a - std::sys::imp::backtrace::tracing::imp::write::h0d1aacfb8fc693ac
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:42
   2:     0x7f27b5bce6ff - std::panicking::default_hook::{{closure}}::hff87359baf5754d0
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:349
   3:     0x7f27b5bce29d - std::panicking::default_hook::h936f17ca3b2b98dc
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:359
   4:     0x7f27b5bceba7 - std::panicking::rust_panic_with_hook::he9c830ab830c7944
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:553
   5:     0x7f27b5bcea34 - std::panicking::begin_panic::hbd10b7f500042f98
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:515
   6:     0x7f27b5bce959 - std::panicking::begin_panic_fmt::h49583ddd44614a0d
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:499
   7:     0x7f27b362edc2 - <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::def_to_ty::h103f6798e7cce8d2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1451
   8:     0x7f27b3630446 - <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty::h6713e7bc915e3b01
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1661
   9:     0x7f27b362fcfe - <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty::h6713e7bc915e3b01
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/astconv.rs:1665
  10:     0x7f27b35f0032 - <rustc_typeck::check::GatherLocalsVisitor<'a, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local::h32caf495969107a5
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:1871
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:711
  11:     0x7f27b3568d85 - rustc::hir::intravisit::walk_expr::h46c69156dee86d5f
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:894
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:251
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:882
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:242
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/obj/<walk_list macros>:2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:743
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:969
  12:     0x7f27b35f0c27 - rustc_typeck::check::check_fn::h21a5f04436a5bbc5
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/intravisit.rs:254
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:821
  13:     0x7f27b35efa1b - rustc_typeck::check::check_bare_fn::h38d017b7cdf453a4
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:661
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:502
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/infer/mod.rs:442
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1033
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1030
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:846
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/infer/mod.rs:442
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:502
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:651
  14:     0x7f27b35f2783 - rustc_typeck::check::check_item_body::h93dbfca77b60ad10
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:928
  15:     0x7f27b35ed2b0 - rustc_typeck::check::check_item_bodies::ha9191bbc667904b7
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:565
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/dep_graph/visit.rs:45
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/hir/mod.rs:456
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/dep_graph/visit.rs:67
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/mod.rs:2681
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:591
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/session/mod.rs:232
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/check/mod.rs:589
  16:     0x7f27b3658f2f - rustc_typeck::check_crate::hd31dd2bc6ea91ceb
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/lib.rs:347
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/util/common.rs:34
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_typeck/lib.rs:347
  17:     0x7f27b5f64d01 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::hd352d0090529a6be
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:895
  18:     0x7f27b5f51b88 - rustc_driver::driver::phase_3_run_analysis_passes::hf45ad5d717ac6301
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1033
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1030
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1017
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/local.rs:245
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:1014
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc/ty/context.rs:782
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:865
  19:     0x7f27b5f381d2 - rustc_driver::driver::compile_input::hc9da7de451d406ba
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/driver.rs:171
  20:     0x7f27b5f7db47 - rustc_driver::run_compiler::h408af14fa24a33a5
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:221
  21:     0x7f27b5e9b9e8 - std::panicking::try::do_call::h2c149962956958c1
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:1117
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:137
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/librustc_driver/lib.rs:1051
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:295
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:458
  22:     0x7f27b5bd73ca - __rust_maybe_catch_panic
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libpanic_unwind/lib.rs:98
  23:     0x7f27b5ebd328 - <F as alloc::boxed::FnBox<A>>::call_box::hf839c55097f480b2
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panicking.rs:434
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/panic.rs:351
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/thread/mod.rs:287
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:605
  24:     0x7f27b5bcd564 - std::sys::imp::thread::Thread::new::thread_start::h1fa04983ba2271d0
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/liballoc/boxed.rs:615
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys_common/thread.rs:21
                        at /buildslave/rust-buildbot/slave/nightly-dist-rustc-linux/build/src/libstd/sys/unix/thread.rs:84
  25:     0x7f27addd1709 - start_thread
  26:     0x7f27b588a82c - clone
  27:                0x0 - <unknown>

error: Could not compile `compiler_error`.

Caused by:
  process didn't exit successfully: `rustc --crate-name compiler_error src/lib.rs --crate-type lib -g -C metadata=8b5a0bdfc8a3f707 -C extra-filename=-8b5a0bdfc8a3f707 --out-dir /home/pfaria/compiler_error/target/debug/deps --emit=dep-info,link -L dependency=/home/pfaria/compiler_error/target/debug/deps` (exit code: 101)
@petrochenkov
Copy link
Contributor

Duplicate of #38409, fixed in #38154

bors added a commit that referenced this issue Dec 26, 2016
More systematic error reporting in path resolution

Path resolution for types, expressions and patterns used various heuristics to give more helpful messages on unresolved or incorrectly resolved paths.
This PR combines these heuristics and applies them to all non-import paths.

First a path is resolved in all namespaces, starting from its primary namespace (to give messages like "expected function, found macro, you probably forgot `!`").
If this resolution doesn't give a desired result we create a base error - either "path is not resolved" or "path is resolved, but the resolution is not acceptable in this context".
Other helps and notes are applied to this base error using heuristics.

Here's the list of heuristics for a path with a last segment `name` in order.
First we issue special messages for unresolved `Self` and `self`.
Second we try to find free items named `name` in other modules and suggest to import them.
Then we try to find fields and associated items named `name` and suggest `self.name` or `Self::name`.
After that we try several deterministic context dependent heuristics like "expected value, found struct, you probably forgot `{}`".
If nothing of the above works we try to find candidates with other names using Levenshtein distance.

---

Some alternatives/notes/unresolved questions:
- ~~I had a strong desire to migrate all affected tests to `test/ui`, diagnostics comparison becomes much more meaningful, but I did this only for few tests so far.~~ (Done)
- ~~Labels for "unresolved path" errors are mostly useless now, it may make sense to move some help/notes to these labels, help becomes closer to the error this way.~~ (Done)
- ~~Currently only the first successful heuristic results in additional message shown to the user, it may make sense to print them all, they are rarely compatible, so the diagnostics bloat is unlikely.~~ (Done)
- Now when #38014 landed `resolve_path` can potentially be replaced with `smart_resolve_path` in couple more places - e.g. ~~visibilities~~ (done), ~~import prefixes~~ (done), HIR paths.

---

Some additional fixes:
- Associated suggestions and typo suggestions are filtered with a context specific predicate to avoid inapplicable suggestions.
- `adjust_local_def` works properly in speculative resolution.
- I also fixed a recently introduced ICE in partially resolved UFCS paths (see test `ufcs-partially-resolved.rs`).     Minimal reproduction:
    ```
    enum E {}
    fn main() {
        <u8 as E>::A;
    }
    ```
    Fixes #38409, fixes #38504 (duplicates).
- Some bugs in resolution of visibilities are fixed - `pub(Enum)`, `pub(Trait)`, `pub(non::local::path)`.
- Fixes #38012.
---

r? @jseyfried for technical details + @jonathandturner  for diagnostics changes
How to read the patch: `smart_resolve_path(_fragment)/resolve_qpath_anywhere` are written anew and replace `resolve_trait_reference`/`resolve_type`/`resolve_pattern_path`/`resolve_struct_path`/`resolve_expr` for `ExprKind::Path`, everything else can be read as a diff.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants