pub enum Expr<'db> {
Show 13 variants
Const(Const),
Static(Static),
Local(Local),
ConstParam(ConstParam),
FamousType {
ty: Type<'db>,
value: &'static str,
},
Function {
func: Function,
generics: Vec<Type<'db>>,
params: Vec<Expr<'db>>,
},
Method {
func: Function,
generics: Vec<Type<'db>>,
target: Box<Expr<'db>>,
params: Vec<Expr<'db>>,
},
Variant {
variant: Variant,
generics: Vec<Type<'db>>,
params: Vec<Expr<'db>>,
},
Struct {
strukt: Struct,
generics: Vec<Type<'db>>,
params: Vec<Expr<'db>>,
},
Tuple {
ty: Type<'db>,
params: Vec<Expr<'db>>,
},
Field {
expr: Box<Expr<'db>>,
field: Field,
},
Reference(Box<Expr<'db>>),
Many(Type<'db>),
}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: boolSo 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<'db>>)
Passing type as reference (with &)
Many(Type<'db>)
Indicates possibility of many different options that all evaluate to ty
Implementations§
Source§impl<'db> Expr<'db>
impl<'db> Expr<'db>
Sourcepub fn gen_source_code(
&self,
sema_scope: &SemanticsScope<'db>,
many_formatter: &mut dyn FnMut(&Type<'db>) -> String,
cfg: FindPathConfig,
display_target: DisplayTarget,
) -> Result<String, DisplaySourceCodeError>
pub fn gen_source_code( &self, sema_scope: &SemanticsScope<'db>, many_formatter: &mut dyn FnMut(&Type<'db>) -> String, cfg: FindPathConfig, display_target: DisplayTarget, ) -> 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: &'db dyn HirDatabase) -> Type<'db>
pub fn ty(&self, db: &'db dyn HirDatabase) -> Type<'db>
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<'db> Eq for Expr<'db>
impl<'db> StructuralPartialEq for Expr<'db>
Auto Trait Implementations§
impl<'db> Freeze for Expr<'db>
impl<'db> RefUnwindSafe for Expr<'db>
impl<'db> Send for Expr<'db>
impl<'db> Sync for Expr<'db>
impl<'db> Unpin for Expr<'db>
impl<'db> UnwindSafe for Expr<'db>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
§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<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<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