Fix warnings & format

This commit is contained in:
Florian Diebold 2021-05-02 16:20:37 +02:00
parent 693582946f
commit 4ca1981c91
3 changed files with 11 additions and 20 deletions

View file

@ -6,15 +6,15 @@ use chalk_ir::{
cast::{Cast, CastTo, Caster}, cast::{Cast, CastTo, Caster},
fold::Fold, fold::Fold,
interner::HasInterner, interner::HasInterner,
AdtId, BoundVar, DebruijnIndex, Safety, Scalar, AdtId, BoundVar, DebruijnIndex, Scalar,
}; };
use hir_def::{builtin_type::BuiltinType, GenericDefId, TraitId, TypeAliasId}; use hir_def::{builtin_type::BuiltinType, GenericDefId, TraitId, TypeAliasId};
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::{ use crate::{
db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders, db::HirDatabase, primitive, to_assoc_type_id, to_chalk_trait_id, utils::generics, Binders,
CallableSig, FnPointer, FnSig, FnSubst, GenericArg, Interner, ProjectionTy, Substitution, CallableSig, GenericArg, Interner, ProjectionTy, Substitution, TraitRef, Ty, TyDefId, TyExt,
TraitRef, Ty, TyDefId, TyExt, TyKind, ValueTyDefId, TyKind, ValueTyDefId,
}; };
/// This is a builder for `Ty` or anything that needs a `Substitution`. /// This is a builder for `Ty` or anything that needs a `Substitution`.

View file

@ -65,7 +65,7 @@ impl<'a> InferenceContext<'a> {
} }
} }
fn coerce_inner(&mut self, mut from_ty: Ty, to_ty: &Ty) -> InferResult { fn coerce_inner(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult {
if from_ty.is_never() { if from_ty.is_never() {
// Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound // Subtle: If we are coercing from `!` to `?T`, where `?T` is an unbound
// type variable, we want `?T` to fallback to `!` if not // type variable, we want `?T` to fallback to `!` if not
@ -145,10 +145,9 @@ impl<'a> InferenceContext<'a> {
/// To match `A` with `B`, autoderef will be performed, /// To match `A` with `B`, autoderef will be performed,
/// calling `deref`/`deref_mut` where necessary. /// calling `deref`/`deref_mut` where necessary.
fn coerce_ref(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> InferResult { fn coerce_ref(&mut self, from_ty: Ty, to_ty: &Ty, to_mt: Mutability) -> InferResult {
let (from_mt, from_inner) = match from_ty.kind(&Interner) { match from_ty.kind(&Interner) {
TyKind::Ref(mt, _, ty) => { TyKind::Ref(mt, _, _) => {
coerce_mutabilities(*mt, to_mt)?; coerce_mutabilities(*mt, to_mt)?;
(*mt, ty.clone())
} }
_ => return self.unify_inner(&from_ty, to_ty), _ => return self.unify_inner(&from_ty, to_ty),
}; };
@ -160,7 +159,7 @@ impl<'a> InferenceContext<'a> {
// the structure like it is. // the structure like it is.
let canonicalized = self.canonicalize(from_ty.clone()); let canonicalized = self.canonicalize(from_ty.clone());
let mut autoderef = autoderef::autoderef( let autoderef = autoderef::autoderef(
self.db, self.db,
self.resolver.krate(), self.resolver.krate(),
InEnvironment { InEnvironment {
@ -237,7 +236,7 @@ impl<'a> InferenceContext<'a> {
/// or a function pointer. /// or a function pointer.
fn coerce_from_fn_item(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult { fn coerce_from_fn_item(&mut self, from_ty: Ty, to_ty: &Ty) -> InferResult {
match to_ty.kind(&Interner) { match to_ty.kind(&Interner) {
TyKind::Function(b_sig) => { TyKind::Function(_) => {
let from_sig = from_ty.callable_sig(self.db).expect("FnDef had no sig"); let from_sig = from_ty.callable_sig(self.db).expect("FnDef had no sig");
// FIXME check ABI: Intrinsics are not coercible to function pointers // FIXME check ABI: Intrinsics are not coercible to function pointers

View file

@ -134,18 +134,10 @@ pub(super) struct TypeVariableTable {
} }
impl TypeVariableTable { impl TypeVariableTable {
fn push(&mut self, data: TypeVariableData) {
self.inner.push(data);
}
pub(super) fn set_diverging(&mut self, iv: InferenceVar, diverging: bool) { pub(super) fn set_diverging(&mut self, iv: InferenceVar, diverging: bool) {
self.inner[iv.index() as usize].diverging = diverging; self.inner[iv.index() as usize].diverging = diverging;
} }
fn is_diverging(&mut self, iv: InferenceVar) -> bool {
self.inner[iv.index() as usize].diverging
}
fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty { fn fallback_value(&self, iv: InferenceVar, kind: TyVariableKind) -> Ty {
match kind { match kind {
_ if self.inner[iv.index() as usize].diverging => TyKind::Never, _ if self.inner[iv.index() as usize].diverging => TyKind::Never,
@ -221,7 +213,7 @@ impl<'a> InferenceTable<'a> {
/// Unify two types and register new trait goals that arise from that. /// Unify two types and register new trait goals that arise from that.
// TODO give these two functions better names // TODO give these two functions better names
pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool { pub(crate) fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
let result = if let Ok(r) = self.unify_inner(ty1, ty2) { let _result = if let Ok(r) = self.unify_inner(ty1, ty2) {
r r
} else { } else {
return false; return false;
@ -241,11 +233,11 @@ impl<'a> InferenceTable<'a> {
ty1, ty1,
ty2, ty2,
) { ) {
Ok(result) => { Ok(_result) => {
// TODO deal with new goals // TODO deal with new goals
Ok(InferOk {}) Ok(InferOk {})
} }
Err(NoSolution) => Err(TypeError), Err(chalk_ir::NoSolution) => Err(TypeError),
} }
} }