Rollup merge of #134154 - dev-ardi:field-expr-generics, r=compiler-errors
suppress field expr with generics error message if it's a method Don't emit "field expressions may not have generic arguments" if it's a method call without `()` r? estebank Fixes #67680 Is this the best way to go? It's by far the simplest I could come up with.
This commit is contained in:
commit
1d784225f1
6 changed files with 18 additions and 17 deletions
|
@ -576,6 +576,10 @@ pub enum StashKey {
|
|||
UndeterminedMacroResolution,
|
||||
/// Used by `Parser::maybe_recover_trailing_expr`
|
||||
ExprInPat,
|
||||
/// If in the parser we detect a field expr with turbofish generic params it's possible that
|
||||
/// 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,
|
||||
}
|
||||
|
||||
fn default_track_diagnostic<R>(diag: DiagInner, f: &mut dyn FnMut(DiagInner) -> R) -> R {
|
||||
|
|
|
@ -3076,7 +3076,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
err.help("methods are immutable and cannot be assigned to");
|
||||
}
|
||||
|
||||
err.emit()
|
||||
// See `StashKey::GenericInFieldExpr` for more info
|
||||
self.dcx().try_steal_replace_and_emit_err(field.span, StashKey::GenericInFieldExpr, err)
|
||||
}
|
||||
|
||||
fn point_at_param_definition(&self, err: &mut Diag<'_>, param: ty::ParamTy) {
|
||||
|
|
|
@ -1369,11 +1369,14 @@ impl<'a> Parser<'a> {
|
|||
))
|
||||
} else {
|
||||
// Field access `expr.f`
|
||||
let span = lo.to(self.prev_token.span);
|
||||
if let Some(args) = seg.args {
|
||||
self.dcx().emit_err(errors::FieldExpressionWithGeneric(args.span()));
|
||||
// See `StashKey::GenericInFieldExpr` for more info on why we stash this.
|
||||
self.dcx()
|
||||
.create_err(errors::FieldExpressionWithGeneric(args.span()))
|
||||
.stash(seg.ident.span, StashKey::GenericInFieldExpr);
|
||||
}
|
||||
|
||||
let span = lo.to(self.prev_token.span);
|
||||
Ok(self.mk_expr(span, ExprKind::Field(self_arg, seg.ident)))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue