Skip to content

Commit 7533777

Browse files
Remove final_arg_types, improve tuple wrapping suggestion
1 parent f2277e0 commit 7533777

File tree

7 files changed

+199
-179
lines changed

7 files changed

+199
-179
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
342342
)
343343
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
344344
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
345-
(&ty::Ref(reg_a, ty_a, mut_a), &ty::Ref(reg_b, ty_b, mut_b)) => {
346-
reg_a == reg_b && mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
345+
(&ty::Ref(_, ty_a, mut_a), &ty::Ref(_, ty_b, mut_b)) => {
346+
mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
347347
}
348348
_ => a == b,
349349
}

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

+140-170
Large diffs are not rendered by default.

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: tuple variant defined here
99
|
1010
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
1111
| ^^
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | let _: Result<(i32, i8), ()> = Ok((1, 2));
1515
| + +
@@ -25,7 +25,7 @@ note: tuple variant defined here
2525
|
2626
LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
2727
| ^^^^
28-
help: use parentheses to construct a tuple
28+
help: wrap these arguments in parentheses to construct a tuple
2929
|
3030
LL | let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi"));
3131
| + +
@@ -97,7 +97,7 @@ note: function defined here
9797
|
9898
LL | fn two_ints(_: (i32, i32)) {
9999
| ^^^^^^^^ -------------
100-
help: use parentheses to construct a tuple
100+
help: wrap these arguments in parentheses to construct a tuple
101101
|
102102
LL | two_ints((1, 2));
103103
| + +
@@ -113,7 +113,7 @@ note: function defined here
113113
|
114114
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
115115
| ^^^^^^^^^^^^ ----------------
116-
help: use parentheses to construct a tuple
116+
help: wrap these arguments in parentheses to construct a tuple
117117
|
118118
LL | with_generic((3, 4));
119119
| + +
@@ -129,7 +129,7 @@ note: function defined here
129129
|
130130
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
131131
| ^^^^^^^^^^^^ ----------------
132-
help: use parentheses to construct a tuple
132+
help: wrap these arguments in parentheses to construct a tuple
133133
|
134134
LL | with_generic((a, b));
135135
| + +
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fn foo(s: &str, a: (i32, i32), s2: &str) {}
2+
3+
fn bar(s: &str, a: (&str,), s2: &str) {}
4+
5+
fn main() {
6+
foo("hi", 1, 2, "hi");
7+
//~^ ERROR this function takes 3 arguments but 4 arguments were supplied
8+
bar("hi", "hi", "hi");
9+
//~^ ERROR mismatched types
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
2+
--> $DIR/add-tuple-within-arguments.rs:6:5
3+
|
4+
LL | foo("hi", 1, 2, "hi");
5+
| ^^^
6+
|
7+
note: function defined here
8+
--> $DIR/add-tuple-within-arguments.rs:1:4
9+
|
10+
LL | fn foo(s: &str, a: (i32, i32), s2: &str) {}
11+
| ^^^ ------- ------------- --------
12+
help: wrap these arguments in parentheses to construct a tuple
13+
|
14+
LL | foo("hi", (1, 2), "hi");
15+
| + +
16+
17+
error[E0308]: mismatched types
18+
--> $DIR/add-tuple-within-arguments.rs:8:15
19+
|
20+
LL | bar("hi", "hi", "hi");
21+
| --- ^^^^ expected tuple, found `&str`
22+
| |
23+
| arguments to this function are incorrect
24+
|
25+
= note: expected tuple `(&str,)`
26+
found reference `&'static str`
27+
note: function defined here
28+
--> $DIR/add-tuple-within-arguments.rs:3:4
29+
|
30+
LL | fn bar(s: &str, a: (&str,), s2: &str) {}
31+
| ^^^ ------- ---------- --------
32+
help: use a trailing comma to create a tuple with one element
33+
|
34+
LL | bar("hi", ("hi",), "hi");
35+
| + ++
36+
37+
error: aborting due to 2 previous errors
38+
39+
Some errors have detailed explanations: E0061, E0308.
40+
For more information about an error, try `rustc --explain E0061`.

src/test/ui/tuple/wrong_argument_ice-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: function defined here
99
|
1010
LL | fn test(t: (i32, i32)) {}
1111
| ^^^^ -------------
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | test((x.qux(), x.qux()));
1515
| + +

src/test/ui/tuple/wrong_argument_ice.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ note: associated function defined here
99
|
1010
LL | pub fn push_back(&mut self, value: T) {
1111
| ^^^^^^^^^
12-
help: use parentheses to construct a tuple
12+
help: wrap these arguments in parentheses to construct a tuple
1313
|
1414
LL | self.acc.push_back((self.current_provides, self.current_requires));
1515
| + +

0 commit comments

Comments
 (0)