Skip to content

ICE with explicit const params in method call. #70217

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
lcnr opened this issue Mar 21, 2020 · 4 comments · Fixed by #74392
Closed

ICE with explicit const params in method call. #70217

lcnr opened this issue Mar 21, 2020 · 4 comments · Fixed by #74392
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 21, 2020

split from #70167

comment by @eddyb

Alternatively, instead of using path.res to get the DefId, maybe we could use the Resolution from the segment we found the const parameter in?
I believe nowadays we have per-segment resolutions, which would avoid breaking GATs in the future.

Actually, I expect Struct::<N>::method::<M>() is also broken, let's try it... Yupp: (playground)

#![feature(const_generics)]

struct Struct<const N: usize>;

impl<const N: usize> Struct<N> {
    fn method<const M: usize>(&self) {}
}

fn test<const N: usize, const M: usize>(x: Struct<N>) {
    Struct::<N>::method::<M>(&x);
    x.method::<N>();
}

EDIT: took a second look and that M is in a QPath::TypeRelative, which has to be resolved by the body of test, which means it's as bad as the method call form (which I just added).

Maybe we should disallow passing explicit generic args to methods for now?
Since I have no idea how one would figure out the expected type.

playground

This fails with

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

error: internal compiler error: unexpected const parent path Expr(expr(HirId { owner: DefId(0:10 ~ playground[eddc]::test[0]), local_id: 12 }: Struct<>::method::<>))

error: internal compiler error: unexpected const parent in type_of_def_id(): Expr(expr(HirId { owner: DefId(0:10 ~ playground[eddc]::test[0]), local_id: 24 }: x.method::<>()))

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/lib.rs:10:27
   |
10 |     Struct::<N>::method::<M>(&x);
   |                           ^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:10:27
   |
10 |     Struct::<N>::method::<M>(&x);
   |                           ^

error: internal compiler error: broken MIR in DefId(0:15 ~ playground[eddc]::test[0]::{{constant}}[1]) ("return type"): bad type [type error]
  --> src/lib.rs:10:27
   |
10 |     Struct::<N>::method::<M>(&x);
   |                           ^

error: internal compiler error: broken MIR in DefId(0:15 ~ playground[eddc]::test[0]::{{constant}}[1]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/lib.rs:10:27: 10:28, scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:10:27
   |
10 |     Struct::<N>::method::<M>(&x);
   |                           ^

error: internal compiler error: mir_const_qualif: MIR had errors
  --> src/lib.rs:11:16
   |
11 |     x.method::<N>();
   |                ^

error: internal compiler error: PromoteTemps: MIR had errors
  --> src/lib.rs:11:16
   |
11 |     x.method::<N>();
   |                ^

error: internal compiler error: broken MIR in DefId(0:16 ~ playground[eddc]::test[0]::{{constant}}[2]) ("return type"): bad type [type error]
  --> src/lib.rs:11:16
   |
11 |     x.method::<N>();
   |                ^

error: internal compiler error: broken MIR in DefId(0:16 ~ playground[eddc]::test[0]::{{constant}}[2]) (LocalDecl { mutability: Mut, local_info: Other, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, source_info: SourceInfo { span: src/lib.rs:11:16: 11:17, scope: scope[0] } }): bad type [type error]
  --> src/lib.rs:11:16
   |
11 |     x.method::<N>();
   |                ^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:360:17
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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (1057dc97a 2020-03-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: could not compile `playground`.
@lcnr lcnr added the C-bug Category: This is a bug. label Mar 21, 2020
@eddyb
Copy link
Member

eddyb commented Mar 21, 2020

cc @varkor @yodaldevoid

@LeSeulArtichaut

This comment has been minimized.

@rustbot rustbot removed the C-bug Category: This is a bug. label Mar 21, 2020
@LeSeulArtichaut

This comment has been minimized.

@LeSeulArtichaut

This comment has been minimized.

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Mar 21, 2020
@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 21, 2020
@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Mar 23, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 27, 2020
lcnr added a commit to lcnr/rust that referenced this issue Jul 16, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jul 16, 2020
const generics triage

I went through all const generics issues and closed all issues which are already fixed.

Some issues already have a regression test but were not closed. Also doing this as part of this PR.

uff r? @eddyb @varkor

closes rust-lang#61936
closes rust-lang#62878
closes rust-lang#63695
closes rust-lang#67144
closes rust-lang#68596
closes rust-lang#69816
closes rust-lang#70217
closes rust-lang#70507
closes rust-lang#70586
closes rust-lang#71348
closes rust-lang#71805
closes rust-lang#73120
closes rust-lang#73508
closes rust-lang#73730
closes rust-lang#74255
@bors bors closed this as completed in c354524 Jul 16, 2020
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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