This commit is contained in:
Florian Diebold 2022-03-21 00:08:12 +01:00
parent b632d706c7
commit 2ef541b35f
7 changed files with 25 additions and 59 deletions

View file

@ -5,7 +5,7 @@
//! be expressed in terms of hir types themselves.
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use hir_def::{path::ModPath, type_ref::Mutability};
use hir_def::path::ModPath;
use hir_expand::{name::Name, HirFileId, InFile};
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};

View file

@ -58,7 +58,6 @@ use hir_ty::{
consteval::{
eval_const, unknown_const_as_generic, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt,
},
could_unify,
diagnostics::BodyValidationDiagnostic,
method_resolution::{self, TyFingerprint},
primitive::UintTy,
@ -1014,9 +1013,7 @@ impl Adt {
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
match x {
ParamKind::Type => GenericArgData::Ty(r).intern(Interner),
ParamKind::Const(ty) => {
unknown_const_as_generic(ty.clone())
}
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
}
})
.build();
@ -1329,7 +1326,6 @@ impl DefWithBody {
Err(SyntheticSyntax) => (),
}
}
_ => {} // TODO fixme
}
}
@ -2644,11 +2640,14 @@ impl Type {
}
pub fn reference(inner: &Type, m: Mutability) -> Type {
inner.derived(TyKind::Ref(
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
hir_ty::static_lifetime(),
inner.ty.clone(),
).intern(Interner))
inner.derived(
TyKind::Ref(
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
hir_ty::static_lifetime(),
inner.ty.clone(),
)
.intern(Interner),
)
}
fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {

View file

@ -4,10 +4,7 @@
use std::sync::Arc;
use hir_def::{
expr::Statement, path::path, resolver::HasResolver, type_ref::Mutability, AssocItemId,
DefWithBodyId, HasModule,
};
use hir_def::{path::path, resolver::HasResolver, AssocItemId, DefWithBodyId, HasModule};
use hir_expand::name;
use itertools::Either;
use rustc_hash::FxHashSet;
@ -20,7 +17,7 @@ use crate::{
deconstruct_pat::DeconstructedPat,
usefulness::{compute_match_usefulness, MatchCheckCtx},
},
AdtId, InferenceResult, Interner, Ty, TyExt, TyKind,
InferenceResult, Interner, TyExt,
};
pub(crate) use hir_def::{
@ -428,30 +425,3 @@ fn types_of_subpatterns_do_match(pat: PatId, body: &Body, infer: &InferenceResul
walk(pat, body, infer, &mut has_type_mismatches);
!has_type_mismatches
}
fn check_missing_refs(
infer: &InferenceResult,
arg: ExprId,
param: &Ty,
) -> Option<(ExprId, Mutability)> {
let arg_ty = infer.type_of_expr.get(arg)?;
let reference_one = arg_ty.as_reference();
let reference_two = param.as_reference();
match (reference_one, reference_two) {
(None, Some((referenced_ty, _, mutability))) if referenced_ty == arg_ty => {
Some((arg, Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut))))
}
(None, Some((referenced_ty, _, mutability))) => match referenced_ty.kind(Interner) {
TyKind::Slice(subst) if matches!(arg_ty.kind(Interner), TyKind::Array(arr_subst, _) if arr_subst == subst) => {
Some((
arg,
Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut)),
))
}
_ => None,
},
_ => None,
}
}

View file

@ -43,9 +43,9 @@ use crate::{
// This lint has a false positive here. See the link below for details.
//
// https://github.com/rust-lang/rust/issues/57411
pub use coerce::could_coerce;
#[allow(unreachable_pub)]
pub use unify::could_unify;
pub use coerce::could_coerce;
pub(crate) mod unify;
mod path;

View file

@ -7,19 +7,20 @@
use std::{iter, sync::Arc};
use chalk_ir::{cast::Cast, Goal, Mutability, TyVariableKind, BoundVar};
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyVariableKind};
use hir_def::{expr::ExprId, lang_item::LangItemTarget};
use stdx::always;
use syntax::SmolStr;
use crate::{
autoderef::{Autoderef, AutoderefKind},
db::HirDatabase,
infer::{
Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref,
PointerCast, TypeError, TypeMismatch,
Adjust, Adjustment, AutoBorrow, InferOk, InferenceContext, OverloadedDeref, PointerCast,
TypeError, TypeMismatch,
},
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner,
Solution, Substitution, Ty, TyBuilder, TyExt, TyKind, db::HirDatabase, TraitEnvironment, GenericArgData,
Solution, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
};
use super::unify::InferenceTable;

View file

@ -3,8 +3,8 @@
use std::{fmt, mem, sync::Arc};
use chalk_ir::{
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, NoSolution,
TyVariableKind, UniverseIndex, CanonicalVarKind,
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, IntTy,
NoSolution, TyVariableKind, UniverseIndex,
};
use chalk_solve::infer::ParameterEnaVariableExt;
use ena::unify::UnifyKey;
@ -299,14 +299,12 @@ impl<'a> InferenceTable<'a> {
self.resolve_with_fallback_inner(&mut Vec::new(), t, &fallback)
}
pub(crate) fn fresh_subst(
&mut self,
binders: &[CanonicalVarKind<Interner>],
) -> Substitution {
pub(crate) fn fresh_subst(&mut self, binders: &[CanonicalVarKind<Interner>]) -> Substitution {
Substitution::from_iter(
Interner,
binders.iter().map(|kind| {
let param_infer_var = kind.map_ref(|&ui| self.var_unification_table.new_variable(ui));
let param_infer_var =
kind.map_ref(|&ui| self.var_unification_table.new_variable(ui));
param_infer_var.to_generic_arg(Interner)
}),
)

View file

@ -1,13 +1,11 @@
use hir::{db::AstDatabase, HirDisplay, Type, TypeInfo};
use ide_db::{
base_db::{FileLoader, FileRange},
famous_defs::FamousDefs,
source_change::SourceChange,
famous_defs::FamousDefs, source_change::SourceChange,
syntax_helpers::node_ext::for_each_tail_expr,
};
use syntax::{
ast::{BlockExpr, ExprStmt},
AstNode, TextRange, TextSize,
AstNode,
};
use text_edit::TextEdit;