diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-27 21:42:25 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-27 21:42:25 +0100 |
| commit | bd77fbfef1d7be3fd8d8db137b800476199fa11b (patch) | |
| tree | 3316d110c63a53cbbfe0267126a3c74bdabbb43d | |
| parent | b57a6b38c5b3ac932cf5bc70558fc2b4d0792e91 (diff) | |
| parent | 643484416b6f09cf40c7583b4259e685c1e30f03 (diff) | |
| download | rust-bd77fbfef1d7be3fd8d8db137b800476199fa11b.tar.gz rust-bd77fbfef1d7be3fd8d8db137b800476199fa11b.zip | |
Rollup merge of #92112 - SparrowLii:issue92010, r=cjgillot
Fix the error of checking `base_expr` twice in type_changing_struct_update Fixes #92010
3 files changed, 25 insertions, 1 deletions
diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index 096c4fcf472..8d370e440ea 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, 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 00000000000..f1a54ee5867 --- /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<T> { + x: T, + y: f64, +} + +impl<T> P<T> { + 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 00000000000..5957ea7c9ef --- /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<T>` + | + = note: expected struct `P<T>` + found reference `&P<T>` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
