Skip to content

Commit

Permalink
Rollup merge of #92112 - SparrowLii:issue92010, r=cjgillot
Browse files Browse the repository at this point in the history
Fix the error of checking `base_expr` twice in type_changing_struct_update

Fixes #92010
  • Loading branch information
matthiaskrgr authored Dec 27, 2021
2 parents b57a6b3 + 6434844 commit bd77fbf
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit bd77fbf

Please sign in to comment.