From 75430670b33f04f2f32aa14aadb559314b573a44 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 25 Feb 2022 20:20:26 -0800 Subject: [PATCH 1/2] only check method inputs once --- compiler/rustc_typeck/src/check/demand.rs | 2 +- compiler/rustc_typeck/src/check/expr.rs | 2 +- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 9 --------- .../rustc_typeck/src/check/fn_ctxt/checks.rs | 19 ++++++++++++++----- .../mismatched_types/overloaded-calls-bad.rs | 1 - .../overloaded-calls-bad.stderr | 8 +------- src/test/ui/tuple/wrong_argument_ice-2.rs | 17 +++++++++++++++++ src/test/ui/tuple/wrong_argument_ice-2.stderr | 19 +++++++++++++++++++ 8 files changed, 53 insertions(+), 24 deletions(-) create mode 100644 src/test/ui/tuple/wrong_argument_ice-2.rs create mode 100644 src/test/ui/tuple/wrong_argument_ice-2.stderr diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs index 80096b90f9530..e046e4817036b 100644 --- a/compiler/rustc_typeck/src/check/demand.rs +++ b/compiler/rustc_typeck/src/check/demand.rs @@ -470,7 +470,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { return None; }; - let self_ty = self.typeck_results.borrow().node_type(method_expr[0].hir_id); + let self_ty = self.typeck_results.borrow().expr_ty(&method_expr[0]); let self_ty = format!("{:?}", self_ty); let name = method_path.ident.name; let is_as_ref_able = (self_ty.starts_with("&std::option::Option") diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 8d4ffefda73bb..34fe4d3675a01 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1506,7 +1506,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } else { self.check_expr_has_type_or_error(base_expr, adt_ty, |_| { - let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id); + let base_ty = self.typeck_results.borrow().expr_ty(*base_expr); let same_adt = match (adt_ty.kind(), base_ty.kind()) { (ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true, _ => false, diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 5cb1fe8cd94ee..2c81745836cdb 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -313,15 +313,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) => { // A reborrow has no effect before a dereference. } - // Catch cases which have Deref(None) - // having them slip to bug! causes ICE - // see #94291 for more info - (&[Adjustment { kind: Adjust::Deref(None), .. }], _) => { - self.tcx.sess.delay_span_bug( - DUMMY_SP, - &format!("Can't compose Deref(None) expressions"), - ) - } // FIXME: currently we never try to compose autoderefs // and ReifyFnPointer/UnsafeFnPointer, but we could. _ => bug!( diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs index 4b6460b62b77a..9b26eb9f04487 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/checks.rs @@ -133,7 +133,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let expected_arg_count = formal_input_tys.len(); // expected_count, arg_count, error_code, sugg_unit, sugg_tuple_wrap_args - let mut error: Option<(usize, usize, &str, bool, Option>)> = None; + let mut arg_count_error: Option<(usize, usize, &str, bool, Option>)> = + None; // If the arguments should be wrapped in a tuple (ex: closures), unwrap them here let (formal_input_tys, expected_input_tys) = if tuple_arguments == TupleArguments { @@ -143,7 +144,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ty::Tuple(arg_types) => { // Argument length differs if arg_types.len() != provided_args.len() { - error = Some((arg_types.len(), provided_args.len(), "E0057", false, None)); + arg_count_error = + Some((arg_types.len(), provided_args.len(), "E0057", false, None)); } let expected_input_tys = match expected_input_tys.get(0) { Some(&ty) => match ty.kind() { @@ -174,7 +176,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if supplied_arg_count >= expected_arg_count { (formal_input_tys.to_vec(), expected_input_tys) } else { - error = Some((expected_arg_count, supplied_arg_count, "E0060", false, None)); + arg_count_error = + Some((expected_arg_count, supplied_arg_count, "E0060", false, None)); (self.err_args(supplied_arg_count), vec![]) } } else { @@ -198,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let sugg_tuple_wrap_args = self.suggested_tuple_wrap(expected_input_tys, provided_args); - error = Some(( + arg_count_error = Some(( expected_arg_count, supplied_arg_count, "E0061", @@ -231,6 +234,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // This is more complicated than just checking type equality, as arguments could be coerced // This version writes those types back so further type checking uses the narrowed types let demand_compatible = |idx, final_arg_types: &mut Vec, Ty<'tcx>)>>| { + // Do not check argument compatibility if the number of args do not match + if arg_count_error.is_some() { + return; + } + let formal_input_ty: Ty<'tcx> = formal_input_tys[idx]; let expected_input_ty: Ty<'tcx> = expected_input_tys[idx]; let provided_arg = &provided_args[idx]; @@ -328,7 +336,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } // If there was an error in parameter count, emit that here - if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) = error + if let Some((expected_count, arg_count, err_code, sugg_unit, sugg_tuple_wrap_args)) = + arg_count_error { let (span, start_span, args, ctor_of) = match &call_expr.kind { hir::ExprKind::Call( diff --git a/src/test/ui/mismatched_types/overloaded-calls-bad.rs b/src/test/ui/mismatched_types/overloaded-calls-bad.rs index d62625faaaa08..902a6ec81d60b 100644 --- a/src/test/ui/mismatched_types/overloaded-calls-bad.rs +++ b/src/test/ui/mismatched_types/overloaded-calls-bad.rs @@ -30,5 +30,4 @@ fn main() { //~^ ERROR this function takes 1 argument but 0 arguments were supplied let ans = s("burma", "shave"); //~^ ERROR this function takes 1 argument but 2 arguments were supplied - //~| ERROR mismatched types } diff --git a/src/test/ui/mismatched_types/overloaded-calls-bad.stderr b/src/test/ui/mismatched_types/overloaded-calls-bad.stderr index 9ae9c474162d9..264d7cbb9b1cb 100644 --- a/src/test/ui/mismatched_types/overloaded-calls-bad.stderr +++ b/src/test/ui/mismatched_types/overloaded-calls-bad.stderr @@ -18,12 +18,6 @@ note: associated function defined here LL | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; | ^^^^^^^^ -error[E0308]: mismatched types - --> $DIR/overloaded-calls-bad.rs:31:17 - | -LL | let ans = s("burma", "shave"); - | ^^^^^^^ expected `isize`, found `&str` - error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/overloaded-calls-bad.rs:31:15 | @@ -38,7 +32,7 @@ note: associated function defined here LL | extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; | ^^^^^^^^ -error: aborting due to 4 previous errors +error: aborting due to 3 previous errors Some errors have detailed explanations: E0057, E0308. For more information about an error, try `rustc --explain E0057`. diff --git a/src/test/ui/tuple/wrong_argument_ice-2.rs b/src/test/ui/tuple/wrong_argument_ice-2.rs new file mode 100644 index 0000000000000..b0f814616f2ec --- /dev/null +++ b/src/test/ui/tuple/wrong_argument_ice-2.rs @@ -0,0 +1,17 @@ +fn test(t: (i32, i32)) {} + +struct Foo; + +impl Foo { + fn qux(&self) -> i32 { + 0 + } +} + +fn bar() { + let x = Foo; + test(x.qux(), x.qux()); + //~^ ERROR this function takes 1 argument but 2 arguments were supplied +} + +fn main() {} diff --git a/src/test/ui/tuple/wrong_argument_ice-2.stderr b/src/test/ui/tuple/wrong_argument_ice-2.stderr new file mode 100644 index 0000000000000..ddafc9763e79a --- /dev/null +++ b/src/test/ui/tuple/wrong_argument_ice-2.stderr @@ -0,0 +1,19 @@ +error[E0061]: this function takes 1 argument but 2 arguments were supplied + --> $DIR/wrong_argument_ice-2.rs:13:5 + | +LL | test(x.qux(), x.qux()); + | ^^^^ ------- ------- supplied 2 arguments + | +note: function defined here + --> $DIR/wrong_argument_ice-2.rs:1:4 + | +LL | fn test(t: (i32, i32)) {} + | ^^^^ ------------- +help: use parentheses to construct a tuple + | +LL | test((x.qux(), x.qux())); + | + + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0061`. From 6b476fe6ded39dc0efbf74066ca3fc45449fc694 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 28 Feb 2022 12:41:51 -0800 Subject: [PATCH 2/2] Update cargo 11 changes in d6cdde584a1f15ea086bae922e20fd27f7165431..3d6970d50e30e797b8e26b2b9b1bdf92dc381f34 2022-02-22 19:55:51 +0000 to 2022-02-28 19:29:07 +0000: - https://github.com/rust-lang/cargo/pull/10395 - https://github.com/rust-lang/cargo/pull/10425 - https://github.com/rust-lang/cargo/pull/10428 - https://github.com/rust-lang/cargo/pull/10388 - https://github.com/rust-lang/cargo/pull/10167 - https://github.com/rust-lang/cargo/pull/10429 - https://github.com/rust-lang/cargo/pull/10426 - https://github.com/rust-lang/cargo/pull/10372 - https://github.com/rust-lang/cargo/pull/10420 - https://github.com/rust-lang/cargo/pull/10416 - https://github.com/rust-lang/cargo/pull/10417 --- Cargo.lock | 2 +- src/tools/cargo | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d462a143abc8..f0c6e371c38be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -318,7 +318,7 @@ dependencies = [ [[package]] name = "cargo" -version = "0.61.0" +version = "0.62.0" dependencies = [ "anyhow", "atty", diff --git a/src/tools/cargo b/src/tools/cargo index d6cdde584a1f1..3d6970d50e30e 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit d6cdde584a1f15ea086bae922e20fd27f7165431 +Subproject commit 3d6970d50e30e797b8e26b2b9b1bdf92dc381f34