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

thread 'rustc' panicked at rust-nightly/compiler/rustc_errors/src/diagnostic.rs:1006:9: #133834

Closed
wxie7 opened this issue Dec 4, 2024 · 10 comments · Fixed by #133843
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-debug-assertions This issue requires a build of rustc or tooling with debug-assertions in some way S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wxie7
Copy link

wxie7 commented Dec 4, 2024

I tried this code:

use std::env;
use std::fs::{self, File};
use std::io::{self, Read, Write};
use std::process::{Command, Stdio};
use std::sync::{Arc, Mutex};
use std::thread;
use std::time::{Duration, Instant};
static PROGRAM: &'static str = "ls";
fn main() {
    let args: Vec<String> = env::args().collect();
    let mut list = String::from("");
    if args.len() < 2 {
        list += format!("{}/ \n", env!("PWD")).as_str();
    } else {
        list = get_files(&args[1]);
    };
    println!("The ls: \n{}", list);
}
fn get_files(dir_path: &str) -> String {
    let mut list = {
        print1!("Hello ");
        println1!("Dad!");
        println1!("Rust programming language is one of most famous.");
        println1!("You can click below link to learn more : https://www.rust-lang.org/");
    };
    let f = fs::read_dir(format!("{}", dir_path)).unwrap();
    for d in f {
        let dir = match d {
            Ok(d) => d,
            Err(e) => panic!("{:?}", e),
        };
        list += format!("{}\n", dir.path().display()).as_str();
    }
    return list;
}

I expected to see this happen: explanation

Instead, this happened: explanation

Meta

rustc --version --verbose:

commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.85.0-dev
LLVM version: 19.1.4
Backtrace

