Enum hir::term_search::Expr
source · pub enum Expr {
Show 13 variants
Const(Const),
Static(Static),
Local(Local),
ConstParam(ConstParam),
FamousType {
ty: Type,
value: &'static str,
},
Function {
func: Function,
generics: Vec<Type>,
params: Vec<Expr>,
},
Method {
func: Function,
generics: Vec<Type>,
target: Box<Expr>,
params: Vec<Expr>,
},
Variant {
variant: Variant,
generics: Vec<Type>,
params: Vec<Expr>,
},
Struct {
strukt: Struct,
generics: Vec<Type>,
params: Vec<Expr>,
},
Tuple {
ty: Type,
params: Vec<Expr>,
},
Field {
expr: Box<Expr>,
field: Field,
},
Reference(Box<Expr>),
Many(Type),
}
Expand description
Type tree shows how can we get from set of types to some type.
Consider the following code as an example
fn foo(x: i32, y: bool) -> Option<i32> { None }
fn bar() {
let a = 1;
let b = true;
let c: Option<i32> = _;
}
If we generate type tree in the place of _
we get
Option<i32>
|
foo(i32, bool)
/ \
a: i32 b: bool
So in short it pretty much gives us a way to get type Option<i32>
using the items we have in
scope.
Variants§
Const(Const)
Constant
Static(Static)
Static variable
Local(Local)
Local variable
ConstParam(ConstParam)
Constant generic parameter
FamousType
Well known type (such as true
for bool)
Function
Function call (does not take self param)
Method
Method call (has self param)
Variant
Enum variant construction
Struct
Struct construction
Tuple
Tuple construction
Field
Struct field access
Reference(Box<Expr>)
Passing type as reference (with &
)
Many(Type)
Indicates possibility of many different options that all evaluate to ty
Implementations§
source§impl Expr
impl Expr
sourcepub fn gen_source_code(
&self,
sema_scope: &SemanticsScope<'_>,
many_formatter: &mut dyn FnMut(&Type) -> String,
cfg: ImportPathConfig,
edition: Edition,
) -> Result<String, DisplaySourceCodeError>
pub fn gen_source_code( &self, sema_scope: &SemanticsScope<'_>, many_formatter: &mut dyn FnMut(&Type) -> String, cfg: ImportPathConfig, edition: Edition, ) -> Result<String, DisplaySourceCodeError>
Generate source code for type tree.
Note that trait imports are not added to generated code.
To make sure that the code is valid, callee has to also ensure that all the traits listed
by traits_used
method are also imported.
sourcepub fn ty(&self, db: &dyn HirDatabase) -> Type
pub fn ty(&self, db: &dyn HirDatabase) -> Type
Get type of the type tree.
Same as getting the type of root node
sourcepub fn traits_used(&self, db: &dyn HirDatabase) -> Vec<Trait>
pub fn traits_used(&self, db: &dyn HirDatabase) -> Vec<Trait>
List the traits used in type tree
Trait Implementations§
impl Eq for Expr
impl StructuralPartialEq for Expr
Auto Trait Implementations§
impl Freeze for Expr
impl RefUnwindSafe for Expr
impl Send for Expr
impl Sync for Expr
impl Unpin for Expr
impl UnwindSafe for Expr
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Cast for T
impl<T> Cast for T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more