Remove 1-tuple unreachable case
This commit is contained in:
parent
a129a85144
commit
a8bac9879a
3 changed files with 24 additions and 21 deletions
|
@ -28,9 +28,9 @@ use crate::structured_errors::StructuredDiagnostic;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
enum FnArgsAsTuple<'hir> {
|
struct FnArgsAsTuple<'hir> {
|
||||||
Single(&'hir hir::Expr<'hir>),
|
first: &'hir hir::Expr<'hir>,
|
||||||
Multi { first: &'hir hir::Expr<'hir>, last: &'hir hir::Expr<'hir> },
|
last: &'hir hir::Expr<'hir>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
|
@ -432,23 +432,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
String::from("()"),
|
String::from("()"),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else if let Some(tuple_fn_arg) = sugg_tuple_wrap_args {
|
} else if let Some(FnArgsAsTuple { first, last }) = sugg_tuple_wrap_args {
|
||||||
use FnArgsAsTuple::*;
|
err.multipart_suggestion(
|
||||||
|
"use parentheses to construct a tuple",
|
||||||
let spans = match tuple_fn_arg {
|
vec![
|
||||||
Multi { first, last } => vec![
|
|
||||||
(first.span.shrink_to_lo(), '('.to_string()),
|
(first.span.shrink_to_lo(), '('.to_string()),
|
||||||
(last.span.shrink_to_hi(), ')'.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,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -519,8 +509,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
if all_match {
|
if all_match {
|
||||||
match provided_args {
|
match provided_args {
|
||||||
[] => None,
|
[] => None,
|
||||||
[single] => Some(FnArgsAsTuple::Single(single)),
|
[_] => unreachable!(
|
||||||
[first, .., last] => Some(FnArgsAsTuple::Multi { first, last }),
|
"shouldn't reach here - need count mismatch between 1-tuple and 1-argument"
|
||||||
|
),
|
||||||
|
[first, .., last] => Some(FnArgsAsTuple { first, last }),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -7,6 +7,9 @@ fn main() {
|
||||||
//~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied
|
//~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied
|
||||||
int_bool(1, 2);
|
int_bool(1, 2);
|
||||||
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
|
//~^ 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)) {
|
fn int_bool(_: (i32, bool)) {
|
||||||
|
|
|
@ -15,11 +15,19 @@ LL | int_bool(1, 2);
|
||||||
| expected 1 argument
|
| expected 1 argument
|
||||||
|
|
|
|
||||||
note: function defined here
|
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)) {
|
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`.
|
For more information about this error, try `rustc --explain E0061`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue