rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.1k stars 12.55k forks source link

Internal Compiler Error building sample code from https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html #85070

Closed rootingfortrees closed 3 years ago

rootingfortrees commented 3 years ago

Edit: this sounds like https://github.com/rust-lang/rust/issues/84341. Let me know if there's something useful I can provide from my local environment (I have the incremental compilation artifacts backed up).

Code

The code on its own is probably not helpful (it's the final version of the guessing game from chapter 2 of the book). I wrote this in VS code with the Rust extension installed and built it successfully with cargo; then I installed the rust-analyzer extension, disabled Rust, restarted VS code, and hit this error when trying to run from within the editor (and then after that consistently saw the same error when trying to build from the command line). Happy to provide any build artifacts that are useful (this is on Windows 10 Pro 19042.928).

use rand::Rng;
use std::cmp::Ordering;
use std::io;

fn main() {
    println!("Guess the number!");

    let secret_number = rand::thread_rng().gen_range(1..101);

    loop {
        println!("Please input your guess.");

        let mut guess = String::new();

        io::stdin()
            .read_line(&mut guess)
            .expect("Failed to read line");

        let guess: u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };

        println!("You guessed: {}", guess);

        match guess.cmp(&secret_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {
                println!("You win!");
                break;
            }
        }
    }
}

Meta

rustc --version --verbose:

>rustc --version --verbose
rustc 1.52.0 (88f19c6da 2021-05-03)
binary: rustc
commit-hash: 88f19c6dab716c6281af7602e30f413e809c5974
commit-date: 2021-05-03
host: x86_64-pc-windows-msvc
release: 1.52.0
LLVM version: 12.0.0

Error output

>cargo build --verbose
       Fresh cfg-if v1.0.0
       Fresh ppv-lite86 v0.2.10
       Fresh getrandom v0.2.2
       Fresh rand_core v0.6.2
       Fresh rand_chacha v0.3.0
       Fresh rand v0.8.3
   Compiling guessing_game v0.1.0 (C:\Users\{username}\code\rust\guessing_game)
     Running `rustc --crate-name guessing_game --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=5c97f38c8efdf5da --out-dir C:\Users\{username}\code\rust\guessing_game\target\debug\deps -C incremental=C:\Users\{username}\code\rust\guessing_game\target\debug\incremental -L dependency=C:\Users\{username}\code\rust\guessing_game\target\debug\deps --extern rand=C:\Users\{username}\code\rust\guessing_game\target\debug\deps\librand-cf02a276127e463a.rlib`
thread 'rustc' panicked at 'found unstable fingerprints for predicates_of(core[bd3a]::ops::deref::Deref): GenericPredicates { parent: None, predicates: [(Binder(TraitPredicate(<Self as std::ops::Deref>)), C:\Users\{username}\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\ops\deref.rs:64:1: 64:16 (#0))] }', /rustc/88f19c6dab716c6281af7602e30f413e809c5974\compiler\rustc_query_system\src\query\plumbing.rs:593:5
{backtrace moved to separate section}

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0 (88f19c6da 2021-05-03) running on x86_64-pc-windows-msvc

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [predicates_of] computing predicates of `std::ops::Deref`
#1 [typeck] type-checking `main`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `guessing_game`

Caused by:
  process didn't exit successfully: `rustc --crate-name guessing_game --edition=2018 src\main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=5c97f38c8efdf5da --out-dir C:\Users\{username}\code\rust\guessing_game\target\debug\deps -C incremental=C:\Users\{username}\code\rust\guessing_game\target\debug\incremental -L dependency=C:\Users\{username}\code\rust\guessing_game\target\debug\deps --extern rand=C:\Users\{username}\code\rust\guessing_game\target\debug\deps\librand-cf02a276127e463a.rlib` (exit code: 101)
Backtrace

