diff options
| author | lcnr <rust@lcnr.de> | 2025-09-11 13:08:36 +0200 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2025-09-18 12:58:38 +0200 |
| commit | f4e19c68786211f3c3cf2593442629599678800a (patch) | |
| tree | e4eafc26e6dad3c7fb9bf418ab476ac64b555fab /compiler/rustc_hir_analysis | |
| parent | d1ed52b1f5b78bf66127b670af813b84d57aeedb (diff) | |
| download | rust-f4e19c68786211f3c3cf2593442629599678800a.tar.gz rust-f4e19c68786211f3c3cf2593442629599678800a.zip | |
support calls on opaque types :<
Diffstat (limited to 'compiler/rustc_hir_analysis')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/autoderef.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/compiler/rustc_hir_analysis/src/autoderef.rs b/compiler/rustc_hir_analysis/src/autoderef.rs index e8237471e1b..88bd3339e4e 100644 --- a/compiler/rustc_hir_analysis/src/autoderef.rs +++ b/compiler/rustc_hir_analysis/src/autoderef.rs @@ -68,7 +68,14 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> { return None; } - if self.state.cur_ty.is_ty_var() { + // We want to support method and function calls for `impl Deref<Target = ..>`. + // + // To do so we don't eagerly bail if the current type is the hidden type of an + // opaque type and instead return `None` in `fn overloaded_deref_ty` if the + // opaque does not have a `Deref` item-bound. + if let &ty::Infer(ty::TyVar(vid)) = self.state.cur_ty.kind() + && !self.infcx.has_opaques_with_sub_unified_hidden_type(vid) + { return None; } @@ -160,7 +167,11 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> { self.param_env, ty::Binder::dummy(trait_ref), ); - if !self.infcx.next_trait_solver() && !self.infcx.predicate_may_hold(&obligation) { + // We detect whether the self type implements `Deref` before trying to + // structurally normalize. We use `predicate_may_hold_opaque_types_jank` + // to support not-yet-defined opaque types. It will succeed for `impl Deref` + // but fail for `impl OtherTrait`. + if !self.infcx.predicate_may_hold_opaque_types_jank(&obligation) { debug!("overloaded_deref_ty: cannot match obligation"); return None; } |
