Emit fewer errors for incorrect rtn and = -> : typos in bindings

Stash parse errors when pasing rtn that doesn't use `(..)`.
Emit single error on `Foo::bar(qux)` that looks like rtn in incorrect position and suggest `Foo::bar(..)`.
```
error: return type notation not allowed in this position yet
  --> $DIR/let-binding-init-expr-as-ty.rs:18:10
   |
LL | struct K(S::new(()));
   |          ^^^^^^^^^^
   |
help: furthermore, argument types not allowed with return type notation
   |
LL - struct K(S::new(()));
LL + struct K(S::new(..));
   |
```
On incorrect rtn in let binding type for an existing inherent associated function, suggest `:` -> `=` to turn the "type" into a call expression.
```
error: expected type, found associated function call
  --> $DIR/let-binding-init-expr-as-ty.rs:29:12
   |
LL |     let x: S::new(());
   |            ^^^^^^^^^^
   |
help: use `=` if you meant to assign
   |
LL -     let x: S::new(());
LL +     let x = S::new(());
   |
```
This commit is contained in:
Esteban Küber
2026-03-20 19:33:05 +00:00
parent 244322f0be
commit d48e699b6c
6 changed files with 268 additions and 21 deletions
+1
View File
@@ -386,6 +386,7 @@ pub enum StashKey {
/// it's a method call without parens. If later on in `hir_typeck` we find out that this is
/// the case we suppress this message and we give a better suggestion.
GenericInFieldExpr,
ReturnTypeNotation,
}
fn default_track_diagnostic<R>(diag: DiagInner, f: &mut dyn FnMut(DiagInner) -> R) -> R {