Skip to content

Compiler crashes on a piece of code that misses some parenthesis around a tuple contained in Result::Ok #94334

@rgiot

Description

@rgiot

I am doing deep modifications to an existing program that was not raising compilation issues.
It is not yet finished, it is probably not nice rust code, but I am reaching a point where it make crashe the compiler.
You can reproduce it with:

git clone --depth=1 --branch rustc_crash https://github.com/cpcsdk/rust.cpclib.git cd rust.cpclib/cpclib-asm/ && cargo +nightly build 

I have to admit that I do not really know how to guide more to find the reason. But I can make specific tests on request.
I would say it is realted to issue #94291

Code

Here is the problematic code:

fn located_expr(input: Z80Span) -> IResult<Z80Span, LocatedExpr, VerboseError<Z80Span>> { let start = input.clone(); let (stop, exp) = expr(input)?; Ok( stop, LocatedExpr::new(exp, start.take(stop.input_len()-start.input_len())) ) }

When trying to reproducing it with this minimal example

use nom::{IResult, error::VerboseError, bytes::complete::tag, InputTake, InputLength}; type Z80Span = nom_locate::LocatedSpan<&'static str>; struct Expr(); struct LocatedExpr(Expr, Z80Span); impl LocatedExpr { fn new(expr: Expr, span: Z80Span) -> Self { todo!(); } } fn expr(input: Z80Span) -> IResult<Z80Span, Expr, VerboseError<Z80Span>> { todo!() } fn located_expr(input: Z80Span) -> IResult<Z80Span, LocatedExpr, VerboseError<Z80Span>> { let start = input.clone(); let (stop, exp) = expr(input)?; Ok( stop, LocatedExpr::new(exp, start.take(stop.input_len() - start.input_len())) ) }

The compiler does not crashes, but raises the following error:

error[E0061]: this enum variant takes 1 argument but 2 arguments were supplied --> src/lib.rs:20:5 | 20 | Ok( | ^^ expected 1 argument 21 | stop, | ---- 22 | LocatedExpr::new(exp, start.take(stop.input_len() - start.input_len())) | ----------------------------------------------------------------------- supplied 2 arguments 

If I add the missing pair of parenthesis for the tuple contained in Ok in my project, the compiler does not crashes anymore. (Maybe it means the bug is after the detection of these missing parenthesis).

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (532d3cda9 2022-02-23) binary: rustc commit-hash: 532d3cda90b8a729cd982548649d32803d265052 commit-date: 2022-02-23 host: x86_64-unknown-linux-gnu release: 1.61.0-nightly LLVM version: 14.0.0 

Error output

error: internal compiler error: compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs:318:26: while adjusting Expr { hir_id: HirId { owner: DefId(0:984 ~ cpclib_asm[cd45]::parser::parser::located_expr), local_id: 48 }, kind: Path(Resolved(None, Path { span: cpclib-asm/src/parser/parser.rs:3919:31: 3919:36 (#0), res: Local(HirId { owner: DefId(0:984 ~ cpclib_asm[cd45]::parser::parser::located_expr), local_id: 9 }), segments: [PathSegment { ident: start#0, hir_id: Some(HirId { owner: DefId(0:984 ~ cpclib_asm[cd45]::parser::parser::located_expr), local_id: 47 }), res: Some(Local(HirId { owner: DefId(0:984 ~ cpclib_asm[cd45]::parser::parser::located_expr), local_id: 9 })), args: None, infer_args: true }] })), span: cpclib-asm/src/parser/parser.rs:3919:31: 3919:36 (#0) }, can't compose [Borrow(Ref('_#2r, Not)) -> &source::Z80Span] and [Borrow(Ref('_#8r, Not)) -> &source::Z80Span] note: the compiler unexpectedly panicked. this is a bug. 
Backtrace

 thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1160:9 stack backtrace: 0: 0x7f09b1552d2c - std::backtrace_rs::backtrace::libunwind::trace::ha6a3383edab6e13f at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 1: 0x7f09b1552d2c - std::backtrace_rs::backtrace::trace_unsynchronized::h7678ada881e148be at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f09b1552d2c - std::sys_common::backtrace::_print_fmt::h0fccf51c6aaaecaa at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/sys_common/backtrace.rs:66:5 3: 0x7f09b1552d2c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd62bee1af47947a0 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/sys_common/backtrace.rs:45:22 4: 0x7f09b15b29dc - core::fmt::write::ha9439145beb73667 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/core/src/fmt/mod.rs:1190:17 5: 0x7f09b1542e58 - std::io::Write::write_fmt::h6c29ca798b983a86 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/io/mod.rs:1657:15 6: 0x7f09b1556d07 - std::sys_common::backtrace::_print::h3035fd29ed56746e at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/sys_common/backtrace.rs:48:5 7: 0x7f09b1556d07 - std::sys_common::backtrace::print::h67b4e33a29e4428d at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/sys_common/backtrace.rs:35:9 8: 0x7f09b1556d07 - std::panicking::default_hook::{{closure}}::h82b81eb8bc9dd6ef at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/panicking.rs:295:22 9: 0x7f09b15569bf - std::panicking::default_hook::h2bb2e237c5c6b178 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/panicking.rs:314:9 10: 0x7f09b1cec111 - rustc_driver[26d3d5263add57]::DEFAULT_HOOK::{closure#0}::{closure#0} 11: 0x7f099c85e423 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2048d48fe6c1b2ad at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/alloc/src/boxed.rs:1868:9 12: 0x7f099c8919ac - proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}::{{closure}}::h54144fafa68fac7a at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/proc_macro/src/bridge/client.rs:319:21 13: 0x7f099c890c70 - std::panicking::update_hook::{{closure}}::h19bf199960f99baf at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/panicking.rs:258:41 14: 0x7f09b15575d6 - std::panicking::rust_panic_with_hook::hdbef34545998f799 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/panicking.rs:702:17 15: 0x7f09b2dc1d71 - std[159a6a17188a9e73]::panicking::begin_panic::<rustc_errors[a8dffc0962701d3a]::ExplicitBug>::{closure#0} 16: 0x7f09b2dc1cd6 - std[159a6a17188a9e73]::sys_common::backtrace::__rust_end_short_backtrace::<std[159a6a17188a9e73]::panicking::begin_panic<rustc_errors[a8dffc0962701d3a]::ExplicitBug>::{closure#0}, !> 17: 0x7f09b2dc81cf - std[159a6a17188a9e73]::panicking::begin_panic::<rustc_errors[a8dffc0962701d3a]::ExplicitBug> 18: 0x7f09b2dd52fd - std[159a6a17188a9e73]::panic::panic_any::<rustc_errors[a8dffc0962701d3a]::ExplicitBug> 19: 0x7f09b2dd4587 - <rustc_errors[a8dffc0962701d3a]::HandlerInner>::bug 20: 0x7f09b2dd4080 - <rustc_errors[a8dffc0962701d3a]::Handler>::bug 21: 0x7f09b2c50421 - rustc_middle[98146359f81daf65]::ty::context::tls::with_opt::<rustc_middle[98146359f81daf65]::util::bug::opt_span_bug_fmt<rustc_span[7d35b7cf06b95e2a]::span_encoding::Span>::{closure#0}, ()> 22: 0x7f09b2c50650 - rustc_middle[98146359f81daf65]::util::bug::opt_span_bug_fmt::<rustc_span[7d35b7cf06b95e2a]::span_encoding::Span> 23: 0x7f09b2c505c6 - rustc_middle[98146359f81daf65]::util::bug::bug_fmt 24: 0x7f09b30cc1da - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::apply_adjustments 25: 0x7f09b3152718 - <rustc_typeck[c75d5fa9d82901dd]::check::method::confirm::ConfirmContext>::confirm 26: 0x7f09b30d48c3 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::lookup_method 27: 0x7f09b30bf23b - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_expr_kind 28: 0x7f09b30a4808 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_argument_types 29: 0x7f09b3081738 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_call 30: 0x7f09b30bf15c - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_expr_kind 31: 0x7f09b30a4808 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_argument_types 32: 0x7f09b3081738 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_call 33: 0x7f09b30bf15c - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_expr_kind 34: 0x7f09b30bd102 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation 35: 0x7f09b30ab854 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_block_with_expected 36: 0x7f09b30bd102 - <rustc_typeck[c75d5fa9d82901dd]::check::fn_ctxt::FnCtxt>::check_expr_with_expectation 37: 0x7f09b31bd4ed - rustc_typeck[c75d5fa9d82901dd]::check::check::check_fn 38: 0x7f09b313932a - <rustc_infer[6a8a85696ee20aa1]::infer::InferCtxtBuilder>::enter::<&rustc_middle[98146359f81daf65]::ty::context::TypeckResults, <rustc_typeck[c75d5fa9d82901dd]::check::inherited::InheritedBuilder>::enter<rustc_typeck[c75d5fa9d82901dd]::check::typeck_with_fallback<rustc_typeck[c75d5fa9d82901dd]::check::typeck::{closure#0}>::{closure#1}, &rustc_middle[98146359f81daf65]::ty::context::TypeckResults>::{closure#0}> 39: 0x7f09b311a69d - rustc_typeck[c75d5fa9d82901dd]::check::typeck 40: 0x7f09b40ebe10 - <rustc_query_system[e5ce915dae2fd7e8]::dep_graph::graph::DepGraph<rustc_middle[98146359f81daf65]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[98146359f81daf65]::ty::context::TyCtxt, rustc_span[7d35b7cf06b95e2a]::def_id::LocalDefId, &rustc_middle[98146359f81daf65]::ty::context::TypeckResults> 41: 0x7f09b35d2a48 - rustc_query_system[e5ce915dae2fd7e8]::query::plumbing::try_execute_query::<rustc_query_impl[c516436ef3f447dc]::plumbing::QueryCtxt, rustc_query_system[e5ce915dae2fd7e8]::query::caches::DefaultCache<rustc_span[7d35b7cf06b95e2a]::def_id::LocalDefId, &rustc_middle[98146359f81daf65]::ty::context::TypeckResults>> 42: 0x7f09b3629a0c - <rustc_query_impl[c516436ef3f447dc]::Queries as rustc_middle[98146359f81daf65]::ty::query::QueryEngine>::typeck 43: 0x7f09b317a42a - <rustc_middle[98146359f81daf65]::hir::map::Map>::par_body_owners::<rustc_typeck[c75d5fa9d82901dd]::check::typeck_item_bodies::{closure#0}> 44: 0x7f09b3e10dec - rustc_typeck[c75d5fa9d82901dd]::check::typeck_item_bodies 45: 0x7f09b410ac21 - <rustc_query_system[e5ce915dae2fd7e8]::dep_graph::graph::DepGraph<rustc_middle[98146359f81daf65]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[98146359f81daf65]::ty::context::TyCtxt, (), ()> 46: 0x7f09b405712c - rustc_query_system[e5ce915dae2fd7e8]::query::plumbing::try_execute_query::<rustc_query_impl[c516436ef3f447dc]::plumbing::QueryCtxt, rustc_query_system[e5ce915dae2fd7e8]::query::caches::DefaultCache<(), ()>> 47: 0x7f09b407fa88 - rustc_query_system[e5ce915dae2fd7e8]::query::plumbing::get_query::<rustc_query_impl[c516436ef3f447dc]::queries::typeck_item_bodies, rustc_query_impl[c516436ef3f447dc]::plumbing::QueryCtxt> 48: 0x7f09b3e14cb9 - <rustc_session[9a0814f637980201]::session::Session>::time::<(), rustc_typeck[c75d5fa9d82901dd]::check_crate::{closure#7}> 49: 0x7f09b3e114e3 - rustc_typeck[c75d5fa9d82901dd]::check_crate 50: 0x7f09b3b9e877 - rustc_interface[773294294e34a240]::passes::analysis 51: 0x7f09b4106f70 - <rustc_query_system[e5ce915dae2fd7e8]::dep_graph::graph::DepGraph<rustc_middle[98146359f81daf65]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[98146359f81daf65]::ty::context::TyCtxt, (), core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>> 52: 0x7f09b404ce40 - rustc_query_system[e5ce915dae2fd7e8]::query::plumbing::try_execute_query::<rustc_query_impl[c516436ef3f447dc]::plumbing::QueryCtxt, rustc_query_system[e5ce915dae2fd7e8]::query::caches::DefaultCache<(), core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>>> 53: 0x7f09b408eb65 - rustc_query_system[e5ce915dae2fd7e8]::query::plumbing::get_query::<rustc_query_impl[c516436ef3f447dc]::queries::analysis, rustc_query_impl[c516436ef3f447dc]::plumbing::QueryCtxt> 54: 0x7f09b3b7c8f8 - <rustc_interface[773294294e34a240]::passes::QueryContext>::enter::<rustc_driver[26d3d5263add57]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>> 55: 0x7f09b3b6bb6a - <rustc_interface[773294294e34a240]::interface::Compiler>::enter::<rustc_driver[26d3d5263add57]::run_compiler::{closure#1}::{closure#2}, core[b1995bd94a57dbad]::result::Result<core[b1995bd94a57dbad]::option::Option<rustc_interface[773294294e34a240]::queries::Linker>, rustc_errors[a8dffc0962701d3a]::ErrorReported>> 56: 0x7f09b3b6dd66 - rustc_span[7d35b7cf06b95e2a]::with_source_map::<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_interface[773294294e34a240]::interface::create_compiler_and_run<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_driver[26d3d5263add57]::run_compiler::{closure#1}>::{closure#1}> 57: 0x7f09b3b6b571 - rustc_interface[773294294e34a240]::interface::create_compiler_and_run::<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_driver[26d3d5263add57]::run_compiler::{closure#1}> 58: 0x7f09b3b56e72 - <scoped_tls[54534a13b092d0ba]::ScopedKey<rustc_span[7d35b7cf06b95e2a]::SessionGlobals>>::set::<rustc_interface[773294294e34a240]::interface::run_compiler<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_driver[26d3d5263add57]::run_compiler::{closure#1}>::{closure#0}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>> 59: 0x7f09b3b5672d - std[159a6a17188a9e73]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[773294294e34a240]::util::run_in_thread_pool_with_globals<rustc_interface[773294294e34a240]::interface::run_compiler<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_driver[26d3d5263add57]::run_compiler::{closure#1}>::{closure#0}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>>::{closure#0}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>> 60: 0x7f09b3b54f19 - <<std[159a6a17188a9e73]::thread::Builder>::spawn_unchecked_<rustc_interface[773294294e34a240]::util::run_in_thread_pool_with_globals<rustc_interface[773294294e34a240]::interface::run_compiler<core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>, rustc_driver[26d3d5263add57]::run_compiler::{closure#1}>::{closure#0}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>>::{closure#0}, core[b1995bd94a57dbad]::result::Result<(), rustc_errors[a8dffc0962701d3a]::ErrorReported>>::{closure#1} as core[b1995bd94a57dbad]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 61: 0x7f09b1563163 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hed4bb989451a58dc at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/alloc/src/boxed.rs:1854:9 62: 0x7f09b1563163 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha3b82106bd47d0e3 at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/alloc/src/boxed.rs:1854:9 63: 0x7f09b1563163 - std::sys::unix::thread::Thread::new::thread_start::h170b42a5b9d0a9fe at /rustc/532d3cda90b8a729cd982548649d32803d265052/library/std/src/sys/unix/thread.rs:108:17 64: 0x7f09b12fc927 - start_thread at ./nptl/./nptl/pthread_create.c:435:8 65: 0x7f09b138c9e4 - __clone at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:100 66: 0x0 - <unknown> 

Additional Trace

query stack during panic: #0 [typeck] type-checking `parser::parser::located_expr` #1 [typeck_item_bodies] type-checking all item bodies #2 [analysis] running analysis passes on this crate end of query stack 

Metadata

Metadata

Labels

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.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions