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

Bad interaction between missing semicolon in fully qualified fn path and type ascription #54516

Closed
leonardo-m opened this issue Sep 23, 2018 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@leonardo-m
Copy link

This is almost a feature request. This code:

fn main() {
    use std::collections::BTreeMap;
    println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
}

Gives the errors (rustc 1.30.0-nightly 4591a24 2018-09-22):

warning: unnecessary path disambiguator
 --> ...\test.rs:3:36
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
  |                                    ^^ try removing `::`

error: expected token: `,`
 --> ...\test.rs:3:58
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
  |                                                          ^

error: aborting due to previous error

But the problem is a missing : after std::mem:. Can rustc give a better error message here?

@varkor varkor added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 23, 2018
@estebank
Copy link
Contributor

CC #47666

@estebank
Copy link
Contributor

After #59150, if you add a comma where it asks for one the output is slightly better:

warning: unnecessary path disambiguator
 --> file2.rs:3:36
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>,());
  |                                    ^^ try removing `::`

error: argument never used
 --> file2.rs:3:59
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>,());
  |              ---- formatting specifier missing            ^^ argument never used

error[E0423]: expected value, found module `std::mem`
 --> file2.rs:3:20
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>,());
  |                    ^^^^^^^^- help: maybe you meant to write a path separator here: `::`
  |                    |
  |                    not a value

error[E0412]: cannot find type `size_of` in this scope
 --> file2.rs:3:29
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>,());
  |                            -^^^^^^^ not found in this scope
  |                            |
  |                            help: maybe you meant to write a path separator here: `::`

error[E0658]: type ascription is experimental (see issue #23416)
 --> file2.rs:3:20
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>,());
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = help: add #![feature(type_ascription)] to the crate attributes to enable

Centril added a commit to Centril/rust that referenced this issue Mar 26, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 26, 2019
Centril added a commit to Centril/rust that referenced this issue Mar 26, 2019
@estebank estebank changed the title Suboptimal warning/error/suggestion Bad interaction between missing semicolon in fully qualified fn path and type ascription Apr 30, 2019
Centril added a commit to Centril/rust that referenced this issue Jul 21, 2019
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Jul 23, 2019
@estebank
Copy link
Contributor

Current output:

error: expected one of `!`, `,`, or `::`, found `(`
 --> file8.rs:3:58
  |
3 |     println!("{}", std::mem:size_of::<BTreeMap<u32, u32>>());
  |                            -                             ^ expected one of `!`, `,`, or `::` here
  |                            |
  |                            help: maybe write a path separator here: `::`
  |
  = note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
  = note: for more information, see https://github.com/rust-lang/rust/issues/23416

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
Projects
None yet
Development

No branches or pull requests

3 participants