diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-11-02 13:08:53 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-11-02 13:08:53 +0000 |
commit | 731b38fa3c1694648e6c8e60f61820f9783343eb (patch) | |
tree | b3f4e94e8eac9bb24296aacafacb100930bee59e /crates/hir_ty/src/infer | |
parent | 6507877e7039d4517682a4fc232356662f509d81 (diff) | |
parent | b6101184537b1165cfdd5fc473e04ad4c5b7bffa (diff) |
Merge #6438
6438: Deny unreachable-pub r=matklad a=matklad
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.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/hir_ty/src/infer')
-rw-r--r-- | crates/hir_ty/src/infer/expr.rs | 2 | ||||
-rw-r--r-- | crates/hir_ty/src/infer/unify.rs | 35 |
2 files changed, 23 insertions, 14 deletions
diff --git a/crates/hir_ty/src/infer/expr.rs b/crates/hir_ty/src/infer/expr.rs index 8ac4cf89a..605951b10 100644 --- a/crates/hir_ty/src/infer/expr.rs +++ b/crates/hir_ty/src/infer/expr.rs | |||
@@ -107,7 +107,7 @@ impl<'a> InferenceContext<'a> { | |||
107 | } | 107 | } |
108 | } | 108 | } |
109 | 109 | ||
110 | pub fn callable_sig(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> { | 110 | pub(crate) fn callable_sig(&mut self, ty: &Ty, num_args: usize) -> Option<(Vec<Ty>, Ty)> { |
111 | match ty.callable_sig(self.db) { | 111 | match ty.callable_sig(self.db) { |
112 | Some(sig) => Some((sig.params().to_vec(), sig.ret().clone())), | 112 | Some(sig) => Some((sig.params().to_vec(), sig.ret().clone())), |
113 | None => self.callable_sig_from_fn_trait(ty, num_args), | 113 | None => self.callable_sig_from_fn_trait(ty, num_args), |
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 | |||
127 | } | 127 | } |
128 | 128 | ||
129 | impl<T> Canonicalized<T> { | 129 | impl<T> Canonicalized<T> { |
130 | pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { | 130 | pub(super) fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { |
131 | ty.walk_mut_binders( | 131 | ty.walk_mut_binders( |
132 | &mut |ty, binders| { | 132 | &mut |ty, binders| { |
133 | if let &mut Ty::Bound(bound) = ty { | 133 | if let &mut Ty::Bound(bound) = ty { |
@@ -141,7 +141,11 @@ impl<T> Canonicalized<T> { | |||
141 | ty | 141 | ty |
142 | } | 142 | } |
143 | 143 | ||
144 | pub fn apply_solution(&self, ctx: &mut InferenceContext<'_>, solution: Canonical<Substs>) { | 144 | pub(super) fn apply_solution( |
145 | &self, | ||
146 | ctx: &mut InferenceContext<'_>, | ||
147 | solution: Canonical<Substs>, | ||
148 | ) { | ||
145 | // the solution may contain new variables, which we need to convert to new inference vars | 149 | // the solution may contain new variables, which we need to convert to new inference vars |
146 | let new_vars = Substs( | 150 | let new_vars = Substs( |
147 | solution | 151 | solution |
@@ -164,7 +168,7 @@ impl<T> Canonicalized<T> { | |||
164 | } | 168 | } |
165 | } | 169 | } |
166 | 170 | ||
167 | pub fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { | 171 | pub(crate) fn unify(tys: &Canonical<(Ty, Ty)>) -> Option<Substs> { |
168 | let mut table = InferenceTable::new(); | 172 | let mut table = InferenceTable::new(); |
169 | let vars = Substs( | 173 | let vars = Substs( |
170 | tys.kinds | 174 | tys.kinds |
@@ -199,41 +203,46 @@ pub(crate) struct InferenceTable { | |||
199 | } | 203 | } |
200 | 204 | ||
201 | impl InferenceTable { | 205 | impl InferenceTable { |
202 | pub fn new() -> Self { | 206 | pub(crate) fn new() -> Self { |
203 | InferenceTable { var_unification_table: InPlaceUnificationTable::new() } | 207 | InferenceTable { var_unification_table: InPlaceUnificationTable::new() } |
204 | } | 208 | } |
205 | 209 | ||
206 | pub fn new_type_var(&mut self) -> Ty { | 210 | pub(crate) fn new_type_var(&mut self) -> Ty { |
207 | Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 211 | Ty::Infer(InferTy::TypeVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
208 | } | 212 | } |
209 | 213 | ||
210 | pub fn new_integer_var(&mut self) -> Ty { | 214 | pub(crate) fn new_integer_var(&mut self) -> Ty { |
211 | Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 215 | Ty::Infer(InferTy::IntVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
212 | } | 216 | } |
213 | 217 | ||
214 | pub fn new_float_var(&mut self) -> Ty { | 218 | pub(crate) fn new_float_var(&mut self) -> Ty { |
215 | Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) | 219 | Ty::Infer(InferTy::FloatVar(self.var_unification_table.new_key(TypeVarValue::Unknown))) |
216 | } | 220 | } |
217 | 221 | ||
218 | pub fn new_maybe_never_type_var(&mut self) -> Ty { | 222 | pub(crate) fn new_maybe_never_type_var(&mut self) -> Ty { |
219 | Ty::Infer(InferTy::MaybeNeverTypeVar( | 223 | Ty::Infer(InferTy::MaybeNeverTypeVar( |
220 | self.var_unification_table.new_key(TypeVarValue::Unknown), | 224 | self.var_unification_table.new_key(TypeVarValue::Unknown), |
221 | )) | 225 | )) |
222 | } | 226 | } |
223 | 227 | ||
224 | pub fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { | 228 | pub(crate) fn resolve_ty_completely(&mut self, ty: Ty) -> Ty { |
225 | self.resolve_ty_completely_inner(&mut Vec::new(), ty) | 229 | self.resolve_ty_completely_inner(&mut Vec::new(), ty) |
226 | } | 230 | } |
227 | 231 | ||
228 | pub fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { | 232 | pub(crate) fn resolve_ty_as_possible(&mut self, ty: Ty) -> Ty { |
229 | self.resolve_ty_as_possible_inner(&mut Vec::new(), ty) | 233 | self.resolve_ty_as_possible_inner(&mut Vec::new(), ty) |
230 | } | 234 | } |
231 | 235 | ||
232 | pub fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { | 236 | pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { |
233 | self.unify_inner(ty1, ty2, 0) | 237 | self.unify_inner(ty1, ty2, 0) |
234 | } | 238 | } |
235 | 239 | ||
236 | pub fn unify_substs(&mut self, substs1: &Substs, substs2: &Substs, depth: usize) -> bool { | 240 | pub(crate) fn unify_substs( |
241 | &mut self, | ||
242 | substs1: &Substs, | ||
243 | substs2: &Substs, | ||
244 | depth: usize, | ||
245 | ) -> bool { | ||
237 | substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) | 246 | substs1.0.iter().zip(substs2.0.iter()).all(|(t1, t2)| self.unify_inner(t1, t2, depth)) |
238 | } | 247 | } |
239 | 248 | ||
@@ -331,7 +340,7 @@ impl InferenceTable { | |||
331 | 340 | ||
332 | /// If `ty` is a type variable with known type, returns that type; | 341 | /// If `ty` is a type variable with known type, returns that type; |
333 | /// otherwise, return ty. | 342 | /// otherwise, return ty. |
334 | pub fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { | 343 | pub(crate) fn resolve_ty_shallow<'b>(&mut self, ty: &'b Ty) -> Cow<'b, Ty> { |
335 | let mut ty = Cow::Borrowed(ty); | 344 | let mut ty = Cow::Borrowed(ty); |
336 | // The type variable could resolve to a int/float variable. Hence try | 345 | // The type variable could resolve to a int/float variable. Hence try |
337 | // resolving up to three times; each type of variable shouldn't occur | 346 | // resolving up to three times; each type of variable shouldn't occur |