``` stack backtrace: 0: 0x7ffa6af581fe - ::fmt::h3ee8647f7e1079db 1: 0x7ffa6af832fc - core::fmt::write::h37cf99794c5c88ee 2: 0x7ffa6af4bc58 - ::fmt::hbb31fdd82c487bf0 3: 0x7ffa6af5c39d - std::panicking::take_hook::he8d839f36ebc5025 4: 0x7ffa6af5be69 - std::panicking::take_hook::he8d839f36ebc5025 5: 0x7ffa4f11d9c7 - rustc_driver::report_ice::hc57d4e141f91d8a8 6: 0x7ffa6af5cbf5 - std::panicking::rust_panic_with_hook::h82b4e4f3be46852c 7: 0x7ffa6af5c761 - rust_begin_unwind 8: 0x7ffa6af58b4f - ::fmt::h3ee8647f7e1079db 9: 0x7ffa6af5c6b9 - rust_begin_unwind 10: 0x7ffa6afb4dec - std::panicking::begin_panic_fmt::h3cee835f7be6e70f 11: 0x7ffa51cddffc - ::visit_foreign_item::h8a641d9769f09835 12: 0x7ffa51d05b44 - ::visit_foreign_item::h8a641d9769f09835 13: 0x7ffa51f3a91b - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 14: 0x7ffa51c1a290 - ::visit_foreign_item::h8a641d9769f09835 15: 0x7ffa51e5c18d - ::try_print_query_stack::hcfeb9e88469194a3 16: 0x7ffa53151c11 - rustc_middle::ty::generics::GenericPredicates::instantiate_own::h51d523cc130602b9 17: 0x7ffa53151617 - rustc_middle::ty::generics::GenericPredicates::instantiate::he2f245abffd92c7a 18: 0x7ffa517b3633 - rustc_typeck::check::method::::lookup_method_in_trait::h262c595ae062c836 19: 0x7ffa517d0e74 - rustc_typeck::check::method::::resolve_ufcs::hc84cae5416e458b0 20: 0x7ffa519584d6 - rustc_lint::context::LintStore::get_lints::h121906fa46b88a25 21: 0x7ffa51741978 - rustc_typeck::check::autoderef::::adjust_steps::hfd03b1c5e67de876 22: 0x7ffa51820ba5 - rustc_typeck::check::inherited::Inherited::register_predicate::hb2a29cb9b7dd2d79 23: 0x7ffa517b1f84 - rustc_typeck::check::method::::lookup_method::h9facae27a820694d 24: 0x7ffa51759916 - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 25: 0x7ffa517592df - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 26: 0x7ffa517598d5 - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 27: 0x7ffa517592df - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 28: 0x7ffa51740e65 - rustc_typeck::check::_match::::check_match::h9f626a622567ce73 29: 0x7ffa5173e08e - rustc_typeck::check::_match::::check_match::h9f626a622567ce73 30: 0x7ffa5175984d - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 31: 0x7ffa517592df - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 32: 0x7ffa51759141 - rustc_typeck::check::demand::::check_for_cast::h547397e8d87f8fec 33: 0x7ffa5177c44f - rustc_typeck::check::fn_ctxt::checks::::check_decl_local::hf88eb3dd0a5e8b21 34: 0x7ffa5177c5c1 - rustc_typeck::check::fn_ctxt::checks::::check_stmt::h24e664f26b14ece2 35: 0x7ffa5177d041 - rustc_typeck::check::fn_ctxt::checks::::check_block_no_value::h04dadce00f98d3e8 36: 0x7ffa5177cbca - rustc_typeck::check::fn_ctxt::checks::::check_block_no_value::h04dadce00f98d3e8 37: 0x7ffa5175c8c1 - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 38: 0x7ffa517592df - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 39: 0x7ffa5177d089 - rustc_typeck::check::fn_ctxt::checks::::check_block_no_value::h04dadce00f98d3e8 40: 0x7ffa517592df - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 41: 0x7ffa51766534 - rustc_typeck::check::expr::::check_expr_with_expectation::ha3f484f82cb4a6ff 42: 0x7ffa51908cd1 - rustc_typeck::check::check::check_wf_new::h9c32b11c71de1be8 43: 0x7ffa51894488 - ::fmt::h5519b26bf4527d33 44: 0x7ffa51925641 - ::fold_ty::hd4ce30df61a3cf38 45: 0x7ffa51f22379 - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 46: 0x7ffa51e89989 - ::try_print_query_stack::hcfeb9e88469194a3 47: 0x7ffa51f4bc88 - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 48: 0x7ffa51c8b3ea - ::visit_foreign_item::h8a641d9769f09835 49: 0x7ffa51bf1958 - ::visit_foreign_item::h8a641d9769f09835 50: 0x7ffa51e60082 - ::try_print_query_stack::hcfeb9e88469194a3 51: 0x7ffa5181862b - ::fmt::h5859ca23977fa056 52: 0x7ffa51926ff3 - ::visit_item::h979a7c3a154b2bcd 53: 0x7ffa51f23ef9 - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 54: 0x7ffa51e8de3f - ::try_print_query_stack::hcfeb9e88469194a3 55: 0x7ffa51f5d56a - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 56: 0x7ffa51ca937b - ::visit_foreign_item::h8a641d9769f09835 57: 0x7ffa51be38db - ::visit_foreign_item::h8a641d9769f09835 58: 0x7ffa51e5ffc2 - ::try_print_query_stack::hcfeb9e88469194a3 59: 0x7ffa51819389 - ::fmt::h5859ca23977fa056 60: 0x7ffa51845ed7 - rustc_typeck::check_crate::ha5af7191d683cc6d 61: 0x7ffa4f270f2e - rustc_interface::passes::BoxedResolver::to_resolver_outputs::h7a1a389ffa8b4ef1 62: 0x7ffa51f23509 - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 63: 0x7ffa51e90b76 - ::try_print_query_stack::hcfeb9e88469194a3 64: 0x7ffa51f527c7 - ::store_diagnostics_for_anon_node::h5397f0d33c4b219c 65: 0x7ffa51cb5cca - ::visit_foreign_item::h8a641d9769f09835 66: 0x7ffa51c1774e - ::visit_foreign_item::h8a641d9769f09835 67: 0x7ffa51e5bfd2 - ::try_print_query_stack::hcfeb9e88469194a3 68: 0x7ffa4f189809 - ::fmt::he9bb74d196e6a2c3 69: 0x7ffa4f136a2b - ::fmt::hcb9f176ea80c3032 70: 0x7ffa4f1206cc - ::fmt::h5d81a6d2c7da3faa 71: 0x7ffa4f138637 - ::fmt::hcb9f176ea80c3032 72: 0x7ffa4f127de4 - rustc_driver::pretty::print_after_hir_lowering::hfe86111045a339ee 73: 0x7ffa4f139bbf - ::fmt::hcb9f176ea80c3032 74: 0x7ffa4f15929d - ::fmt::hcb9f176ea80c3032 75: 0x7ffa6af6bc9a - std::sys::windows::thread::Thread::new::h171cad5aadd5b51e 76: 0x7ffabe467034 - BaseThreadInitThunk 77: 0x7ffabe702651 - RtlUserThreadStart ```

bingo-ctrl commented 3 years ago

this may be helpful #84970

rootingfortrees commented 3 years ago

@bingo-ctrl thanks! Yeah deleting the incremental output did fix the error.

wesleywiser commented 3 years ago

Thanks for filing the bug report! We are currently triaging issues related to #84970 to ensure each underlying problem gets resolved. Since this appears to be a duplicate of #83259 so I'm going to close in favor of that issue.