Closed
Description
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.
Metadata
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsCategory: This is a bug.Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustcIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: A Minimal Complete and Verifiable Example has been found for this issueRelevant to the compiler team, which will review and decide on the PR/issue.This issue requires a build of rustc or tooling with debug-assertions in some way