From b6101184537b1165cfdd5fc473e04ad4c5b7bffa Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Mon, 2 Nov 2020 13:13:32 +0100 Subject: Deny unreachable-pub It's very useful when `pub` is equivalent to "this is crate's public API", let's enforce this! Ideally, we should enforce it for local `cargo test`, and only during CI, but that needs https://github.com/rust-lang/cargo/issues/5034. --- crates/hir_ty/src/infer/unify.rs | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'crates/hir_ty/src/infer/unify.rs') diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 2e895d911..2406a7361 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -127,7 +127,7 @@ where } impl Canonicalized { - pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { + pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { ty.walk_mut_binders( &mut |ty, binders| { if let &mut Ty::Bound(bound) = ty { @@ -141,7 +141,11 @@ impl Canonicalized { ty } - pub fn apply_solution(&self, ctx: &mut InferenceContext<'_>, solution: Canonical) { + pub(super) fn apply_solution( + &self, + ctx: &mut InferenceContext<'_>, + solution: Canonical, + ) { // the solution may contain new variables, which we need to convert to new inference vars let new_vars = Substs( solution @@ -164,7 +168,7 @@ impl Canonicalized { } } -pub fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { +pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option { let mut table = InferenceTable::new(); let vars = Substs( tys.kinds @@ -199,41 +203,46 @@ pub(crate) struct InferenceTable { } impl InferenceTable { - pub fn new() -> Self { + pub(crate) fn new() -> Self { InferenceTable { var_unification_table: InPlaceUnificationTable::new() } } - pub fn new_type_var(&mut self) -> Ty { + pub(crate) fn new_type_var(&mut self) -> Ty { Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } - pub fn new_integer_var(&mut self) -> Ty { + pub(crate) fn new_integer_var(&mut self) -> Ty { Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } - pub fn new_float_var(&mut self) -> Ty { + pub(crate) fn new_float_var(&mut self) -> Ty { Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) } - pub fn new_maybe_never_type_var(&mut self) -> Ty { + pub(crate) fn new_maybe_never_type_var(&mut self) -> Ty { Ty::Infer(InferTy::MaybeNeverTypeVar( self.var_unification_table.new_key(TypeVarValue::Unknown), )) } - pub fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { + pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { self.resolve_ty_completely_inner(&mut Vec::new(), ty) } - pub fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { + pub(crate) fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { self.resolve_ty_as_possible_inner(&mut Vec::new(), ty) } - pub fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { + pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { self.unify_inner(ty1, ty2, 0) } - pub fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool { + pub(crate) fn unify_substs( + &mut self, + substs1: &Substs, + substs2: &Substs, + depth: usize, + ) -> bool { substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) } @@ -331,7 +340,7 @@ impl InferenceTable { /// If `ty` is a type variable with known type, returns that type; /// otherwise, return ty. - pub fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { + pub(crate) fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { let mut ty = Cow::Borrowed(ty); // The type variable could resolve to a int/float variable. Hence try // resolving up to three times; each type of variable shouldn't occur -- cgit v1.2.3