Auto merge of #14517 - Veykril:hir-def-refac, r=Veykril

internal: Shuffle around some hir_def modules
This commit is contained in:
bors 2023-04-06 17:58:28 +00:00
commit 58da3fc240
53 changed files with 150 additions and 145 deletions

View file

@ -1,5 +1,7 @@
//! A higher level attributes based on TokenTree, with also some shortcuts.
pub mod builtin;
#[cfg(test)]
mod tests;

View file

@ -25,7 +25,7 @@ use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr};
use crate::{
attr::Attrs,
db::DefDatabase,
expr::{
hir::{
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
},
item_scope::BuiltinShadowMode,

View file

@ -26,12 +26,14 @@ use syntax::{
};
use crate::{
adt::StructKind,
body::{Body, BodySourceMap, Expander, ExprPtr, LabelPtr, LabelSource, PatPtr},
body::{BodyDiagnostic, ExprSource, PatSource},
body::{
Body, BodyDiagnostic, BodySourceMap, Expander, ExprPtr, ExprSource, LabelPtr, LabelSource,
PatPtr, PatSource,
},
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
data::adt::StructKind,
db::DefDatabase,
expr::{
hir::{
dummy_expr_id, Array, Binding, BindingAnnotation, BindingId, ClosureKind, Expr, ExprId,
FloatTypeWrapper, Label, LabelId, Literal, MatchArm, Movability, Pat, PatId,
RecordFieldPat, RecordLitField, Statement,

View file

@ -5,7 +5,7 @@ use std::fmt::{self, Write};
use syntax::ast::HasName;
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},
type_ref::TypeRef,
};

View file

@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
use crate::{
body::Body,
db::DefDatabase,
expr::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
hir::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
BlockId, DefWithBodyId,
};

View file

@ -10,9 +10,8 @@ use syntax::ast::HasDocComments;
use crate::{
db::DefDatabase,
dyn_map::DynMap,
dyn_map::{keys, DynMap},
item_scope::ItemScope,
keys,
src::{HasChildSource, HasSource},
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, MacroId,
ModuleDefId, ModuleId, TraitId, VariantId,

View file

@ -1,5 +1,7 @@
//! Contains basic data about various HIR declarations.
pub mod adt;
use std::sync::Arc;
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};

View file

@ -9,10 +9,10 @@ use la_arena::ArenaMap;
use syntax::{ast, AstPtr};
use crate::{
adt::{EnumData, StructData},
attr::{Attrs, AttrsWithOwner},
body::{scope::ExprScopes, Body, BodySourceMap},
data::{
adt::{EnumData, StructData},
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
TraitAliasData, TraitData, TypeAliasData,
},

View file

@ -21,6 +21,8 @@
//!
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
//! a coincidence.
pub mod keys;
use std::{
hash::Hash,
marker::PhantomData,

View file

@ -20,8 +20,7 @@ use crate::{
body::{Expander, LowerCtx},
child_by_source::ChildBySource,
db::DefDatabase,
dyn_map::DynMap,
keys,
dyn_map::{keys, DynMap},
src::{HasChildSource, HasSource},
type_ref::{LifetimeRef, TypeBound, TypeRef},
AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId,

View file

@ -12,6 +12,8 @@
//!
//! See also a neighboring `body` module.
pub mod type_ref;
use std::fmt;
use hir_expand::name::Name;
@ -28,10 +30,10 @@ use crate::{
pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp};
pub type ExprId = Idx<Expr>;
pub type BindingId = Idx<Binding>;
pub type ExprId = Idx<Expr>;
/// FIXME: this is a hacky function which should be removed
pub(crate) fn dummy_expr_id() -> ExprId {
ExprId::from_raw(RawIdx::from(u32::MAX))

View file

@ -13,7 +13,7 @@ use syntax::ast::{self, HasName};
use crate::{
body::LowerCtx,
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
expr::Literal,
hir::Literal,
path::Path,
};

View file

@ -18,24 +18,21 @@ pub mod db;
pub mod attr;
pub mod path;
pub mod type_ref;
pub mod builtin_type;
pub mod builtin_attr;
pub mod per_ns;
pub mod item_scope;
pub mod dyn_map;
pub mod keys;
pub mod item_tree;
pub mod adt;
pub mod data;
pub mod generics;
pub mod lang_item;
pub mod layout;
pub mod expr;
pub mod hir;
pub use self::hir::type_ref;
pub mod body;
pub mod resolver;
@ -82,8 +79,8 @@ use syntax::ast;
use ::tt::token_id as tt;
use crate::{
adt::VariantData,
builtin_type::BuiltinType,
data::adt::VariantData,
item_tree::{
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
Static, Struct, Trait, TraitAlias, TypeAlias, Union,
@ -236,7 +233,7 @@ pub struct EnumVariantId {
pub local_id: LocalEnumVariantId,
}
pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
pub type LocalEnumVariantId = Idx<data::adt::EnumVariantData>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FieldId {
@ -244,7 +241,7 @@ pub struct FieldId {
pub local_id: LocalFieldId,
}
pub type LocalFieldId = Idx<adt::FieldData>;
pub type LocalFieldId = Idx<data::adt::FieldData>;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConstId(salsa::InternId);

View file

@ -4,7 +4,8 @@ use hir_expand::{attrs::Attr, MacroCallId};
use syntax::{ast, SmolStr};
use crate::{
attr_macro_as_call_id, builtin_attr,
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
attr_macro_as_call_id,
db::DefDatabase,
item_scope::BuiltinShadowMode,
macro_id_to_def_id,
@ -76,19 +77,15 @@ impl DefMap {
let pred = |n: &_| *n == name;
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
if is_tool {
return true;
}
if segments.len() == 1 {
let registered = self.registered_attrs.iter().map(SmolStr::as_str);
let is_inert = builtin_attr::INERT_ATTRIBUTES
.iter()
.map(|it| it.name)
.chain(registered)
.any(pred);
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
let is_inert = find_builtin_attr_idx(&name).is_some() || registered.any(pred);
return is_inert;
}
}

View file

@ -331,11 +331,11 @@ impl DefMap {
Some(local_id) => {
let variant = EnumVariantId { parent: e, local_id };
match &*enum_data.variants[local_id].variant_data {
crate::adt::VariantData::Record(_) => {
crate::data::adt::VariantData::Record(_) => {
PerNs::types(variant.into(), Visibility::Public)
}
crate::adt::VariantData::Tuple(_)
| crate::adt::VariantData::Unit => {
crate::data::adt::VariantData::Tuple(_)
| crate::data::adt::VariantData::Unit => {
PerNs::both(variant.into(), variant.into(), Visibility::Public)
}
}

View file

@ -12,8 +12,8 @@ use crate::{
body::scope::{ExprScopes, ScopeId},
builtin_type::BuiltinType,
db::DefDatabase,
expr::{BindingId, ExprId, LabelId},
generics::{GenericParams, TypeOrConstParamData},
hir::{BindingId, ExprId, LabelId},
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
lang_item::LangItemTarget,
nameres::DefMap,

View file

@ -9,7 +9,7 @@ use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
use base_db::CrateId;
use hir_def::{
expr::Movability,
hir::Movability,
lang_item::{lang_attr, LangItem, LangItemTarget},
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 movability = match self.db.body(parent)[expr] {
hir_def::expr::Expr::Closure {
closure_kind: hir_def::expr::ClosureKind::Generator(movability),
hir_def::hir::Expr::Closure {
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
..
} => movability,
_ => unreachable!("non generator expression interned as generator"),

View file

@ -3,7 +3,7 @@
use base_db::CrateId;
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData};
use hir_def::{
expr::Expr,
hir::Expr,
path::Path,
resolver::{Resolver, ValueNs},
type_ref::ConstRef,

View file

@ -6,7 +6,7 @@ use std::sync::Arc;
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
use hir_def::{
db::DefDatabase,
expr::ExprId,
hir::ExprId,
layout::{Layout, LayoutError, TargetDataLayout},
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GenericDefId,
ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,

View file

@ -16,8 +16,8 @@ use std::fmt;
use base_db::CrateId;
use hir_def::{
adt::VariantData,
expr::{Pat, PatId},
data::adt::VariantData,
hir::{Pat, PatId},
src::HasSource,
AdtId, AttrDefId, ConstId, EnumId, FunctionId, ItemContainerId, Lookup, ModuleDefId, StaticId,
StructId,

View file

@ -27,7 +27,7 @@ use crate::{
pub(crate) use hir_def::{
body::Body,
expr::{Expr, ExprId, MatchArm, Pat, PatId},
hir::{Expr, ExprId, MatchArm, Pat, PatId},
LocalFieldId, VariantId,
};

View file

@ -1,6 +1,6 @@
//! 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.
//!
//! 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 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 stdx::{always, never};
@ -125,15 +125,15 @@ impl<'a> PatCtxt<'a> {
let variant = self.infer.variant_resolution_for_pat(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);
}
hir_def::expr::Pat::Tuple { ref args, ellipsis } => {
hir_def::hir::Pat::Tuple { ref args, ellipsis } => {
let arity = match *ty.kind(Interner) {
TyKind::Tuple(arity, _) => arity,
_ => {
@ -146,7 +146,7 @@ impl<'a> PatCtxt<'a> {
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 name = &self.body.bindings[id].name;
match (bm, ty.kind(Interner)) {
@ -161,13 +161,13 @@ impl<'a> PatCtxt<'a> {
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 subpatterns = self.lower_tuple_subpats(args, expected_len, ellipsis);
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 subpatterns = args
.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);
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);
@ -279,8 +279,8 @@ impl<'a> PatCtxt<'a> {
}
}
fn lower_lit(&mut self, expr: hir_def::expr::ExprId) -> PatKind {
use hir_def::expr::{Expr, Literal::Bool};
fn lower_lit(&mut self, expr: hir_def::hir::ExprId) -> PatKind {
use hir_def::hir::{Expr, Literal::Bool};
match self.body[expr] {
Expr::Literal(Bool(value)) => PatKind::LiteralBool { value },

View file

@ -3,7 +3,7 @@
use hir_def::{
body::Body,
expr::{Expr, ExprId, UnaryOp},
hir::{Expr, ExprId, UnaryOp},
resolver::{resolver_for_expr, ResolveValueResult, ValueNs},
DefWithBodyId,
};

View file

@ -7,8 +7,8 @@ use std::fmt::{self, Debug};
use base_db::CrateId;
use chalk_ir::{BoundVar, TyKind};
use hir_def::{
adt::VariantData,
body,
data::adt::VariantData,
db::DefDatabase,
find_path,
generics::{TypeOrConstParamData, TypeParamProvenance},

View file

@ -18,12 +18,12 @@ use std::{convert::identity, ops::Index};
use chalk_ir::{cast::Cast, DebruijnIndex, Mutability, Safety, Scalar, TypeFlags};
use either::Either;
use hir_def::expr::LabelId;
use hir_def::hir::LabelId;
use hir_def::{
body::Body,
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
data::{ConstData, StaticData},
expr::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, PatId},
hir::{BindingAnnotation, BindingId, ExprId, ExprOrPatId, PatId},
lang_item::{LangItem, LangItemTarget},
layout::Integer,
path::{ModPath, Path},

View file

@ -1,7 +1,7 @@
//! Inference of closure parameter types based on the closure's expected type.
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 crate::{

View file

@ -9,7 +9,7 @@ use std::{iter, sync::Arc};
use chalk_ir::{cast::Cast, BoundVar, Goal, Mutability, TyVariableKind};
use hir_def::{
expr::ExprId,
hir::ExprId,
lang_item::{LangItem, LangItemTarget},
};
use stdx::always;

View file

@ -10,10 +10,10 @@ use chalk_ir::{
cast::Cast, fold::Shift, DebruijnIndex, GenericArgData, Mutability, TyKind, TyVariableKind,
};
use hir_def::{
expr::{
generics::TypeOrConstParamData,
hir::{
ArithOp, Array, BinaryOp, ClosureKind, Expr, ExprId, LabelId, Literal, Statement, UnaryOp,
},
generics::TypeOrConstParamData,
lang_item::LangItem,
path::{GenericArg, GenericArgs},
BlockId, ConstParamId, FieldId, ItemContainerId, Lookup,

View file

@ -3,7 +3,7 @@
use chalk_ir::Mutability;
use hir_def::{
expr::{Array, BindingAnnotation, Expr, ExprId, PatId, Statement, UnaryOp},
hir::{Array, BindingAnnotation, Expr, ExprId, PatId, Statement, UnaryOp},
lang_item::LangItem,
};
use hir_expand::name;

View file

@ -5,7 +5,7 @@ use std::iter::repeat_with;
use chalk_ir::Mutability;
use hir_def::{
body::Body,
expr::{Binding, BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, Literal, Pat, PatId},
hir::{Binding, BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, Literal, Pat, PatId},
path::Path,
};
use hir_expand::name::Name;

View file

@ -6,8 +6,8 @@ use chalk_ir::{
DebruijnIndex,
};
use hir_def::{
adt::VariantData, attr::Attrs, visibility::Visibility, AdtId, EnumVariantId, HasModule, Lookup,
ModuleId, VariantId,
attr::Attrs, data::adt::VariantData, visibility::Visibility, AdtId, EnumVariantId, HasModule,
Lookup, ModuleId, VariantId,
};
use rustc_hash::FxHashSet;

View file

@ -1,6 +1,6 @@
//! 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 crate::db::HirDatabase;

View file

@ -3,7 +3,7 @@
use std::ops::Bound;
use hir_def::{
adt::VariantData,
data::adt::VariantData,
layout::{Integer, IntegerExt, Layout, LayoutCalculator, LayoutError, RustcEnumVariantIdx},
AdtId, EnumVariantId, HasModule, LocalEnumVariantId, VariantId,
};

View file

@ -44,7 +44,7 @@ use chalk_ir::{
NoSolution, TyData,
};
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 la_arena::{Arena, Idx};
use mir::MirEvalError;

View file

@ -18,9 +18,9 @@ use chalk_ir::{
use either::Either;
use hir_def::{
adt::StructKind,
body::{Expander, LowerCtx},
builtin_type::BuiltinType,
data::adt::StructKind,
generics::{
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
},

View file

@ -7,9 +7,11 @@ use std::{ops::ControlFlow, sync::Arc};
use base_db::{CrateId, Edition};
use chalk_ir::{cast::Cast, Mutability, TyKind, UniverseIndex, WhereClause};
use hir_def::{
adt::StructFlags, data::ImplData, item_scope::ItemScope, nameres::DefMap, AssocItemId, BlockId,
ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup, ModuleDefId, ModuleId,
TraitId,
data::{adt::StructFlags, ImplData},
item_scope::ItemScope,
nameres::DefMap,
AssocItemId, BlockId, ConstId, FunctionId, HasModule, ImplId, ItemContainerId, Lookup,
ModuleDefId, ModuleId, TraitId,
};
use hir_expand::name::Name;
use rustc_hash::{FxHashMap, FxHashSet};

View file

@ -7,7 +7,7 @@ use crate::{
};
use chalk_ir::Mutability;
use hir_def::{
expr::{BindingId, Expr, ExprId, Ordering, PatId},
hir::{BindingId, Expr, ExprId, Ordering, PatId},
DefWithBodyId, FieldId, UnionId, VariantId,
};
use la_arena::{Arena, ArenaMap, Idx, RawIdx};
@ -588,32 +588,32 @@ impl Display for BinOp {
}
}
impl From<hir_def::expr::ArithOp> for BinOp {
fn from(value: hir_def::expr::ArithOp) -> Self {
impl From<hir_def::hir::ArithOp> for BinOp {
fn from(value: hir_def::hir::ArithOp) -> Self {
match value {
hir_def::expr::ArithOp::Add => BinOp::Add,
hir_def::expr::ArithOp::Mul => BinOp::Mul,
hir_def::expr::ArithOp::Sub => BinOp::Sub,
hir_def::expr::ArithOp::Div => BinOp::Div,
hir_def::expr::ArithOp::Rem => BinOp::Rem,
hir_def::expr::ArithOp::Shl => BinOp::Shl,
hir_def::expr::ArithOp::Shr => BinOp::Shr,
hir_def::expr::ArithOp::BitXor => BinOp::BitXor,
hir_def::expr::ArithOp::BitOr => BinOp::BitOr,
hir_def::expr::ArithOp::BitAnd => BinOp::BitAnd,
hir_def::hir::ArithOp::Add => BinOp::Add,
hir_def::hir::ArithOp::Mul => BinOp::Mul,
hir_def::hir::ArithOp::Sub => BinOp::Sub,
hir_def::hir::ArithOp::Div => BinOp::Div,
hir_def::hir::ArithOp::Rem => BinOp::Rem,
hir_def::hir::ArithOp::Shl => BinOp::Shl,
hir_def::hir::ArithOp::Shr => BinOp::Shr,
hir_def::hir::ArithOp::BitXor => BinOp::BitXor,
hir_def::hir::ArithOp::BitOr => BinOp::BitOr,
hir_def::hir::ArithOp::BitAnd => BinOp::BitAnd,
}
}
}
impl From<hir_def::expr::CmpOp> for BinOp {
fn from(value: hir_def::expr::CmpOp) -> Self {
impl From<hir_def::hir::CmpOp> for BinOp {
fn from(value: hir_def::hir::CmpOp) -> Self {
match value {
hir_def::expr::CmpOp::Eq { negated: false } => BinOp::Eq,
hir_def::expr::CmpOp::Eq { negated: true } => BinOp::Ne,
hir_def::expr::CmpOp::Ord { ordering: Ordering::Greater, strict: false } => BinOp::Ge,
hir_def::expr::CmpOp::Ord { ordering: Ordering::Greater, strict: true } => BinOp::Gt,
hir_def::expr::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::Eq { negated: false } => BinOp::Eq,
hir_def::hir::CmpOp::Eq { negated: true } => BinOp::Ne,
hir_def::hir::CmpOp::Ord { ordering: Ordering::Greater, strict: false } => BinOp::Ge,
hir_def::hir::CmpOp::Ord { ordering: Ordering::Greater, strict: true } => BinOp::Gt,
hir_def::hir::CmpOp::Ord { ordering: Ordering::Less, strict: false } => BinOp::Le,
hir_def::hir::CmpOp::Ord { ordering: Ordering::Less, strict: true } => BinOp::Lt,
}
}
}

View file

@ -4,9 +4,9 @@ use std::{iter, mem, sync::Arc};
use chalk_ir::{BoundVar, ConstData, DebruijnIndex, TyKind};
use hir_def::{
adt::{StructKind, VariantData},
body::Body,
expr::{
data::adt::{StructKind, VariantData},
hir::{
Array, BindingAnnotation, BindingId, ExprId, LabelId, Literal, MatchArm, Pat, PatId,
RecordFieldPat, RecordLitField,
},
@ -713,20 +713,20 @@ impl MirLowerCtx<'_> {
Ok(Some(current))
}
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 {
return Ok(None);
};
self.push_assignment(current, place, Operand::Copy(p).into(), expr_id.into());
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 {
return Ok(None);
};
let operation = match op {
hir_def::expr::UnaryOp::Not => UnOp::Not,
hir_def::expr::UnaryOp::Neg => UnOp::Neg,
hir_def::hir::UnaryOp::Not => UnOp::Not,
hir_def::hir::UnaryOp::Neg => UnOp::Neg,
_ => unreachable!(),
};
self.push_assignment(
@ -739,7 +739,7 @@ impl MirLowerCtx<'_> {
},
Expr::BinaryOp { lhs, rhs, op } => {
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() {
not_supported!("assignment with arith op (like +=)");
}
@ -765,13 +765,13 @@ impl MirLowerCtx<'_> {
place,
Rvalue::CheckedBinaryOp(
match op {
hir_def::expr::BinaryOp::LogicOp(op) => match op {
hir_def::expr::LogicOp::And => BinOp::BitAnd, // FIXME: make these short circuit
hir_def::expr::LogicOp::Or => BinOp::BitOr,
hir_def::hir::BinaryOp::LogicOp(op) => match op {
hir_def::hir::LogicOp::And => BinOp::BitAnd, // FIXME: make these short circuit
hir_def::hir::LogicOp::Or => BinOp::BitOr,
},
hir_def::expr::BinaryOp::ArithOp(op) => BinOp::from(op),
hir_def::expr::BinaryOp::CmpOp(op) => BinOp::from(op),
hir_def::expr::BinaryOp::Assignment { .. } => unreachable!(), // handled above
hir_def::hir::BinaryOp::ArithOp(op) => BinOp::from(op),
hir_def::hir::BinaryOp::CmpOp(op) => BinOp::from(op),
hir_def::hir::BinaryOp::Assignment { .. } => unreachable!(), // handled above
},
lhs_op,
rhs_op,
@ -910,7 +910,7 @@ impl MirLowerCtx<'_> {
.size
.bytes_usize();
let bytes = match l {
hir_def::expr::Literal::String(b) => {
hir_def::hir::Literal::String(b) => {
let b = b.as_bytes();
let mut data = vec![];
data.extend(0usize.to_le_bytes());
@ -919,7 +919,7 @@ impl MirLowerCtx<'_> {
mm.insert(0, b.to_vec());
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![];
data.extend(0usize.to_le_bytes());
data.extend(b.len().to_le_bytes());
@ -927,11 +927,11 @@ impl MirLowerCtx<'_> {
mm.insert(0, b.to_vec());
return Ok(Operand::from_concrete_const(data, mm, ty));
}
hir_def::expr::Literal::Char(c) => u32::from(*c).to_le_bytes().into(),
hir_def::expr::Literal::Bool(b) => vec![*b as u8],
hir_def::expr::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::expr::Literal::Float(f, _) => match size {
hir_def::hir::Literal::Char(c) => u32::from(*c).to_le_bytes().into(),
hir_def::hir::Literal::Bool(b) => vec![*b as u8],
hir_def::hir::Literal::Int(x, _) => x.to_le_bytes()[0..size].into(),
hir_def::hir::Literal::Uint(x, _) => x.to_le_bytes()[0..size].into(),
hir_def::hir::Literal::Float(f, _) => match size {
8 => f.into_f64().to_le_bytes().into(),
4 => f.into_f32().to_le_bytes().into(),
_ => {
@ -1218,14 +1218,14 @@ impl MirLowerCtx<'_> {
fn lower_block_to_place(
&mut self,
statements: &[hir_def::expr::Statement],
statements: &[hir_def::hir::Statement],
mut current: BasicBlockId,
tail: Option<ExprId>,
place: Place,
) -> Result<Option<Idx<BasicBlock>>> {
for statement in statements.iter() {
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 {
let else_block;
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 {
return Ok(None);
};

View file

@ -141,7 +141,7 @@ impl MirLowerCtx<'_> {
}
}
Expr::UnaryOp { expr, op } => match op {
hir_def::expr::UnaryOp::Deref => {
hir_def::hir::UnaryOp::Deref => {
if !matches!(
self.expr_ty(*expr).kind(Interner),
TyKind::Ref(..) | TyKind::Raw(..)

View file

@ -2,7 +2,7 @@
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 la_arena::ArenaMap;

View file

@ -17,7 +17,7 @@ use expect_test::Expect;
use hir_def::{
body::{Body, BodySourceMap, SyntheticSyntax},
db::{DefDatabase, InternDatabase},
expr::{ExprId, PatId},
hir::{ExprId, PatId},
item_scope::ItemScope,
nameres::DefMap,
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() {
let Some(node) = (match expr_or_pat {
hir_def::expr::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::ExprId(expr) => expr_node(&body_source_map, expr, &db),
hir_def::hir::ExprOrPatId::PatId(pat) => pat_node(&body_source_map, pat, &db),
}) else { continue; };
let range = node.as_ref().original_file_range(&db);
let actual = format!(

View file

@ -1,6 +1,6 @@
//! HirDisplay implementations for various hir types.
use hir_def::{
adt::VariantData,
data::adt::VariantData,
generics::{
TypeOrConstParamData, TypeParamProvenance, WherePredicate, WherePredicateTypeTarget,
},

View file

@ -4,7 +4,7 @@
//! are splitting the hir.
use hir_def::{
expr::{BindingId, LabelId},
hir::{BindingId, LabelId},
AdtId, AssocItemId, DefWithBodyId, EnumVariantId, FieldId, GenericDefId, GenericParamId,
ModuleDefId, VariantId,
};

View file

@ -39,10 +39,10 @@ use arrayvec::ArrayVec;
use base_db::{CrateDisplayName, CrateId, CrateOrigin, Edition, FileId, ProcMacroKind};
use either::Either;
use hir_def::{
adt::VariantData,
body::{BodyDiagnostic, SyntheticSyntax},
expr::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
data::adt::VariantData,
generics::{LifetimeParamData, TypeOrConstParamData, TypeParamProvenance},
hir::{BindingAnnotation, BindingId, ExprOrPatId, LabelId, Pat},
item_tree::ItemTreeNode,
lang_item::{LangItem, LangItemTarget},
layout::{Layout, LayoutError, ReprOptions},
@ -109,9 +109,8 @@ pub use crate::{
pub use {
cfg::{CfgAtom, CfgExpr, CfgOptions},
hir_def::{
adt::StructKind,
attr::{Attrs, AttrsWithOwner, Documentation},
builtin_attr::AttributeTemplate,
attr::{builtin::AttributeTemplate, Attrs, AttrsWithOwner, Documentation},
data::adt::StructKind,
find_path::PrefixKind,
import_map,
nameres::ModuleSource,
@ -2697,9 +2696,7 @@ impl BuiltinAttr {
}
fn builtin(name: &str) -> Option<Self> {
hir_def::builtin_attr::INERT_ATTRIBUTES
.iter()
.position(|tool| tool.name == name)
hir_def::attr::builtin::find_builtin_attr_idx(name)
.map(|idx| BuiltinAttr { krate: None, idx: idx as u32 })
}
@ -2707,14 +2704,14 @@ impl BuiltinAttr {
// FIXME: Return a `Name` here
match self.krate {
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> {
match self.krate {
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> {
hir_def::builtin_attr::TOOL_MODULES
hir_def::attr::builtin::TOOL_MODULES
.iter()
.position(|&tool| tool == name)
.map(|idx| ToolModule { krate: None, idx: idx as u32 })
@ -2747,7 +2744,7 @@ impl ToolModule {
// FIXME: Return a `Name` here
match self.krate {
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]),
}
}
}

View file

@ -8,7 +8,7 @@ use base_db::{FileId, FileRange};
use either::Either;
use hir_def::{
body,
expr::Expr,
hir::Expr,
macro_id_to_def_id,
resolver::{self, HasResolver, Resolver, TypeNs},
type_ref::Mutability,

View file

@ -14,7 +14,7 @@
//! expression, an item definition.
//!
//! 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
//! 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
@ -88,9 +88,11 @@
use base_db::FileId;
use hir_def::{
child_by_source::ChildBySource,
dyn_map::DynMap,
expr::{BindingId, LabelId},
keys::{self, Key},
dyn_map::{
keys::{self, Key},
DynMap,
},
hir::{BindingId, LabelId},
AdtId, ConstId, ConstParamId, DefWithBodyId, EnumId, EnumVariantId, FieldId, FunctionId,
GenericDefId, GenericParamId, ImplId, LifetimeParamId, MacroId, ModuleId, StaticId, StructId,
TraitAliasId, TraitId, TypeAliasId, TypeParamId, UnionId, VariantId,

View file

@ -17,7 +17,7 @@ use hir_def::{
scope::{ExprScopes, ScopeId},
Body, BodySourceMap,
},
expr::{ExprId, Pat, PatId},
hir::{ExprId, Pat, PatId},
lang_item::LangItem,
macro_id_to_def_id,
path::{ModPath, Path, PathKind},

View file

@ -116,9 +116,11 @@ trait AddRewrite {
new: Vec<T>,
target: TextRange,
) -> Option<()>;
fn yeet() {}
}
impl AddRewrite for Assists {
fn yeet() {}
fn add_rewrite<T: AstNode>(
&mut self,
label: &str,

View file

@ -13,7 +13,7 @@ use hir::{
};
use hir_def::{
body::{BodySourceMap, SyntheticSyntax},
expr::{ExprId, PatId},
hir::{ExprId, PatId},
FunctionId,
};
use hir_ty::{Interner, TyExt, TypeFlags};