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

Improve error messages involving type aliases #17164

Open
nodakai opened this issue Sep 11, 2014 · 7 comments
Open

Improve error messages involving type aliases #17164

nodakai opened this issue Sep 11, 2014 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@nodakai
Copy link
Contributor

nodakai commented Sep 11, 2014

extern crate libc;
fn main() {
    let a: libc::ssize_t = 0;
    let () = a;
}
$ rustc show-typedef.rs
show-typedef.rs:4:17: 4:19 error: mismatched types: expected `i64`, found `()` (expected i64, found ())
show-typedef.rs:4             let () = a;
                                  ^~
error: aborting due to previous error

It would be great if rustc could show libc::ssize_t as well as i64 in the error message. Compare it with GCC 4.9

$ g++49 show-typedef.cpp
show-typedef.cpp: In function 'int main()':
show-typedef.cpp:3:28: error: invalid operands of types 'void' and 'const size_type {aka const long unsigned int}' to binary 'operator+'
     (void)0 + std::string::npos;
                            ^
#include <string>
int main() {
    (void)0 + std::string::npos;
}
@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 27, 2015
@steveklabnik
Copy link
Member

This doesn't need libc to reproduce, it happens with any type synonym:

type Lol = i32;
fn main() {
    let a: Lol = 0;
    let () = a;
}

@nodakai
Copy link
Contributor Author

nodakai commented Feb 2, 2016

Right, libc was just for presenting a motivating example.

@nodakai nodakai changed the title Improve error messages involving defined types Improve error messages involving type synonyms Feb 2, 2016
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title Improve error messages involving type synonyms Improve error messages involving type aliases May 31, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@steveklabnik
Copy link
Member

Triage: no change

@estebank
Copy link
Contributor

This is fundamentally the same as #21934, only more specific.

@camelid
Copy link
Member

camelid commented Mar 2, 2022

@TimJentzsch
Copy link

Current output with 1.65.0-nightly (2022-08-10 29e4a9ee0253cd39e552):

type Lol = i32;
fn main() {
    let a: Lol = 0;
    let () = a;
}
error[[E0308]](https://doc.rust-lang.org/nightly/error-index.html#E0308): mismatched types
 --> src/main.rs:4:9
  |
4 |     let () = a;
  |         ^^   - this expression has type `i32`
  |         |
  |         expected `i32`, found `()`

For more information about this error, try `rustc --explain E0308`.

@estebank
Copy link
Contributor

CC #97974

@fmease fmease added E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants