From a129a85144efb67bfd8f380a758ed6be41d3e29b Mon Sep 17 00:00:00 2001 From: Rob Pilling Date: Sun, 16 Jan 2022 21:47:44 +0000 Subject: [PATCH] Handle generics with ParamEnv --- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 4 +-- .../suggestions/args-instead-of-tuple.fixed | 9 +++++ .../ui/suggestions/args-instead-of-tuple.rs | 9 +++++ .../suggestions/args-instead-of-tuple.stderr | 36 +++++++++++++++++-- 4 files changed, 54 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index a94e6b480d6..af0c9e5e509 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -18,7 +18,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::{ExprKind, Node, QPath}; use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::fold::TypeFoldable; -use rustc_middle::ty::{self, ParamEnv, Ty}; +use rustc_middle::ty::{self, Ty}; use rustc_session::Session; use rustc_span::symbol::Ident; use rustc_span::{self, MultiSpan, Span}; @@ -514,7 +514,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let supplied_types: Vec<_> = provided_args.iter().map(|arg| self.check_expr(arg)).collect(); let all_match = iter::zip(expected_types, supplied_types) - .all(|(expected, supplied)| self.can_eq(ParamEnv::empty(), expected, supplied).is_ok()); + .all(|(expected, supplied)| self.can_eq(self.param_env, expected, supplied).is_ok()); if all_match { match provided_args { diff --git a/src/test/ui/suggestions/args-instead-of-tuple.fixed b/src/test/ui/suggestions/args-instead-of-tuple.fixed index 095be95f185..c9b8a41d469 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.fixed +++ b/src/test/ui/suggestions/args-instead-of-tuple.fixed @@ -12,7 +12,16 @@ fn main() { //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied two_ints((1, 2)); //~ ERROR this function takes 1 argument + + with_generic((3, 4)); //~ ERROR this function takes 1 argument } fn two_ints(_: (i32, i32)) { } + +fn with_generic((a, b): (i32, T)) { + if false { + // test generics/bound handling + with_generic((a, b)); //~ ERROR this function takes 1 argument + } +} diff --git a/src/test/ui/suggestions/args-instead-of-tuple.rs b/src/test/ui/suggestions/args-instead-of-tuple.rs index 3466a46df84..d4cc3024dd0 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.rs +++ b/src/test/ui/suggestions/args-instead-of-tuple.rs @@ -12,7 +12,16 @@ fn main() { //~^ ERROR this enum variant takes 1 argument but 0 arguments were supplied two_ints(1, 2); //~ ERROR this function takes 1 argument + + with_generic(3, 4); //~ ERROR this function takes 1 argument } fn two_ints(_: (i32, i32)) { } + +fn with_generic((a, b): (i32, T)) { + if false { + // test generics/bound handling + with_generic(a, b); //~ ERROR this function takes 1 argument + } +} diff --git a/src/test/ui/suggestions/args-instead-of-tuple.stderr b/src/test/ui/suggestions/args-instead-of-tuple.stderr index 1bf7e7a8d17..172db7ee3df 100644 --- a/src/test/ui/suggestions/args-instead-of-tuple.stderr +++ b/src/test/ui/suggestions/args-instead-of-tuple.stderr @@ -38,7 +38,7 @@ LL | two_ints(1, 2); | ^^^^^^^^ - - supplied 2 arguments | note: function defined here - --> $DIR/args-instead-of-tuple.rs:17:4 + --> $DIR/args-instead-of-tuple.rs:19:4 | LL | fn two_ints(_: (i32, i32)) { | ^^^^^^^^ ------------- @@ -47,6 +47,38 @@ help: use parentheses to construct a tuple LL | two_ints((1, 2)); | + + -error: aborting due to 4 previous errors +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:16:5 + | +LL | with_generic(3, 4); + | ^^^^^^^^^^^^ - - supplied 2 arguments + | +note: function defined here + --> $DIR/args-instead-of-tuple.rs:22:4 + | +LL | fn with_generic((a, b): (i32, T)) { + | ^^^^^^^^^^^^ ---------------- +help: use parentheses to construct a tuple + | +LL | with_generic((3, 4)); + | + + + +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/args-instead-of-tuple.rs:25:9 + | +LL | with_generic(a, b); + | ^^^^^^^^^^^^ - - supplied 2 arguments + | +note: function defined here + --> $DIR/args-instead-of-tuple.rs:22:4 + | +LL | fn with_generic((a, b): (i32, T)) { + | ^^^^^^^^^^^^ ---------------- +help: use parentheses to construct a tuple + | +LL | with_generic((a, b)); + | + + + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0061`.