From 5b2a7606aeabfc2c78e0475f18d24d6c9e6910e8 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Mon, 20 Dec 2021 10:21:07 +0800 Subject: [PATCH 1/2] Fix the error of checking `base_expr` twice in type_changing_struct_update --- compiler/rustc_typeck/src/check/expr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 096c4fcf47207..8d370e440eaf1 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1508,7 +1508,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } else { self.check_expr_has_type_or_error(base_expr, adt_ty, |_| { - let base_ty = self.check_expr(base_expr); + let base_ty = self.typeck_results.borrow().node_type(base_expr.hir_id); let same_adt = match (adt_ty.kind(), base_ty.kind()) { (ty::Adt(adt, _), ty::Adt(base_adt, _)) if adt == base_adt => true, _ => false, From 643484416b6f09cf40c7583b4259e685c1e30f03 Mon Sep 17 00:00:00 2001 From: SparrowLii Date: Mon, 20 Dec 2021 10:39:02 +0800 Subject: [PATCH 2/2] add test files --- .../issue-92010-trait-bound-not-satisfied.rs | 12 ++++++++++++ .../issue-92010-trait-bound-not-satisfied.stderr | 12 ++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs create mode 100644 src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr diff --git a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs new file mode 100644 index 0000000000000..f1a54ee5867c5 --- /dev/null +++ b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.rs @@ -0,0 +1,12 @@ +#[derive(Clone)] +struct P { + x: T, + y: f64, +} + +impl P { + fn y(&self, y: f64) -> Self { P{y, .. self.clone() } } + //~^ mismatched types [E0308] +} + +fn main() {} diff --git a/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr new file mode 100644 index 0000000000000..5957ea7c9efdd --- /dev/null +++ b/src/test/ui/rfcs/rfc-2528-type-changing-struct-update/issue-92010-trait-bound-not-satisfied.stderr @@ -0,0 +1,12 @@ +error[E0308]: mismatched types + --> $DIR/issue-92010-trait-bound-not-satisfied.rs:8:43 + | +LL | fn y(&self, y: f64) -> Self { P{y, .. self.clone() } } + | ^^^^^^^^^^^^ expected struct `P`, found `&P` + | + = note: expected struct `P` + found reference `&P` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`.