aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src
diff options
context:
space:
mode:
authorrobojumper <[email protected]>2020-05-28 20:42:22 +0100
committerrobojumper <[email protected]>2020-05-28 20:42:22 +0100
commit367487fe88dca78cffad5138673d5259f7f7ba6b (patch)
tree2846ebee3a16875674aed26b534f905a30cb598f /crates/ra_hir_def/src
parent190a0595a478d059fdd95a179fe38d59cb6379be (diff)
Support raw_ref_op's raw reference operator
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r--crates/ra_hir_def/src/body/lower.rs19
-rw-r--r--crates/ra_hir_def/src/expr.rs3
-rw-r--r--crates/ra_hir_def/src/type_ref.rs16
3 files changed, 34 insertions, 4 deletions
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs
index e08d62dd6..905c0cf5d 100644
--- a/crates/ra_hir_def/src/body/lower.rs
+++ b/crates/ra_hir_def/src/body/lower.rs
@@ -28,7 +28,7 @@ use crate::{
28 }, 28 },
29 item_scope::BuiltinShadowMode, 29 item_scope::BuiltinShadowMode,
30 path::{GenericArgs, Path}, 30 path::{GenericArgs, Path},
31 type_ref::{Mutability, TypeRef}, 31 type_ref::{Mutability, Rawness, TypeRef},
32 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId, 32 AdtId, ConstLoc, ContainerId, DefWithBodyId, EnumLoc, FunctionLoc, Intern, ModuleDefId,
33 StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc, 33 StaticLoc, StructLoc, TraitLoc, TypeAliasLoc, UnionLoc,
34}; 34};
@@ -378,8 +378,21 @@ impl ExprCollector<'_> {
378 } 378 }
379 ast::Expr::RefExpr(e) => { 379 ast::Expr::RefExpr(e) => {
380 let expr = self.collect_expr_opt(e.expr()); 380 let expr = self.collect_expr_opt(e.expr());
381 let mutability = Mutability::from_mutable(e.mut_token().is_some()); 381 let raw_tok = e.raw_token().is_some();
382 self.alloc_expr(Expr::Ref { expr, mutability }, syntax_ptr) 382 let mutability = if raw_tok {
383 if e.mut_token().is_some() {
384 Mutability::Mut
385 } else if e.const_token().is_some() {
386 Mutability::Shared
387 } else {
388 unreachable!("parser only remaps to raw_token() if matching mutability token follows")
389 }
390 } else {
391 Mutability::from_mutable(e.mut_token().is_some())
392 };
393 let rawness = Rawness::from_raw(raw_tok);
394
395 self.alloc_expr(Expr::Ref { expr, rawness, mutability }, syntax_ptr)
383 } 396 }
384 ast::Expr::PrefixExpr(e) => { 397 ast::Expr::PrefixExpr(e) => {
385 let expr = self.collect_expr_opt(e.expr()); 398 let expr = self.collect_expr_opt(e.expr());
diff --git a/crates/ra_hir_def/src/expr.rs b/crates/ra_hir_def/src/expr.rs
index a0cdad529..f25c6f958 100644
--- a/crates/ra_hir_def/src/expr.rs
+++ b/crates/ra_hir_def/src/expr.rs
@@ -19,7 +19,7 @@ use ra_syntax::ast::RangeOp;
19use crate::{ 19use crate::{
20 builtin_type::{BuiltinFloat, BuiltinInt}, 20 builtin_type::{BuiltinFloat, BuiltinInt},
21 path::{GenericArgs, Path}, 21 path::{GenericArgs, Path},
22 type_ref::{Mutability, TypeRef}, 22 type_ref::{Mutability, Rawness, TypeRef},
23}; 23};
24 24
25pub type ExprId = Idx<Expr>; 25pub type ExprId = Idx<Expr>;
@@ -110,6 +110,7 @@ pub enum Expr {
110 }, 110 },
111 Ref { 111 Ref {
112 expr: ExprId, 112 expr: ExprId,
113 rawness: Rawness,
113 mutability: Mutability, 114 mutability: Mutability,
114 }, 115 },
115 Box { 116 Box {
diff --git a/crates/ra_hir_def/src/type_ref.rs b/crates/ra_hir_def/src/type_ref.rs
index 5bdad9efd..86a77b704 100644
--- a/crates/ra_hir_def/src/type_ref.rs
+++ b/crates/ra_hir_def/src/type_ref.rs
@@ -35,6 +35,22 @@ impl Mutability {
35 } 35 }
36} 36}
37 37
38#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
39pub enum Rawness {
40 RawPtr,
41 Ref,
42}
43
44impl Rawness {
45 pub fn from_raw(is_raw: bool) -> Rawness {
46 if is_raw {
47 Rawness::RawPtr
48 } else {
49 Rawness::Ref
50 }
51 }
52}
53
38/// Compare ty::Ty 54/// Compare ty::Ty
39#[derive(Clone, PartialEq, Eq, Hash, Debug)] 55#[derive(Clone, PartialEq, Eq, Hash, Debug)]
40pub enum TypeRef { 56pub enum TypeRef {