Skip to content

Internal compiler error (traits & associated consts) #56870

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
idubrov opened this issue Dec 16, 2018 · 4 comments · Fixed by #63473
Closed

Internal compiler error (traits & associated consts) #56870

idubrov opened this issue Dec 16, 2018 · 4 comments · Fixed by #63473
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@idubrov
Copy link

idubrov commented Dec 16, 2018

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

@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Dec 16, 2018
@Centril
Copy link
Contributor

Centril commented Dec 16, 2018

Regression seems to have happened in 1.26; Testing this with godbolt (1.25) works but it doesn't with 1.26.

@alexcrichton alexcrichton removed the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Dec 18, 2018
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 13, 2019
@Goddard
Copy link

Goddard commented Jun 1, 2019

error: internal compiler error: src/librustc/ty/subst.rs:491: Type parameter T/#1 (T/1) out of range when substituting (root type=Some(T)) substs=[T]

thread 'main' panicked at 'Box', src/librustc_errors/lib.rs:538:9
note: Run with RUST_BACKTRACE=1 for a backtrace.

@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system labels Jun 9, 2019
@andjo403
Copy link
Contributor

the example do not ICE any more from version 1.34.0 see https://godbolt.org/z/rQN231

@Centril Centril added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-help-wanted Call for participation: Help is requested to fix this issue. labels Aug 11, 2019
@adrian-budau
Copy link
Contributor

I'd like to work on this (specifically to add the tests). I've tested and can confirm as @andjo403 that the example does not trigger an ICE anymore.

Tested on:

  • rustc 1.36.0 (a53f9df32 2019-07-03)
  • rustc 1.38.0-nightly (9703ef666 2019-08-10)

adrian-budau added a commit to adrian-budau/rust that referenced this issue Aug 11, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 12, 2019
bors added a commit that referenced this issue Aug 12, 2019
Rollup of 10 pull requests

Successful merges:

 - #62108 (Use sharded maps for queries)
 - #63297 (Improve pointer offset method docs)
 - #63306 (Adapt AddRetag for shallow retagging)
 - #63406 (Suggest using a qualified path in patterns with inconsistent bindings)
 - #63431 (Revert "Simplify MIR generation for logical ops")
 - #63449 (resolve: Remove remaining special cases from built-in macros)
 - #63461 (docs: add stdlib env::var(_os) panic)
 - #63473 (Regression test for #56870)
 - #63474 (Add tests for issue #53598 and #57700)
 - #63480 (Fixes #63477)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this issue Aug 12, 2019
bors added a commit that referenced this issue Aug 12, 2019
Rollup of 9 pull requests

Successful merges:

 - #62108 (Use sharded maps for queries)
 - #63297 (Improve pointer offset method docs)
 - #63406 (Suggest using a qualified path in patterns with inconsistent bindings)
 - #63431 (Revert "Simplify MIR generation for logical ops")
 - #63449 (resolve: Remove remaining special cases from built-in macros)
 - #63461 (docs: add stdlib env::var(_os) panic)
 - #63473 (Regression test for #56870)
 - #63474 (Add tests for issue #53598 and #57700)
 - #63480 (Fixes #63477)

Failed merges:

r? @ghost
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-trait-system Area: Trait system C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-help-wanted Call for participation: Help is requested to fix this issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants