Skip to content

Commit a129a85

Browse files
committed
Handle generics with ParamEnv
1 parent 54d2d30 commit a129a85

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_hir::def_id::DefId;
1818
use rustc_hir::{ExprKind, Node, QPath};
1919
use rustc_middle::ty::adjustment::AllowTwoPhase;
2020
use rustc_middle::ty::fold::TypeFoldable;
21-
use rustc_middle::ty::{self, ParamEnv, Ty};
21+
use rustc_middle::ty::{self, Ty};
2222
use rustc_session::Session;
2323
use rustc_span::symbol::Ident;
2424
use rustc_span::{self, MultiSpan, Span};
@@ -514,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
514514
let supplied_types: Vec<_> = provided_args.iter().map(|arg| self.check_expr(arg)).collect();
515515

516516
let all_match = iter::zip(expected_types, supplied_types)
517-
.all(|(expected, supplied)| self.can_eq(ParamEnv::empty(), expected, supplied).is_ok());
517+
.all(|(expected, supplied)| self.can_eq(self.param_env, expected, supplied).is_ok());
518518

519519
if all_match {
520520
match provided_args {

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

+9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ fn main() {
1212
//~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied
1313

1414
two_ints((1, 2)); //~ ERROR this function takes 1 argument
15+
16+
with_generic((3, 4)); //~ ERROR this function takes 1 argument
1517
}
1618

1719
fn two_ints(_: (i32, i32)) {
1820
}
21+
22+
fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
23+
if false {
24+
// test generics/bound handling
25+
with_generic((a, b)); //~ ERROR this function takes 1 argument
26+
}
27+
}

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

+9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@ fn main() {
1212
//~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied
1313

1414
two_ints(1, 2); //~ ERROR this function takes 1 argument
15+
16+
with_generic(3, 4); //~ ERROR this function takes 1 argument
1517
}
1618

1719
fn two_ints(_: (i32, i32)) {
1820
}
21+
22+
fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
23+
if false {
24+
// test generics/bound handling
25+
with_generic(a, b); //~ ERROR this function takes 1 argument
26+
}
27+
}

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

+34-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ LL | two_ints(1, 2);
3838
| ^^^^^^^^ - - supplied 2 arguments
3939
|
4040
note: function defined here
41-
--> $DIR/args-instead-of-tuple.rs:17:4
41+
--> $DIR/args-instead-of-tuple.rs:19:4
4242
|
4343
LL | fn two_ints(_: (i32, i32)) {
4444
| ^^^^^^^^ -------------
@@ -47,6 +47,38 @@ help: use parentheses to construct a tuple
4747
LL | two_ints((1, 2));
4848
| + +
4949

50-
error: aborting due to 4 previous errors
50+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
51+
--> $DIR/args-instead-of-tuple.rs:16:5
52+
|
53+
LL | with_generic(3, 4);
54+
| ^^^^^^^^^^^^ - - supplied 2 arguments
55+
|
56+
note: function defined here
57+
--> $DIR/args-instead-of-tuple.rs:22:4
58+
|
59+
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
60+
| ^^^^^^^^^^^^ ----------------
61+
help: use parentheses to construct a tuple
62+
|
63+
LL | with_generic((3, 4));
64+
| + +
65+
66+
error[E0061]: this function takes 1 argument but 2 arguments were supplied
67+
--> $DIR/args-instead-of-tuple.rs:25:9
68+
|
69+
LL | with_generic(a, b);
70+
| ^^^^^^^^^^^^ - - supplied 2 arguments
71+
|
72+
note: function defined here
73+
--> $DIR/args-instead-of-tuple.rs:22:4
74+
|
75+
LL | fn with_generic<T: Copy + Send>((a, b): (i32, T)) {
76+
| ^^^^^^^^^^^^ ----------------
77+
help: use parentheses to construct a tuple
78+
|
79+
LL | with_generic((a, b));
80+
| + +
81+
82+
error: aborting due to 6 previous errors
5183

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

0 commit comments

Comments
 (0)