mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-15 22:54:00 +00:00
Auto merge of #14517 - Veykril:hir-def-refac, r=Veykril
internal: Shuffle around some hir_def modules
This commit is contained in:
commit
58da3fc240
53 changed files with 150 additions and 145 deletions
|
@ -1,5 +1,7 @@
|
||||||
//! A higher level attributes based on TokenTree, with also some shortcuts.
|
//! A higher level attributes based on TokenTree, with also some shortcuts.
|
||||||
|
|
||||||
|
pub mod builtin;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr};
|
||||||
use crate::{
|
use crate::{
|
||||||
attr::Attrs,
|
attr::Attrs,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
expr::{
|
hir::{
|
||||||
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
|
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
|
||||||
},
|
},
|
||||||
item_scope::BuiltinShadowMode,
|
item_scope::BuiltinShadowMode,
|
||||||
|
|
|
@ -26,12 +26,14 @@ use syntax::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::StructKind,
|
body::{
|
||||||
body::{Body, BodySourceMap, Expander, ExprPtr, LabelPtr, LabelSource, PatPtr},
|
Body, BodyDiagnostic, BodySourceMap, Expander, ExprPtr, ExprSource, LabelPtr, LabelSource,
|
||||||
body::{BodyDiagnostic, ExprSource, PatSource},
|
PatPtr, PatSource,
|
||||||
|
},
|
||||||
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
|
||||||
|
data::adt::StructKind,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
expr::{
|
hir::{
|
||||||
dummy_expr_id, Array, Binding, BindingAnnotation, BindingId, ClosureKind, Expr, ExprId,
|
dummy_expr_id, Array, Binding, BindingAnnotation, BindingId, ClosureKind, Expr, ExprId,
|
||||||
FloatTypeWrapper, Label, LabelId, Literal, MatchArm, Movability, Pat, PatId,
|
FloatTypeWrapper, Label, LabelId, Literal, MatchArm, Movability, Pat, PatId,
|
||||||
RecordFieldPat, RecordLitField, Statement,
|
RecordFieldPat, RecordLitField, Statement,
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::fmt::{self, Write};
|
||||||
use syntax::ast::HasName;
|
use syntax::ast::HasName;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
expr::{Array, BindingAnnotation, BindingId, ClosureKind, Literal, Movability, Statement},
|
hir::{Array, BindingAnnotation, BindingId, ClosureKind, Literal, Movability, Statement},
|
||||||
pretty::{print_generic_args, print_path, print_type_ref},
|
pretty::{print_generic_args, print_path, print_type_ref},
|
||||||
type_ref::TypeRef,
|
type_ref::TypeRef,
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
|
||||||
use crate::{
|
use crate::{
|
||||||
body::Body,
|
body::Body,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
expr::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
|
hir::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
|
||||||
BlockId, DefWithBodyId,
|
BlockId, DefWithBodyId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,8 @@ use syntax::ast::HasDocComments;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
dyn_map::DynMap,
|
dyn_map::{keys, DynMap},
|
||||||
item_scope::ItemScope,
|
item_scope::ItemScope,
|
||||||
keys,
|
|
||||||
src::{HasChildSource, HasSource},
|
src::{HasChildSource, HasSource},
|
||||||
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, MacroId,
|
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, MacroId,
|
||||||
ModuleDefId, ModuleId, TraitId, VariantId,
|
ModuleDefId, ModuleId, TraitId, VariantId,
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
//! Contains basic data about various HIR declarations.
|
//! Contains basic data about various HIR declarations.
|
||||||
|
|
||||||
|
pub mod adt;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};
|
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};
|
||||||
|
|
|
@ -9,10 +9,10 @@ use la_arena::ArenaMap;
|
||||||
use syntax::{ast, AstPtr};
|
use syntax::{ast, AstPtr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::{EnumData, StructData},
|
|
||||||
attr::{Attrs, AttrsWithOwner},
|
attr::{Attrs, AttrsWithOwner},
|
||||||
body::{scope::ExprScopes, Body, BodySourceMap},
|
body::{scope::ExprScopes, Body, BodySourceMap},
|
||||||
data::{
|
data::{
|
||||||
|
adt::{EnumData, StructData},
|
||||||
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
|
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
|
||||||
TraitAliasData, TraitData, TypeAliasData,
|
TraitAliasData, TraitData, TypeAliasData,
|
||||||
},
|
},
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
//!
|
//!
|
||||||
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
|
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
|
||||||
//! a coincidence.
|
//! a coincidence.
|
||||||
|
pub mod keys;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
|
|
|
@ -20,8 +20,7 @@ use crate::{
|
||||||
body::{Expander, LowerCtx},
|
body::{Expander, LowerCtx},
|
||||||
child_by_source::ChildBySource,
|
child_by_source::ChildBySource,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
dyn_map::DynMap,
|
dyn_map::{keys, DynMap},
|
||||||
keys,
|
|
||||||
src::{HasChildSource, HasSource},
|
src::{HasChildSource, HasSource},
|
||||||
type_ref::{LifetimeRef, TypeBound, TypeRef},
|
type_ref::{LifetimeRef, TypeBound, TypeRef},
|
||||||
AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId,
|
AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId,
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
//!
|
//!
|
||||||
//! See also a neighboring `body` module.
|
//! See also a neighboring `body` module.
|
||||||
|
|
||||||
|
pub mod type_ref;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
@ -28,10 +30,10 @@ use crate::{
|
||||||
|
|
||||||
pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp};
|
pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp};
|
||||||
|
|
||||||
pub type ExprId = Idx<Expr>;
|
|
||||||
|
|
||||||
pub type BindingId = Idx<Binding>;
|
pub type BindingId = Idx<Binding>;
|
||||||
|
|
||||||
|
pub type ExprId = Idx<Expr>;
|
||||||
|
|
||||||
/// FIXME: this is a hacky function which should be removed
|
/// FIXME: this is a hacky function which should be removed
|
||||||
pub(crate) fn dummy_expr_id() -> ExprId {
|
pub(crate) fn dummy_expr_id() -> ExprId {
|
||||||
ExprId::from_raw(RawIdx::from(u32::MAX))
|
ExprId::from_raw(RawIdx::from(u32::MAX))
|
|
@ -13,7 +13,7 @@ use syntax::ast::{self, HasName};
|
||||||
use crate::{
|
use crate::{
|
||||||
body::LowerCtx,
|
body::LowerCtx,
|
||||||
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
||||||
expr::Literal,
|
hir::Literal,
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,24 +18,21 @@ pub mod db;
|
||||||
|
|
||||||
pub mod attr;
|
pub mod attr;
|
||||||
pub mod path;
|
pub mod path;
|
||||||
pub mod type_ref;
|
|
||||||
pub mod builtin_type;
|
pub mod builtin_type;
|
||||||
pub mod builtin_attr;
|
|
||||||
pub mod per_ns;
|
pub mod per_ns;
|
||||||
pub mod item_scope;
|
pub mod item_scope;
|
||||||
|
|
||||||
pub mod dyn_map;
|
pub mod dyn_map;
|
||||||
pub mod keys;
|
|
||||||
|
|
||||||
pub mod item_tree;
|
pub mod item_tree;
|
||||||
|
|
||||||
pub mod adt;
|
|
||||||
pub mod data;
|
pub mod data;
|
||||||
pub mod generics;
|
pub mod generics;
|
||||||
pub mod lang_item;
|
pub mod lang_item;
|
||||||
pub mod layout;
|
pub mod layout;
|
||||||
|
|
||||||
pub mod expr;
|
pub mod hir;
|
||||||
|
pub use self::hir::type_ref;
|
||||||
pub mod body;
|
pub mod body;
|
||||||
pub mod resolver;
|
pub mod resolver;
|
||||||
|
|
||||||
|
@ -82,8 +79,8 @@ use syntax::ast;
|
||||||
use ::tt::token_id as tt;
|
use ::tt::token_id as tt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
adt::VariantData,
|
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
data::adt::VariantData,
|
||||||
item_tree::{
|
item_tree::{
|
||||||
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
|
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
|
||||||
Static, Struct, Trait, TraitAlias, TypeAlias, Union,
|
Static, Struct, Trait, TraitAlias, TypeAlias, Union,
|
||||||
|
@ -236,7 +233,7 @@ pub struct EnumVariantId {
|
||||||
pub local_id: LocalEnumVariantId,
|
pub local_id: LocalEnumVariantId,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
|
pub type LocalEnumVariantId = Idx<data::adt::EnumVariantData>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct FieldId {
|
pub struct FieldId {
|
||||||
|
@ -244,7 +241,7 @@ pub struct FieldId {
|
||||||
pub local_id: LocalFieldId,
|
pub local_id: LocalFieldId,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type LocalFieldId = Idx<adt::FieldData>;
|
pub type LocalFieldId = Idx<data::adt::FieldData>;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub struct ConstId(salsa::InternId);
|
pub struct ConstId(salsa::InternId);
|
||||||
|
|
|
@ -4,7 +4,8 @@ use hir_expand::{attrs::Attr, MacroCallId};
|
||||||
use syntax::{ast, SmolStr};
|
use syntax::{ast, SmolStr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
attr_macro_as_call_id, builtin_attr,
|
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
|
||||||
|
attr_macro_as_call_id,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::BuiltinShadowMode,
|
item_scope::BuiltinShadowMode,
|
||||||
macro_id_to_def_id,
|
macro_id_to_def_id,
|
||||||
|
@ -76,19 +77,15 @@ impl DefMap {
|
||||||
let pred = |n: &_| *n == name;
|
let pred = |n: &_| *n == name;
|
||||||
|
|
||||||
let registered = self.registered_tools.iter().map(SmolStr::as_str);
|
let registered = self.registered_tools.iter().map(SmolStr::as_str);
|
||||||
let is_tool = builtin_attr::TOOL_MODULES.iter().copied().chain(registered).any(pred);
|
let is_tool = TOOL_MODULES.iter().copied().chain(registered).any(pred);
|
||||||
// FIXME: tool modules can be shadowed by actual modules
|
// FIXME: tool modules can be shadowed by actual modules
|
||||||
if is_tool {
|
if is_tool {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 {
|
||||||
let registered = self.registered_attrs.iter().map(SmolStr::as_str);
|
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
|
||||||
let is_inert = builtin_attr::INERT_ATTRIBUTES
|
let is_inert = find_builtin_attr_idx(&name).is_some() || registered.any(pred);
|
||||||
.iter()
|
|
||||||
.map(|it| it.name)
|
|
||||||
.chain(registered)
|
|
||||||
.any(pred);
|
|
||||||
return is_inert;
|
return is_inert;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -331,11 +331,11 @@ impl DefMap {
|
||||||
Some(local_id) => {
|
Some(local_id) => {
|
||||||
let variant = EnumVariantId { parent: e, local_id };
|
let variant = EnumVariantId { parent: e, local_id };
|
||||||
match &*enum_data.variants[local_id].variant_data {
|
match &*enum_data.variants[local_id].variant_data {
|
||||||
crate::adt::VariantData::Record(_) => {
|
crate::data::adt::VariantData::Record(_) => {
|
||||||
PerNs::types(variant.into(), Visibility::Public)
|
PerNs::types(variant.into(), Visibility::Public)
|
||||||
}
|
}
|
||||||
crate::adt::VariantData::Tuple(_)
|
crate::data::adt::VariantData::Tuple(_)
|
||||||
| crate::adt::VariantData::Unit => {
|
| crate::data::adt::VariantData::Unit => {
|
||||||
PerNs::both(variant.into(), variant.into(), Visibility::Public)
|
PerNs::both(variant.into(), variant.into(), Visibility::Public)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,8 +12,8 @@ use crate::{
|
||||||
body::scope::{ExprScopes, ScopeId},
|
body::scope::{ExprScopes, ScopeId},
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
expr::{BindingId, ExprId, LabelId},
|
|
||||||
generics::{GenericParams, TypeOrConstParamData},
|
generics::{GenericParams, TypeOrConstParamData},
|
||||||
|
hir::{BindingId, ExprId, LabelId},
|
||||||
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
|
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
|
||||||
lang_item::LangItemTarget,
|
lang_item::LangItemTarget,
|
||||||
nameres::DefMap,
|
nameres::DefMap,
|
||||||
|
|
|
@ -9,7 +9,7 @@ use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::Movability,
|
hir::Movability,
|
||||||
lang_item::{lang_attr, LangItem, LangItemTarget},
|
lang_item::{lang_attr, LangItem, LangItemTarget},
|
||||||
AssocItemId, BlockId, GenericDefId, HasModule, ItemContainerId, Lookup, TypeAliasId,
|
AssocItemId, BlockId, GenericDefId, HasModule, ItemContainerId, Lookup, TypeAliasId,
|
||||||
};
|
};
|
||||||
|
@ -415,8 +415,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
||||||
let input_output = crate::make_type_and_const_binders(it, input_output);
|
let input_output = crate::make_type_and_const_binders(it, input_output);
|
||||||
|
|
||||||
let movability = match self.db.body(parent)[expr] {
|
let movability = match self.db.body(parent)[expr] {
|
||||||
hir_def::expr::Expr::Closure {
|
hir_def::hir::Expr::Closure {
|
||||||
closure_kind: hir_def::expr::ClosureKind::Generator(movability),
|
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
|
||||||
..
|
..
|
||||||
} => movability,
|
} => movability,
|
||||||
_ => unreachable!("non generator expression interned as generator"),
|
_ => unreachable!("non generator expression interned as generator"),
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData};
|
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::Expr,
|
hir::Expr,
|
||||||
path::Path,
|
path::Path,
|
||||||
resolver::{Resolver, ValueNs},
|
resolver::{Resolver, ValueNs},
|
||||||
type_ref::ConstRef,
|
type_ref::ConstRef,
|
||||||
|
|
|
@ -6,7 +6,7 @@ use std::sync::Arc;
|
||||||
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
|
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
expr::ExprId,
|
hir::ExprId,
|
||||||
layout::{Layout, LayoutError, TargetDataLayout},
|
layout::{Layout, LayoutError, TargetDataLayout},
|
||||||
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GenericDefId,
|
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GenericDefId,
|
||||||
ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,
|
ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,
|
||||||
|
|
|
@ -16,8 +16,8 @@ use std::fmt;
|
||||||
|
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
data::adt::VariantData,
|
||||||
expr::{Pat, PatId},
|
hir::{Pat, PatId},
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
AdtId, AttrDefId, ConstId, EnumId, FunctionId, ItemContainerId, Lookup, ModuleDefId, StaticId,
|
AdtId, AttrDefId, ConstId, EnumId, FunctionId, ItemContainerId, Lookup, ModuleDefId, StaticId,
|
||||||
StructId,
|
StructId,
|
||||||
|
|
|
@ -27,7 +27,7 @@ use crate::{
|
||||||
|
|
||||||
pub(crate) use hir_def::{
|
pub(crate) use hir_def::{
|
||||||
body::Body,
|
body::Body,
|
||||||
expr::{Expr, ExprId, MatchArm, Pat, PatId},
|
hir::{Expr, ExprId, MatchArm, Pat, PatId},
|
||||||
LocalFieldId, VariantId,
|
LocalFieldId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Validation of matches.
|
//! Validation of matches.
|
||||||
//!
|
//!
|
||||||
//! This module provides lowering from [hir_def::expr::Pat] to [self::Pat] and match
|
//! This module provides lowering from [hir_def::hir::Pat] to [self::Pat] and match
|
||||||
//! checking algorithm.
|
//! checking algorithm.
|
||||||
//!
|
//!
|
||||||
//! It is modeled on the rustc module `rustc_mir_build::thir::pattern`.
|
//! It is modeled on the rustc module `rustc_mir_build::thir::pattern`.
|
||||||
|
@ -12,7 +12,7 @@ pub(crate) mod usefulness;
|
||||||
|
|
||||||
use chalk_ir::Mutability;
|
use chalk_ir::Mutability;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData, body::Body, expr::PatId, AdtId, EnumVariantId, LocalFieldId, VariantId,
|
body::Body, data::adt::VariantData, hir::PatId, AdtId, EnumVariantId, LocalFieldId, VariantId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use stdx::{always, never};
|
use stdx::{always, never};
|
||||||
|
@ -125,15 +125,15 @@ impl<'a> PatCtxt<'a> {
|
||||||
let variant = self.infer.variant_resolution_for_pat(pat);
|
let variant = self.infer.variant_resolution_for_pat(pat);
|
||||||
|
|
||||||
let kind = match self.body[pat] {
|
let kind = match self.body[pat] {
|
||||||
hir_def::expr::Pat::Wild => PatKind::Wild,
|
hir_def::hir::Pat::Wild => PatKind::Wild,
|
||||||
|
|
||||||
hir_def::expr::Pat::Lit(expr) => self.lower_lit(expr),
|
hir_def::hir::Pat::Lit(expr) => self.lower_lit(expr),
|
||||||
|
|
||||||
hir_def::expr::Pat::Path(ref path) => {
|
hir_def::hir::Pat::Path(ref path) => {
|
||||||
return self.lower_path(pat, path);
|
return self.lower_path(pat, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
hir_def::expr::Pat::Tuple { ref args, ellipsis } => {
|
hir_def::hir::Pat::Tuple { ref args, ellipsis } => {
|
||||||
let arity = match *ty.kind(Interner) {
|
let arity = match *ty.kind(Interner) {
|
||||||
TyKind::Tuple(arity, _) => arity,
|
TyKind::Tuple(arity, _) => arity,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -146,7 +146,7 @@ impl<'a> PatCtxt<'a> {
|
||||||
PatKind::Leaf { subpatterns }
|
PatKind::Leaf { subpatterns }
|
||||||
}
|
}
|
||||||
|
|
||||||
hir_def::expr::Pat::Bind { id, subpat, .. } => {
|
hir_def::hir::Pat::Bind { id, subpat, .. } => {
|
||||||
let bm = self.infer.pat_binding_modes[&pat];
|
let bm = self.infer.pat_binding_modes[&pat];
|
||||||
let name = &self.body.bindings[id].name;
|
let name = &self.body.bindings[id].name;
|
||||||
match (bm, ty.kind(Interner)) {
|
match (bm, ty.kind(Interner)) {
|
||||||
|
@ -161,13 +161,13 @@ impl<'a> PatCtxt<'a> {
|
||||||
PatKind::Binding { name: name.clone(), subpattern: self.lower_opt_pattern(subpat) }
|
PatKind::Binding { name: name.clone(), subpattern: self.lower_opt_pattern(subpat) }
|
||||||
}
|
}
|
||||||
|
|
||||||
hir_def::expr::Pat::TupleStruct { ref args, ellipsis, .. } if variant.is_some() => {
|
hir_def::hir::Pat::TupleStruct { ref args, ellipsis, .. } if variant.is_some() => {
|
||||||
let expected_len = variant.unwrap().variant_data(self.db.upcast()).fields().len();
|
let expected_len = variant.unwrap().variant_data(self.db.upcast()).fields().len();
|
||||||
let subpatterns = self.lower_tuple_subpats(args, expected_len, ellipsis);
|
let subpatterns = self.lower_tuple_subpats(args, expected_len, ellipsis);
|
||||||
self.lower_variant_or_leaf(pat, ty, subpatterns)
|
self.lower_variant_or_leaf(pat, ty, subpatterns)
|
||||||
}
|
}
|
||||||
|
|
||||||
hir_def::expr::Pat::Record { ref args, .. } if variant.is_some() => {
|
hir_def::hir::Pat::Record { ref args, .. } if variant.is_some() => {
|
||||||
let variant_data = variant.unwrap().variant_data(self.db.upcast());
|
let variant_data = variant.unwrap().variant_data(self.db.upcast());
|
||||||
let subpatterns = args
|
let subpatterns = args
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -187,12 +187,12 @@ impl<'a> PatCtxt<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir_def::expr::Pat::TupleStruct { .. } | hir_def::expr::Pat::Record { .. } => {
|
hir_def::hir::Pat::TupleStruct { .. } | hir_def::hir::Pat::Record { .. } => {
|
||||||
self.errors.push(PatternError::UnresolvedVariant);
|
self.errors.push(PatternError::UnresolvedVariant);
|
||||||
PatKind::Wild
|
PatKind::Wild
|
||||||
}
|
}
|
||||||
|
|
||||||
hir_def::expr::Pat::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
|
hir_def::hir::Pat::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
|
||||||
|
|
||||||
_ => {
|
_ => {
|
||||||
self.errors.push(PatternError::Unimplemented);
|
self.errors.push(PatternError::Unimplemented);
|
||||||
|
@ -279,8 +279,8 @@ impl<'a> PatCtxt<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_lit(&mut self, expr: hir_def::expr::ExprId) -> PatKind {
|
fn lower_lit(&mut self, expr: hir_def::hir::ExprId) -> PatKind {
|
||||||
use hir_def::expr::{Expr, Literal::Bool};
|
use hir_def::hir::{Expr, Literal::Bool};
|
||||||
|
|
||||||
match self.body[expr] {
|
match self.body[expr] {
|
||||||
Expr::Literal(Bool(value)) => PatKind::LiteralBool { value },
|
Expr::Literal(Bool(value)) => PatKind::LiteralBool { value },
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::Body,
|
body::Body,
|
||||||
expr::{Expr, ExprId, UnaryOp},
|
hir::{Expr, ExprId, UnaryOp},
|
||||||
resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
|
resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
|
||||||
DefWithBodyId,
|
DefWithBodyId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,8 +7,8 @@ use std::fmt::{self, Debug};
|
||||||
use base_db::CrateId;
|
use base_db::CrateId;
|
||||||
use chalk_ir::{BoundVar, TyKind};
|
use chalk_ir::{BoundVar, TyKind};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
|
||||||
body,
|
body,
|
||||||
|
data::adt::VariantData,
|
||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
find_path,
|
find_path,
|
||||||
generics::{TypeOrConstParamData, TypeParamProvenance},
|
generics::{TypeOrConstParamData, TypeParamProvenance},
|
||||||
|
|
|
@ -18,12 +18,12 @@ use std::{convert::identity, ops::Index};
|
||||||
|
|
||||||
use chalk_ir::{cast::Cast, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags};
|
use chalk_ir::{cast::Cast, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::expr::LabelId;
|
use hir_def::hir::LabelId;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::Body,
|
body::Body,
|
||||||
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
|
||||||
data::{ConstData, StaticData},
|
data::{ConstData, StaticData},
|
||||||
expr::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, PatId},
|
hir::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, PatId},
|
||||||
lang_item::{LangItem, LangItemTarget},
|
lang_item::{LangItem, LangItemTarget},
|
||||||
layout::Integer,
|
layout::Integer,
|
||||||
path::{ModPath, Path},
|
path::{ModPath, Path},
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
//! Inference of closure parameter types based on the closure's expected type.
|
//! Inference of closure parameter types based on the closure's expected type.
|
||||||
|
|
||||||
use chalk_ir::{cast::Cast, AliasEq, AliasTy, FnSubst, WhereClause};
|
use chalk_ir::{cast::Cast, AliasEq, AliasTy, FnSubst, WhereClause};
|
||||||
use hir_def::{expr::ExprId, HasModule};
|
use hir_def::{hir::ExprId, HasModule};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
|
@ -9,7 +9,7 @@ use std::{iter, sync::Arc};
|
||||||
|
|
||||||
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyVariableKind};
|
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyVariableKind};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::ExprId,
|
hir::ExprId,
|
||||||
lang_item::{LangItem, LangItemTarget},
|
lang_item::{LangItem, LangItemTarget},
|
||||||
};
|
};
|
||||||
use stdx::always;
|
use stdx::always;
|
||||||
|
|
|
@ -10,10 +10,10 @@ use chalk_ir::{
|
||||||
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyKind, TyVariableKind,
|
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyKind, TyVariableKind,
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::{
|
generics::TypeOrConstParamData,
|
||||||
|
hir::{
|
||||||
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
|
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
|
||||||
},
|
},
|
||||||
generics::TypeOrConstParamData,
|
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
path::{GenericArg, GenericArgs},
|
path::{GenericArg, GenericArgs},
|
||||||
BlockId, ConstParamId, FieldId, ItemContainerId, Lookup,
|
BlockId, ConstParamId, FieldId, ItemContainerId, Lookup,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use chalk_ir::Mutability;
|
use chalk_ir::Mutability;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::{Array, BindingAnnotation, Expr, ExprId, PatId, Statement, UnaryOp},
|
hir::{Array, BindingAnnotation, Expr, ExprId, PatId, Statement, UnaryOp},
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
};
|
};
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::iter::repeat_with;
|
||||||
use chalk_ir::Mutability;
|
use chalk_ir::Mutability;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::Body,
|
body::Body,
|
||||||
expr::{Binding, BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, Literal, Pat, PatId},
|
hir::{Binding, BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, Literal, Pat, PatId},
|
||||||
path::Path,
|
path::Path,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
|
|
@ -6,8 +6,8 @@ use chalk_ir::{
|
||||||
DebruijnIndex,
|
DebruijnIndex,
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData, attr::Attrs, visibility::Visibility, AdtId, EnumVariantId, HasModule, Lookup,
|
attr::Attrs, data::adt::VariantData, visibility::Visibility, AdtId, EnumVariantId, HasModule,
|
||||||
ModuleId, VariantId,
|
Lookup, ModuleId, VariantId,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! Functions to detect special lang items
|
//! Functions to detect special lang items
|
||||||
|
|
||||||
use hir_def::{adt::StructFlags, lang_item::LangItem, AdtId};
|
use hir_def::{data::adt::StructFlags, lang_item::LangItem, AdtId};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
|
|
||||||
use crate::db::HirDatabase;
|
use crate::db::HirDatabase;
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use std::ops::Bound;
|
use std::ops::Bound;
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
data::adt::VariantData,
|
||||||
layout::{Integer, IntegerExt, Layout, LayoutCalculator, LayoutError, RustcEnumVariantIdx},
|
layout::{Integer, IntegerExt, Layout, LayoutCalculator, LayoutError, RustcEnumVariantIdx},
|
||||||
AdtId, EnumVariantId, HasModule, LocalEnumVariantId, VariantId,
|
AdtId, EnumVariantId, HasModule, LocalEnumVariantId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -44,7 +44,7 @@ use chalk_ir::{
|
||||||
NoSolution, TyData,
|
NoSolution, TyData,
|
||||||
};
|
};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{expr::ExprId, type_ref::Rawness, TypeOrConstParamId};
|
use hir_def::{hir::ExprId, type_ref::Rawness, TypeOrConstParamId};
|
||||||
use hir_expand::name;
|
use hir_expand::name;
|
||||||
use la_arena::{Arena, Idx};
|
use la_arena::{Arena, Idx};
|
||||||
use mir::MirEvalError;
|
use mir::MirEvalError;
|
||||||
|
|
|
@ -18,9 +18,9 @@ use chalk_ir::{
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::StructKind,
|
|
||||||
body::{Expander, LowerCtx},
|
body::{Expander, LowerCtx},
|
||||||
builtin_type::BuiltinType,
|
builtin_type::BuiltinType,
|
||||||
|
data::adt::StructKind,
|
||||||
generics::{
|
generics::{
|
||||||
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,9 +7,11 @@ use std::{ops::ControlFlow, sync::Arc};
|
||||||
use base_db::{CrateId, Edition};
|
use base_db::{CrateId, Edition};
|
||||||
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
|
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::StructFlags, data::ImplData, item_scope::ItemScope, nameres::DefMap, AssocItemId, BlockId,
|
data::{adt::StructFlags, ImplData},
|
||||||
ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup, ModuleDefId, ModuleId,
|
item_scope::ItemScope,
|
||||||
TraitId,
|
nameres::DefMap,
|
||||||
|
AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup,
|
||||||
|
ModuleDefId, ModuleId, TraitId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use rustc_hash::{FxHashMap, FxHashSet};
|
use rustc_hash::{FxHashMap, FxHashSet};
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use chalk_ir::Mutability;
|
use chalk_ir::Mutability;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::{BindingId, Expr, ExprId, Ordering, PatId},
|
hir::{BindingId, Expr, ExprId, Ordering, PatId},
|
||||||
DefWithBodyId, FieldId, UnionId, VariantId,
|
DefWithBodyId, FieldId, UnionId, VariantId,
|
||||||
};
|
};
|
||||||
use la_arena::{Arena, ArenaMap, Idx, RawIdx};
|
use la_arena::{Arena, ArenaMap, Idx, RawIdx};
|
||||||
|
@ -588,32 +588,32 @@ impl Display for BinOp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<hir_def::expr::ArithOp> for BinOp {
|
impl From<hir_def::hir::ArithOp> for BinOp {
|
||||||
fn from(value: hir_def::expr::ArithOp) -> Self {
|
fn from(value: hir_def::hir::ArithOp) -> Self {
|
||||||
match value {
|
match value {
|
||||||
hir_def::expr::ArithOp::Add => BinOp::Add,
|
hir_def::hir::ArithOp::Add => BinOp::Add,
|
||||||
hir_def::expr::ArithOp::Mul => BinOp::Mul,
|
hir_def::hir::ArithOp::Mul => BinOp::Mul,
|
||||||
hir_def::expr::ArithOp::Sub => BinOp::Sub,
|
hir_def::hir::ArithOp::Sub => BinOp::Sub,
|
||||||
hir_def::expr::ArithOp::Div => BinOp::Div,
|
hir_def::hir::ArithOp::Div => BinOp::Div,
|
||||||
hir_def::expr::ArithOp::Rem => BinOp::Rem,
|
hir_def::hir::ArithOp::Rem => BinOp::Rem,
|
||||||
hir_def::expr::ArithOp::Shl => BinOp::Shl,
|
hir_def::hir::ArithOp::Shl => BinOp::Shl,
|
||||||
hir_def::expr::ArithOp::Shr => BinOp::Shr,
|
hir_def::hir::ArithOp::Shr => BinOp::Shr,
|
||||||
hir_def::expr::ArithOp::BitXor => BinOp::BitXor,
|
hir_def::hir::ArithOp::BitXor => BinOp::BitXor,
|
||||||
hir_def::expr::ArithOp::BitOr => BinOp::BitOr,
|
hir_def::hir::ArithOp::BitOr => BinOp::BitOr,
|
||||||
hir_def::expr::ArithOp::BitAnd => BinOp::BitAnd,
|
hir_def::hir::ArithOp::BitAnd => BinOp::BitAnd,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<hir_def::expr::CmpOp> for BinOp {
|
impl From<hir_def::hir::CmpOp> for BinOp {
|
||||||
fn from(value: hir_def::expr::CmpOp) -> Self {
|
fn from(value: hir_def::hir::CmpOp) -> Self {
|
||||||
match value {
|
match value {
|
||||||
hir_def::expr::CmpOp::Eq { negated: false } => BinOp::Eq,
|
hir_def::hir::CmpOp::Eq { negated: false } => BinOp::Eq,
|
||||||
hir_def::expr::CmpOp::Eq { negated: true } => BinOp::Ne,
|
hir_def::hir::CmpOp::Eq { negated: true } => BinOp::Ne,
|
||||||
hir_def::expr::CmpOp::Ord { ordering: Ordering::Greater, strict: false } => BinOp::Ge,
|
hir_def::hir::CmpOp::Ord { ordering: Ordering::Greater, strict: false } => BinOp::Ge,
|
||||||
hir_def::expr::CmpOp::Ord { ordering: Ordering::Greater, strict: true } => BinOp::Gt,
|
hir_def::hir::CmpOp::Ord { ordering: Ordering::Greater, strict: true } => BinOp::Gt,
|
||||||
hir_def::expr::CmpOp::Ord { ordering: Ordering::Less, strict: false } => BinOp::Le,
|
hir_def::hir::CmpOp::Ord { ordering: Ordering::Less, strict: false } => BinOp::Le,
|
||||||
hir_def::expr::CmpOp::Ord { ordering: Ordering::Less, strict: true } => BinOp::Lt,
|
hir_def::hir::CmpOp::Ord { ordering: Ordering::Less, strict: true } => BinOp::Lt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ use std::{iter, mem, sync::Arc};
|
||||||
|
|
||||||
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
|
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::{StructKind, VariantData},
|
|
||||||
body::Body,
|
body::Body,
|
||||||
expr::{
|
data::adt::{StructKind, VariantData},
|
||||||
|
hir::{
|
||||||
Array, BindingAnnotation, BindingId, ExprId, LabelId, Literal, MatchArm, Pat, PatId,
|
Array, BindingAnnotation, BindingId, ExprId, LabelId, Literal, MatchArm, Pat, PatId,
|
||||||
RecordFieldPat, RecordLitField,
|
RecordFieldPat, RecordLitField,
|
||||||
},
|
},
|
||||||
|
@ -713,20 +713,20 @@ impl MirLowerCtx<'_> {
|
||||||
Ok(Some(current))
|
Ok(Some(current))
|
||||||
}
|
}
|
||||||
Expr::Box { .. } => not_supported!("box expression"),
|
Expr::Box { .. } => not_supported!("box expression"),
|
||||||
Expr::Field { .. } | Expr::Index { .. } | Expr::UnaryOp { op: hir_def::expr::UnaryOp::Deref, .. } => {
|
Expr::Field { .. } | Expr::Index { .. } | Expr::UnaryOp { op: hir_def::hir::UnaryOp::Deref, .. } => {
|
||||||
let Some((p, current)) = self.lower_expr_as_place_without_adjust(current, expr_id, true)? else {
|
let Some((p, current)) = self.lower_expr_as_place_without_adjust(current, expr_id, true)? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
|
self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
|
||||||
Ok(Some(current))
|
Ok(Some(current))
|
||||||
}
|
}
|
||||||
Expr::UnaryOp { expr, op: op @ (hir_def::expr::UnaryOp::Not | hir_def::expr::UnaryOp::Neg) } => {
|
Expr::UnaryOp { expr, op: op @ (hir_def::hir::UnaryOp::Not | hir_def::hir::UnaryOp::Neg) } => {
|
||||||
let Some((operand, current)) = self.lower_expr_to_some_operand(*expr, current)? else {
|
let Some((operand, current)) = self.lower_expr_to_some_operand(*expr, current)? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
let operation = match op {
|
let operation = match op {
|
||||||
hir_def::expr::UnaryOp::Not => UnOp::Not,
|
hir_def::hir::UnaryOp::Not => UnOp::Not,
|
||||||
hir_def::expr::UnaryOp::Neg => UnOp::Neg,
|
hir_def::hir::UnaryOp::Neg => UnOp::Neg,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
self.push_assignment(
|
self.push_assignment(
|
||||||
|
@ -739,7 +739,7 @@ impl MirLowerCtx<'_> {
|
||||||
},
|
},
|
||||||
Expr::BinaryOp { lhs, rhs, op } => {
|
Expr::BinaryOp { lhs, rhs, op } => {
|
||||||
let op = op.ok_or(MirLowerError::IncompleteExpr)?;
|
let op = op.ok_or(MirLowerError::IncompleteExpr)?;
|
||||||
if let hir_def::expr::BinaryOp::Assignment { op } = op {
|
if let hir_def::hir::BinaryOp::Assignment { op } = op {
|
||||||
if op.is_some() {
|
if op.is_some() {
|
||||||
not_supported!("assignment with arith op (like +=)");
|
not_supported!("assignment with arith op (like +=)");
|
||||||
}
|
}
|
||||||
|
@ -765,13 +765,13 @@ impl MirLowerCtx<'_> {
|
||||||
place,
|
place,
|
||||||
Rvalue::CheckedBinaryOp(
|
Rvalue::CheckedBinaryOp(
|
||||||
match op {
|
match op {
|
||||||
hir_def::expr::BinaryOp::LogicOp(op) => match op {
|
hir_def::hir::BinaryOp::LogicOp(op) => match op {
|
||||||
hir_def::expr::LogicOp::And => BinOp::BitAnd, // FIXME: make these short circuit
|
hir_def::hir::LogicOp::And => BinOp::BitAnd, // FIXME: make these short circuit
|
||||||
hir_def::expr::LogicOp::Or => BinOp::BitOr,
|
hir_def::hir::LogicOp::Or => BinOp::BitOr,
|
||||||
},
|
},
|
||||||
hir_def::expr::BinaryOp::ArithOp(op) => BinOp::from(op),
|
hir_def::hir::BinaryOp::ArithOp(op) => BinOp::from(op),
|
||||||
hir_def::expr::BinaryOp::CmpOp(op) => BinOp::from(op),
|
hir_def::hir::BinaryOp::CmpOp(op) => BinOp::from(op),
|
||||||
hir_def::expr::BinaryOp::Assignment { .. } => unreachable!(), // handled above
|
hir_def::hir::BinaryOp::Assignment { .. } => unreachable!(), // handled above
|
||||||
},
|
},
|
||||||
lhs_op,
|
lhs_op,
|
||||||
rhs_op,
|
rhs_op,
|
||||||
|
@ -910,7 +910,7 @@ impl MirLowerCtx<'_> {
|
||||||
.size
|
.size
|
||||||
.bytes_usize();
|
.bytes_usize();
|
||||||
let bytes = match l {
|
let bytes = match l {
|
||||||
hir_def::expr::Literal::String(b) => {
|
hir_def::hir::Literal::String(b) => {
|
||||||
let b = b.as_bytes();
|
let b = b.as_bytes();
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
data.extend(0usize.to_le_bytes());
|
data.extend(0usize.to_le_bytes());
|
||||||
|
@ -919,7 +919,7 @@ impl MirLowerCtx<'_> {
|
||||||
mm.insert(0, b.to_vec());
|
mm.insert(0, b.to_vec());
|
||||||
return Ok(Operand::from_concrete_const(data, mm, ty));
|
return Ok(Operand::from_concrete_const(data, mm, ty));
|
||||||
}
|
}
|
||||||
hir_def::expr::Literal::ByteString(b) => {
|
hir_def::hir::Literal::ByteString(b) => {
|
||||||
let mut data = vec![];
|
let mut data = vec![];
|
||||||
data.extend(0usize.to_le_bytes());
|
data.extend(0usize.to_le_bytes());
|
||||||
data.extend(b.len().to_le_bytes());
|
data.extend(b.len().to_le_bytes());
|
||||||
|
@ -927,11 +927,11 @@ impl MirLowerCtx<'_> {
|
||||||
mm.insert(0, b.to_vec());
|
mm.insert(0, b.to_vec());
|
||||||
return Ok(Operand::from_concrete_const(data, mm, ty));
|
return Ok(Operand::from_concrete_const(data, mm, ty));
|
||||||
}
|
}
|
||||||
hir_def::expr::Literal::Char(c) => u32::from(*c).to_le_bytes().into(),
|
hir_def::hir::Literal::Char(c) => u32::from(*c).to_le_bytes().into(),
|
||||||
hir_def::expr::Literal::Bool(b) => vec![*b as u8],
|
hir_def::hir::Literal::Bool(b) => vec![*b as u8],
|
||||||
hir_def::expr::Literal::Int(x, _) => x.to_le_bytes()[0..size].into(),
|
hir_def::hir::Literal::Int(x, _) => x.to_le_bytes()[0..size].into(),
|
||||||
hir_def::expr::Literal::Uint(x, _) => x.to_le_bytes()[0..size].into(),
|
hir_def::hir::Literal::Uint(x, _) => x.to_le_bytes()[0..size].into(),
|
||||||
hir_def::expr::Literal::Float(f, _) => match size {
|
hir_def::hir::Literal::Float(f, _) => match size {
|
||||||
8 => f.into_f64().to_le_bytes().into(),
|
8 => f.into_f64().to_le_bytes().into(),
|
||||||
4 => f.into_f32().to_le_bytes().into(),
|
4 => f.into_f32().to_le_bytes().into(),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -1218,14 +1218,14 @@ impl MirLowerCtx<'_> {
|
||||||
|
|
||||||
fn lower_block_to_place(
|
fn lower_block_to_place(
|
||||||
&mut self,
|
&mut self,
|
||||||
statements: &[hir_def::expr::Statement],
|
statements: &[hir_def::hir::Statement],
|
||||||
mut current: BasicBlockId,
|
mut current: BasicBlockId,
|
||||||
tail: Option<ExprId>,
|
tail: Option<ExprId>,
|
||||||
place: Place,
|
place: Place,
|
||||||
) -> Result<Option<Idx<BasicBlock>>> {
|
) -> Result<Option<Idx<BasicBlock>>> {
|
||||||
for statement in statements.iter() {
|
for statement in statements.iter() {
|
||||||
match statement {
|
match statement {
|
||||||
hir_def::expr::Statement::Let { pat, initializer, else_branch, type_ref: _ } => {
|
hir_def::hir::Statement::Let { pat, initializer, else_branch, type_ref: _ } => {
|
||||||
if let Some(expr_id) = initializer {
|
if let Some(expr_id) = initializer {
|
||||||
let else_block;
|
let else_block;
|
||||||
let Some((init_place, c)) =
|
let Some((init_place, c)) =
|
||||||
|
@ -1261,7 +1261,7 @@ impl MirLowerCtx<'_> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hir_def::expr::Statement::Expr { expr, has_semi: _ } => {
|
hir_def::hir::Statement::Expr { expr, has_semi: _ } => {
|
||||||
let Some((_, c)) = self.lower_expr_as_place(current, *expr, true)? else {
|
let Some((_, c)) = self.lower_expr_as_place(current, *expr, true)? else {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
};
|
};
|
||||||
|
|
|
@ -141,7 +141,7 @@ impl MirLowerCtx<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Expr::UnaryOp { expr, op } => match op {
|
Expr::UnaryOp { expr, op } => match op {
|
||||||
hir_def::expr::UnaryOp::Deref => {
|
hir_def::hir::UnaryOp::Deref => {
|
||||||
if !matches!(
|
if !matches!(
|
||||||
self.expr_ty(*expr).kind(Interner),
|
self.expr_ty(*expr).kind(Interner),
|
||||||
TyKind::Ref(..) | TyKind::Raw(..)
|
TyKind::Ref(..) | TyKind::Raw(..)
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use std::fmt::{Debug, Display, Write};
|
use std::fmt::{Debug, Display, Write};
|
||||||
|
|
||||||
use hir_def::{body::Body, expr::BindingId};
|
use hir_def::{body::Body, hir::BindingId};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use la_arena::ArenaMap;
|
use la_arena::ArenaMap;
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ use expect_test::Expect;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{Body, BodySourceMap, SyntheticSyntax},
|
body::{Body, BodySourceMap, SyntheticSyntax},
|
||||||
db::{DefDatabase, InternDatabase},
|
db::{DefDatabase, InternDatabase},
|
||||||
expr::{ExprId, PatId},
|
hir::{ExprId, PatId},
|
||||||
item_scope::ItemScope,
|
item_scope::ItemScope,
|
||||||
nameres::DefMap,
|
nameres::DefMap,
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
|
@ -198,8 +198,8 @@ fn check_impl(ra_fixture: &str, allow_none: bool, only_types: bool, display_sour
|
||||||
|
|
||||||
for (expr_or_pat, mismatch) in inference_result.type_mismatches() {
|
for (expr_or_pat, mismatch) in inference_result.type_mismatches() {
|
||||||
let Some(node) = (match expr_or_pat {
|
let Some(node) = (match expr_or_pat {
|
||||||
hir_def::expr::ExprOrPatId::ExprId(expr) => expr_node(&body_source_map, expr, &db),
|
hir_def::hir::ExprOrPatId::ExprId(expr) => expr_node(&body_source_map, expr, &db),
|
||||||
hir_def::expr::ExprOrPatId::PatId(pat) => pat_node(&body_source_map, pat, &db),
|
hir_def::hir::ExprOrPatId::PatId(pat) => pat_node(&body_source_map, pat, &db),
|
||||||
}) else { continue; };
|
}) else { continue; };
|
||||||
let range = node.as_ref().original_file_range(&db);
|
let range = node.as_ref().original_file_range(&db);
|
||||||
let actual = format!(
|
let actual = format!(
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! HirDisplay implementations for various hir types.
|
//! HirDisplay implementations for various hir types.
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
data::adt::VariantData,
|
||||||
generics::{
|
generics::{
|
||||||
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! are splitting the hir.
|
//! are splitting the hir.
|
||||||
|
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
expr::{BindingId, LabelId},
|
hir::{BindingId, LabelId},
|
||||||
AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, GenericParamId,
|
AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, GenericParamId,
|
||||||
ModuleDefId, VariantId,
|
ModuleDefId, VariantId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -39,10 +39,10 @@ use arrayvec::ArrayVec;
|
||||||
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
|
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
|
||||||
body::{BodyDiagnostic, SyntheticSyntax},
|
body::{BodyDiagnostic, SyntheticSyntax},
|
||||||
expr::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
|
data::adt::VariantData,
|
||||||
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
|
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
|
||||||
|
hir::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
|
||||||
item_tree::ItemTreeNode,
|
item_tree::ItemTreeNode,
|
||||||
lang_item::{LangItem, LangItemTarget},
|
lang_item::{LangItem, LangItemTarget},
|
||||||
layout::{Layout, LayoutError, ReprOptions},
|
layout::{Layout, LayoutError, ReprOptions},
|
||||||
|
@ -109,9 +109,8 @@ pub use crate::{
|
||||||
pub use {
|
pub use {
|
||||||
cfg::{CfgAtom, CfgExpr, CfgOptions},
|
cfg::{CfgAtom, CfgExpr, CfgOptions},
|
||||||
hir_def::{
|
hir_def::{
|
||||||
adt::StructKind,
|
attr::{builtin::AttributeTemplate, Attrs, AttrsWithOwner, Documentation},
|
||||||
attr::{Attrs, AttrsWithOwner, Documentation},
|
data::adt::StructKind,
|
||||||
builtin_attr::AttributeTemplate,
|
|
||||||
find_path::PrefixKind,
|
find_path::PrefixKind,
|
||||||
import_map,
|
import_map,
|
||||||
nameres::ModuleSource,
|
nameres::ModuleSource,
|
||||||
|
@ -2697,9 +2696,7 @@ impl BuiltinAttr {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn builtin(name: &str) -> Option<Self> {
|
fn builtin(name: &str) -> Option<Self> {
|
||||||
hir_def::builtin_attr::INERT_ATTRIBUTES
|
hir_def::attr::builtin::find_builtin_attr_idx(name)
|
||||||
.iter()
|
|
||||||
.position(|tool| tool.name == name)
|
|
||||||
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
|
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2707,14 +2704,14 @@ impl BuiltinAttr {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
|
Some(krate) => db.crate_def_map(krate).registered_attrs()[self.idx as usize].clone(),
|
||||||
None => SmolStr::new(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].name),
|
None => SmolStr::new(hir_def::attr::builtin::INERT_ATTRIBUTES[self.idx as usize].name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
pub fn template(&self, _: &dyn HirDatabase) -> Option<AttributeTemplate> {
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(_) => None,
|
Some(_) => None,
|
||||||
None => Some(hir_def::builtin_attr::INERT_ATTRIBUTES[self.idx as usize].template),
|
None => Some(hir_def::attr::builtin::INERT_ATTRIBUTES[self.idx as usize].template),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2737,7 +2734,7 @@ impl ToolModule {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn builtin(name: &str) -> Option<Self> {
|
fn builtin(name: &str) -> Option<Self> {
|
||||||
hir_def::builtin_attr::TOOL_MODULES
|
hir_def::attr::builtin::TOOL_MODULES
|
||||||
.iter()
|
.iter()
|
||||||
.position(|&tool| tool == name)
|
.position(|&tool| tool == name)
|
||||||
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
|
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
|
||||||
|
@ -2747,7 +2744,7 @@ impl ToolModule {
|
||||||
// FIXME: Return a `Name` here
|
// FIXME: Return a `Name` here
|
||||||
match self.krate {
|
match self.krate {
|
||||||
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
|
Some(krate) => db.crate_def_map(krate).registered_tools()[self.idx as usize].clone(),
|
||||||
None => SmolStr::new(hir_def::builtin_attr::TOOL_MODULES[self.idx as usize]),
|
None => SmolStr::new(hir_def::attr::builtin::TOOL_MODULES[self.idx as usize]),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,7 @@ use base_db::{FileId, FileRange};
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body,
|
body,
|
||||||
expr::Expr,
|
hir::Expr,
|
||||||
macro_id_to_def_id,
|
macro_id_to_def_id,
|
||||||
resolver::{self, HasResolver, Resolver, TypeNs},
|
resolver::{self, HasResolver, Resolver, TypeNs},
|
||||||
type_ref::Mutability,
|
type_ref::Mutability,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
//! expression, an item definition.
|
//! expression, an item definition.
|
||||||
//!
|
//!
|
||||||
//! Knowing only the syntax gives us relatively little info. For example,
|
//! Knowing only the syntax gives us relatively little info. For example,
|
||||||
//! looking at the syntax of the function we can realise that it is a part of an
|
//! looking at the syntax of the function we can realize that it is a part of an
|
||||||
//! `impl` block, but we won't be able to tell what trait function the current
|
//! `impl` block, but we won't be able to tell what trait function the current
|
||||||
//! function overrides, and whether it does that correctly. For that, we need to
|
//! function overrides, and whether it does that correctly. For that, we need to
|
||||||
//! go from [`ast::Fn`] to [`crate::Function`], and that's exactly what this
|
//! go from [`ast::Fn`] to [`crate::Function`], and that's exactly what this
|
||||||
|
@ -88,9 +88,11 @@
|
||||||
use base_db::FileId;
|
use base_db::FileId;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
child_by_source::ChildBySource,
|
child_by_source::ChildBySource,
|
||||||
dyn_map::DynMap,
|
dyn_map::{
|
||||||
expr::{BindingId, LabelId},
|
keys::{self, Key},
|
||||||
keys::{self, Key},
|
DynMap,
|
||||||
|
},
|
||||||
|
hir::{BindingId, LabelId},
|
||||||
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
|
||||||
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
|
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
|
||||||
TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,
|
||||||
|
|
|
@ -17,7 +17,7 @@ use hir_def::{
|
||||||
scope::{ExprScopes, ScopeId},
|
scope::{ExprScopes, ScopeId},
|
||||||
Body, BodySourceMap,
|
Body, BodySourceMap,
|
||||||
},
|
},
|
||||||
expr::{ExprId, Pat, PatId},
|
hir::{ExprId, Pat, PatId},
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
macro_id_to_def_id,
|
macro_id_to_def_id,
|
||||||
path::{ModPath, Path, PathKind},
|
path::{ModPath, Path, PathKind},
|
||||||
|
|
|
@ -116,9 +116,11 @@ trait AddRewrite {
|
||||||
new: Vec<T>,
|
new: Vec<T>,
|
||||||
target: TextRange,
|
target: TextRange,
|
||||||
) -> Option<()>;
|
) -> Option<()>;
|
||||||
|
fn yeet() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AddRewrite for Assists {
|
impl AddRewrite for Assists {
|
||||||
|
fn yeet() {}
|
||||||
fn add_rewrite<T: AstNode>(
|
fn add_rewrite<T: AstNode>(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: &str,
|
label: &str,
|
||||||
|
|
|
@ -13,7 +13,7 @@ use hir::{
|
||||||
};
|
};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{BodySourceMap, SyntheticSyntax},
|
body::{BodySourceMap, SyntheticSyntax},
|
||||||
expr::{ExprId, PatId},
|
hir::{ExprId, PatId},
|
||||||
FunctionId,
|
FunctionId,
|
||||||
};
|
};
|
||||||
use hir_ty::{Interner, TyExt, TypeFlags};
|
use hir_ty::{Interner, TyExt, TypeFlags};
|
||||||
|
|
Loading…
Reference in a new issue