From 9446be29992fe14ec529874622311c3ae7a49b0e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:43:25 +0300 Subject: remove Cancelable from adt API --- crates/ra_hir/src/adt.rs | 23 ++++--------- crates/ra_hir/src/code_model_api.rs | 50 ++++++++++++----------------- crates/ra_hir/src/code_model_impl/module.rs | 2 +- crates/ra_hir/src/db.rs | 6 ++-- crates/ra_hir/src/ty.rs | 8 ++--- 5 files changed, 36 insertions(+), 53 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/adt.rs b/crates/ra_hir/src/adt.rs index bcb705c24..57d112f74 100644 --- a/crates/ra_hir/src/adt.rs +++ b/crates/ra_hir/src/adt.rs @@ -19,7 +19,7 @@ impl Struct { } pub(crate) fn variant_data(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.struct_data(self.def_id)?.variant_data.clone()) + Ok(db.struct_data(self.def_id).variant_data.clone()) } } @@ -37,16 +37,13 @@ impl StructData { StructData { name, variant_data } } - pub(crate) fn struct_data_query( - db: &impl HirDatabase, - def_id: DefId, - ) -> Cancelable> { + pub(crate) fn struct_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc { let def_loc = def_id.loc(db); assert!(def_loc.kind == DefKind::Struct); let syntax = db.file_item(def_loc.source_item_id); let struct_def = ast::StructDef::cast(&syntax).expect("struct def should point to StructDef node"); - Ok(Arc::new(StructData::new(struct_def))) + Arc::new(StructData::new(struct_def)) } } @@ -84,10 +81,7 @@ impl EnumData { EnumData { name, variants } } - pub(crate) fn enum_data_query( - db: &impl HirDatabase, - def_id: DefId, - ) -> Cancelable> { + pub(crate) fn enum_data_query(db: &impl HirDatabase, def_id: DefId) -> Arc { let def_loc = def_id.loc(db); assert!(def_loc.kind == DefKind::Enum); let syntax = db.file_item(def_loc.source_item_id); @@ -107,7 +101,7 @@ impl EnumData { } else { Vec::new() }; - Ok(Arc::new(EnumData::new(enum_def, variants))) + Arc::new(EnumData::new(enum_def, variants)) } } @@ -133,7 +127,7 @@ impl EnumVariantData { pub(crate) fn enum_variant_data_query( db: &impl HirDatabase, def_id: DefId, - ) -> Cancelable> { + ) -> Arc { let def_loc = def_id.loc(db); assert!(def_loc.kind == DefKind::EnumVariant); let syntax = db.file_item(def_loc.source_item_id); @@ -146,10 +140,7 @@ impl EnumVariantData { .expect("enum variant list should have enum ancestor"); let enum_def_id = get_def_id(db, &def_loc, enum_node, DefKind::Enum); - Ok(Arc::new(EnumVariantData::new( - variant_def, - Enum::new(enum_def_id), - ))) + Arc::new(EnumVariantData::new(variant_def, Enum::new(enum_def_id))) } } diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index db270b871..cd61d922b 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -175,13 +175,12 @@ impl Struct { self.def_id } - pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.struct_data(self.def_id)?.name.clone()) + pub fn name(&self, db: &impl HirDatabase) -> Option { + db.struct_data(self.def_id).name.clone() } - pub fn fields(&self, db: &impl HirDatabase) -> Cancelable> { - let res = db - .struct_data(self.def_id)? + pub fn fields(&self, db: &impl HirDatabase) -> Vec { + db.struct_data(self.def_id) .variant_data .fields() .iter() @@ -189,15 +188,11 @@ impl Struct { struct_: self.clone(), name: it.name.clone(), }) - .collect(); - Ok(res) + .collect() } - pub fn source( - &self, - db: &impl HirDatabase, - ) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } @@ -215,16 +210,16 @@ impl Enum { self.def_id } - pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.enum_data(self.def_id)?.name.clone()) + pub fn name(&self, db: &impl HirDatabase) -> Option { + db.enum_data(self.def_id).name.clone() } - pub fn variants(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.enum_data(self.def_id)?.variants.clone()) + pub fn variants(&self, db: &impl HirDatabase) -> Vec<(Name, EnumVariant)> { + db.enum_data(self.def_id).variants.clone() } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } @@ -242,23 +237,20 @@ impl EnumVariant { self.def_id } - pub fn parent_enum(&self, db: &impl HirDatabase) -> Cancelable { - Ok(db.enum_variant_data(self.def_id)?.parent_enum.clone()) + pub fn parent_enum(&self, db: &impl HirDatabase) -> Enum { + db.enum_variant_data(self.def_id).parent_enum.clone() } - pub fn name(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.enum_variant_data(self.def_id)?.name.clone()) + pub fn name(&self, db: &impl HirDatabase) -> Option { + db.enum_variant_data(self.def_id).name.clone() } - pub fn variant_data(&self, db: &impl HirDatabase) -> Cancelable> { - Ok(db.enum_variant_data(self.def_id)?.variant_data.clone()) + pub fn variant_data(&self, db: &impl HirDatabase) -> Arc { + db.enum_variant_data(self.def_id).variant_data.clone() } - pub fn source( - &self, - db: &impl HirDatabase, - ) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index 8668d6c8a..f27523753 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -154,7 +154,7 @@ impl Module { if segments.len() == idx + 1 { // enum variant let matching_variant = - e.variants(db)?.into_iter().find(|(n, _variant)| n == name); + e.variants(db).into_iter().find(|(n, _variant)| n == name); if let Some((_n, variant)) = matching_variant { return Ok(PerNs::both(variant.def_id(), e.def_id())); diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 3b2498d5a..6229f9778 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -37,17 +37,17 @@ pub trait HirDatabase: SyntaxDatabase use fn query_definitions::fn_scopes; } - fn struct_data(def_id: DefId) -> Cancelable> { + fn struct_data(def_id: DefId) -> Arc { type StructDataQuery; use fn crate::adt::StructData::struct_data_query; } - fn enum_data(def_id: DefId) -> Cancelable> { + fn enum_data(def_id: DefId) -> Arc { type EnumDataQuery; use fn crate::adt::EnumData::enum_data_query; } - fn enum_variant_data(def_id: DefId) -> Cancelable> { + fn enum_variant_data(def_id: DefId) -> Arc { type EnumVariantDataQuery; use fn crate::adt::EnumVariantData::enum_variant_data_query; } diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 03787bd89..b0642d905 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -463,19 +463,19 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable { fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Cancelable { Ok(Ty::Adt { def_id: s.def_id(), - name: s.name(db)?.unwrap_or_else(Name::missing), + name: s.name(db).unwrap_or_else(Name::missing), }) } pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Cancelable { Ok(Ty::Adt { def_id: s.def_id(), - name: s.name(db)?.unwrap_or_else(Name::missing), + name: s.name(db).unwrap_or_else(Name::missing), }) } pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> Cancelable { - let enum_parent = ev.parent_enum(db)?; + let enum_parent = ev.parent_enum(db); type_for_enum(db, enum_parent) } @@ -510,7 +510,7 @@ pub(super) fn type_for_field( let def = def_id.resolve(db)?; let variant_data = match def { Def::Struct(s) => s.variant_data(db)?, - Def::EnumVariant(ev) => ev.variant_data(db)?, + Def::EnumVariant(ev) => ev.variant_data(db), // TODO: unions _ => panic!( "trying to get type for field in non-struct/variant {:?}", -- cgit v1.2.3 From 9dd4099d9388b5f61e99f923dd6c523f76ad43ff Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:45:01 +0300 Subject: remove Cancelable from static&const API --- crates/ra_hir/src/code_model_api.rs | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index cd61d922b..f6d1d6b23 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -333,8 +333,8 @@ impl Const { Const { def_id } } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } @@ -348,11 +348,8 @@ impl Static { Static { def_id } } - pub fn source( - &self, - db: &impl HirDatabase, - ) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } @@ -366,8 +363,8 @@ impl Trait { Trait { def_id } } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } @@ -381,7 +378,7 @@ impl Type { Type { def_id } } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } } -- cgit v1.2.3 From f1367e0370d5de5cba13c853c7df5f0c5a0edf59 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 15 Jan 2019 18:50:16 +0300 Subject: remove Cancelable from navigation target --- crates/ra_hir/src/code_model_api.rs | 4 ++-- crates/ra_hir/src/code_model_impl/module.rs | 2 +- crates/ra_hir/src/expr.rs | 4 ++-- crates/ra_hir/src/ids.rs | 7 +++---- crates/ra_hir/src/ty.rs | 6 +++--- 5 files changed, 11 insertions(+), 12 deletions(-) (limited to 'crates/ra_hir/src') diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index f6d1d6b23..f28e077c6 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs @@ -297,8 +297,8 @@ impl Function { self.def_id } - pub fn source(&self, db: &impl HirDatabase) -> Cancelable<(HirFileId, TreeArc)> { - Ok(def_id_to_ast(db, self.def_id)) + pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { + def_id_to_ast(db, self.def_id) } pub fn body_syntax_mapping(&self, db: &impl HirDatabase) -> Cancelable> { diff --git a/crates/ra_hir/src/code_model_impl/module.rs b/crates/ra_hir/src/code_model_impl/module.rs index f27523753..331b0500e 100644 --- a/crates/ra_hir/src/code_model_impl/module.rs +++ b/crates/ra_hir/src/code_model_impl/module.rs @@ -148,7 +148,7 @@ impl Module { } else { return Ok(PerNs::none()); }; - let module = match curr.resolve(db)? { + let module = match curr.resolve(db) { Def::Module(it) => it, Def::Enum(e) => { if segments.len() == idx + 1 { diff --git a/crates/ra_hir/src/expr.rs b/crates/ra_hir/src/expr.rs index 5081466a2..a1e8da348 100644 --- a/crates/ra_hir/src/expr.rs +++ b/crates/ra_hir/src/expr.rs @@ -832,10 +832,10 @@ pub(crate) fn body_syntax_mapping( db: &impl HirDatabase, def_id: DefId, ) -> Cancelable> { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); let body_syntax_mapping = match def { - Def::Function(f) => collect_fn_body_syntax(&f.source(db)?.1), + Def::Function(f) => collect_fn_body_syntax(&f.source(db).1), // TODO: consts, etc. _ => panic!("Trying to get body for item type without body"), }; diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 7b572061a..3cbf8070f 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -159,9 +159,9 @@ impl DefId { db.as_ref().id2loc(self) } - pub fn resolve(self, db: &impl HirDatabase) -> Cancelable { + pub fn resolve(self, db: &impl HirDatabase) -> Def { let loc = self.loc(db); - let res = match loc.kind { + match loc.kind { DefKind::Module => { let module = Module::from_module_id(db, loc.source_root_id, loc.module_id); Def::Module(module) @@ -195,8 +195,7 @@ impl DefId { DefKind::StructCtor => Def::Item, DefKind::Item => Def::Item, - }; - Ok(res) + } } pub(crate) fn source(self, db: &impl HirDatabase) -> (HirFileId, TreeArc) { diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index b0642d905..3607969ed 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs @@ -481,7 +481,7 @@ pub(crate) fn type_for_enum_variant(db: &impl HirDatabase, ev: EnumVariant) -> C } pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Cancelable { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); match def { Def::Module(..) => { log::debug!("trying to get type for module {:?}", def_id); @@ -507,7 +507,7 @@ pub(super) fn type_for_field( def_id: DefId, field: Name, ) -> Cancelable> { - let def = def_id.resolve(db)?; + let def = def_id.resolve(db); let variant_data = match def { Def::Struct(s) => s.variant_data(db)?, Def::EnumVariant(ev) => ev.variant_data(db), @@ -877,7 +877,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } else { return Ok((Ty::Unknown, None)); }; - Ok(match def_id.resolve(self.db)? { + Ok(match def_id.resolve(self.db) { Def::Struct(s) => { let ty = type_for_struct(self.db, s)?; (ty, Some(def_id)) -- cgit v1.2.3