suggest removing the tuple struct field for the unwrapped value
add a test case for macro
This commit is contained in:
parent
9a7b7d5e50
commit
f85f37583d
4 changed files with 90 additions and 0 deletions
|
@ -287,6 +287,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
expr_ty: Ty<'tcx>,
|
||||
) {
|
||||
if let ty::Adt(expected_adt, substs) = expected.kind() {
|
||||
if let hir::ExprKind::Field(base, ident) = expr.kind {
|
||||
let base_ty = self.typeck_results.borrow().expr_ty(base);
|
||||
if self.can_eq(self.param_env, base_ty, expected).is_ok()
|
||||
&& let Some(base_span) = base.span.find_ancestor_inside(expr.span)
|
||||
{
|
||||
err.span_suggestion_verbose(
|
||||
expr.span.with_lo(base_span.hi()),
|
||||
format!("consider removing the tuple struct field `{ident}`"),
|
||||
"",
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// If the expression is of type () and it's the return expression of a block,
|
||||
// we suggest adding a separate return expression instead.
|
||||
// (To avoid things like suggesting `Ok(while .. { .. })`.)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue