Skip to content

Commit 2ef541b

Browse files
committed
Cleanups
1 parent b632d70 commit 2ef541b

File tree

7 files changed

+25
-59
lines changed

7 files changed

+25
-59
lines changed

crates/hir/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! be expressed in terms of hir types themselves.
66
use cfg::{CfgExpr, CfgOptions};
77
use either::Either;
8-
use hir_def::{path::ModPath, type_ref::Mutability};
8+
use hir_def::path::ModPath;
99
use hir_expand::{name::Name, HirFileId, InFile};
1010
use syntax::{ast, AstPtr, SyntaxNodePtr, TextRange};
1111

crates/hir/src/lib.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ use hir_ty::{
5858
consteval::{
5959
eval_const, unknown_const_as_generic, ComputedExpr, ConstEvalCtx, ConstEvalError, ConstExt,
6060
},
61-
could_unify,
6261
diagnostics::BodyValidationDiagnostic,
6362
method_resolution::{self, TyFingerprint},
6463
primitive::UintTy,
@@ -1014,9 +1013,7 @@ impl Adt {
10141013
let r = it.next().unwrap_or_else(|| TyKind::Error.intern(Interner));
10151014
match x {
10161015
ParamKind::Type => GenericArgData::Ty(r).intern(Interner),
1017-
ParamKind::Const(ty) => {
1018-
unknown_const_as_generic(ty.clone())
1019-
}
1016+
ParamKind::Const(ty) => unknown_const_as_generic(ty.clone()),
10201017
}
10211018
})
10221019
.build();
@@ -1329,7 +1326,6 @@ impl DefWithBody {
13291326
Err(SyntheticSyntax) => (),
13301327
}
13311328
}
1332-
_ => {} // TODO fixme
13331329
}
13341330
}
13351331

@@ -2644,11 +2640,14 @@ impl Type {
26442640
}
26452641

26462642
pub fn reference(inner: &Type, m: Mutability) -> Type {
2647-
inner.derived(TyKind::Ref(
2648-
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
2649-
hir_ty::static_lifetime(),
2650-
inner.ty.clone(),
2651-
).intern(Interner))
2643+
inner.derived(
2644+
TyKind::Ref(
2645+
if m.is_mut() { hir_ty::Mutability::Mut } else { hir_ty::Mutability::Not },
2646+
hir_ty::static_lifetime(),
2647+
inner.ty.clone(),
2648+
)
2649+
.intern(Interner),
2650+
)
26522651
}
26532652

26542653
fn new(db: &dyn HirDatabase, krate: CrateId, lexical_env: impl HasResolver, ty: Ty) -> Type {

crates/hir_ty/src/diagnostics/expr.rs

+2-32
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
55
use std::sync::Arc;
66

7-
use hir_def::{
8-
expr::Statement, path::path, resolver::HasResolver, type_ref::Mutability, AssocItemId,
9-
DefWithBodyId, HasModule,
10-
};
7+
use hir_def::{path::path, resolver::HasResolver, AssocItemId, DefWithBodyId, HasModule};
118
use hir_expand::name;
129
use itertools::Either;
1310
use rustc_hash::FxHashSet;
@@ -20,7 +17,7 @@ use crate::{
2017
deconstruct_pat::DeconstructedPat,
2118
usefulness::{compute_match_usefulness, MatchCheckCtx},
2219
},
23-
AdtId, InferenceResult, Interner, Ty, TyExt, TyKind,
20+
InferenceResult, Interner, TyExt,
2421
};
2522

2623
pub(crate) use hir_def::{
@@ -428,30 +425,3 @@ fn types_of_subpatterns_do_match(pat: PatId, body: &Body, infer: &InferenceResul
428425
walk(pat, body, infer, &mut has_type_mismatches);
429426
!has_type_mismatches
430427
}
431-
432-
fn check_missing_refs(
433-
infer: &InferenceResult,
434-
arg: ExprId,
435-
param: &Ty,
436-
) -> Option<(ExprId, Mutability)> {
437-
let arg_ty = infer.type_of_expr.get(arg)?;
438-
439-
let reference_one = arg_ty.as_reference();
440-
let reference_two = param.as_reference();
441-
442-
match (reference_one, reference_two) {
443-
(None, Some((referenced_ty, _, mutability))) if referenced_ty == arg_ty => {
444-
Some((arg, Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut))))
445-
}
446-
(None, Some((referenced_ty, _, mutability))) => match referenced_ty.kind(Interner) {
447-
TyKind::Slice(subst) if matches!(arg_ty.kind(Interner), TyKind::Array(arr_subst, _) if arr_subst == subst) => {
448-
Some((
449-
arg,
450-
Mutability::from_mutable(matches!(mutability, chalk_ir::Mutability::Mut)),
451-
))
452-
}
453-
_ => None,
454-
},
455-
_ => None,
456-
}
457-
}

crates/hir_ty/src/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ use crate::{
4343
// This lint has a false positive here. See the link below for details.
4444
//
4545
// https://github.com/rust-lang/rust/issues/57411
46+
pub use coerce::could_coerce;
4647
#[allow(unreachable_pub)]
4748
pub use unify::could_unify;
48-
pub use coerce::could_coerce;
4949

5050
pub(crate) mod unify;
5151
mod path;

crates/hir_ty/src/infer/coerce.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,20 @@
77
88
use std::{iter, sync::Arc};
99

10-
use chalk_ir::{cast::Cast, Goal, Mutability, TyVariableKind, BoundVar};
10+
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyVariableKind};
1111
use hir_def::{expr::ExprId, lang_item::LangItemTarget};
1212
use stdx::always;
1313
use syntax::SmolStr;
1414

1515
use crate::{
1616
autoderef::{Autoderef, AutoderefKind},
17+
db::HirDatabase,
1718
infer::{
18-
Adjust, Adjustment, AutoBorrow, InferOk, InferResult, InferenceContext, OverloadedDeref,
19-
PointerCast, TypeError, TypeMismatch,
19+
Adjust, Adjustment, AutoBorrow, InferOk, InferenceContext, OverloadedDeref, PointerCast,
20+
TypeError, TypeMismatch,
2021
},
2122
static_lifetime, Canonical, DomainGoal, FnPointer, FnSig, Guidance, InEnvironment, Interner,
22-
Solution, Substitution, Ty, TyBuilder, TyExt, TyKind, db::HirDatabase, TraitEnvironment, GenericArgData,
23+
Solution, Substitution, TraitEnvironment, Ty, TyBuilder, TyExt, TyKind,
2324
};
2425

2526
use super::unify::InferenceTable;

crates/hir_ty/src/infer/unify.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use std::{fmt, mem, sync::Arc};
44

55
use chalk_ir::{
6-
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, FloatTy, IntTy, NoSolution,
7-
TyVariableKind, UniverseIndex, CanonicalVarKind,
6+
cast::Cast, fold::Fold, interner::HasInterner, zip::Zip, CanonicalVarKind, FloatTy, IntTy,
7+
NoSolution, TyVariableKind, UniverseIndex,
88
};
99
use chalk_solve::infer::ParameterEnaVariableExt;
1010
use ena::unify::UnifyKey;
@@ -299,14 +299,12 @@ impl<'a> InferenceTable<'a> {
299299
self.resolve_with_fallback_inner(&mut Vec::new(), t, &fallback)
300300
}
301301

302-
pub(crate) fn fresh_subst(
303-
&mut self,
304-
binders: &[CanonicalVarKind<Interner>],
305-
) -> Substitution {
302+
pub(crate) fn fresh_subst(&mut self, binders: &[CanonicalVarKind<Interner>]) -> Substitution {
306303
Substitution::from_iter(
307304
Interner,
308305
binders.iter().map(|kind| {
309-
let param_infer_var = kind.map_ref(|&ui| self.var_unification_table.new_variable(ui));
306+
let param_infer_var =
307+
kind.map_ref(|&ui| self.var_unification_table.new_variable(ui));
310308
param_infer_var.to_generic_arg(Interner)
311309
}),
312310
)

crates/ide_diagnostics/src/handlers/type_mismatch.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
use hir::{db::AstDatabase, HirDisplay, Type, TypeInfo};
22
use ide_db::{
3-
base_db::{FileLoader, FileRange},
4-
famous_defs::FamousDefs,
5-
source_change::SourceChange,
3+
famous_defs::FamousDefs, source_change::SourceChange,
64
syntax_helpers::node_ext::for_each_tail_expr,
75
};
86
use syntax::{
97
ast::{BlockExpr, ExprStmt},
10-
AstNode, TextRange, TextSize,
8+
AstNode,
119
};
1210
use text_edit::TextEdit;
1311

0 commit comments

Comments
 (0)