Closed
Description
Code
(hand reduced)
pub trait A {}
pub trait Mirror {
type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for dyn A {
type Assoc = T;
}
struct Bar {
foo: <dyn A + 'static as Mirror>::Assoc,
}
pub fn main() {
let strct = Bar { foo: 3 };
match strct {
Bar { foo: 1, .. } => {}
_ => (),
};
}
- Compared to original code, keyword
dyn
added atimpl<T: ?Sized> Mirror for dyn A
, to reduce error message.
original code
pub trait A {}
pub trait B: A {}
pub trait Mirror {
type Assoc: ?Sized;
}
impl<T: ?Sized> Mirror for A {
type Assoc = T;
}
pub fn foo<'a>(x: &'a <dyn A + 'static as Mirror>::Assoc) -> &'a <dyn B + 'static as Mirror>::Assoc {
static
}
//@ run-pass
#![feature(postfix_match)]
struct Bar {
foo: <dyn A + 'static as Mirror>::Assoc,
baz: u8,
}
pub fn main() {
let thing = Some("thing");
thing.match {
Some("nothing") => {},
Some(text) if text.eq_ignore_ascii_case("tapir") => {},
Some("true") | Some("false") => {},
Some("thing") => {},
Some(_) => {},
None => {}
};
let num = 2u8;
num.match {
0 => {},
1..=5 => {},
_ => {},
};
let slic = &[1, 2, 3, 4][..];
slic.match {
[1] => {},
[2, _tail @ ..] => {},
[1, _] => {},
_ => {},
};
slic[0].match {
1 => 0,
i => i,
};
let out = (1, 2).match {
(1, 3) => 0,
(_, 1) => 0,
(1, i) => i,
_ => 3,
};
assert!(out == 2);
let strct = Bar {
foo: 3,
baz: 4
};
strct.match {
Bar { foo: 1, .. } => {},
Bar { baz: 2, .. } => {},
_ => (),
};
}
Meta
rustc --version --verbose
:
rustc 1.80.0-nightly (f67a1acc0 2024-06-01)
binary: rustc
commit-hash: f67a1acc04c7ecbf05751b17592dd8d245b75256
commit-date: 2024-06-01
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Error output
Command: rustc
error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> r_rustc_1A93F6.rs:6:6
|
6 | impl<T: ?Sized> Mirror for dyn A {
| ^ unconstrained type parameter
error[E0282]: type annotations needed
--> r_rustc_1A93F6.rs:11:10
|
11 | foo: <dyn A + 'static as Mirror>::Assoc,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `T`
Backtrace
error: internal compiler error: compiler/rustc_pattern_analysis/src/rustc.rs:412:17: Encountered unexpected type in `ConstructorSet::for_ty`: ?0t
thread 'rustc' panicked at compiler/rustc_pattern_analysis/src/rustc.rs:412:17:
Box<dyn Any>
stack backtrace:
0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
5: rustc_middle::util::bug::bug_fmt
6: <rustc_pattern_analysis::rustc::RustcPatCtxt>::ctors_for_ty
7: rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>
8: rustc_pattern_analysis::usefulness::compute_exhaustiveness_and_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>
9: rustc_pattern_analysis::usefulness::compute_match_usefulness::<rustc_pattern_analysis::rustc::RustcPatCtxt>
10: rustc_pattern_analysis::analyze_match
11: <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::analyze_patterns
12: <rustc_mir_build::thir::pattern::check_match::MatchVisitor>::check_match
13: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
14: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
15: rustc_middle::thir::visit::walk_expr::<rustc_mir_build::thir::pattern::check_match::MatchVisitor>
16: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
17: <rustc_mir_build::thir::pattern::check_match::MatchVisitor as rustc_middle::thir::visit::Visitor>::visit_expr
18: rustc_mir_build::thir::pattern::check_match::check_match
[... omitted 2 frames ...]
19: rustc_mir_build::build::mir_build
20: rustc_mir_transform::mir_built
[... omitted 2 frames ...]
21: rustc_mir_build::check_unsafety::check_unsafety
[... omitted 2 frames ...]
22: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
23: <rustc_data_structures::sync::parallel::ParallelGuard>::run::<(), rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &[rustc_span::def_id::LocalDefId], <rustc_middle::hir::map::Map>::par_body_owners<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}>::{closure#0}::{closure#0}::{closure#0}>
24: <rustc_session::session::Session>::time::<(), rustc_interface::passes::run_required_analyses::{closure#1}>
25: rustc_interface::passes::analysis
[... omitted 2 frames ...]
26: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
27: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
28: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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: please make sure that you have updated to the latest nightly
note: please attach the file at `/Users/jisukbyun/workspace/240531_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-02T02_04_15-52985.txt` to your bug report
query stack during panic:
#0 [check_match] match-checking `main`
#1 [mir_built] building MIR for `main`
#2 [check_unsafety] unsafety-checking `main`
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0207, E0282.
For more information about an error, try `rustc --explain E0207`.
Note
- ICE location:
rustc_pattern_analysis/src/rustc.rs L412
rust/compiler/rustc_pattern_analysis/src/rustc.rs
Lines 411 to 413 in f67a1ac
Metadata
Metadata
Assignees
Labels
Relating to patterns and pattern matchingCategory: This is a bug.Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Status: This bug is tracked inside the repo by a `known-bug` test.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.