diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2024-04-17 00:00:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-17 00:00:24 +0200 |
| commit | c7b009f38a340892a500e009c9d3ccd300e6d5af (patch) | |
| tree | fc699f7d13b7a28fb5f69331213d9f4d5c445c40 | |
| parent | 51cfa95668c8a0ce5c87bd5fe649d577a040cce7 (diff) | |
| parent | 9cc4e2361ecffd6848f69f28e926e7ed952fca6d (diff) | |
| download | rust-c7b009f38a340892a500e009c9d3ccd300e6d5af.tar.gz rust-c7b009f38a340892a500e009c9d3ccd300e6d5af.zip | |
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](https://github.com/rust-lang/rust/pull/41937)
| -rw-r--r-- | compiler/rustc_hir_analysis/src/coherence/builtin.rs | 35 |
1 files changed, 13 insertions, 22 deletions
diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 5e404847656..0b6c60e4ba2 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -10,8 +10,8 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::lang_items::LangItem; use rustc_hir::ItemKind; use rustc_infer::infer::outlives::env::OutlivesEnvironment; +use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::{self, RegionResolutionError}; -use rustc_infer::infer::{DefineOpaqueTypes, TyCtxtInferExt}; use rustc_infer::traits::Obligation; use rustc_middle::ty::adjustment::CoerceUnsizedInfo; 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<() // even if they do not carry that attribute. use rustc_type_ir::TyKind::*; match (source.kind(), target.kind()) { - (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) - if infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, r_a, *r_b).is_ok() - && mutbl_a == *mutbl_b => - { + (&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => { Ok(()) } (&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<() } } - if let Ok(ok) = - infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, ty_a, ty_b) - { - if ok.obligations.is_empty() { - res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST { - span, - name: field.name, - ty: ty_a, - })); + if ty_a == ty_b { + res = Err(tcx.dcx().emit_err(errors::DispatchFromDynZST { + span, + name: field.name, + ty: ty_a, + })); - return false; - } + return false; } return true; @@ -433,14 +426,12 @@ pub fn coerce_unsized_info<'tcx>( // something more accepting, but we use // equality because we want to be able to // perform this check without computing - // variance where possible. (This is because - // we may have to evaluate constraint + // variance or constraining opaque types' hidden types. + // (This is because we may have to evaluate constraint // expressions in the course of execution.) // See e.g., #41936. - if let Ok(ok) = infcx.at(&cause, param_env).eq(DefineOpaqueTypes::No, a, b) { - if ok.obligations.is_empty() { - return None; - } + if a == b { + return None; } // Collect up all fields that were significantly changed |
