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 ++-- crates/ra_ide_api/src/completion/complete_dot.rs | 2 +- crates/ra_ide_api/src/completion/complete_path.rs | 2 +- crates/ra_ide_api/src/navigation_target.rs | 6 +-- 8 files changed, 41 insertions(+), 58 deletions(-) (limited to 'crates') 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 {:?}", diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 37985b398..bf6d91a09 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -29,7 +29,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) Ty::Adt { def_id, .. } => { match def_id.resolve(ctx.db)? { Def::Struct(s) => { - for field in s.fields(ctx.db)? { + for field in s.fields(ctx.db) { CompletionItem::new( CompletionKind::Reference, field.name().to_string(), diff --git a/crates/ra_ide_api/src/completion/complete_path.rs b/crates/ra_ide_api/src/completion/complete_path.rs index a25ad3f13..6388197be 100644 --- a/crates/ra_ide_api/src/completion/complete_path.rs +++ b/crates/ra_ide_api/src/completion/complete_path.rs @@ -22,7 +22,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) -> C } } hir::Def::Enum(e) => { - e.variants(ctx.db)? + e.variants(ctx.db) .into_iter() .for_each(|(variant_name, _variant)| { CompletionItem::new(CompletionKind::Reference, variant_name.to_string()) diff --git a/crates/ra_ide_api/src/navigation_target.rs b/crates/ra_ide_api/src/navigation_target.rs index 7562b9a1f..306dbfd92 100644 --- a/crates/ra_ide_api/src/navigation_target.rs +++ b/crates/ra_ide_api/src/navigation_target.rs @@ -112,15 +112,15 @@ impl NavigationTarget { pub(crate) fn from_def(db: &RootDatabase, def: Def) -> Cancelable> { let res = match def { Def::Struct(s) => { - let (file_id, node) = s.source(db)?; + let (file_id, node) = s.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Enum(e) => { - let (file_id, node) = e.source(db)?; + let (file_id, node) = e.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::EnumVariant(ev) => { - let (file_id, node) = ev.source(db)?; + let (file_id, node) = ev.source(db); NavigationTarget::from_named(file_id.original_file(db), &*node) } Def::Function(f) => { -- cgit v1.2.3