thread 'rustc' panicked at /data/xieym/workspace/rust/rust-nightly/compiler/rustc_errors/src/diagnostic.rs:1006:9:
Span must not be empty and have no suggestion
stack backtrace:
   0:     0x7f71a9f8bead - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h51e5276f25f67b8a
   1:     0x7f71aa045ea3 - core::fmt::write::h0a73bee6158cdbf1
   2:     0x7f71a9fb2309 - std::io::Write::write_fmt::h206d582822858877
   3:     0x7f71a9f8bd53 - std::sys::backtrace::BacktraceLock::print::h84a9a4c750ade733
   4:     0x7f71a9fc26fc - std::panicking::default_hook::{{closure}}::h216e29259e3d5cff
   5:     0x7f71a9fc24c5 - std::panicking::default_hook::h03ce982d60640bc4
   6:     0x7f71a5869e42 - <alloc[7c2d8435141f8e1e]::boxed::Box<rustc_driver_impl[d7b86d9e63f9aaed]::install_ice_hook::{closure#0}> as core[dcda4f281d996093]::ops::function::Fn<(&dyn for<'a
   7:     0x7f71a9fc2e68 - std::panicking::rust_panic_with_hook::h88b680004200a63a
   8:     0x7f71a9f8c33a - std::panicking::begin_panic_handler::{{closure}}::ha56090df9488ab86
   9:     0x7f71a9f8c169 - std::sys::backtrace::__rust_end_short_backtrace::h8833a10924a5c2d2
  10:     0x7f71a9fc27ed - rust_begin_unwind
  11:     0x7f71aa050a40 - core::panicking::panic_fmt::h57d6d212ea0ce749
  12:     0x7f71a60b734c - <rustc_errors[20cbecb65c2fd5d8]::diagnostic::Diag>::span_suggestion_with_style::<&str, &str>
  13:     0x7f71a5f199c6 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::emit_coerce_suggestions
  14:     0x7f71a622abbf - <rustc_hir_typeck[c5136c63f534b988]::coercion::CoerceMany<&rustc_hir[e98c40ff9570e545]::hir::Expr>>::coerce
  15:     0x7f71a5f1e25d - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_return_or_body_tail
  16:     0x7f71a5fb14a4 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_kind
  17:     0x7f71a5f1cbdf - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  18:     0x7f71a5faddc5 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  19:     0x7f71a5f4f056 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_block
  20:     0x7f71a5faf982 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_kind
  21:     0x7f71a5f1cbdf - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  22:     0x7f71a5faddc5 - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23:     0x7f71a5f1e1bf - <rustc_hir_typeck[c5136c63f534b988]::fn_ctxt::FnCtxt>::check_return_or_body_tail
  24:     0x7f71a624917b - rustc_hir_typeck[c5136c63f534b988]::check::check_fn
  25:     0x7f71a6241e2f - rustc_hir_typeck[c5136c63f534b988]::typeck
  26:     0x7f71a8045a35 - rustc_query_impl[bec2af351405b693]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bec2af351405b693]::query_impl::typeck::dynamic_query::{closure#2}::{
  27:     0x7f71a7fb5115 - <rustc_query_impl[bec2af351405b693]::query_impl::typeck::dynamic_query::{closure#2} as core[dcda4f281d996093]::ops::function::FnOnce<(rustc_middle[e6c5fc1c8185df8
  28:     0x7f71a7f12d34 - rustc_query_system[1b6cbf762e62559d]::query::plumbing::try_execute_query::<rustc_query_impl[bec2af351405b693]::DynamicConfig<rustc_data_structures[8c79ebd7d363ac4
  29:     0x7f71a81349fb - rustc_query_impl[bec2af351405b693]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f71a64a1e04 - <rustc_middle[e6c5fc1c8185df83]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[beef3382d6061d7f]::check_crate::{closure#4}>::{closure#0}
  31:     0x7f71a649155d - <rustc_data_structures[8c79ebd7d363ac43]::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures[8c79ebd7d363ac43]::sync::parallel::par_for_each_in<&rust
  32:     0x7f71a65098be - rustc_hir_analysis[beef3382d6061d7f]::check_crate
  33:     0x7f71a5b4b3b1 - rustc_interface[3a875bb8a3a01a82]::passes::analysis
  34:     0x7f71a8046053 - rustc_query_impl[bec2af351405b693]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[bec2af351405b693]::query_impl::analysis::dynamic_query::{closure#2}:
  35:     0x7f71a7fb5c41 - <rustc_query_impl[bec2af351405b693]::query_impl::analysis::dynamic_query::{closure#2} as core[dcda4f281d996093]::ops::function::FnOnce<(rustc_middle[e6c5fc1c8185d
  36:     0x7f71a7e608fc - rustc_query_system[1b6cbf762e62559d]::query::plumbing::try_execute_query::<rustc_query_impl[bec2af351405b693]::DynamicConfig<rustc_query_system[1b6cbf762e62559d]:
  37:     0x7f71a8243338 - rustc_query_impl[bec2af351405b693]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f71a583f8bb - <rustc_middle[e6c5fc1c8185df83]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}::{closure#1}::{closure#4}, core[
  39:     0x7f71a57f465a - <rustc_interface[3a875bb8a3a01a82]::queries::QueryResult<&rustc_middle[e6c5fc1c8185df83]::ty::context::GlobalCtxt>>::enter::<core[dcda4f281d996093]::result::Resul
  40:     0x7f71a580037c - <rustc_interface[3a875bb8a3a01a82]::interface::Compiler>::enter::<rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}::{closure#1}, core[dcda4f281d9960
  41:     0x7f71a58301de - <scoped_tls[46415f2badf08390]::ScopedKey<rustc_span[37f46e797e36bb53]::SessionGlobals>>::set::<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_with_globals
  42:     0x7f71a57e24dc - rustc_span[37f46e797e36bb53]::create_session_globals_then::<core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_intercore[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}>::{closure#1}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}>
  43:     0x7f71a586d232 - std[31742bae037c253]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_with_globals<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_pool_with_globals<rustc_interface[3a875bb8a3a01a82]::interface::run_compiler<core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}>::{closure#1}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>
  44:     0x7f71a57ee574 - <<std[31742bae037c253]::thread::Builder>::spawn_unchecked_<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_with_globals<rustc_interface[3a875bb8a3a01a82]::util::run_in_thread_pool_with_globals<rustc_interface[3a875bb8a3a01a82]::interface::run_compiler<core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>, rustc_driver_impl[d7b86d9e63f9aaed]::run_compiler::{closure#0}>::{closure#1}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dcda4f281d996093]::result::Result<(), rustc_span[37f46e797e36bb53]::ErrorGuaranteed>>::{closure#1} as core[dcda4f281d996093]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7f71aa00119d - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc538cfe9cf5a97c8
  46:     0x7f71a9f903ab - std::sys::pal::unix::thread::Thread::new::thread_start::h7a196e16c036c2e2
  47:     0x7f71a373cac3 - start_thread
                               at ./nptl/pthread_create.c:442:8
  48:     0x7f71a37ce850 - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  49:                0x0 - <unknown>

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

@wxie7 wxie7 added the C-bug Category: This is a bug. label Dec 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

I can't repro this. @wxie7 how did you invoke rustc? Does it require debug assertions?

@wxie7
Copy link
Author

wxie7 commented Dec 4, 2024

I can't repro this. @wxie7 how did you invoke rustc? Does it require debug assertions?

Yes, I compiled Rust on the latest commit c44b3d5 with assertions and debug-assertions enabled.

@jieyouxu jieyouxu added the requires-debug-assertions This issue requires a build of rustc or tooling with debug-assertions in some way label Dec 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

@wxie7 thanks for the report. Can you make sure that for future reports, if an ICE needs debug assertions to trigger that you explicitly state that in the issue description? You can also add the label yourself via @/rustbot label +requires-debug-assertions. Also it would be helpful if you can also add which exact commit you compiled rustc from (it's latest now but it won't be several hours later).

@jieyouxu jieyouxu added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Dec 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

@wxie7 also how did you derive this example? This and #133833 looks synthetically generated? Was it through fuzzing?

@jieyouxu jieyouxu added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 4, 2024
@wxie7
Copy link
Author

wxie7 commented Dec 4, 2024

@jieyouxu Mutate on the seed provided by the LLM.

@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

@wxie7 ok, so basically fuzzing. Can you make sure for fuzzed examples, that you follow the fuzzing guidelines https://rustc-dev-guide.rust-lang.org/fuzzing.html?highlight=fuzzing#in-a-nutshell, e.g. that you state that the example was fuzzer-produced and include sufficient info like rustc commit hash and debug assertions so we can repro? In particular, it would be very helpful if these examples can be further minimized.

@jieyouxu jieyouxu added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Dec 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

Minimized:

#![crate_type = "lib"]

fn foo() -> String {
    let mut bar = {
        unknown_macro!();
    };
    return bar;
}

requires the block-of-an-undefined-macro.

@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Dec 4, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 4, 2024

This one is suggest_return_binding_for_missing_tail_expr. I think the suggestion was always reachable by an empty span (probably due to resolve error from the undefined macro) since #106519 introduced the suggestion, but debug assertion makes the bisection tricky. cc @estebank for FYI.

@matthiaskrgr
Copy link
Member

duplicate of #114251 ? cc @Noratrieb

@estebank
Copy link
Contributor

estebank commented Dec 4, 2024

@matthiaskrgr not a duplicate, but the same underlying issue: trying to get the ; from a statement whose span doesn't include it (I believe it's a macro span issue).

estebank added a commit to estebank/rust that referenced this issue Dec 4, 2024
The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix rust-lang#133833, fix rust-lang#133834.
fmease added a commit to fmease/rust that referenced this issue Dec 4, 2024
Do not emit empty suggestion

The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix rust-lang#133833, fix rust-lang#133834.
fmease added a commit to fmease/rust that referenced this issue Dec 4, 2024
Do not emit empty suggestion

The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix rust-lang#133833, fix rust-lang#133834.
fmease added a commit to fmease/rust that referenced this issue Dec 5, 2024
Do not emit empty suggestion

The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix rust-lang#133833, fix rust-lang#133834.
@bors bors closed this as completed in 1b449e1 Dec 5, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 5, 2024
Rollup merge of rust-lang#133843 - estebank:empty-semi-sugg, r=jieyouxu

Do not emit empty suggestion

The `println!();` statement's span doesn't include the `;`, and the modified suggestions where trying to get the `;` by getting the differenece between the statement's and the expression's spans, which was an empty suggestion.

Fix rust-lang#133833, fix rust-lang#133834.
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. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-debug-assertions This issue requires a build of rustc or tooling with debug-assertions in some way S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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