Skip to content

Commit 49bdf46

Browse files
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 #116652
2 parents 46e4398 + 3f2f843 commit 49bdf46

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

compiler/rustc_hir_typeck/src/coercion.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -1245,11 +1245,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12451245
expr,
12461246
);
12471247

1248-
return self
1248+
return Err(self
12491249
.commit_if_ok(|_| {
1250-
self.at(cause, self.param_env).lub(DefineOpaqueTypes::No, prev_ty, new_ty)
1250+
self.at(cause, self.param_env).lub(DefineOpaqueTypes::Yes, prev_ty, new_ty)
12511251
})
1252-
.map(|ok| self.register_infer_ok_obligations(ok));
1252+
.unwrap_err());
12531253
}
12541254
}
12551255

@@ -1259,10 +1259,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12591259
if let Some(e) = first_error {
12601260
Err(e)
12611261
} else {
1262-
self.commit_if_ok(|_| {
1263-
self.at(cause, self.param_env).lub(DefineOpaqueTypes::No, prev_ty, new_ty)
1264-
})
1265-
.map(|ok| self.register_infer_ok_obligations(ok))
1262+
Err(self
1263+
.commit_if_ok(|_| {
1264+
self.at(cause, self.param_env).lub(
1265+
DefineOpaqueTypes::Yes,
1266+
prev_ty,
1267+
new_ty,
1268+
)
1269+
})
1270+
.unwrap_err())
12661271
}
12671272
}
12681273
Ok(ok) => {

0 commit comments

Comments
 (0)