Skip to content

encountered a fresh type during canonicalization #103626

@dwrensha

Description

@dwrensha

rustc crashes on the following input, found by fuzz_rustc:

fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m }
error[E0261]: use of undeclared lifetime name `'a` --> bug.rs:1:20 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^^ undeclared lifetime | = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html help: consider making the bound lifetime-generic with a new `'a` lifetime | 1 | fn w() where F:for<'a> Fn(&'a u){ b:std::ops::FromResidual & m } | +++++++ help: consider making the bound lifetime-generic with a new `'a` lifetime | 1 | fn w() where for<'a> F:Fn(&'a u){ b:std::ops::FromResidual & m } | +++++++ help: consider introducing lifetime `'a` here | 1 | fn w<'a>() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ++++ error[E0412]: cannot find type `F` in this scope --> bug.rs:1:14 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^ | help: a trait with a similar name exists | 1 | fn w() where Fn:Fn(&'a u){ b:std::ops::FromResidual & m } | ~~ help: you might be missing a type parameter | 1 | fn w<F>() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | +++ error[E0412]: cannot find type `u` in this scope --> bug.rs:1:23 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^ help: a builtin type with a similar name exists: `u8` error[E0425]: cannot find value `b` in this scope --> bug.rs:1:27 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^- help: maybe you meant to write a path separator here: `::` | | | not found in this scope error[E0425]: cannot find value `m` in this scope --> bug.rs:1:54 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^ not found in this scope error[E0601]: `main` function not found in crate `bug` --> bug.rs:1:57 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^ consider adding a `main` function to `bug.rs` error[E0658]: use of unstable library feature 'try_trait_v2' --> bug.rs:1:29 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^^^^^^^^^^^^^^^^^^^^^^ | = note: see issue #84277 <https://github.com/rust-lang/rust/issues/84277> for more information = help: add `#![feature(try_trait_v2)]` to the crate attributes to enable warning: trait objects without an explicit `dyn` are deprecated --> bug.rs:1:29 | 1 | fn w() where F:Fn(&'a u){ b:std::ops::FromResidual & m } | ^^^^^^^^^^^^^^^^^^^^^^ | = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021! = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html> = note: `#[warn(bare_trait_objects)]` on by default help: use `dyn` | 1 | fn w() where F:Fn(&'a u){ b:dyn std::ops::FromResidual & m } | +++ error: internal compiler error: compiler/rustc_infer/src/infer/canonical/canonicalizer.rs:420:17: encountered a fresh type during canonicalization thread 'rustc' panicked at 'Box<dyn Any>', /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/compiler/rustc_errors/src/lib.rs:1519:9 stack backtrace: 0: 0x7f0740dd95c0 - std::backtrace_rs::backtrace::libunwind::trace::hc24175774fcccc98 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 1: 0x7f0740dd95c0 - std::backtrace_rs::backtrace::trace_unsynchronized::hddff1d85f511dc1b at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7f0740dd95c0 - std::sys_common::backtrace::_print_fmt::he96e84d8aca849f4 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/sys_common/backtrace.rs:65:5 3: 0x7f0740dd95c0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8c690aa67f9b9f0b at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/sys_common/backtrace.rs:44:22 4: 0x7f07412587ae - core::fmt::write::h9205d5073fda8a0b at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/core/src/fmt/mod.rs:1209:17 5: 0x7f0740dcd375 - std::io::Write::write_fmt::h72ccddbdf2befca8 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/io/mod.rs:1682:15 6: 0x7f0740dd9385 - std::sys_common::backtrace::_print::h2243d2fa1c5bb008 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/sys_common/backtrace.rs:47:5 7: 0x7f0740dd9385 - std::sys_common::backtrace::print::hf6a50c16875f42b0 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/sys_common/backtrace.rs:34:9 8: 0x7f0740ddb6df - std::panicking::default_hook::{{closure}}::h57a3846e717bd3fa at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/panicking.rs:267:22 9: 0x7f0740ddb41a - std::panicking::default_hook::h1631ff080b8ff770 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/panicking.rs:286:9 10: 0x7f074009f634 - rustc_driver[62b0704af81f9759]::DEFAULT_HOOK::{closure#0}::{closure#0} 11: 0x7f0740ddbec9 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h353f36a44a5eebf1 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/alloc/src/boxed.rs:2001:9 12: 0x7f0740ddbec9 - std::panicking::rust_panic_with_hook::h483dc93595b087d7 at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/panicking.rs:692:13 13: 0x7f0740532bc1 - std[e5fb0ad32021ee83]::panicking::begin_panic::<rustc_errors[f55630e1eea6f6be]::ExplicitBug>::{closure#0} 14: 0x7f074052f696 - std[e5fb0ad32021ee83]::sys_common::backtrace::__rust_end_short_backtrace::<std[e5fb0ad32021ee83]::panicking::begin_panic<rustc_errors[f55630e1eea6f6be]::ExplicitBug>::{closure#0}, !> 15: 0x7f074052f636 - std[e5fb0ad32021ee83]::panicking::begin_panic::<rustc_errors[f55630e1eea6f6be]::ExplicitBug> 16: 0x7f07404c6016 - std[e5fb0ad32021ee83]::panic::panic_any::<rustc_errors[f55630e1eea6f6be]::ExplicitBug> 17: 0x7f07404c4eed - <rustc_errors[f55630e1eea6f6be]::HandlerInner>::bug::<&alloc[d7ff0ae8c2a4ed81]::string::String> 18: 0x7f07404c4960 - <rustc_errors[f55630e1eea6f6be]::Handler>::bug::<&alloc[d7ff0ae8c2a4ed81]::string::String> 19: 0x7f074057750d - rustc_middle[c0b7815efd07efec]::ty::context::tls::with_context_opt::<rustc_middle[c0b7815efd07efec]::ty::context::tls::with_opt<rustc_middle[c0b7815efd07efec]::util::bug::opt_span_bug_fmt<rustc_span[7a2d20772580c7f8]::span_encoding::Span>::{closure#0}, ()>::{closure#0}, ()> 20: 0x7f0740577866 - rustc_middle[c0b7815efd07efec]::util::bug::opt_span_bug_fmt::<rustc_span[7a2d20772580c7f8]::span_encoding::Span> 21: 0x7f073e37d003 - rustc_middle[c0b7815efd07efec]::util::bug::bug_fmt 22: 0x7f073e17697b - <rustc_infer[8e0743cc678018cd]::infer::canonical::canonicalizer::Canonicalizer as rustc_middle[c0b7815efd07efec]::ty::fold::TypeFolder>::fold_ty 23: 0x7f073e767b08 - <rustc_infer[8e0743cc678018cd]::infer::canonical::canonicalizer::Canonicalizer as rustc_middle[c0b7815efd07efec]::ty::fold::FallibleTypeFolder>::try_fold_predicate 24: 0x7f073e767098 - <rustc_infer[8e0743cc678018cd]::infer::canonical::canonicalizer::Canonicalizer>::canonicalize::<rustc_middle[c0b7815efd07efec]::ty::ParamEnvAnd<rustc_middle[c0b7815efd07efec]::ty::Predicate>> 25: 0x7f073e766a55 - <rustc_infer[8e0743cc678018cd]::infer::InferCtxt as rustc_trait_selection[7a29399ba840f18c]::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow 26: 0x7f0740c09bc5 - <rustc_infer[8e0743cc678018cd]::infer::InferCtxt>::probe::<bool, <rustc_infer[8e0743cc678018cd]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[7a29399ba840f18c]::traits::error_reporting::InferCtxtPrivExt>::predicate_can_apply::{closure#0}> 27: 0x7f0740c4f4dd - <rustc_infer[8e0743cc678018cd]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[7a29399ba840f18c]::traits::error_reporting::TypeErrCtxtExt>::report_selection_error 28: 0x7f0740c56c4c - <rustc_infer[8e0743cc678018cd]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[7a29399ba840f18c]::traits::error_reporting::InferCtxtPrivExt>::report_fulfillment_error 29: 0x7f0740c4b07d - <rustc_infer[8e0743cc678018cd]::infer::error_reporting::TypeErrCtxt as rustc_trait_selection[7a29399ba840f18c]::traits::error_reporting::TypeErrCtxtExt>::report_fulfillment_errors 30: 0x7f073e4e665e - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::demand_coerce 31: 0x7f073e4e0de5 - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_overloaded_binop 32: 0x7f073e463ede - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_binop 33: 0x7f073e45867b - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args 34: 0x7f073e49af27 - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_block_with_expected 35: 0x7f073e45669b - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args 36: 0x7f073f0d5f86 - <rustc_hir_typeck[92d554a17c266936]::fn_ctxt::FnCtxt>::check_return_expr 37: 0x7f073f0d386a - rustc_hir_typeck[92d554a17c266936]::check::check_fn 38: 0x7f073f0c036c - rustc_hir_typeck[92d554a17c266936]::typeck 39: 0x7f073e6e482d - rustc_query_system[e96faf9c245748b3]::query::plumbing::try_execute_query::<rustc_query_impl[e8c6edc993fa4034]::plumbing::QueryCtxt, rustc_query_system[e96faf9c245748b3]::query::caches::DefaultCache<rustc_span[7a2d20772580c7f8]::def_id::LocalDefId, &rustc_middle[c0b7815efd07efec]::ty::context::TypeckResults>> 40: 0x7f073f8a3478 - rustc_data_structures[5434cf185ef65262]::sync::par_for_each_in::<&[rustc_span[7a2d20772580c7f8]::def_id::LocalDefId], <rustc_middle[c0b7815efd07efec]::hir::map::Map>::par_body_owners<rustc_hir_typeck[92d554a17c266936]::typeck_item_bodies::{closure#0}>::{closure#0}> 41: 0x7f073f8a3153 - rustc_hir_typeck[92d554a17c266936]::typeck_item_bodies 42: 0x7f073f79394a - rustc_query_system[e96faf9c245748b3]::query::plumbing::try_execute_query::<rustc_query_impl[e8c6edc993fa4034]::plumbing::QueryCtxt, rustc_query_system[e96faf9c245748b3]::query::caches::DefaultCache<(), ()>> 43: 0x7f073f793647 - rustc_query_system[e96faf9c245748b3]::query::plumbing::get_query::<rustc_query_impl[e8c6edc993fa4034]::queries::typeck_item_bodies, rustc_query_impl[e8c6edc993fa4034]::plumbing::QueryCtxt> 44: 0x7f073e6103aa - <rustc_session[f004b37ccc5cd57]::session::Session>::time::<(), rustc_hir_analysis[2e9e393b1de5c568]::check_crate::{closure#7}> 45: 0x7f073e60f56b - rustc_hir_analysis[2e9e393b1de5c568]::check_crate 46: 0x7f073e60f19b - rustc_interface[fd3d32691052b72b]::passes::analysis 47: 0x7f073f8f66e4 - rustc_query_system[e96faf9c245748b3]::query::plumbing::try_execute_query::<rustc_query_impl[e8c6edc993fa4034]::plumbing::QueryCtxt, rustc_query_system[e96faf9c245748b3]::query::caches::DefaultCache<(), core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>>> 48: 0x7f073f8f63e7 - rustc_query_system[e96faf9c245748b3]::query::plumbing::get_query::<rustc_query_impl[e8c6edc993fa4034]::queries::analysis, rustc_query_impl[e8c6edc993fa4034]::plumbing::QueryCtxt> 49: 0x7f073f423f7d - <rustc_interface[fd3d32691052b72b]::passes::QueryContext>::enter::<rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}::{closure#2}::{closure#3}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>> 50: 0x7f073f4204df - <rustc_interface[fd3d32691052b72b]::interface::Compiler>::enter::<rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}::{closure#2}, core[69220df7bf4c31ea]::result::Result<core[69220df7bf4c31ea]::option::Option<rustc_interface[fd3d32691052b72b]::queries::Linker>, rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>> 51: 0x7f073f4176d2 - rustc_span[7a2d20772580c7f8]::with_source_map::<core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>, rustc_interface[fd3d32691052b72b]::interface::run_compiler<core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>, rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}>::{closure#0}::{closure#1}> 52: 0x7f073f4171c9 - <scoped_tls[c5a5fd0946957a01]::ScopedKey<rustc_span[7a2d20772580c7f8]::SessionGlobals>>::set::<rustc_interface[fd3d32691052b72b]::interface::run_compiler<core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>, rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}>::{closure#0}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>> 53: 0x7f073f4167d8 - std[e5fb0ad32021ee83]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[fd3d32691052b72b]::util::run_in_thread_pool_with_globals<rustc_interface[fd3d32691052b72b]::interface::run_compiler<core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>, rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}>::{closure#0}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>> 54: 0x7f073f4164fc - <<std[e5fb0ad32021ee83]::thread::Builder>::spawn_unchecked_<rustc_interface[fd3d32691052b72b]::util::run_in_thread_pool_with_globals<rustc_interface[fd3d32691052b72b]::interface::run_compiler<core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>, rustc_driver[62b0704af81f9759]::run_compiler::{closure#1}>::{closure#0}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[69220df7bf4c31ea]::result::Result<(), rustc_errors[f55630e1eea6f6be]::ErrorGuaranteed>>::{closure#1} as core[69220df7bf4c31ea]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 55: 0x7f0740de2e33 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hab9c0585205bcace at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/alloc/src/boxed.rs:1987:9 56: 0x7f0740de2e33 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc1b376671ff7f5ba at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/alloc/src/boxed.rs:1987:9 57: 0x7f0740de2e33 - std::sys::unix::thread::Thread::new::thread_start::h1e626d066d8b584f at /rustc/bed4ad65bf7a1cef39e3d66b3670189581b3b073/library/std/src/sys/unix/thread.rs:108:17 58: 0x7f073cc94b43 - start_thread at ./nptl/./nptl/pthread_create.c:442:8 59: 0x7f073cd26a00 - clone3 at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 60: 0x0 - <unknown> 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.66.0-nightly (bed4ad65b 2022-10-25) running on x86_64-unknown-linux-gnu query stack during panic: #0 [typeck] type-checking `w` #1 [typeck_item_bodies] type-checking all item bodies #2 [analysis] running analysis passes on this crate end of query stack error: aborting due to 8 previous errors; 1 warning emitted Some errors have detailed explanations: E0261, E0412, E0425, E0601, E0658. For more information about an error, try `rustc --explain E0261`. 

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions