mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Cleanups
This commit is contained in:
parent
b632d706c7
commit
2ef541b35f
7 changed files with 25 additions and 59 deletions
|
@ -5,7 +5,7 @@
|
||||||
//! be expressed in terms of hir types themselves.
|
//! be expressed in terms of hir types themselves.
|
||||||
use cfg::{CfgExpr, CfgOptions};
|
use cfg::{CfgExpr, CfgOptions};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{path::ModPath, type_ref::Mutability};
|
use hir_def::path::ModPath;
|
||||||
use hir_expand::{name::Name, HirFileId, InFile};
|
use hir_expand::{name::Name, HirFileId, InFile};
|
||||||
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
|
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,6 @@ use hir_ty::{
|
||||||
consteval::{
|
consteval::{
|
||||||
eval_const, unknown_const_as_generic, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt,
|
eval_const, unknown_const_as_generic, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt,
|
||||||
},
|
},
|
||||||
could_unify,
|
|
||||||
diagnostics::BodyValidationDiagnostic,
|
diagnostics::BodyValidationDiagnostic,
|
||||||
method_resolution::{self, TyFingerprint},
|
method_resolution::{self, TyFingerprint},
|
||||||
primitive::UintTy,
|
primitive::UintTy,
|
||||||
|
@ -1014,9 +1013,7 @@ impl Adt {
|
||||||
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
|
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
|
||||||
match x {
|
match x {
|
||||||
ParamKind::Type => GenericArgData::Ty(r).intern(Interner),
|
ParamKind::Type => GenericArgData::Ty(r).intern(Interner),
|
||||||
ParamKind::Const(ty) => {
|
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
|
||||||
unknown_const_as_generic(ty.clone())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
|
@ -1329,7 +1326,6 @@ impl DefWithBody {
|
||||||
Err(SyntheticSyntax) => (),
|
Err(SyntheticSyntax) => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {} // TODO fixme
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2644,11 +2640,14 @@ impl Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reference(inner: &Type, m: Mutability) -> Type {
|
pub fn reference(inner: &Type, m: Mutability) -> Type {
|
||||||
inner.derived(TyKind::Ref(
|
inner.derived(
|
||||||
|
TyKind::Ref(
|
||||||
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
|
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
|
||||||
hir_ty::static_lifetime(),
|
hir_ty::static_lifetime(),
|
||||||
inner.ty.clone(),
|
inner.ty.clone(),
|
||||||
).intern(Interner))
|
)
|
||||||
|
.intern(Interner),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {
|
fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {
|
||||||
|
|
|
@ -4,10 +4,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{path::path, resolver::HasResolver, AssocItemId, DefWithBodyId, HasModule};
|
||||||
expr::Statement, path::path, resolver::HasResolver, type_ref::Mutability, AssocItemId,
|
|
||||||
DefWithBodyId, HasModule,
|
|
||||||
};
|
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
use itertools::Either;
|
use itertools::Either;
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
@ -20,7 +17,7 @@ use crate::{
|
||||||
deconstruct_pat::DeconstructedPat,
|
deconstruct_pat::DeconstructedPat,
|
||||||
usefulness::{compute_match_usefulness, MatchCheckCtx},
|
usefulness::{compute_match_usefulness, MatchCheckCtx},
|
||||||
},
|
},
|
||||||
AdtId, InferenceResult, Interner, Ty, TyExt, TyKind,
|
InferenceResult, Interner, TyExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use hir_def::{
|
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);
|
walk(pat, body, infer, &mut has_type_mismatches);
|
||||||
!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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -43,9 +43,9 @@ use crate::{
|
||||||
// This lint has a false positive here. See the link below for details.
|
// This lint has a false positive here. See the link below for details.
|
||||||
//
|
//
|
||||||
// https://github.com/rust-lang/rust/issues/57411
|
// https://github.com/rust-lang/rust/issues/57411
|
||||||
|
pub use coerce::could_coerce;
|
||||||
#[allow(unreachable_pub)]
|
#[allow(unreachable_pub)]
|
||||||
pub use unify::could_unify;
|
pub use unify::could_unify;
|
||||||
pub use coerce::could_coerce;
|
|
||||||
|
|
||||||
pub(crate) mod unify;
|
pub(crate) mod unify;
|
||||||
mod path;
|
mod path;
|
||||||
|
|
|
@ -7,19 +7,20 @@
|
||||||
|
|
||||||
use std::{iter, sync::Arc};
|
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 hir_def::{expr::ExprId, lang_item::LangItemTarget};
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
use syntax::SmolStr;
|
use syntax::SmolStr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
autoderef::{Autoderef, AutoderefKind},
|
autoderef::{Autoderef, AutoderefKind},
|
||||||
|
db::HirDatabase,
|
||||||
infer::{
|
infer::{
|
||||||
Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref,
|
Adjust, Adjustment, AutoBorrow, InferOk, InferenceContext, OverloadedDeref, PointerCast,
|
||||||
PointerCast, TypeError, TypeMismatch,
|
TypeError, TypeMismatch,
|
||||||
},
|
},
|
||||||
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner,
|
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;
|
use super::unify::InferenceTable;
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
use std::{fmt, mem, sync::Arc};
|
use std::{fmt, mem, sync::Arc};
|
||||||
|
|
||||||
use chalk_ir::{
|
use chalk_ir::{
|
||||||
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, NoSolution,
|
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, IntTy,
|
||||||
TyVariableKind, UniverseIndex, CanonicalVarKind,
|
NoSolution, TyVariableKind, UniverseIndex,
|
||||||
};
|
};
|
||||||
use chalk_solve::infer::ParameterEnaVariableExt;
|
use chalk_solve::infer::ParameterEnaVariableExt;
|
||||||
use ena::unify::UnifyKey;
|
use ena::unify::UnifyKey;
|
||||||
|
@ -299,14 +299,12 @@ impl<'a> InferenceTable<'a> {
|
||||||
self.resolve_with_fallback_inner(&mut Vec::new(), t, &fallback)
|
self.resolve_with_fallback_inner(&mut Vec::new(), t, &fallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fresh_subst(
|
pub(crate) fn fresh_subst(&mut self, binders: &[CanonicalVarKind<Interner>]) -> Substitution {
|
||||||
&mut self,
|
|
||||||
binders: &[CanonicalVarKind<Interner>],
|
|
||||||
) -> Substitution {
|
|
||||||
Substitution::from_iter(
|
Substitution::from_iter(
|
||||||
Interner,
|
Interner,
|
||||||
binders.iter().map(|kind| {
|
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)
|
param_infer_var.to_generic_arg(Interner)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
use hir::{db::AstDatabase, HirDisplay, Type, TypeInfo};
|
use hir::{db::AstDatabase, HirDisplay, Type, TypeInfo};
|
||||||
use ide_db::{
|
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,
|
syntax_helpers::node_ext::for_each_tail_expr,
|
||||||
};
|
};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{BlockExpr, ExprStmt},
|
ast::{BlockExpr, ExprStmt},
|
||||||
AstNode, TextRange, TextSize,
|
AstNode,
|
||||||
};
|
};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue