Closed
Description
Code
(hand-reduced)
trait Trait<T> {
type Assoc;
}
impl<T> Trait<T> for Vec<T> {
type Assoc = ();
}
impl Trait<u8> for Vec<u8> {}
const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;
pub fn main() {
let x: isize = 3;
let _ = match x {
BAR => 2,
_ => 3,
};
}
(original)
use inner_private_module::*;
mod inner_private_module {
pub struct Unnameable1;
pub struct Unnameable2;
#[derive(Clone, Copy)]
pub struct Unnameable3;
pub struct Unnameable4;
pub struct Unnameable5;
pub struct Unnameable6;
pub struct Unnameable7;
#[derive(Default)]
pub struct Unnameable8;
pub enum UnnameableEnum {
NameableVariant
}
pub trait UnnameableTrait {
type Alias: Default;
}
impl Unnameable1 {
pub fn method_of_unnameable_type1(&self) -> &'static str {
"Hello1"
}
}
impl Unnameable2 {
pub fn method_of_unnameable_type2(&self) -> &'static str {
"Hello2"
}
}
impl Unnameable3 {
pub fn method_of_unnameable_type3(&self) -> &'static str {
"Hello3"
}
}
impl Unnameable4 {
pub fn method_of_unnameable_type4(&self) -> &'static str {
"Hello4"
}
}
impl Unnameable5 {
pub fn method_of_unnameable_type5(&self) -> &'static str {
"Hello5"
}
}
impl Unnameable6 {
pub fn method_of_unnameable_type6(&self) -> &'static str {
"Hello6"
}
}
impl Unnameable7 {
pub fn method_of_unnameable_type7(&self) -> &'static str {
"Hello7"
}
}
impl Unnameable8 {
pub fn method_of_unnameable_type8(&self) -> &'static str {
"Hello8"
}
}
impl UnnameableEnum {
pub fn method_of_unnameable_enum(&self) -> &'static str {
"HelloEnum"
}
}
}
pub fn function_returning_unnameable_type() -> Unnameable1 {
Unnameable1
}
pub const CONSTANT_OF_UNNAMEABLE_TYPE: Unnameable2 =
Unnameable2;
pub fn function_accepting_unnameable_type(_: Option<Unnameable3>) {}
pub type AliasOfUnnameableType = Unnameable4;
impl Unnameable1 {
pub fn inherent_method_returning_unnameable_type(&self) -> Unnameable5 {
Unnameable5
}
}
pub trait Tr {
fn trait_method_returning_unnameable_type(&self) -> Unnameable6 {
Unnameable6
}
}
impl Tr for Unnameable1 {}
pub use inner_private_module::UnnameableEnum::NameableVariant;
pub struct Struct {
pub field_of_unnameable_type: Unnameable7
}
pub static STATIC: Struct = Struct { field_of_unnameable_type: Unnameable7 } ;
impl UnnameableTrait for AliasOfUnnameableType {
type Alias = Unnameable8;
}
pub fn generic_function<T: UnnameableTrait>() -> T::Alias {
Default::default()
}
// Formerly this ICEd with the following message:
// Tried to project an inherited associated type during coherence checking,
// which is currently not supported.
//
// No we expect to run into a more user-friendly cycle error instead.
#![feature(specialization)]
//~^ WARN the feature `specialization` is incomplete
trait Trait<T> { type Assoc; }
//~^ ERROR E0391
impl<T> Trait<T> for Vec<T> {
type Assoc = ();
}
impl Trait<u8> for Vec<u8> {}
impl<T> Trait<T> for String {
type Assoc = ();
}
impl Trait<<Vec<u8> as T::Alias<u8>>::Assoc> for String {}
fn main() {}
//@ run-pass
const FOO: isize = 10;
const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;
const ZST: &() = unsafe { std::mem::transmute(1usize) };
const ZST_ARR: &[u8; 0] = unsafe { std::mem::transmute(1usize) };
const fn foo() -> isize { 4 }
const BOO: isize = foo();
pub fn main() {
let x: isize = 3;
let y = match x {
FOO => 1,
BAR => 2,
BOO => 4,
_ => 3
};
assert_eq!(y, 2);
let z = match &() {
ZST => 9,
};
assert_eq!(z, 9);
let z = match b"" {
ZST_ARR => 10,
};
assert_eq!(z, 10);
}
Meta
rustc --version --verbose
:
rustc 1.80.0-nightly (6f3df08aa 2024-05-30)
binary: rustc
commit-hash: 6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4
commit-date: 2024-05-30
host: x86_64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6
Error output
Command: rustc
error[E0119]: conflicting implementations of trait `Trait<u8>` for type `Vec<u8>`
--> r_consts_17666C.rs:9:1
|
5 | impl<T> Trait<T> for Vec<T> {
| --------------------------- first implementation here
...
9 | impl Trait<u8> for Vec<u8> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Vec<u8>`
Backtrace
error: internal compiler error: /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_middle/src/mir/consts.rs:374:32: expected bits of isize, got Ty(
3_isize,
)
thread 'rustc' panicked at /rustc/6f3df08aadf71e8d4bf7e49f5dc10dfa6f254cb4/compiler/rustc_middle/src/mir/consts.rs:374:32:
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_middle::mir::consts::Const>::eval_bits::{closure#0}
7: <rustc_mir_build::build::Builder>::test_candidates_with_or
8: <rustc_mir_build::build::Builder>::match_candidates::{closure#0}
9: <rustc_mir_build::build::Builder>::match_candidates
10: <rustc_mir_build::build::Builder>::lower_match_tree
11: <rustc_mir_build::build::Builder>::expr_into_dest
12: <rustc_mir_build::build::Builder>::as_temp_inner
13: <rustc_mir_build::build::Builder>::expr_as_place
14: <rustc_mir_build::build::Builder>::expr_as_place
15: <rustc_mir_build::build::Builder>::lower_scrutinee
16: <rustc_mir_build::build::Builder>::ast_block_stmts
17: <rustc_mir_build::build::Builder>::expr_into_dest
18: <rustc_mir_build::build::Builder>::expr_into_dest::{closure#0}
19: <rustc_mir_build::build::Builder>::expr_into_dest
20: rustc_mir_build::build::construct_fn
21: rustc_mir_build::build::mir_build
22: rustc_mir_transform::mir_built
[... omitted 1 frame ...]
23: rustc_mir_build::check_unsafety::check_unsafety
[... omitted 1 frame ...]
24: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_interface::passes::run_required_analyses::{closure#1}::{closure#0}>::{closure#0}
25: rustc_interface::passes::run_required_analyses
26: rustc_interface::passes::analysis
[... omitted 1 frame ...]
27: <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}>
28: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
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 `/Volumes/T7/workspace/240530_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-05-31T07_39_02-97364.txt` to your bug report
query stack during panic:
#0 [mir_built] building MIR for `main`
#1 [check_unsafety] unsafety-checking `main`
#2 [analysis] running analysis passes on this crate
end of query stack
error[E0282]: type annotations needed
--> r_consts_17666C.rs:11:12
|
11 | const BAR: <Vec<u8> as Trait<u8>>::Assoc = 3;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0119, E0282.
For more information about an error, try `rustc --explain E0119`.
Note
- ICE location:
rustc_middle/src/mir/consts.rs L374
rust/compiler/rustc_middle/src/mir/consts.rs
Lines 370 to 375 in 6f3df08
- A solved ICE issue ICE:
expected bits of u8, got Ty(10_u32,)
#123092 has identical ICE location.
Metadata
Metadata
Assignees
Labels
Area: Constant evaluation, covers all const contexts (static, const fn, ...)Category: 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.
Type
Projects
Status
Done