Skip to content

Commit 7bd1b35

Browse files
committed
fast_reject: remove StripReferences
1 parent 60930fc commit 7bd1b35

File tree

7 files changed

+19
-65
lines changed

7 files changed

+19
-65
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_middle::mir::interpret;
2626
use rustc_middle::thir;
2727
use rustc_middle::traits::specialization_graph;
2828
use rustc_middle::ty::codec::TyEncoder;
29-
use rustc_middle::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
29+
use rustc_middle::ty::fast_reject::{self, SimplifiedType, SimplifyParams};
3030
use rustc_middle::ty::query::Providers;
3131
use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt};
3232
use rustc_serialize::{opaque, Encodable, Encoder};
@@ -2066,7 +2066,6 @@ impl<'tcx, 'v> ItemLikeVisitor<'v> for ImplsVisitor<'tcx> {
20662066
self.tcx,
20672067
trait_ref.self_ty(),
20682068
SimplifyParams::No,
2069-
StripReferences::No,
20702069
);
20712070

20722071
self.impls

compiler/rustc_middle/src/ty/fast_reject.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,6 @@ pub enum SimplifyParams {
5454
No,
5555
}
5656

57-
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
58-
pub enum StripReferences {
59-
Yes,
60-
No,
61-
}
62-
6357
/// Tries to simplify a type by only returning the outermost injective¹ layer, if one exists.
6458
///
6559
/// 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 {
7367
/// When using `SimplifyParams::Yes`, we still return a simplified type for params and projections²,
7468
/// the reasoning for this can be seen at the places doing this.
7569
///
76-
/// For diagnostics we strip references with `StripReferences::Yes`. This is currently the best
77-
/// way to skip some unhelpful suggestions.
7870
///
7971
/// ¹ meaning that if two outermost layers are different, then the whole types are also different.
8072
/// ² 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(
8779
tcx: TyCtxt<'_>,
8880
ty: Ty<'_>,
8981
can_simplify_params: SimplifyParams,
90-
strip_references: StripReferences,
9182
) -> Option<SimplifiedType> {
9283
match *ty.kind() {
9384
ty::Bool => Some(BoolSimplifiedType),
@@ -106,16 +97,7 @@ pub fn simplify_type(
10697
}
10798
_ => Some(MarkerTraitObjectSimplifiedType),
10899
},
109-
ty::Ref(_, ty, mutbl) => {
110-
if strip_references == StripReferences::Yes {
111-
// For diagnostics, when recommending similar impls we want to
112-
// recommend impls even when there is a reference mismatch,
113-
// so we treat &T and T equivalently in that case.
114-
simplify_type(tcx, ty, can_simplify_params, strip_references)
115-
} else {
116-
Some(RefSimplifiedType(mutbl))
117-
}
118-
}
100+
ty::Ref(_, _, mutbl) => Some(RefSimplifiedType(mutbl)),
119101
ty::FnDef(def_id, _) | ty::Closure(def_id, _) => Some(ClosureSimplifiedType(def_id)),
120102
ty::Generator(def_id, _, _) => Some(GeneratorSimplifiedType(def_id)),
121103
ty::GeneratorWitness(ref tys) => {

compiler/rustc_middle/src/ty/trait_def.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
2+
use crate::ty::fast_reject::{self, SimplifiedType, SimplifyParams};
33
use crate::ty::fold::TypeFoldable;
44
use crate::ty::{Ident, Ty, TyCtxt};
55
use rustc_hir as hir;
@@ -172,9 +172,7 @@ impl<'tcx> TyCtxt<'tcx> {
172172
// whose outer level is not a parameter or projection. Especially for things like
173173
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
174174
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
175-
if let Some(simp) =
176-
fast_reject::simplify_type(self, self_ty, SimplifyParams::Yes, StripReferences::No)
177-
{
175+
if let Some(simp) = fast_reject::simplify_type(self, self_ty, SimplifyParams::Yes) {
178176
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
179177
for &impl_def_id in impls {
180178
if let result @ Some(_) = f(impl_def_id) {
@@ -234,7 +232,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
234232
}
235233

236234
if let Some(simplified_self_ty) =
237-
fast_reject::simplify_type(tcx, impl_self_ty, SimplifyParams::No, StripReferences::No)
235+
fast_reject::simplify_type(tcx, impl_self_ty, SimplifyParams::No)
238236
{
239237
impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id);
240238
} else {

compiler/rustc_trait_selection/src/traits/coherence.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::traits::{
1414
PredicateObligations, SelectionContext,
1515
};
1616
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
17-
use rustc_middle::ty::fast_reject::{self, SimplifyParams, StripReferences};
17+
use rustc_middle::ty::fast_reject::{self, SimplifyParams};
1818
use rustc_middle::ty::fold::TypeFoldable;
1919
use rustc_middle::ty::subst::Subst;
2020
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -80,8 +80,8 @@ where
8080
impl2_ref.iter().flat_map(|tref| tref.substs.types()),
8181
)
8282
.any(|(ty1, ty2)| {
83-
let t1 = fast_reject::simplify_type(tcx, ty1, SimplifyParams::No, StripReferences::No);
84-
let t2 = fast_reject::simplify_type(tcx, ty2, SimplifyParams::No, StripReferences::No);
83+
let t1 = fast_reject::simplify_type(tcx, ty1, SimplifyParams::No);
84+
let t2 = fast_reject::simplify_type(tcx, ty2, SimplifyParams::No);
8585

8686
if let (Some(t1), Some(t2)) = (t1, t2) {
8787
// Simplified successfully

compiler/rustc_trait_selection/src/traits/select/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use rustc_infer::infer::LateBoundRegionConversionTime;
3636
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
3737
use rustc_middle::mir::interpret::ErrorHandled;
3838
use rustc_middle::thir::abstract_const::NotConstEvaluatable;
39-
use rustc_middle::ty::fast_reject::{self, SimplifyParams, StripReferences};
39+
use rustc_middle::ty::fast_reject::{self, SimplifyParams};
4040
use rustc_middle::ty::print::with_no_trimmed_paths;
4141
use rustc_middle::ty::relate::TypeRelation;
4242
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef};
@@ -2174,14 +2174,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
21742174
self.tcx(),
21752175
obligation_ty,
21762176
SimplifyParams::Yes,
2177-
StripReferences::No,
2178-
);
2179-
let simplified_impl_ty = fast_reject::simplify_type(
2180-
self.tcx(),
2181-
impl_ty,
2182-
SimplifyParams::No,
2183-
StripReferences::No,
21842177
);
2178+
let simplified_impl_ty =
2179+
fast_reject::simplify_type(self.tcx(), impl_ty, SimplifyParams::No);
21852180

21862181
simplified_obligation_ty.is_some()
21872182
&& simplified_impl_ty.is_some()

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::OverlapError;
22

33
use crate::traits;
44
use rustc_hir::def_id::DefId;
5-
use rustc_middle::ty::fast_reject::{self, SimplifiedType, SimplifyParams, StripReferences};
5+
use rustc_middle::ty::fast_reject::{self, SimplifiedType, SimplifyParams};
66
use rustc_middle::ty::print::with_no_trimmed_paths;
77
use rustc_middle::ty::{self, TyCtxt, TypeFoldable};
88

@@ -48,12 +48,7 @@ impl ChildrenExt<'_> for Children {
4848
/// Insert an impl into this set of children without comparing to any existing impls.
4949
fn insert_blindly(&mut self, tcx: TyCtxt<'_>, impl_def_id: DefId) {
5050
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
51-
if let Some(st) = fast_reject::simplify_type(
52-
tcx,
53-
trait_ref.self_ty(),
54-
SimplifyParams::No,
55-
StripReferences::No,
56-
) {
51+
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), SimplifyParams::No) {
5752
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
5853
self.non_blanket_impls.entry(st).or_default().push(impl_def_id)
5954
} else {
@@ -68,12 +63,7 @@ impl ChildrenExt<'_> for Children {
6863
fn remove_existing(&mut self, tcx: TyCtxt<'_>, impl_def_id: DefId) {
6964
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
7065
let vec: &mut Vec<DefId>;
71-
if let Some(st) = fast_reject::simplify_type(
72-
tcx,
73-
trait_ref.self_ty(),
74-
SimplifyParams::No,
75-
StripReferences::No,
76-
) {
66+
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), SimplifyParams::No) {
7767
debug!("remove_existing: impl_def_id={:?} st={:?}", impl_def_id, st);
7868
vec = self.non_blanket_impls.get_mut(&st).unwrap();
7969
} else {
@@ -316,12 +306,7 @@ impl GraphExt for Graph {
316306

317307
let mut parent = trait_def_id;
318308
let mut last_lint = None;
319-
let simplified = fast_reject::simplify_type(
320-
tcx,
321-
trait_ref.self_ty(),
322-
SimplifyParams::No,
323-
StripReferences::No,
324-
);
309+
let simplified = fast_reject::simplify_type(tcx, trait_ref.self_ty(), SimplifyParams::No);
325310

326311
// Descend the specialization tree, where `parent` is the current parent node.
327312
loop {

compiler/rustc_typeck/src/check/method/suggest.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
99
use rustc_hir::lang_items::LangItem;
1010
use rustc_hir::{ExprKind, Node, QPath};
1111
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
12-
use rustc_middle::ty::fast_reject::{simplify_type, SimplifyParams, StripReferences};
12+
use rustc_middle::ty::fast_reject::{simplify_type, SimplifyParams};
1313
use rustc_middle::ty::print::with_crate_prefix;
1414
use rustc_middle::ty::{self, DefIdTree, ToPredicate, Ty, TyCtxt, TypeFoldable};
1515
use rustc_span::lev_distance;
@@ -1748,8 +1748,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17481748
// FIXME: Even though negative bounds are not implemented, we could maybe handle
17491749
// cases where a positive bound implies a negative impl.
17501750
(candidates, Vec::new())
1751-
} else if let Some(simp_rcvr_ty) =
1752-
simplify_type(self.tcx, rcvr_ty, SimplifyParams::Yes, StripReferences::No)
1751+
} else if let Some(simp_rcvr_ty) = simplify_type(self.tcx, rcvr_ty, SimplifyParams::Yes)
17531752
{
17541753
let mut potential_candidates = Vec::new();
17551754
let mut explicitly_negative = Vec::new();
@@ -1763,12 +1762,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17631762
})
17641763
.any(|imp_did| {
17651764
let imp = self.tcx.impl_trait_ref(imp_did).unwrap();
1766-
let imp_simp = simplify_type(
1767-
self.tcx,
1768-
imp.self_ty(),
1769-
SimplifyParams::Yes,
1770-
StripReferences::No,
1771-
);
1765+
let imp_simp =
1766+
simplify_type(self.tcx, imp.self_ty(), SimplifyParams::Yes);
17721767
imp_simp.map_or(false, |s| s == simp_rcvr_ty)
17731768
})
17741769
{

0 commit comments

Comments
 (0)