Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7829d9d

Browse files
committed
Document overlap check filter
1 parent 5a72753 commit 7829d9d

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,27 @@ fn overlap_within_probe(
185185

186186
debug!("overlap: unification check succeeded");
187187

188-
// Are any of the obligations unsatisfiable? If so, no overlap.
188+
// There's no overlap if obligations are unsatisfiable or if the obligation negated is
189+
// satisfied.
190+
//
191+
// For example, given these two impl headers:
192+
//
193+
// `impl<'a> From<&'a str> for Box<dyn Error>`
194+
// `impl<E> From<E> for Box<dyn Error> where E: Error`
195+
//
196+
// So we have:
197+
//
198+
// `Box<dyn Error>: From<&'?a str>`
199+
// `Box<dyn Error>: From<?E>`
200+
//
201+
// After equating the two headers:
202+
//
203+
// `Box<dyn Error> = Box<dyn Error>`
204+
// So, `?E = &'?a str` and then given the where clause `&'?a str: Error`.
205+
//
206+
// If the obligation `&'?a str: Error` holds, it means that there's overlap. If that doesn't
207+
// hold we need to check if `&'?a str: !Error` holds, if doesn't hold there's overlap because
208+
// at some point an impl for `&'?a str: Error` could be added.
189209
let infcx = selcx.infcx();
190210
let tcx = infcx.tcx;
191211
let opt_failing_obligation = a_impl_header

0 commit comments

Comments
 (0)