-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call 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) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Internal compiler error happens compiling weird code with traits and associated consts.
I tried this code:
use std::fmt::Debug;
pub trait Foo<T> {
const FOO: *const u8;
}
impl <T: Debug> Foo<T> for Debug {
const FOO: *const u8 = <T as Debug>::fmt as *const u8;
}
pub trait Bar {
const BAR: *const u8;
}
pub trait Baz {
type Data: Debug;
}
pub struct BarStruct<S: Baz>(S);
impl<S: Baz> Bar for BarStruct<S> {
const BAR: *const u8 = <Debug as Foo<<S as Baz>::Data>>::FOO;
}
struct AnotherStruct;
#[derive(Debug)]
struct SomeStruct;
impl Baz for AnotherStruct {
type Data = SomeStruct;
}
fn main() {
let _x = <BarStruct<AnotherStruct> as Bar>::BAR;
}
I expected to see this happen: compiler not to crash
Instead, this happened: compiler crashed with:
error: internal compiler error: src/librustc_traits/normalize_erasing_regions.rs:53: could not fully normalize `for<'r, 's, 't0> fn(&'r <S as Baz>::Data, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>`
thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:600:9
query stack during panic:
#0 [normalize_ty_after_erasing_regions] normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: for<'r, 's, 't0> fn(&'r <S as Baz>::Data, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> }`
#1 [const_eval_raw] const-evaluating `<(dyn std::fmt::Debug + 'static) as Foo<T>>::FOO`
--> src/main.rs:22:26
|
22 | const BAR: *const u8 = <Debug as Foo<<S as Baz>::Data>>::FOO;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#2 [optimized_mir] processing `<BarStruct<S> as Bar>::BAR`
#3 [const_eval_raw] const-evaluating `<BarStruct<S> as Bar>::BAR`
--> src/main.rs:34:12
|
34 | let _x = <BarStruct<AnotherStruct> as Bar>::BAR;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#4 [optimized_mir] processing `main`
#5 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error
Meta
Playground nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=59adf803ef87a6d4b1251408811542dd
Playground stable: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=59adf803ef87a6d4b1251408811542dd
Metadata
Metadata
Assignees
Labels
A-associated-itemsArea: Associated items (types, constants & functions)Area: Associated items (types, constants & functions)A-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-help-wantedCall for participation: Help is requested to fix this issue.Call for participation: Help is requested to fix this issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.Call 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) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.