rust/compiler/rustc_typeck
Yuki Okushi 52afa3a70c
Rollup merge of #97964 - WaffleLapkin:fix_borrow_par_suggestions, r=compiler-errors
Fix suggestions for `&a: T` parameters

I've accidentally discovered that we have broken suggestions for `&a: T` parameters:
```rust
fn f(&mut bar: u32) {}

fn main() {
    let _ = |&mut a| ();
}
```
```text
error[E0308]: mismatched types
 --> ./t.rs:1:6
  |
1 | fn f(&mut bar: u32) {}
  |      ^^^^^^^^-----
  |      |         |
  |      |         expected due to this
  |      expected `u32`, found `&mut _`
  |      help: did you mean `bar`: `&u32`
  |
  = note:           expected type `u32`
          found mutable reference `&mut _`

error[E0308]: mismatched types
 --> ./t.rs:4:23
  |
4 |     let _: fn(u32) = |&mut a| ();
  |                       ^^^^^--
  |                       |    |
  |                       |    expected due to this
  |                       expected `u32`, found `&mut _`
  |                       help: did you mean `a`: `&u32`
  |
  = note:           expected type `u32`
          found mutable reference `&mut _`
```

It's hard to see, but
1. The help span is overlapping with "expected" spans
2. It suggests `fn f( &u32) {}` (no `mut` and lost parameter name) and `|&u32 ()` (no closing `|` and lost parameter name)

I've tried to fix this.

r? ``@compiler-errors``
2022-06-16 07:24:39 +09:00
..
src Rollup merge of #97964 - WaffleLapkin:fix_borrow_par_suggestions, r=compiler-errors 2022-06-16 07:24:39 +09:00
Cargo.toml Initial fixes on top of type interner commit 2022-05-28 11:38:22 -07:00
README.md

For high-level intro to how type checking works in rustc, see the type checking chapter of the rustc dev guide.