Better API factoring around self access modes

This commit is contained in:
Aleksey Kladov 2020-08-19 17:02:50 +02:00
parent 73f4fcbd0f
commit 61754678fb
4 changed files with 30 additions and 56 deletions

View file

@ -12,6 +12,7 @@ use hir_def::{
docs::Documentation,
expr::{BindingAnnotation, Pat, PatId},
import_map,
lang_item::LangItemTarget,
path::ModPath,
per_ns::PerNs,
resolver::{HasResolver, Resolver},
@ -36,7 +37,7 @@ use rustc_hash::FxHashSet;
use stdx::impl_from;
use syntax::{
ast::{self, AttrsOwner, NameOwner},
AstNode,
AstNode, SmolStr,
};
use crate::{
@ -1287,6 +1288,15 @@ impl Type {
db.trait_solve(self.krate, goal).is_some()
}
pub fn is_copy(&self, db: &dyn HirDatabase) -> bool {
let lang_item = db.lang_item(self.krate, SmolStr::new("copy"));
let copy_trait = match lang_item {
Some(LangItemTarget::TraitId(it)) => it,
_ => return false,
};
self.impls_trait(db, copy_trait.into(), &[])
}
pub fn as_callable(&self, db: &dyn HirDatabase) -> Option<Callable> {
let def = match self.ty.value {
Ty::Apply(ApplicationTy { ctor: TypeCtor::FnDef(def), parameters: _ }) => Some(def),