Skip to content

Commit

Permalink
Document overlap check filter
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed Oct 22, 2021
1 parent 5a72753 commit 7829d9d
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion compiler/rustc_trait_selection/src/traits/coherence.rs
Expand Up @@ -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
Expand Down

0 comments on commit 7829d9d

Please sign in to comment.