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:
commit
c74ff8b563
5 changed files with 28 additions and 19 deletions
|
@ -349,9 +349,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
ty::FnPtr(sig) => (sig, None),
|
ty::FnPtr(sig) => (sig, None),
|
||||||
ref t => {
|
ref t => {
|
||||||
let mut unit_variant = None;
|
let mut unit_variant = None;
|
||||||
|
let mut removal_span = call_expr.span;
|
||||||
if let ty::Adt(adt_def, ..) = t {
|
if let ty::Adt(adt_def, ..) = t {
|
||||||
if adt_def.is_enum() {
|
if adt_def.is_enum() {
|
||||||
if let hir::ExprKind::Call(expr, _) = call_expr.kind {
|
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 =
|
unit_variant =
|
||||||
self.tcx.sess.source_map().span_to_snippet(expr.span).ok();
|
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 {
|
if let Some(ref path) = unit_variant {
|
||||||
err.span_suggestion(
|
err.span_suggestion_verbose(
|
||||||
call_expr.span,
|
removal_span,
|
||||||
&format!(
|
&format!(
|
||||||
"`{}` is a unit variant, you need to write it \
|
"`{}` is a unit variant, you need to write it without the parentheses",
|
||||||
without the parentheses",
|
|
||||||
path
|
path
|
||||||
),
|
),
|
||||||
path.to_string(),
|
String::new(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,9 @@ LL | let e4 = E::Empty4();
|
||||||
|
|
|
|
||||||
help: `E::Empty4` is a unit variant, you need to write it without the parentheses
|
help: `E::Empty4` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | let e4 = E::Empty4;
|
LL - let e4 = E::Empty4();
|
||||||
| ~~~~~~~~~
|
LL + let e4 = E::Empty4;
|
||||||
|
|
|
||||||
|
|
||||||
error[E0618]: expected function, found `empty_struct::XEmpty2`
|
error[E0618]: expected function, found `empty_struct::XEmpty2`
|
||||||
--> $DIR/empty-struct-unit-expr.rs:18:15
|
--> $DIR/empty-struct-unit-expr.rs:18:15
|
||||||
|
@ -43,8 +44,9 @@ LL | let xe4 = XE::XEmpty4();
|
||||||
|
|
|
|
||||||
help: `XE::XEmpty4` is a unit variant, you need to write it without the parentheses
|
help: `XE::XEmpty4` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | let xe4 = XE::XEmpty4;
|
LL - let xe4 = XE::XEmpty4();
|
||||||
| ~~~~~~~~~~~
|
LL + let xe4 = XE::XEmpty4;
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
|
|
@ -11,8 +11,9 @@ LL | X::Entry();
|
||||||
|
|
|
|
||||||
help: `X::Entry` is a unit variant, you need to write it without the parentheses
|
help: `X::Entry` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | X::Entry;
|
LL - X::Entry();
|
||||||
| ~~~~~~~~
|
LL + X::Entry;
|
||||||
|
|
|
||||||
|
|
||||||
error[E0618]: expected function, found `i32`
|
error[E0618]: expected function, found `i32`
|
||||||
--> $DIR/E0618.rs:9:5
|
--> $DIR/E0618.rs:9:5
|
||||||
|
|
|
@ -340,8 +340,9 @@ LL | let _ = Z::Unit();
|
||||||
|
|
|
|
||||||
help: `Z::Unit` is a unit variant, you need to write it without the parentheses
|
help: `Z::Unit` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | let _ = Z::Unit;
|
LL - let _ = Z::Unit();
|
||||||
| ~~~~~~~
|
LL + let _ = Z::Unit;
|
||||||
|
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/privacy-enum-ctor.rs:43:16
|
--> $DIR/privacy-enum-ctor.rs:43:16
|
||||||
|
@ -374,8 +375,9 @@ LL | let _: E = m::E::Unit();
|
||||||
|
|
|
|
||||||
help: `m::E::Unit` is a unit variant, you need to write it without the parentheses
|
help: `m::E::Unit` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | let _: E = m::E::Unit;
|
LL - let _: E = m::E::Unit();
|
||||||
| ~~~~~~~~~~
|
LL + let _: E = m::E::Unit;
|
||||||
|
|
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error[E0308]: mismatched types
|
||||||
--> $DIR/privacy-enum-ctor.rs:51:16
|
--> $DIR/privacy-enum-ctor.rs:51:16
|
||||||
|
@ -408,8 +410,9 @@ LL | let _: E = E::Unit();
|
||||||
|
|
|
|
||||||
help: `E::Unit` is a unit variant, you need to write it without the parentheses
|
help: `E::Unit` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | let _: E = E::Unit;
|
LL - let _: E = E::Unit();
|
||||||
| ~~~~~~~
|
LL + let _: E = E::Unit;
|
||||||
|
|
|
||||||
|
|
||||||
error: aborting due to 23 previous errors
|
error: aborting due to 23 previous errors
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,9 @@ LL | Alias::Unit();
|
||||||
|
|
|
|
||||||
help: `Alias::Unit` is a unit variant, you need to write it without the parentheses
|
help: `Alias::Unit` is a unit variant, you need to write it without the parentheses
|
||||||
|
|
|
|
||||||
LL | Alias::Unit;
|
LL - Alias::Unit();
|
||||||
| ~~~~~~~~~~~
|
LL + Alias::Unit;
|
||||||
|
|
|
||||||
|
|
||||||
error[E0164]: expected tuple struct or tuple variant, found unit variant `Alias::Unit`
|
error[E0164]: expected tuple struct or tuple variant, found unit variant `Alias::Unit`
|
||||||
--> $DIR/incorrect-variant-form-through-alias-caught.rs:17:9
|
--> $DIR/incorrect-variant-form-through-alias-caught.rs:17:9
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue