Rollup merge of #126673 - oli-obk:dont_rely_on_err_reporting, r=compiler-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 https://github.com/rust-lang/rust/issues/116652
This commit is contained in:
Michael Goulet 2024-06-24 15:51:02 -04:00 committed by GitHub
commit 49bdf460a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1245,11 +1245,11 @@ fn try_find_coercion_lub<E>(
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());
}
}
@ -1259,10 +1259,15 @@ fn try_find_coercion_lub<E>(
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) => {