Skip to content

Commit

Permalink
Rollup merge of #126673 - oli-obk:dont_rely_on_err_reporting, r=compi…
Browse files Browse the repository at this point in the history
…ler-errors

Ensure we don't accidentally succeed when we want to report an error

This also changes the `DefiningOpaqueTypes::No` to `Yes` without adding tests, as it is solely run on the error path to improve diagnostics. I was unable to provide a test that changes diagnostics, as all the tests I came up with ended up successfully constraining the opaque type and thus succeeding the coercion.

r? ```@compiler-errors```

cc #116652
  • Loading branch information
compiler-errors authored Jun 24, 2024
2 parents 46e4398 + 3f2f843 commit 49bdf46
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,11 +1245,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
expr,
);

return self
return Err(self
.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(DefineOpaqueTypes::No, prev_ty, new_ty)
self.at(cause, self.param_env).lub(DefineOpaqueTypes::Yes, prev_ty, new_ty)
})
.map(|ok| self.register_infer_ok_obligations(ok));
.unwrap_err());
}
}

Expand All @@ -1259,10 +1259,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(e) = first_error {
Err(e)
} else {
self.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(DefineOpaqueTypes::No, prev_ty, new_ty)
})
.map(|ok| self.register_infer_ok_obligations(ok))
Err(self
.commit_if_ok(|_| {
self.at(cause, self.param_env).lub(
DefineOpaqueTypes::Yes,
prev_ty,
new_ty,
)
})
.unwrap_err())
}
}
Ok(ok) => {
Expand Down

0 comments on commit 49bdf46

Please sign in to comment.