Skip to content

Commit a8bac98

Browse files
committed
Remove 1-tuple unreachable case
1 parent a129a85 commit a8bac98

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ use crate::structured_errors::StructuredDiagnostic;
2828
use std::iter;
2929
use std::slice;
3030

31-
enum FnArgsAsTuple<'hir> {
32-
Single(&'hir hir::Expr<'hir>),
33-
Multi { first: &'hir hir::Expr<'hir>, last: &'hir hir::Expr<'hir> },
31+
struct FnArgsAsTuple<'hir> {
32+
first: &'hir hir::Expr<'hir>,
33+
last: &'hir hir::Expr<'hir>,
3434
}
3535

3636
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -432,23 +432,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
432432
String::from("()"),
433433
Applicability::MachineApplicable,
434434
);
435-
} else if let Some(tuple_fn_arg) = sugg_tuple_wrap_args {
436-
use FnArgsAsTuple::*;
437-
438-
let spans = match tuple_fn_arg {
439-
Multi { first, last } => vec![
435+
} else if let Some(FnArgsAsTuple { first, last }) = sugg_tuple_wrap_args {
436+
err.multipart_suggestion(
437+
"use parentheses to construct a tuple",
438+
vec![
440439
(first.span.shrink_to_lo(), '('.to_string()),
441440
(last.span.shrink_to_hi(), ')'.to_string()),
442441
],
443-
Single(single) => vec![
444-
(single.span.shrink_to_lo(), '('.to_string()),
445-
(single.span.shrink_to_hi(), ",)".to_string()),
446-
],
447-
};
448-
449-
err.multipart_suggestion(
450-
"use parentheses to construct a tuple",
451-
spans,
452442
Applicability::MachineApplicable,
453443
);
454444
} else {
@@ -519,8 +509,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
519509
if all_match {
520510
match provided_args {
521511
[] => None,
522-
[single] => Some(FnArgsAsTuple::Single(single)),
523-
[first, .., last] => Some(FnArgsAsTuple::Multi { first, last }),
512+
[_] => unreachable!(
513+
"shouldn't reach here - need count mismatch between 1-tuple and 1-argument"
514+
),
515+
[first, .., last] => Some(FnArgsAsTuple { first, last }),
524516
}
525517
} else {
526518
None

src/test/ui/suggestions/args-instead-of-tuple-errors.rs

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ fn main() {
77
//~^ ERROR this enum variant takes 1 argument but 2 arguments were supplied
88
int_bool(1, 2);
99
//~^ ERROR this function takes 1 argument but 2 arguments were supplied
10+
11+
let _: Option<(i8,)> = Some();
12+
//~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied
1013
}
1114

1215
fn int_bool(_: (i32, bool)) {

src/test/ui/suggestions/args-instead-of-tuple-errors.stderr

+10-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,19 @@ LL | int_bool(1, 2);
1515
| expected 1 argument
1616
|
1717
note: function defined here
18-
--> $DIR/args-instead-of-tuple-errors.rs:12:4
18+
--> $DIR/args-instead-of-tuple-errors.rs:15:4
1919
|
2020
LL | fn int_bool(_: (i32, bool)) {
2121
| ^^^^^^^^ --------------
2222

23-
error: aborting due to 2 previous errors
23+
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied
24+
--> $DIR/args-instead-of-tuple-errors.rs:11:28
25+
|
26+
LL | let _: Option<(i8,)> = Some();
27+
| ^^^^-- supplied 0 arguments
28+
| |
29+
| expected 1 argument
30+
31+
error: aborting due to 3 previous errors
2432

2533
For more information about this error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)