diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index af0c9e5e5090e..d7022c27d3984 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -28,9 +28,9 @@ use crate::structured_errors::StructuredDiagnostic; use std::iter; use std::slice; -enum FnArgsAsTuple<'hir> { - Single(&'hir hir::Expr<'hir>), - Multi { first: &'hir hir::Expr<'hir>, last: &'hir hir::Expr<'hir> }, +struct FnArgsAsTuple<'hir> { + first: &'hir hir::Expr<'hir>, + last: &'hir hir::Expr<'hir>, } impl<'a, 'tcx> FnCtxt<'a, 'tcx> { @@ -432,23 +432,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { String::from("()"), Applicability::MachineApplicable, ); - } else if let Some(tuple_fn_arg) = sugg_tuple_wrap_args { - use FnArgsAsTuple::*; - - let spans = match tuple_fn_arg { - Multi { first, last } => vec![ + } else if let Some(FnArgsAsTuple { first, last }) = sugg_tuple_wrap_args { + err.multipart_suggestion( + "use parentheses to construct a tuple", + vec![ (first.span.shrink_to_lo(), '('.to_string()), (last.span.shrink_to_hi(), ')'.to_string()), ], - Single(single) => vec![ - (single.span.shrink_to_lo(), '('.to_string()), - (single.span.shrink_to_hi(), ",)".to_string()), - ], - }; - - err.multipart_suggestion( - "use parentheses to construct a tuple", - spans, Applicability::MachineApplicable, ); } else { @@ -519,8 +509,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if all_match { match provided_args { [] => None, - [single] => Some(FnArgsAsTuple::Single(single)), - [first, .., last] => Some(FnArgsAsTuple::Multi { first, last }), + [_] => unreachable!( + "shouldn't reach here - need count mismatch between 1-tuple and 1-argument" + ), + [first, .., last] => Some(FnArgsAsTuple { first, last }), } } else { None diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.rs b/src/test/ui/suggestions/args-instead-of-tuple-errors.rs index c4e9c68e219e6..2c3ee5fcb8039 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple-errors.rs +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.rs @@ -7,6 +7,9 @@ fn main() { //~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied int_bool(1, 2); //~^ ERROR this function takes 1 argument but 2 arguments were supplied + + let _: Option<(i8,)> = Some(); + //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied } fn int_bool(_: (i32, bool)) { diff --git a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr index c53c8bbdcc9df..a2ad602dbd47a 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple-errors.stderr @@ -15,11 +15,19 @@ LL | int_bool(1, 2); | expected 1 argument | note: function defined here - --> $DIR/args-instead-of-tuple-errors.rs:12:4 + --> $DIR/args-instead-of-tuple-errors.rs:15:4 | LL | fn int_bool(_: (i32, bool)) { | ^^^^^^^^ -------------- -error: aborting due to 2 previous errors +error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied + --> $DIR/args-instead-of-tuple-errors.rs:11:28 + | +LL | let _: Option<(i8,)> = Some(); + | ^^^^-- supplied 0 arguments + | | + | expected 1 argument + +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0061`.