1
Fork 0

Remove 1-tuple unreachable case

This commit is contained in:
Rob Pilling 2022-01-16 22:47:33 +00:00
parent a129a85144
commit a8bac9879a
3 changed files with 24 additions and 21 deletions

View file

@ -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

View file

@ -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)) {

View file

@ -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`.