From 009437f5d9949d2276aa26040e03af0ab328acf3 Mon Sep 17 00:00:00 2001 From: ice1000 Date: Tue, 3 Dec 2019 11:07:56 -0500 Subject: Replace `ra_hir_expand::either` with crate --- crates/ra_hir_def/Cargo.toml | 1 + crates/ra_hir_def/src/adt.rs | 6 +++--- crates/ra_hir_def/src/attr.rs | 7 ++++--- crates/ra_hir_def/src/body.rs | 9 ++++----- crates/ra_hir_def/src/body/lower.rs | 16 +++++++--------- crates/ra_hir_def/src/docs.rs | 6 +++--- crates/ra_hir_def/src/nameres.rs | 8 ++++---- crates/ra_hir_def/src/nameres/raw.rs | 6 +++--- crates/ra_hir_def/src/path.rs | 10 +++++----- 9 files changed, 34 insertions(+), 35 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/Cargo.toml b/crates/ra_hir_def/Cargo.toml index 7e65f4c1d..cf3a446fc 100644 --- a/crates/ra_hir_def/Cargo.toml +++ b/crates/ra_hir_def/Cargo.toml @@ -11,6 +11,7 @@ doctest = false log = "0.4.5" once_cell = "1.0.1" rustc-hash = "1.0" +either = "1.5" ra_arena = { path = "../ra_arena" } ra_db = { path = "../ra_db" } diff --git a/crates/ra_hir_def/src/adt.rs b/crates/ra_hir_def/src/adt.rs index 9ab829aab..db3e63ef8 100644 --- a/crates/ra_hir_def/src/adt.rs +++ b/crates/ra_hir_def/src/adt.rs @@ -2,8 +2,8 @@ use std::sync::Arc; +use either::Either; use hir_expand::{ - either::Either, name::{AsName, Name}, InFile, }; @@ -184,7 +184,7 @@ fn lower_struct( ast::StructKind::Tuple(fl) => { for (i, fd) in fl.fields().enumerate() { trace.alloc( - || Either::A(fd.clone()), + || Either::Left(fd.clone()), || StructFieldData { name: Name::new_tuple_field(i), type_ref: TypeRef::from_ast_opt(fd.type_ref()), @@ -196,7 +196,7 @@ fn lower_struct( ast::StructKind::Record(fl) => { for fd in fl.fields() { trace.alloc( - || Either::B(fd.clone()), + || Either::Right(fd.clone()), || StructFieldData { name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing), type_ref: TypeRef::from_ast_opt(fd.ascribed_type()), diff --git a/crates/ra_hir_def/src/attr.rs b/crates/ra_hir_def/src/attr.rs index bc7ade921..7f9a6e7ca 100644 --- a/crates/ra_hir_def/src/attr.rs +++ b/crates/ra_hir_def/src/attr.rs @@ -2,7 +2,8 @@ use std::{ops, sync::Arc}; -use hir_expand::{either::Either, hygiene::Hygiene, AstId, InFile}; +use either::Either; +use hir_expand::{hygiene::Hygiene, AstId, InFile}; use mbe::ast_to_token_tree; use ra_syntax::{ ast::{self, AstNode, AttrsOwner}, @@ -45,8 +46,8 @@ impl Attrs { AttrDefId::StructFieldId(it) => { let src = it.parent.child_source(db); match &src.value[it.local_id] { - Either::A(_tuple) => Attrs::default(), - Either::B(record) => Attrs::from_attrs_owner(db, src.with_value(record)), + Either::Left(_tuple) => Attrs::default(), + Either::Right(record) => Attrs::from_attrs_owner(db, src.with_value(record)), } } AttrDefId::EnumVariantId(var_id) => { diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 239f35229..ef1816836 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs @@ -5,9 +5,8 @@ pub mod scope; use std::{ops::Index, sync::Arc}; -use hir_expand::{ - either::Either, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind, -}; +use either::Either; +use hir_expand::{hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId, MacroFileKind}; use ra_arena::{map::ArenaMap, Arena}; use ra_syntax::{ast, AstNode, AstPtr}; use rustc_hash::FxHashMap; @@ -210,7 +209,7 @@ impl BodySourceMap { } pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option { - let src = node.map(|it| Either::A(AstPtr::new(it))); + let src = node.map(|it| Either::Left(AstPtr::new(it))); self.expr_map.get(&src).cloned() } @@ -219,7 +218,7 @@ impl BodySourceMap { } pub fn node_pat(&self, node: InFile<&ast::Pat>) -> Option { - let src = node.map(|it| Either::A(AstPtr::new(it))); + let src = node.map(|it| Either::Left(AstPtr::new(it))); self.pat_map.get(&src).cloned() } diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index be1eaa523..71c08f024 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs @@ -1,10 +1,8 @@ //! Transforms `ast::Expr` into an equivalent `hir_def::expr::Expr` //! representation. -use hir_expand::{ - either::Either, - name::{self, AsName, Name}, -}; +use either::Either; +use hir_expand::name::{self, AsName, Name}; use ra_arena::Arena; use ra_syntax::{ ast::{ @@ -74,7 +72,7 @@ where mode: BindingAnnotation::Unannotated, subpat: None, }, - Either::B(ptr), + Either::Right(ptr), ); self.body.params.push(param_pat); } @@ -94,7 +92,7 @@ where } fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::A(ptr); + let ptr = Either::Left(ptr); let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); self.source_map.expr_map.insert(src, id); @@ -107,7 +105,7 @@ where self.body.exprs.alloc(expr) } fn alloc_expr_field_shorthand(&mut self, expr: Expr, ptr: AstPtr) -> ExprId { - let ptr = Either::B(ptr); + let ptr = Either::Right(ptr); let id = self.body.exprs.alloc(expr); let src = self.expander.to_source(ptr); self.source_map.expr_map.insert(src, id); @@ -277,7 +275,7 @@ where ast::Expr::ParenExpr(e) => { let inner = self.collect_expr_opt(e.expr()); // make the paren expr point to the inner expression as well - let src = self.expander.to_source(Either::A(syntax_ptr)); + let src = self.expander.to_source(Either::Left(syntax_ptr)); self.source_map.expr_map.insert(src, inner); inner } @@ -550,7 +548,7 @@ where ast::Pat::SlicePat(_) | ast::Pat::RangePat(_) => Pat::Missing, }; let ptr = AstPtr::new(&pat); - self.alloc_pat(pattern, Either::A(ptr)) + self.alloc_pat(pattern, Either::Left(ptr)) } fn collect_pat_opt(&mut self, pat: Option) -> PatId { diff --git a/crates/ra_hir_def/src/docs.rs b/crates/ra_hir_def/src/docs.rs index ec944373d..3fc6d6934 100644 --- a/crates/ra_hir_def/src/docs.rs +++ b/crates/ra_hir_def/src/docs.rs @@ -5,7 +5,7 @@ use std::sync::Arc; -use hir_expand::either::Either; +use either::Either; use ra_syntax::ast; use crate::{ @@ -46,8 +46,8 @@ impl Documentation { AttrDefId::StructFieldId(it) => { let src = it.parent.child_source(db); match &src.value[it.local_id] { - Either::A(_tuple) => None, - Either::B(record) => docs_from_ast(record), + Either::Left(_tuple) => None, + Either::Right(record) => docs_from_ast(record), } } AttrDefId::AdtId(it) => match it { diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 3e1521870..faf3566f4 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs @@ -57,9 +57,9 @@ mod tests; use std::sync::Arc; +use either::Either; use hir_expand::{ - ast_id_map::FileAstId, diagnostics::DiagnosticSink, either::Either, name::Name, InFile, - MacroDefId, + ast_id_map::FileAstId, diagnostics::DiagnosticSink, name::Name, InFile, MacroDefId, }; use once_cell::sync::Lazy; use ra_arena::Arena; @@ -287,10 +287,10 @@ impl ModuleData { ) -> InFile> { if let Some(file_id) = self.definition { let sf = db.parse(file_id).tree(); - return InFile::new(file_id.into(), Either::A(sf)); + return InFile::new(file_id.into(), Either::Left(sf)); } let decl = self.declaration.unwrap(); - InFile::new(decl.file_id, Either::B(decl.to_node(db))) + InFile::new(decl.file_id, Either::Right(decl.to_node(db))) } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 5196b67ca..de4e706c2 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -7,10 +7,10 @@ use std::{ops::Index, sync::Arc}; +use either::Either; use hir_expand::{ ast_id_map::AstIdMap, db::AstDatabase, - either::Either, hygiene::Hygiene, name::{AsName, Name}, }; @@ -324,7 +324,7 @@ impl RawItemsCollector { is_extern_crate: false, is_macro_use: false, }; - buf.push((import_data, Either::A(AstPtr::new(use_tree)))); + buf.push((import_data, Either::Left(AstPtr::new(use_tree)))); }, ); for (import_data, ptr) in buf { @@ -355,7 +355,7 @@ impl RawItemsCollector { current_module, attrs, import_data, - Either::B(AstPtr::new(&extern_crate)), + Either::Right(AstPtr::new(&extern_crate)), ); } } diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index ff252fe44..3030dcdf6 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs @@ -2,8 +2,8 @@ use std::{iter, sync::Arc}; +use either::Either; use hir_expand::{ - either::Either, hygiene::Hygiene, name::{self, AsName, Name}, }; @@ -111,7 +111,7 @@ impl Path { ast::PathSegmentKind::Name(name_ref) => { // FIXME: this should just return name match hygiene.name_ref_to_name(name_ref) { - Either::A(name) => { + Either::Left(name) => { let args = segment .type_arg_list() .and_then(GenericArgs::from_ast) @@ -125,7 +125,7 @@ impl Path { let segment = PathSegment { name, args_and_bindings: args }; segments.push(segment); } - Either::B(crate_id) => { + Either::Right(crate_id) => { kind = PathKind::DollarCrate(crate_id); break; } @@ -347,7 +347,7 @@ fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> Opt let res = match segment.kind()? { ast::PathSegmentKind::Name(name_ref) => { match hygiene.name_ref_to_name(name_ref) { - Either::A(name) => { + Either::Left(name) => { // no type args in use let mut res = prefix.unwrap_or_else(|| Path { kind: PathKind::Plain, @@ -359,7 +359,7 @@ fn convert_path(prefix: Option, path: ast::Path, hygiene: &Hygiene) -> Opt }); res } - Either::B(crate_id) => { + Either::Right(crate_id) => { return Some(Path::from_simple_segments( PathKind::DollarCrate(crate_id), iter::empty(), -- cgit v1.2.3