Improve error message on namespace collision

856b6c9
Opened by Сухарик at 2019-10-15 18:10:50
struct Model;

fn model(model: Model) -> Model {
    model
}

fn main() {
    let mut model = Model;
    model = model(model);
}

The error message is:

error: expected function, found `Model`
 --> <anon>:9:13
  |
9 |     model = model(model);
  |             ^^^^^^^^^^^^
  |
note: defined here
 --> <anon>:8:9
  |
8 |     let mut model = Model;
  |         ^^^^^^^^^

error: aborting due to previous error

I guess, the compiler should suggest you to avoid using the same names for functions and variables.

  1. Current output:

    error[E0618]: expected function, found `Model`
     --> src/main.rs:9:13
      |
    8 |     let mut model = Model;
      |         --------- `Model` defined here
    9 |     model = model(model);
      |             ^^^^^^^^^^^^ not a function
    

    Should probably be:

    error[E0618]: expected function, found `Model`
     --> src/main.rs:9:13
      |
    3 | fn model(model: Model) -> Model {
      | ------------------------------- this function shadowed by a local binding
    ...
    8 |     let mut model = Model;
      |         --------- `Model` defined here and shadows a function named `model`
    9 |     model = model(model);
      |             ^^^^^^^^^^^^ not a function
    

    Esteban Kuber at 2018-05-29 23:24:44