From 95e27073bd6348e19291628375c5f63bdc202e16 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 10 Oct 2024 01:13:45 -0400 Subject: [PATCH] Stop using resolve_vars_with_obligations in typeck --- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 +++- compiler/rustc_hir_typeck/src/op.rs | 5 ++++- ...dy_owner_parent_found_in_diagnostics.stderr | 18 +++++++++--------- tests/ui/issues/issue-50781.stderr | 10 +++++----- .../overloaded-calls-nontuple.stderr | 8 ++++---- tests/ui/suggestions/fn-trait-notation.stderr | 8 ++++---- .../next-solver/more-object-bound.stderr | 4 ++-- 7 files changed, 31 insertions(+), 26 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index fa471647d02d0..4cbc2faf5481e 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -208,11 +208,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); } + // Guide inference on the formal output ty if necessary. + self.select_obligations_where_possible(|_| {}); + // First, let's unify the formal method signature with the expectation eagerly. // We use this to guide coercion inference; it's output is "fudged" which means // any remaining type variables are assigned to new, unrelated variables. This // is because the inference guidance here is only speculative. - let formal_output = self.resolve_vars_with_obligations(formal_output); let expected_input_tys: Option> = expectation .only_has_type(self) .and_then(|expected_output| { diff --git a/compiler/rustc_hir_typeck/src/op.rs b/compiler/rustc_hir_typeck/src/op.rs index 1574e9e98d4d8..c470457891a7d 100644 --- a/compiler/rustc_hir_typeck/src/op.rs +++ b/compiler/rustc_hir_typeck/src/op.rs @@ -231,7 +231,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.check_expr(lhs_expr) } }; - let lhs_ty = self.resolve_vars_with_obligations(lhs_ty); + + // Guide inference on the lhs ty if necessary. + self.select_obligations_where_possible(|_| {}); + let lhs_ty = self.resolve_vars_if_possible(lhs_ty); // N.B., as we have not yet type-checked the RHS, we don't have the // type at hand. Make a variable to represent it. The whole reason diff --git a/tests/ui/delegation/correct_body_owner_parent_found_in_diagnostics.stderr b/tests/ui/delegation/correct_body_owner_parent_found_in_diagnostics.stderr index 2ce3b388073c4..61e2a8f64dd52 100644 --- a/tests/ui/delegation/correct_body_owner_parent_found_in_diagnostics.stderr +++ b/tests/ui/delegation/correct_body_owner_parent_found_in_diagnostics.stderr @@ -52,6 +52,14 @@ LL | pub struct InvariantRef<'a, T: ?Sized>(&'a T, PhantomData<&'a mut &'a T>); LL | pub const NEW: Self = InvariantRef::new(&()); | ^^^ function or associated item not found in `InvariantRef<'_, _>` +error[E0277]: the trait bound `u8: Trait` is not satisfied + --> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:12 + | +LL | reuse ::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } } + | ^^ the trait `Trait` is not implemented for `u8` + | + = help: the trait `Trait` is implemented for `Z` + error[E0308]: mismatched types --> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:53 | @@ -68,6 +76,7 @@ LL | reuse ::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW | ^^ the trait `Trait` is not implemented for `u8` | = help: the trait `Trait` is implemented for `Z` + = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` error[E0308]: mismatched types --> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:53 @@ -98,15 +107,6 @@ LL | reuse ::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW found struct `InvariantRef<'_, ()>` = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error[E0277]: the trait bound `u8: Trait` is not satisfied - --> $DIR/correct_body_owner_parent_found_in_diagnostics.rs:22:12 - | -LL | reuse ::{foo, bar, meh} { &const { InvariantRef::<'a>::NEW } } - | ^^ the trait `Trait` is not implemented for `u8` - | - = help: the trait `Trait` is implemented for `Z` - = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` - error: aborting due to 10 previous errors Some errors have detailed explanations: E0261, E0277, E0308, E0599. diff --git a/tests/ui/issues/issue-50781.stderr b/tests/ui/issues/issue-50781.stderr index 3e54a53aa95f8..43f558bd86ca5 100644 --- a/tests/ui/issues/issue-50781.stderr +++ b/tests/ui/issues/issue-50781.stderr @@ -15,10 +15,10 @@ LL | fn foo(&self) where Self: Trait; = help: only type `()` implements the trait, consider using it directly instead error[E0038]: the trait `X` cannot be made into an object - --> $DIR/issue-50781.rs:16:23 + --> $DIR/issue-50781.rs:16:6 | LL | ::foo(&()); - | ^^^ `X` cannot be made into an object + | ^^^^^ `X` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/issue-50781.rs:4:8 @@ -29,13 +29,12 @@ LL | fn foo(&self) where Self: Trait; | ^^^ ...because method `foo` references the `Self` type in its `where` clause = help: consider moving `foo` to another trait = help: only type `()` implements the trait, consider using it directly instead - = note: required for the cast from `&()` to `&dyn X` error[E0038]: the trait `X` cannot be made into an object - --> $DIR/issue-50781.rs:16:6 + --> $DIR/issue-50781.rs:16:23 | LL | ::foo(&()); - | ^^^^^ `X` cannot be made into an object + | ^^^ `X` cannot be made into an object | note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit --> $DIR/issue-50781.rs:4:8 @@ -46,6 +45,7 @@ LL | fn foo(&self) where Self: Trait; | ^^^ ...because method `foo` references the `Self` type in its `where` clause = help: consider moving `foo` to another trait = help: only type `()` implements the trait, consider using it directly instead + = note: required for the cast from `&()` to `&dyn X` error: aborting due to 3 previous errors diff --git a/tests/ui/overloaded/overloaded-calls-nontuple.stderr b/tests/ui/overloaded/overloaded-calls-nontuple.stderr index 45a84fc4d7b0e..14e8c73494951 100644 --- a/tests/ui/overloaded/overloaded-calls-nontuple.stderr +++ b/tests/ui/overloaded/overloaded-calls-nontuple.stderr @@ -39,17 +39,17 @@ LL | self.call_mut(z) note: required by a bound in `call_mut` --> $SRC_DIR/core/src/ops/function.rs:LL:COL -error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit +error[E0277]: `isize` is not a tuple --> $DIR/overloaded-calls-nontuple.rs:29:10 | LL | drop(s(3)) - | ^^^^ + | ^^^^ the trait `Tuple` is not implemented for `isize` -error[E0277]: `isize` is not a tuple +error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit --> $DIR/overloaded-calls-nontuple.rs:29:10 | LL | drop(s(3)) - | ^^^^ the trait `Tuple` is not implemented for `isize` + | ^^^^ error: aborting due to 7 previous errors diff --git a/tests/ui/suggestions/fn-trait-notation.stderr b/tests/ui/suggestions/fn-trait-notation.stderr index 9b47c8c02a782..81e72bbc73e11 100644 --- a/tests/ui/suggestions/fn-trait-notation.stderr +++ b/tests/ui/suggestions/fn-trait-notation.stderr @@ -37,17 +37,17 @@ LL | F: Fn, note: required by a bound in `Fn` --> $SRC_DIR/core/src/ops/function.rs:LL:COL -error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit +error[E0277]: `i32` is not a tuple --> $DIR/fn-trait-notation.rs:9:5 | LL | f(3); - | ^^^^ + | ^^^^ the trait `Tuple` is not implemented for `i32` -error[E0277]: `i32` is not a tuple +error[E0059]: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit --> $DIR/fn-trait-notation.rs:9:5 | LL | f(3); - | ^^^^ the trait `Tuple` is not implemented for `i32` + | ^^^^ error[E0308]: mismatched types --> $DIR/fn-trait-notation.rs:17:5 diff --git a/tests/ui/traits/next-solver/more-object-bound.stderr b/tests/ui/traits/next-solver/more-object-bound.stderr index 043cbdff9ab9d..3559e29c4acee 100644 --- a/tests/ui/traits/next-solver/more-object-bound.stderr +++ b/tests/ui/traits/next-solver/more-object-bound.stderr @@ -1,5 +1,5 @@ error[E0271]: type mismatch resolving ` as SuperTrait>::A == B` - --> $DIR/more-object-bound.rs:12:5 + --> $DIR/more-object-bound.rs:12:17 | LL | fn transmute(x: A) -> B { | - - @@ -9,7 +9,7 @@ LL | fn transmute(x: A) -> B { | found type parameter | expected type parameter LL | foo::>(x) - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `A`, found type parameter `B` + | ^^^^^^^^^^^^^^^^^^^^^^^ expected type parameter `A`, found type parameter `B` | = note: expected type parameter `A` found type parameter `B`