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

Const-generic arguments are not printed in error messages #61395

Closed
jplatte opened this issue May 31, 2019 · 5 comments · Fixed by #65154
Closed

Const-generic arguments are not printed in error messages #61395

jplatte opened this issue May 31, 2019 · 5 comments · Fixed by #65154
Labels
A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

@jplatte
Copy link
Contributor

jplatte commented May 31, 2019

This code (playground):

#![feature(const_generics)]

struct Generic<const C: usize>;

fn main() {
    let _: Generic<0> = Generic::<1>;
}

results in

error[E0308]: mismatched types
 --> src/main.rs:6:25
  |
6 |     let _: Generic<0> = Generic::<1>;
  |                         ^^^^^^^^^^^^ expected `0usize`, found `1usize`
  |
  = note: expected type `Generic<>`
             found type `Generic<>`

with missing const arguments in the note: ... at the bottom.

@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 31, 2019
@jplatte jplatte changed the title Generic arguments are not printed in error messages Const-generic arguments are not printed in error messages May 31, 2019
@imbrem
Copy link
Contributor

imbrem commented Jun 1, 2019

Hey guys could I take this on?

@imbrem
Copy link
Contributor

imbrem commented Jun 1, 2019

Just FYI, same problem with messages involving const generics and matches, e.g.

#![feature(const_generics)]

struct Generic<const C: usize>;


fn main() {
    let x = Generic::<0>;
    let y = Generic::<1>;
    let _ = match 1 {
        0 => x,
        _ => y
    };
}

(Playground)
Also for functions:

#![feature(const_generics)]

struct Generic<const C: usize>;

fn foo(x : Generic::<1>) {}

fn main() {
    let x = Generic::<0>;
    foo(x);
}

(Playground)

@imbrem
Copy link
Contributor

imbrem commented Jun 1, 2019

Interestingly, when I use concrete types for the function example, things display properly:

#![feature(const_generics)]

struct Generic<const C: usize>;

fn foo(x : usize) {}

fn main() {
    let x = Generic::<0>;
    foo(x);
}

gives

error[E0308]: mismatched types
 --> src/main.rs:9:9
  |
9 |     foo(x);
  |         ^ expected usize, found struct `Generic`
  |
  = note: expected type `usize`
             found type `Generic<0usize>`

(Playground)

@varkor
Copy link
Member

varkor commented Jun 3, 2019

@imbrem: you're welcome to look into fixing this! However, I'm not sure what might be causing this problem, so I don't have any suggestions for where to start looking yet.

@imbrem
Copy link
Contributor

imbrem commented Jun 3, 2019

@varkor I spent a few hours doing some digging and I can't find anything yet as well, though I'm as of yet still quite unfamiliar with the code-base. I might have more time tomorrow to look things over again, or maybe the day after.

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) A-diagnostics Area: Messages for errors, warnings, and lints C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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.

5 participants