Skip to content

ICE with explicit const params in method call. #70217

Closed
@lcnr

Description

@lcnr

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`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.F-const_generics`#![feature(const_generics)]`I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions