Skip to content

Commit

Permalink
Remove final_arg_types, improve tuple wrapping suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jun 28, 2022
1 parent f2277e0 commit 7533777
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 179 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ pub fn same_type_modulo_infer<'tcx>(a: Ty<'tcx>, b: Ty<'tcx>) -> bool {
)
| (&ty::Infer(ty::InferTy::TyVar(_)), _)
| (_, &ty::Infer(ty::InferTy::TyVar(_))) => true,
(&ty::Ref(reg_a, ty_a, mut_a), &ty::Ref(reg_b, ty_b, mut_b)) => {
reg_a == reg_b && mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
(&ty::Ref(_, ty_a, mut_a), &ty::Ref(_, ty_b, mut_b)) => {
mut_a == mut_b && same_type_modulo_infer(*ty_a, *ty_b)
}
_ => a == b,
}
Expand Down
310 changes: 140 additions & 170 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/test/ui/suggestions/args-instead-of-tuple.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: tuple variant defined here
|
LL | Ok(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | let _: Result<(i32, i8), ()> = Ok((1, 2));
| + +
Expand All @@ -25,7 +25,7 @@ note: tuple variant defined here
|
LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
| ^^^^
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | let _: Option<(i32, i8, &'static str)> = Some((1, 2, "hi"));
| + +
Expand Down Expand Up @@ -97,7 +97,7 @@ note: function defined here
|
LL | fn two_ints(_: (i32, i32)) {
| ^^^^^^^^ -------------
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | two_ints((1, 2));
| + +
Expand All @@ -113,7 +113,7 @@ note: function defined here
|
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
| ^^^^^^^^^^^^ ----------------
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | with_generic((3, 4));
| + +
Expand All @@ -129,7 +129,7 @@ note: function defined here
|
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
| ^^^^^^^^^^^^ ----------------
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | with_generic((a, b));
| + +
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/tuple/add-tuple-within-arguments.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn foo(s: &str, a: (i32, i32), s2: &str) {}

fn bar(s: &str, a: (&str,), s2: &str) {}

fn main() {
foo("hi", 1, 2, "hi");
//~^ ERROR this function takes 3 arguments but 4 arguments were supplied
bar("hi", "hi", "hi");
//~^ ERROR mismatched types
}
40 changes: 40 additions & 0 deletions src/test/ui/tuple/add-tuple-within-arguments.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
error[E0061]: this function takes 3 arguments but 4 arguments were supplied
--> $DIR/add-tuple-within-arguments.rs:6:5
|
LL | foo("hi", 1, 2, "hi");
| ^^^
|
note: function defined here
--> $DIR/add-tuple-within-arguments.rs:1:4
|
LL | fn foo(s: &str, a: (i32, i32), s2: &str) {}
| ^^^ ------- ------------- --------
help: wrap these arguments in parentheses to construct a tuple
|
LL | foo("hi", (1, 2), "hi");
| + +

error[E0308]: mismatched types
--> $DIR/add-tuple-within-arguments.rs:8:15
|
LL | bar("hi", "hi", "hi");
| --- ^^^^ expected tuple, found `&str`
| |
| arguments to this function are incorrect
|
= note: expected tuple `(&str,)`
found reference `&'static str`
note: function defined here
--> $DIR/add-tuple-within-arguments.rs:3:4
|
LL | fn bar(s: &str, a: (&str,), s2: &str) {}
| ^^^ ------- ---------- --------
help: use a trailing comma to create a tuple with one element
|
LL | bar("hi", ("hi",), "hi");
| + ++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0061, E0308.
For more information about an error, try `rustc --explain E0061`.
2 changes: 1 addition & 1 deletion src/test/ui/tuple/wrong_argument_ice-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: function defined here
|
LL | fn test(t: (i32, i32)) {}
| ^^^^ -------------
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | test((x.qux(), x.qux()));
| + +
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/tuple/wrong_argument_ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ note: associated function defined here
|
LL | pub fn push_back(&mut self, value: T) {
| ^^^^^^^^^
help: use parentheses to construct a tuple
help: wrap these arguments in parentheses to construct a tuple
|
LL | self.acc.push_back((self.current_provides, self.current_requires));
| + +
Expand Down

0 comments on commit 7533777

Please sign in to comment.