Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

ICE: usize: cannot relate constants of different types', compiler/rustc_middle/src/ty/relate.rs:502:5 #83253

Closed
chengniansun opened this issue Mar 18, 2021 · 5 comments · Fixed by #83297
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chengniansun
Copy link

Code

impl X {
    fn getn<const N: usize>() -> [u8; N] {
        getn::<N>()
    }
}
fn getn<const N: cfg_attr>() -> [u8; N] {}

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (36f1f04f1 2021-03-17)
binary: rustc
commit-hash: 36f1f04f18b89ba4a999bcfd6584663fd6fc1c5d
commit-date: 2021-03-17
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 12.0.0

Error output

error[E0412]: cannot find type `X` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:6
  |
1 | impl X {
  |      ^ not found in this scope

error[E0573]: expected type, found built-in attribute `cfg_attr`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:6:18
  |
6 | fn getn<const N: cfg_attr>() -> [u8; N] {}
  |                  ^^^^^^^^ not a type

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / impl X {
2 | |     fn getn<const N: usize>() -> [u8; N] {
3 | |         getn::<N>()
4 | |     }
5 | | }
6 | | fn getn<const N: cfg_attr>() -> [u8; N] {}
  | |__________________________________________^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `[type error]`,
 right: `usize`: cannot relate constants of different types', /rustc/36f1f04f18b89ba4a999bcfd6584663fd6fc1c5d/compiler/rustc_middle/src/ty/relate.rs:502:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.52.0-nightly (36f1f04f1 2021-03-17) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1: 5:2>::getn`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0412, E0573, E0601.
For more information about an error, try `rustc --explain E0412`.
Backtrace

error[E0412]: cannot find type `X` in this scope
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:6
  |
1 | impl X {
  |      ^ not found in this scope

error[E0573]: expected type, found built-in attribute `cfg_attr`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:6:18
  |
6 | fn getn<const N: cfg_attr>() -> [u8; N] {}
  |                  ^^^^^^^^ not a type

error[E0601]: `main` function not found in crate `perses_node_priority_with_dfs_delta_reduced_mutant`
 --> perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1
  |
1 | / impl X {
2 | |     fn getn<const N: usize>() -> [u8; N] {
3 | |         getn::<N>()
4 | |     }
5 | | }
6 | | fn getn<const N: cfg_attr>() -> [u8; N] {}
  | |__________________________________________^ consider adding a `main` function to `perses_node_priority_with_dfs_delta_reduced_mutant.rs`

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `[type error]`,
 right: `usize`: cannot relate constants of different types', /rustc/36f1f04f18b89ba4a999bcfd6584663fd6fc1c5d/compiler/rustc_middle/src/ty/relate.rs:502:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/36f1f04f18b89ba4a999bcfd6584663fd6fc1c5d/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/36f1f04f18b89ba4a999bcfd6584663fd6fc1c5d/library/core/src/panicking.rs:92:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
   4: rustc_middle::ty::relate::super_relate_consts
   5: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_consts
   6: rustc_middle::ty::relate::super_relate_tys
   7: rustc_infer::infer::combine::<impl rustc_infer::infer::InferCtxt>::super_combine_tys
   8: <rustc_infer::infer::sub::Sub as rustc_middle::ty::relate::TypeRelation>::tys
   9: rustc_infer::infer::InferCtxt::commit_if_ok
  10: rustc_infer::infer::fudge::<impl rustc_infer::infer::InferCtxt>::fudge_inference_if_ok
  11: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::confirm_builtin_call
  12: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  13: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  14: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  15: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  16: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  17: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  18: rustc_typeck::check::check::check_fn
  19: rustc_infer::infer::InferCtxtBuilder::enter
  20: rustc_typeck::check::typeck
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  22: rustc_query_system::query::plumbing::force_query_with_job
  23: rustc_query_system::query::plumbing::get_query_impl
  24: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  25: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  26: rustc_typeck::check::typeck_item_bodies
  27: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  28: rustc_data_structures::stack::ensure_sufficient_stack
  29: rustc_query_system::query::plumbing::force_query_with_job
  30: rustc_query_system::query::plumbing::get_query_impl
  31: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  32: rustc_session::utils::<impl rustc_session::session::Session>::time
  33: rustc_typeck::check_crate
  34: rustc_interface::passes::analysis
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::force_query_with_job
  38: rustc_query_system::query::plumbing::get_query_impl
  39: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  40: rustc_interface::passes::QueryContext::enter
  41: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  42: rustc_span::with_source_map
  43: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.52.0-nightly (36f1f04f1 2021-03-17) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [typeck] type-checking `<impl at perses_node_priority_with_dfs_delta_reduced_mutant.rs:1:1: 5:2>::getn`
#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 3 previous errors

Some errors have detailed explanations: E0412, E0573, E0601.
For more information about an error, try `rustc --explain E0412`.

@chengniansun chengniansun added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 18, 2021
@SNCPlay42
Copy link
Contributor

getn's N parameter doesn't have to have an error type; it appears it can be any type (that doesn't trip the full const_generics feature gate error.) This version ICEs without any prior diagnostics:

fn foo<const N: usize>() -> [u8; N] {
    bar::<N>()
}

fn bar<const N: u8>() -> [u8; N] {}

Neither version ICEs on beta or stable. (const generics aren't stable on 1.50, but after reporting an error for use of unstable features the compiler reports the same errors as beta and doesn't ICE.)

@rustbot label A-const-generics regression-from-stable-to-nightly

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 18, 2021
@hameerabbasi
Copy link
Contributor

Bisected, this is a weird one:

********************************************************************************
Regression in nightly-2021-03-17
********************************************************************************

fetching https://static.rust-lang.org/dist/2021-03-16/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-03-16: 40 B / 40 B [===============] 100.00 % 697.91 KB/s converted 2021-03-16 to 107896c32d5dda4db508968ff34997a39d286966
fetching https://static.rust-lang.org/dist/2021-03-17/channel-rust-nightly-git-commit-hash.txt
nightly manifest 2021-03-17: 40 B / 40 B [===============] 100.00 % 705.85 KB/s converted 2021-03-17 to f5d8117c338a788bd24abec733fd143dfceb25a0
looking for regression commit between 2021-03-16 and 2021-03-17
opening existing repository at "rust.git"
refreshing repository
fetching (via local git) commits from 107896c32d5dda4db508968ff34997a39d286966 to f5d8117c338a788bd24abec733fd143dfceb25a0
opening existing repository at "rust.git"
refreshing repository
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 6 bors merge commits in the specified range
  commit[0] 2021-03-15UTC: Auto merge of #83121 - the8472:env-rwlock-2, r=joshtriplett
  commit[1] 2021-03-16UTC: Auto merge of #83153 - Aaron1011:eval-always-extern_mod_stmt_cnum, r=michaelwoerister
  commit[2] 2021-03-16UTC: Auto merge of #82898 - oli-obk:tait_🧊, r=nikomatsakis
  commit[3] 2021-03-16UTC: Auto merge of #82838 - Amanieu:rustdoc_asm, r=nagisa
  commit[4] 2021-03-16UTC: Auto merge of #83199 - JohnTitor:rollup-zrfk94a, r=JohnTitor
  commit[5] 2021-03-16UTC: Auto merge of #82536 - sexxi-goose:handle-patterns-take-2, r=nikomatsakis
validated commits found, specifying toolchains

installing 107896c32d5dda4db508968ff34997a39d286966
rustc for x86_64-unknown-linux-gnu: 1003.49 KB / 49.11 MB  2.00 % 881.96 KB/s 56rustc for x86_64-unknown-linux-gnu: 1004.49 KB / 49.11 MB  2.00 % 882.53 KB/s 56rustc for x86_64-unknown-linux-gnu: 1012.49 KB / 49.11 MB  2.01 % 889.51 KB/s 55rustc for x86_64-unknown-linux-gnu: 1020.49 KB / 49.11 MB  2.03 % 896.23 KB/s 55rustc for x86_64-unknown-linux-gnu: 1021.49 KB / 49.11 MB  2.03 % 896.79 KB/s 55cargo for x86_64-unknown-linux-gnu: 5.96 MB / 5.96 MB [====] 100.00 % 7.31 MB/s testing...
RESULT: 107896c32d5dda4db508968ff34997a39d286966, ===> No
uninstalling 107896c32d5dda4db508968ff34997a39d286966

installing f5d8117c338a788bd24abec733fd143dfceb25a0
cargo for x86_64-unknown-linux-gnu: 5.96 MB / 5.96 MB [====] 100.00 % 8.68 MB/s testing...
RESULT: f5d8117c338a788bd24abec733fd143dfceb25a0, ===> No
uninstalling f5d8117c338a788bd24abec733fd143dfceb25a0

ERROR: the commit at the end of the range (f5d8117c338a788bd24abec733fd143dfceb25a0) does not reproduce the regression

@apiraino
Copy link
Contributor

@hameerabbasi I've attempted a second bisection using the snippet from the second comment, I got a different result (not sure why, unsure if it helps)

searched nightlies: from nightly-2021-02-15 to nightly-2021-03-18
regressed nightly: nightly-2021-03-18
searched commits: from f5d8117 to 36f1f04
regressed commit: e655fb6

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --preserve --start=2021-02-15 --regress=ice 

@oli-obk oli-obk self-assigned this Mar 18, 2021
@oli-obk
Copy link
Contributor

oli-obk commented Mar 18, 2021

This PR does not cause functional changes

I guess that was a lie 🙃

I'm looking into this

@camelid
Copy link
Member

camelid commented Mar 19, 2021

Assigning P-high and removing I-prioritize as discussed in the prioritization working group.

@rustbot label: +P-high -I-prioritize

@rustbot rustbot added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 19, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 19, 2021
@bors bors closed this as completed in 51a29cb Mar 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. 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.

8 participants