1
Fork 0

Rollup merge of #90961 - estebank:suggest-removal-of-call, r=nagisa

Suggest removal of arguments for unit variant, not replacement
This commit is contained in:
Yuki Okushi 2021-11-19 13:06:37 +09:00 committed by GitHub
commit c74ff8b563
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 19 deletions

View file

@ -349,9 +349,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
ty::FnPtr(sig) => (sig, None),
ref t => {
let mut unit_variant = None;
let mut removal_span = call_expr.span;
if let ty::Adt(adt_def, ..) = t {
if adt_def.is_enum() {
if let hir::ExprKind::Call(expr, _) = call_expr.kind {
removal_span =
expr.span.shrink_to_hi().to(call_expr.span.shrink_to_hi());
unit_variant =
self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
}
@ -379,14 +382,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
if let Some(ref path) = unit_variant {
err.span_suggestion(
call_expr.span,
err.span_suggestion_verbose(
removal_span,
&format!(
"`{}` is a unit variant, you need to write it \
without the parentheses",
"`{}` is a unit variant, you need to write it without the parentheses",
path
),
path.to_string(),
String::new(),
Applicability::MachineApplicable,
);
}