Skip to content

Commit c7b009f

Browse files
Rollup merge of #124027 - oli-obk:define_opaque_types9, r=compiler-errors
Prefer identity equality over equating types during coercion. These types are always generic only over their own generic parameters with no inference variables involved. r? `@compiler-errors` I love touching code that [hasn't changed meaningfully since 2016](#41937)
2 parents 51cfa95 + 9cc4e23 commit c7b009f

File tree

1 file changed

+13
-22
lines changed
  • compiler/rustc_hir_analysis/src/coherence

1 file changed

+13
-22
lines changed

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ use rustc_hir::def_id::{DefId, LocalDefId};
1010
use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::ItemKind;
1212
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
13+
use rustc_infer::infer::TyCtxtInferExt;
1314
use rustc_infer::infer::{self, RegionResolutionError};
14-
use rustc_infer::infer::{DefineOpaqueTypes, TyCtxtInferExt};
1515
use rustc_infer::traits::Obligation;
1616
use rustc_middle::ty::adjustment::CoerceUnsizedInfo;
1717
use rustc_middle::ty::{self, suggest_constraining_type_params, Ty, TyCtxt, TypeVisitableExt};
@@ -189,10 +189,7 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
189189
// even if they do not carry that attribute.
190190
use rustc_type_ir::TyKind::*;
191191
match (source.kind(), target.kind()) {
192-
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b))
193-
if infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, r_a, *r_b).is_ok()
194-
&& mutbl_a == *mutbl_b =>
195-
{
192+
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => {
196193
Ok(())
197194
}
198195
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
@@ -230,18 +227,14 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
230227
}
231228
}
232229

233-
if let Ok(ok) =
234-
infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, ty_a, ty_b)
235-
{
236-
if ok.obligations.is_empty() {
237-
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
238-
span,
239-
name: field.name,
240-
ty: ty_a,
241-
}));
230+
if ty_a == ty_b {
231+
res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST {
232+
span,
233+
name: field.name,
234+
ty: ty_a,
235+
}));
242236

243-
return false;
244-
}
237+
return false;
245238
}
246239

247240
return true;
@@ -433,14 +426,12 @@ pub fn coerce_unsized_info<'tcx>(
433426
// something more accepting, but we use
434427
// equality because we want to be able to
435428
// perform this check without computing
436-
// variance where possible. (This is because
437-
// we may have to evaluate constraint
429+
// variance or constraining opaque types' hidden types.
430+
// (This is because we may have to evaluate constraint
438431
// expressions in the course of execution.)
439432
// See e.g., #41936.
440-
if let Ok(ok) = infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, a, b) {
441-
if ok.obligations.is_empty() {
442-
return None;
443-
}
433+
if a == b {
434+
return None;
444435
}
445436

446437
// Collect up all fields that were significantly changed

0 commit comments

Comments
 (0)