fast_reject: remove StripReferences
This commit is contained in:
parent
165142e993
commit
0efc6c02cb
7 changed files with 20 additions and 68 deletions
|
@ -54,12 +54,6 @@ pub enum SimplifyParams {
|
|||
No,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
|
||||
pub enum StripReferences {
|
||||
Yes,
|
||||
No,
|
||||
}
|
||||
|
||||
/// Tries to simplify a type by only returning the outermost injective¹ layer, if one exists.
|
||||
///
|
||||
/// The idea is to get something simple that we can use to quickly decide if two types could unify,
|
||||
|
@ -73,8 +67,6 @@ pub enum StripReferences {
|
|||
/// When using `SimplifyParams::Yes`, we still return a simplified type for params and projections²,
|
||||
/// the reasoning for this can be seen at the places doing this.
|
||||
///
|
||||
/// For diagnostics we strip references with `StripReferences::Yes`. This is currently the best
|
||||
/// way to skip some unhelpful suggestions.
|
||||
///
|
||||
/// ¹ meaning that if two outermost layers are different, then the whole types are also different.
|
||||
/// ² FIXME(@lcnr): this seems like it can actually end up being unsound with the way it's used during
|
||||
|
@ -87,7 +79,6 @@ pub fn simplify_type(
|
|||
tcx: TyCtxt<'_>,
|
||||
ty: Ty<'_>,
|
||||
can_simplify_params: SimplifyParams,
|
||||
strip_references: StripReferences,
|
||||
) -> Option<SimplifiedType> {
|
||||
match *ty.kind() {
|
||||
ty::Bool => Some(BoolSimplifiedType),
|
||||
|
@ -106,16 +97,7 @@ pub fn simplify_type(
|
|||
}
|
||||
_ => Some(MarkerTraitObjectSimplifiedType),
|
||||
},
|
||||
ty::Ref(_, ty, mutbl) => {
|
||||
if strip_references == StripReferences::Yes {
|
||||
// For diagnostics, when recommending similar impls we want to
|
||||
// recommend impls even when there is a reference mismatch,
|
||||
// so we treat &T and T equivalently in that case.
|
||||
simplify_type(tcx, ty, can_simplify_params, strip_references)
|
||||
} else {
|
||||
Some(RefSimplifiedType(mutbl))
|
||||
}
|
||||
}
|
||||
ty::Ref(_, _, mutbl) => Some(RefSimplifiedType(mutbl)),
|
||||
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(ClosureSimplifiedType(def_id)),
|
||||
ty::Generator(def_id, _, _) => Some(GeneratorSimplifiedType(def_id)),
|
||||
ty::GeneratorWitness(ref tys) => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::traits::specialization_graph;
|
||||
use crate::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
|
||||
use crate::ty::fast_reject::{self, SimplifiedType, SimplifyParams};
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::{Ident, Ty, TyCtxt};
|
||||
use rustc_hir as hir;
|
||||
|
@ -150,9 +150,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
self_ty: Ty<'tcx>,
|
||||
) -> impl Iterator<Item = DefId> + 'tcx {
|
||||
let impls = self.trait_impls_of(def_id);
|
||||
if let Some(simp) =
|
||||
fast_reject::simplify_type(self, self_ty, SimplifyParams::No, StripReferences::No)
|
||||
{
|
||||
if let Some(simp) = fast_reject::simplify_type(self, self_ty, SimplifyParams::No) {
|
||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||
return impls.iter().copied();
|
||||
}
|
||||
|
@ -189,9 +187,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
// whose outer level is not a parameter or projection. Especially for things like
|
||||
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
|
||||
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
|
||||
if let Some(simp) =
|
||||
fast_reject::simplify_type(self, self_ty, SimplifyParams::Yes, StripReferences::No)
|
||||
{
|
||||
if let Some(simp) = fast_reject::simplify_type(self, self_ty, SimplifyParams::Yes) {
|
||||
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
|
||||
for &impl_def_id in impls {
|
||||
if let result @ Some(_) = f(impl_def_id) {
|
||||
|
@ -251,7 +247,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
|
|||
}
|
||||
|
||||
if let Some(simplified_self_ty) =
|
||||
fast_reject::simplify_type(tcx, impl_self_ty, SimplifyParams::No, StripReferences::No)
|
||||
fast_reject::simplify_type(tcx, impl_self_ty, SimplifyParams::No)
|
||||
{
|
||||
impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue