diff options
| author | lcnr <rust@lcnr.de> | 2025-05-21 14:36:50 +0000 |
|---|---|---|
| committer | lcnr <rust@lcnr.de> | 2025-06-03 18:08:15 +0200 |
| commit | bde63bb251df37022011c391d34ceef12218fb45 (patch) | |
| tree | 3c589347a2c965d9b22cde6a2200f239b2867bf2 /compiler/rustc_trait_selection/src | |
| parent | 2f176126aaf3fd316fc5ced3d9a111a48797b52c (diff) | |
| download | rust-bde63bb251df37022011c391d34ceef12218fb45.tar.gz rust-bde63bb251df37022011c391d34ceef12218fb45.zip | |
builtin dyn impl no guide inference
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/select/mod.rs | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 3a2f9e8ca17..1b9b68fa980 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -1919,12 +1919,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> { // impl `impl<T: ?Sized> Any for T { .. }`. This really shouldn't exist but is // necessary due to #57893. We again arbitrarily prefer the applicable candidate // with the lowest index. + // + // We do not want to use these impls to guide inference in case a user-written impl + // may also apply. let object_bound = candidates .iter() .filter_map(|c| if let ObjectCandidate(i) = c.candidate { Some(i) } else { None }) .try_reduce(|c1, c2| if has_non_region_infer { None } else { Some(c1.min(c2)) }); match object_bound { - Some(Some(index)) => return Some(ObjectCandidate(index)), + Some(Some(index)) => { + return if has_non_region_infer + && candidates.iter().any(|c| matches!(c.candidate, ImplCandidate(_))) + { + None + } else { + Some(ObjectCandidate(index)) + }; + } Some(None) => {} None => return None, } |
