Skip to content

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

@leonardo-m

Description

@leonardo-m

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?

Activity

estebank

estebank commented on Dec 13, 2018

@estebank
Contributor
estebank

estebank commented on Mar 13, 2019

@estebank
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
added 3 commits that reference this issue on Mar 26, 2019
3e7a5fd
bc3295c
b316514
changed the title [-]Suboptimal warning/error/suggestion[/-] [+]Bad interaction between missing semicolon in fully qualified fn path and type ascription[/+] on Apr 30, 2019
added a commit that references this issue on Jul 21, 2019
38532ae
added a commit that references this issue on Jul 23, 2019
ab7149b
estebank

estebank commented on Oct 20, 2019

@estebank
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @estebank@varkor@leonardo-m

        Issue actions

          Bad interaction between missing semicolon in fully qualified fn path and type ascription · Issue #54516 · rust-lang/rust