diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2021-10-22 09:22:19 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2021-10-22 09:22:19 -0300 |
| commit | 7829d9dde3798f16b3db5841593ba1242930a587 (patch) | |
| tree | db8793ceae4b1e64e929088e1f4561d8f920f80f /compiler/rustc_trait_selection | |
| parent | 5a727538f8aeff650b48f7d23a12cef84b549e01 (diff) | |
Document overlap check filter
Diffstat (limited to 'compiler/rustc_trait_selection')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/coherence.rs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index a3fbba3bb89..d422bd66b10 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -185,7 +185,27 @@ fn overlap_within_probe( debug!("overlap: unification check succeeded"); - // Are any of the obligations unsatisfiable? If so, no overlap. + // There's no overlap if obligations are unsatisfiable or if the obligation negated is + // satisfied. + // + // For example, given these two impl headers: + // + // `impl<'a> From<&'a str> for Box<dyn Error>` + // `impl<E> From<E> for Box<dyn Error> where E: Error` + // + // So we have: + // + // `Box<dyn Error>: From<&'?a str>` + // `Box<dyn Error>: From<?E>` + // + // After equating the two headers: + // + // `Box<dyn Error> = Box<dyn Error>` + // So, `?E = &'?a str` and then given the where clause `&'?a str: Error`. + // + // If the obligation `&'?a str: Error` holds, it means that there's overlap. If that doesn't + // hold we need to check if `&'?a str: !Error` holds, if doesn't hold there's overlap because + // at some point an impl for `&'?a str: Error` could be added. let infcx = selcx.infcx(); let tcx = infcx.tcx; let opt_failing_obligation = a_impl_header |
