Refactor variance diagnostics to work with more types
Instead of special-casing mutable pointers/references, we now support general generic types (currently, we handle `ty::Ref`, `ty::RawPtr`, and `ty::Adt`) When a `ty::Adt` is involved, we show an additional note explaining which of the type's generic parameters is invariant (e.g. the `T` in `Cell<T>`). Currently, we don't explain *why* a particular generic parameter ends up becoming invariant. In the general case, this could require printing a long 'backtrace' of types, so doing this would be more suitable for a follow-up PR. We still only handle the case where our variance switches to `ty::Invariant`.
This commit is contained in:
parent
78fd0f633f
commit
b15cb29a4a
25 changed files with 247 additions and 40 deletions
|
@ -572,8 +572,9 @@ impl<'tcx> TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
|
|||
// (e.g., #41849).
|
||||
relate::relate_substs(self, None, a_subst, b_subst)
|
||||
} else {
|
||||
let opt_variances = self.tcx().variances_of(item_def_id);
|
||||
relate::relate_substs(self, Some(&opt_variances), a_subst, b_subst)
|
||||
let tcx = self.tcx();
|
||||
let opt_variances = tcx.variances_of(item_def_id);
|
||||
relate::relate_substs(self, Some((item_def_id, &opt_variances)), a_subst, b_subst)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue