From 2ef541b35f955d3d86014ad855511f155d5ebd47 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Mon, 21 Mar 2022 00:08:12 +0100 Subject: [PATCH] Cleanups --- crates/hir/src/diagnostics.rs | 2 +- crates/hir/src/lib.rs | 19 +++++------ crates/hir_ty/src/diagnostics/expr.rs | 34 ++----------------- crates/hir_ty/src/infer.rs | 2 +- crates/hir_ty/src/infer/coerce.rs | 9 ++--- crates/hir_ty/src/infer/unify.rs | 12 +++---- .../src/handlers/type_mismatch.rs | 6 ++-- 7 files changed, 25 insertions(+), 59 deletions(-) diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 49551bf610..2246e7b486 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -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}; diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 3af56b743f..ba7922ef3d 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -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 { diff --git a/crates/hir_ty/src/diagnostics/expr.rs b/crates/hir_ty/src/diagnostics/expr.rs index 307594d08b..71eb7e3995 100644 --- a/crates/hir_ty/src/diagnostics/expr.rs +++ b/crates/hir_ty/src/diagnostics/expr.rs @@ -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, - } -} diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs index d7913e1dcf..c85112b0db 100644 --- a/crates/hir_ty/src/infer.rs +++ b/crates/hir_ty/src/infer.rs @@ -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; diff --git a/crates/hir_ty/src/infer/coerce.rs b/crates/hir_ty/src/infer/coerce.rs index 1570bf6569..f54440bf5b 100644 --- a/crates/hir_ty/src/infer/coerce.rs +++ b/crates/hir_ty/src/infer/coerce.rs @@ -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; diff --git a/crates/hir_ty/src/infer/unify.rs b/crates/hir_ty/src/infer/unify.rs index 90bccb82f7..84ca1660af 100644 --- a/crates/hir_ty/src/infer/unify.rs +++ b/crates/hir_ty/src/infer/unify.rs @@ -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], - ) -> Substitution { + pub(crate) fn fresh_subst(&mut self, binders: &[CanonicalVarKind]) -> 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) }), ) diff --git a/crates/ide_diagnostics/src/handlers/type_mismatch.rs b/crates/ide_diagnostics/src/handlers/type_mismatch.rs index 2c9f7839ce..040dcbd1d9 100644 --- a/crates/ide_diagnostics/src/handlers/type_mismatch.rs +++ b/crates/ide_diagnostics/src/handlers/type_mismatch.rs @@ -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;