From b8ddcb0652f3ec8683023afc1e1f5166d6a712f4 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Tue, 18 Feb 2020 14:53:02 +0200 Subject: Run cargo +nightly fix --clippy -Z unstable-options --- crates/ra_hir_ty/src/infer.rs | 11 ++++---- crates/ra_hir_ty/src/infer/coerce.rs | 6 ++-- crates/ra_hir_ty/src/infer/expr.rs | 20 +++++-------- crates/ra_hir_ty/src/infer/pat.rs | 4 +-- crates/ra_hir_ty/src/infer/path.rs | 47 ++++++++++++++++--------------- crates/ra_hir_ty/src/lib.rs | 4 +-- crates/ra_hir_ty/src/lower.rs | 22 +++++++-------- crates/ra_hir_ty/src/method_resolution.rs | 12 ++++---- crates/ra_hir_ty/src/traits/builtin.rs | 6 ++-- crates/ra_hir_ty/src/traits/chalk.rs | 10 +++---- 10 files changed, 66 insertions(+), 76 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a9d958c8b..76069eb9c 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -225,14 +225,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), db, owner, - body: db.body(owner.into()), + body: db.body(owner), resolver, } } fn resolve_all(mut self) -> InferenceResult { // FIXME resolve obligations as well (use Guidance if necessary) - let mut result = mem::replace(&mut self.result, InferenceResult::default()); + let mut result = std::mem::take(&mut self.result); for ty in result.type_of_expr.values_mut() { let resolved = self.table.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); *ty = resolved; @@ -261,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: AssocItemId) { - self.result.assoc_resolutions.insert(id, item.into()); + self.result.assoc_resolutions.insert(id, item); } fn write_pat_ty(&mut self, pat: PatId, ty: Ty) { @@ -312,9 +312,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { for obligation in obligations { let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); - let solution = self - .db - .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone()); + let solution = + self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); match solution { Some(Solution::Unique(substs)) => { diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index f68a1439f..4a0eabdfc 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -44,10 +44,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { resolver: &Resolver, ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { let krate = resolver.krate().unwrap(); - let impls = match db.lang_item(krate.into(), "coerce_unsized".into()) { - Some(LangItemTarget::TraitId(trait_)) => { - db.impls_for_trait(krate.into(), trait_.into()) - } + let impls = match db.lang_item(krate, "coerce_unsized".into()) { + Some(LangItemTarget::TraitId(trait_)) => db.impls_for_trait(krate, trait_), _ => return FxHashMap::default(), }; diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 39d8bc0ca..0af94ae32 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -127,10 +127,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, Substs(sig_tys.into()), ); - let closure_ty = Ty::apply_one( - TypeCtor::Closure { def: self.owner.into(), expr: tgt_expr }, - sig_ty, - ); + let closure_ty = + Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); // Eagerly try to relate the closure type with the expected // type, otherwise we often won't have enough information to @@ -165,7 +163,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Expr::Match { expr, arms } => { let input_ty = self.infer_expr(*expr, &Expectation::none()); - let mut result_ty = if arms.len() == 0 { + let mut result_ty = if arms.is_empty() { Ty::simple(TypeCtor::Never) } else { self.table.new_type_var() @@ -188,7 +186,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Expr::Path(p) => { // FIXME this could be more efficient... - let resolver = resolver_for_expr(self.db, self.owner.into(), tgt_expr); + let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) } Expr::Continue => Ty::simple(TypeCtor::Never), @@ -217,8 +215,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { self.unify(&ty, &expected.ty); let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_types = - def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); let variant_data = def_id.map(|it| variant_data(self.db, it)); for (field_idx, field) in fields.iter().enumerate() { let field_def = @@ -264,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), TypeCtor::Adt(AdtId::StructId(s)) => { self.db.struct_data(s).variant_data.field(name).map(|local_id| { - let field = StructFieldId { parent: s.into(), local_id }.into(); + let field = StructFieldId { parent: s.into(), local_id }; self.write_field_resolution(tgt_expr, field); self.db.field_types(s.into())[field.local_id] .clone() @@ -700,10 +697,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // construct a TraitDef let substs = a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); - self.obligations.push(Obligation::Trait(TraitRef { - trait_: trait_.into(), - substs, - })); + self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } } CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index a5dfdf6c4..a495ecbfe 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -28,7 +28,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for (i, &subpat) in subpats.iter().enumerate() { let expected_ty = var_data @@ -60,7 +60,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = ty.substs().unwrap_or_else(Substs::empty); - let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); + let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); for subpat in subpats { let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); let expected_ty = diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 686ce7a21..471d60342 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -104,8 +104,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let segment = remaining_segments.last().expect("there should be at least one segment here"); let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); - let trait_ref = - TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); + let trait_ref = TraitRef::from_resolved_path(&ctx, trait_, resolved_segment, None); self.resolve_trait_assoc_item(trait_ref, segment, id) } (def, _) => { @@ -144,30 +143,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { id: ExprOrPatId, ) -> Option<(ValueNs, Option)> { let trait_ = trait_ref.trait_; - let item = self - .db - .trait_data(trait_) - .items - .iter() - .map(|(_name, id)| (*id).into()) - .find_map(|item| match item { - AssocItemId::FunctionId(func) => { - if segment.name == &self.db.function_data(func).name { - Some(AssocItemId::FunctionId(func)) - } else { - None + let item = + self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { + match item { + AssocItemId::FunctionId(func) => { + if segment.name == &self.db.function_data(func).name { + Some(AssocItemId::FunctionId(func)) + } else { + None + } } - } - AssocItemId::ConstId(konst) => { - if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == segment.name) - { - Some(AssocItemId::ConstId(konst)) - } else { - None + AssocItemId::ConstId(konst) => { + if self + .db + .const_data(konst) + .name + .as_ref() + .map_or(false, |n| n == segment.name) + { + Some(AssocItemId::ConstId(konst)) + } else { + None + } } + AssocItemId::TypeAliasId(_) => None, } - AssocItemId::TypeAliasId(_) => None, })?; let def = match item { AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), @@ -233,7 +234,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { AssocContainerId::ContainerId(_) => None, }; - self.write_assoc_resolution(id, item.into()); + self.write_assoc_resolution(id, item); Some((def, substs)) }, ) diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 571579cc4..302bb8aa2 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -167,7 +167,7 @@ impl TypeCtor { | TypeCtor::Closure { .. } // 1 param representing the signature of the closure => 1, TypeCtor::Adt(adt) => { - let generic_params = generics(db, AdtId::from(adt).into()); + let generic_params = generics(db, adt.into()); generic_params.len() } TypeCtor::FnDef(callable) => { @@ -247,7 +247,7 @@ pub struct ProjectionTy { impl ProjectionTy { pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { - TraitRef { trait_: self.trait_(db).into(), substs: self.parameters.clone() } + TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } } fn trait_(&self, db: &impl HirDatabase) -> TraitId { diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index c2a3703fa..52da34574 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -361,10 +361,8 @@ impl Ty { for t in traits { if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) { - let substs = Substs::build_for_def(ctx.db, t) - .push(self_ty.clone()) - .fill_with_unknown() - .build(); + let substs = + Substs::build_for_def(ctx.db, t).push(self_ty).fill_with_unknown().build(); // FIXME handle type parameters on the segment return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); } @@ -428,7 +426,7 @@ pub(super) fn substs_from_path_segment( _add_self_param: bool, ) -> Substs { let mut substs = Vec::new(); - let def_generics = def_generic.map(|def| generics(ctx.db, def.into())); + let def_generics = def_generic.map(|def| generics(ctx.db, def)); let (parent_params, self_params, type_params, impl_trait_params) = def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); @@ -459,7 +457,7 @@ pub(super) fn substs_from_path_segment( // handle defaults if let Some(def_generic) = def_generic { - let default_substs = ctx.db.generic_defaults(def_generic.into()); + let default_substs = ctx.db.generic_defaults(def_generic); assert_eq!(substs.len(), default_substs.len()); for (i, default_ty) in default_substs.iter().enumerate() { @@ -483,7 +481,7 @@ impl TraitRef { _ => return None, }; let segment = path.segments().last().expect("path should have at least one segment"); - Some(TraitRef::from_resolved_path(ctx, resolved.into(), segment, explicit_self_ty)) + Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) } pub(crate) fn from_resolved_path( @@ -728,7 +726,7 @@ pub(crate) fn generic_predicates_query( pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { let resolver = def.resolver(db); let ctx = TyLoweringContext::new(db, &resolver); - let generic_params = generics(db, def.into()); + let generic_params = generics(db, def); let defaults = generic_params .iter() @@ -792,7 +790,7 @@ fn type_for_builtin(def: BuiltinType) -> Ty { } fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { - let struct_data = db.struct_data(def.into()); + let struct_data = db.struct_data(def); let fields = struct_data.variant_data.fields(); let resolver = def.resolver(db); let ctx = @@ -805,7 +803,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn /// Build the type of a tuple struct constructor. fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders { - let struct_data = db.struct_data(def.into()); + let struct_data = db.struct_data(def); if let StructKind::Unit = struct_data.variant_data.kind() { return type_for_adt(db, def.into()); } @@ -836,7 +834,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) } let generics = generics(db, def.parent.into()); let substs = Substs::bound_vars(&generics); - Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(EnumVariantId::from(def).into()), substs)) + Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) } fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders { @@ -964,6 +962,6 @@ pub(crate) fn impl_trait_query( let target_trait = impl_data.target_trait.as_ref()?; Some(Binders::new( self_ty.num_binders, - TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value.clone()))?, + TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value))?, )) } diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 4f8c52433..964acdb09 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -214,7 +214,7 @@ pub fn iterate_method_candidates( // the methods by autoderef order of *receiver types*, not *self // types*. - let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty.clone()).collect(); + let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect(); for i in 0..deref_chain.len() { if let Some(result) = iterate_method_candidates_with_autoref( &deref_chain[i..], @@ -290,7 +290,7 @@ fn iterate_method_candidates_with_autoref( &ref_muted, deref_chain, db, - env.clone(), + env, krate, &traits_in_scope, name, @@ -391,17 +391,17 @@ fn iterate_trait_method_candidates( // iteration let mut known_implemented = false; for (_name, item) in data.items.iter() { - if !is_valid_candidate(db, name, receiver_ty, (*item).into(), self_ty) { + if !is_valid_candidate(db, name, receiver_ty, *item, self_ty) { continue; } if !known_implemented { let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone()); - if db.trait_solve(krate.into(), goal).is_none() { + if db.trait_solve(krate, goal).is_none() { continue 'traits; } } known_implemented = true; - if let Some(result) = callback(&self_ty.value, (*item).into()) { + if let Some(result) = callback(&self_ty.value, *item) { return Some(result); } } @@ -521,7 +521,7 @@ pub fn implements_trait( return true; } let goal = generic_implements_goal(db, env, trait_, ty.clone()); - let solution = db.trait_solve(krate.into(), goal); + let solution = db.trait_solve(krate, goal); solution.is_some() } diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index dd41176f0..67120abf6 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -98,7 +98,7 @@ fn closure_fn_trait_impl_datum( // the existence of the Fn trait has been checked before .expect("fn trait for closure impl missing"); - let num_args: u16 = match &db.body(data.def.into())[data.expr] { + let num_args: u16 = match &db.body(data.def)[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, _ => { log::warn!("closure for closure type {:?} not found", data); @@ -118,7 +118,7 @@ fn closure_fn_trait_impl_datum( let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); let trait_ref = TraitRef { - trait_: trait_.into(), + trait_, substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), }; @@ -139,7 +139,7 @@ fn closure_fn_trait_output_assoc_ty_value( ) -> BuiltinImplAssocTyValueData { let impl_ = Impl::ClosureFnTraitImpl(data.clone()); - let num_args: u16 = match &db.body(data.def.into())[data.expr] { + let num_args: u16 = match &db.body(data.def)[data.expr] { Expr::Lambda { args, .. } => args.len() as u16, _ => { log::warn!("closure for closure type {:?} not found", data); diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 882160fa8..306909ec2 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -565,10 +565,10 @@ where // and will panic if the trait can't be resolved. let mut result: Vec<_> = self .db - .impls_for_trait(self.krate, trait_.into()) + .impls_for_trait(self.krate, trait_) .iter() .copied() - .map(|it| Impl::ImplBlock(it.into())) + .map(Impl::ImplBlock) .map(|impl_| impl_.to_chalk(self.db)) .collect(); @@ -586,7 +586,7 @@ where false // FIXME } fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc { - self.db.associated_ty_value(self.krate.into(), id) + self.db.associated_ty_value(self.krate, id) } fn custom_clauses(&self) -> Vec> { vec![] @@ -674,7 +674,7 @@ pub(crate) fn struct_datum_query( let where_clauses = type_ctor .as_generic_def() .map(|generic_def| { - let generic_params = generics(db, generic_def.into()); + let generic_params = generics(db, generic_def); let bound_vars = Substs::bound_vars(&generic_params); convert_where_clauses(db, generic_def, &bound_vars) }) @@ -805,7 +805,7 @@ fn type_alias_associated_ty_value( let ty = db.ty(type_alias.into()); let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; let value = chalk_rust_ir::AssociatedTyValue { - impl_id: Impl::ImplBlock(impl_id.into()).to_chalk(db), + impl_id: Impl::ImplBlock(impl_id).to_chalk(db), associated_ty_id: assoc_ty.to_chalk(db), value: make_binders(value_bound, ty.num_binders), }; -- cgit v1.2.3