Skip to content

Commit 58da3fc

Browse files
committed
Auto merge of rust-lang#14517 - Veykril:hir-def-refac, r=Veykril
internal: Shuffle around some hir_def modules
2 parents 3dd17bc + 3f5c992 commit 58da3fc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+150
-145
lines changed

crates/hir-def/src/attr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! A higher level attributes based on TokenTree, with also some shortcuts.
22
3+
pub mod builtin;
4+
35
#[cfg(test)]
46
mod tests;
57

crates/hir-def/src/body.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr};
2525
use crate::{
2626
attr::Attrs,
2727
db::DefDatabase,
28-
expr::{
28+
hir::{
2929
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
3030
},
3131
item_scope::BuiltinShadowMode,

crates/hir-def/src/body/lower.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ use syntax::{
2626
};
2727

2828
use crate::{
29-
adt::StructKind,
30-
body::{Body, BodySourceMap, Expander, ExprPtr, LabelPtr, LabelSource, PatPtr},
31-
body::{BodyDiagnostic, ExprSource, PatSource},
29+
body::{
30+
Body, BodyDiagnostic, BodySourceMap, Expander, ExprPtr, ExprSource, LabelPtr, LabelSource,
31+
PatPtr, PatSource,
32+
},
3233
builtin_type::{BuiltinFloat, BuiltinInt, BuiltinUint},
34+
data::adt::StructKind,
3335
db::DefDatabase,
34-
expr::{
36+
hir::{
3537
dummy_expr_id, Array, Binding, BindingAnnotation, BindingId, ClosureKind, Expr, ExprId,
3638
FloatTypeWrapper, Label, LabelId, Literal, MatchArm, Movability, Pat, PatId,
3739
RecordFieldPat, RecordLitField, Statement,

crates/hir-def/src/body/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fmt::{self, Write};
55
use syntax::ast::HasName;
66

77
use crate::{
8-
expr::{Array, BindingAnnotation, BindingId, ClosureKind, Literal, Movability, Statement},
8+
hir::{Array, BindingAnnotation, BindingId, ClosureKind, Literal, Movability, Statement},
99
pretty::{print_generic_args, print_path, print_type_ref},
1010
type_ref::TypeRef,
1111
};

crates/hir-def/src/body/scope.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
88
use crate::{
99
body::Body,
1010
db::DefDatabase,
11-
expr::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
11+
hir::{Binding, BindingId, Expr, ExprId, LabelId, Pat, PatId, Statement},
1212
BlockId, DefWithBodyId,
1313
};
1414

crates/hir-def/src/child_by_source.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use syntax::ast::HasDocComments;
1010

1111
use crate::{
1212
db::DefDatabase,
13-
dyn_map::DynMap,
13+
dyn_map::{keys, DynMap},
1414
item_scope::ItemScope,
15-
keys,
1615
src::{HasChildSource, HasSource},
1716
AdtId, AssocItemId, DefWithBodyId, EnumId, EnumVariantId, FieldId, ImplId, Lookup, MacroId,
1817
ModuleDefId, ModuleId, TraitId, VariantId,

crates/hir-def/src/data.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Contains basic data about various HIR declarations.
22
3+
pub mod adt;
4+
35
use std::sync::Arc;
46

57
use hir_expand::{name::Name, AstId, ExpandResult, HirFileId, InFile, MacroCallId, MacroDefKind};
File renamed without changes.

crates/hir-def/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ use la_arena::ArenaMap;
99
use syntax::{ast, AstPtr};
1010

1111
use crate::{
12-
adt::{EnumData, StructData},
1312
attr::{Attrs, AttrsWithOwner},
1413
body::{scope::ExprScopes, Body, BodySourceMap},
1514
data::{
15+
adt::{EnumData, StructData},
1616
ConstData, FunctionData, ImplData, Macro2Data, MacroRulesData, ProcMacroData, StaticData,
1717
TraitAliasData, TraitData, TypeAliasData,
1818
},

crates/hir-def/src/dyn_map.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
//!
2222
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
2323
//! a coincidence.
24+
pub mod keys;
25+
2426
use std::{
2527
hash::Hash,
2628
marker::PhantomData,
File renamed without changes.

crates/hir-def/src/generics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ use crate::{
2020
body::{Expander, LowerCtx},
2121
child_by_source::ChildBySource,
2222
db::DefDatabase,
23-
dyn_map::DynMap,
24-
keys,
23+
dyn_map::{keys, DynMap},
2524
src::{HasChildSource, HasSource},
2625
type_ref::{LifetimeRef, TypeBound, TypeRef},
2726
AdtId, ConstParamId, GenericDefId, HasModule, LifetimeParamId, LocalLifetimeParamId,

crates/hir-def/src/expr.rs renamed to crates/hir-def/src/hir.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
//!
1313
//! See also a neighboring `body` module.
1414
15+
pub mod type_ref;
16+
1517
use std::fmt;
1618

1719
use hir_expand::name::Name;
@@ -28,10 +30,10 @@ use crate::{
2830

2931
pub use syntax::ast::{ArithOp, BinaryOp, CmpOp, LogicOp, Ordering, RangeOp, UnaryOp};
3032

31-
pub type ExprId = Idx<Expr>;
32-
3333
pub type BindingId = Idx<Binding>;
3434

35+
pub type ExprId = Idx<Expr>;
36+
3537
/// FIXME: this is a hacky function which should be removed
3638
pub(crate) fn dummy_expr_id() -> ExprId {
3739
ExprId::from_raw(RawIdx::from(u32::MAX))

crates/hir-def/src/type_ref.rs renamed to crates/hir-def/src/hir/type_ref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use syntax::ast::{self, HasName};
1313
use crate::{
1414
body::LowerCtx,
1515
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
16-
expr::Literal,
16+
hir::Literal,
1717
path::Path,
1818
};
1919

crates/hir-def/src/lib.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,21 @@ pub mod db;
1818

1919
pub mod attr;
2020
pub mod path;
21-
pub mod type_ref;
2221
pub mod builtin_type;
23-
pub mod builtin_attr;
2422
pub mod per_ns;
2523
pub mod item_scope;
2624

2725
pub mod dyn_map;
28-
pub mod keys;
2926

3027
pub mod item_tree;
3128

32-
pub mod adt;
3329
pub mod data;
3430
pub mod generics;
3531
pub mod lang_item;
3632
pub mod layout;
3733

38-
pub mod expr;
34+
pub mod hir;
35+
pub use self::hir::type_ref;
3936
pub mod body;
4037
pub mod resolver;
4138

@@ -82,8 +79,8 @@ use syntax::ast;
8279
use ::tt::token_id as tt;
8380

8481
use crate::{
85-
adt::VariantData,
8682
builtin_type::BuiltinType,
83+
data::adt::VariantData,
8784
item_tree::{
8885
Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules, ModItem,
8986
Static, Struct, Trait, TraitAlias, TypeAlias, Union,
@@ -236,15 +233,15 @@ pub struct EnumVariantId {
236233
pub local_id: LocalEnumVariantId,
237234
}
238235

239-
pub type LocalEnumVariantId = Idx<adt::EnumVariantData>;
236+
pub type LocalEnumVariantId = Idx<data::adt::EnumVariantData>;
240237

241238
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
242239
pub struct FieldId {
243240
pub parent: VariantId,
244241
pub local_id: LocalFieldId,
245242
}
246243

247-
pub type LocalFieldId = Idx<adt::FieldData>;
244+
pub type LocalFieldId = Idx<data::adt::FieldData>;
248245

249246
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
250247
pub struct ConstId(salsa::InternId);

crates/hir-def/src/nameres/attr_resolution.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use hir_expand::{attrs::Attr, MacroCallId};
44
use syntax::{ast, SmolStr};
55

66
use crate::{
7-
attr_macro_as_call_id, builtin_attr,
7+
attr::builtin::{find_builtin_attr_idx, TOOL_MODULES},
8+
attr_macro_as_call_id,
89
db::DefDatabase,
910
item_scope::BuiltinShadowMode,
1011
macro_id_to_def_id,
@@ -76,19 +77,15 @@ impl DefMap {
7677
let pred = |n: &_| *n == name;
7778

7879
let registered = self.registered_tools.iter().map(SmolStr::as_str);
79-
let is_tool = builtin_attr::TOOL_MODULES.iter().copied().chain(registered).any(pred);
80+
let is_tool = TOOL_MODULES.iter().copied().chain(registered).any(pred);
8081
// FIXME: tool modules can be shadowed by actual modules
8182
if is_tool {
8283
return true;
8384
}
8485

8586
if segments.len() == 1 {
86-
let registered = self.registered_attrs.iter().map(SmolStr::as_str);
87-
let is_inert = builtin_attr::INERT_ATTRIBUTES
88-
.iter()
89-
.map(|it| it.name)
90-
.chain(registered)
91-
.any(pred);
87+
let mut registered = self.registered_attrs.iter().map(SmolStr::as_str);
88+
let is_inert = find_builtin_attr_idx(&name).is_some() || registered.any(pred);
9289
return is_inert;
9390
}
9491
}

crates/hir-def/src/nameres/path_resolution.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,11 @@ impl DefMap {
331331
Some(local_id) => {
332332
let variant = EnumVariantId { parent: e, local_id };
333333
match &*enum_data.variants[local_id].variant_data {
334-
crate::adt::VariantData::Record(_) => {
334+
crate::data::adt::VariantData::Record(_) => {
335335
PerNs::types(variant.into(), Visibility::Public)
336336
}
337-
crate::adt::VariantData::Tuple(_)
338-
| crate::adt::VariantData::Unit => {
337+
crate::data::adt::VariantData::Tuple(_)
338+
| crate::data::adt::VariantData::Unit => {
339339
PerNs::both(variant.into(), variant.into(), Visibility::Public)
340340
}
341341
}

crates/hir-def/src/resolver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use crate::{
1212
body::scope::{ExprScopes, ScopeId},
1313
builtin_type::BuiltinType,
1414
db::DefDatabase,
15-
expr::{BindingId, ExprId, LabelId},
1615
generics::{GenericParams, TypeOrConstParamData},
16+
hir::{BindingId, ExprId, LabelId},
1717
item_scope::{BuiltinShadowMode, BUILTIN_SCOPE},
1818
lang_item::LangItemTarget,
1919
nameres::DefMap,

crates/hir-ty/src/chalk_db.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
99

1010
use base_db::CrateId;
1111
use hir_def::{
12-
expr::Movability,
12+
hir::Movability,
1313
lang_item::{lang_attr, LangItem, LangItemTarget},
1414
AssocItemId, BlockId, GenericDefId, HasModule, ItemContainerId, Lookup, TypeAliasId,
1515
};
@@ -415,8 +415,8 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
415415
let input_output = crate::make_type_and_const_binders(it, input_output);
416416

417417
let movability = match self.db.body(parent)[expr] {
418-
hir_def::expr::Expr::Closure {
419-
closure_kind: hir_def::expr::ClosureKind::Generator(movability),
418+
hir_def::hir::Expr::Closure {
419+
closure_kind: hir_def::hir::ClosureKind::Generator(movability),
420420
..
421421
} => movability,
422422
_ => unreachable!("non generator expression interned as generator"),

crates/hir-ty/src/consteval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use base_db::CrateId;
44
use chalk_ir::{BoundVar, DebruijnIndex, GenericArgData};
55
use hir_def::{
6-
expr::Expr,
6+
hir::Expr,
77
path::Path,
88
resolver::{Resolver, ValueNs},
99
type_ref::ConstRef,

crates/hir-ty/src/db.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::sync::Arc;
66
use base_db::{impl_intern_key, salsa, CrateId, Upcast};
77
use hir_def::{
88
db::DefDatabase,
9-
expr::ExprId,
9+
hir::ExprId,
1010
layout::{Layout, LayoutError, TargetDataLayout},
1111
AdtId, BlockId, ConstId, ConstParamId, DefWithBodyId, EnumVariantId, FunctionId, GenericDefId,
1212
ImplId, LifetimeParamId, LocalFieldId, TypeOrConstParamId, VariantId,

crates/hir-ty/src/diagnostics/decl_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use std::fmt;
1616

1717
use base_db::CrateId;
1818
use hir_def::{
19-
adt::VariantData,
20-
expr::{Pat, PatId},
19+
data::adt::VariantData,
20+
hir::{Pat, PatId},
2121
src::HasSource,
2222
AdtId, AttrDefId, ConstId, EnumId, FunctionId, ItemContainerId, Lookup, ModuleDefId, StaticId,
2323
StructId,

crates/hir-ty/src/diagnostics/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use crate::{
2727

2828
pub(crate) use hir_def::{
2929
body::Body,
30-
expr::{Expr, ExprId, MatchArm, Pat, PatId},
30+
hir::{Expr, ExprId, MatchArm, Pat, PatId},
3131
LocalFieldId, VariantId,
3232
};
3333

crates/hir-ty/src/diagnostics/match_check.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Validation of matches.
22
//!
3-
//! This module provides lowering from [hir_def::expr::Pat] to [self::Pat] and match
3+
//! This module provides lowering from [hir_def::hir::Pat] to [self::Pat] and match
44
//! checking algorithm.
55
//!
66
//! It is modeled on the rustc module `rustc_mir_build::thir::pattern`.
@@ -12,7 +12,7 @@ pub(crate) mod usefulness;
1212

1313
use chalk_ir::Mutability;
1414
use hir_def::{
15-
adt::VariantData, body::Body, expr::PatId, AdtId, EnumVariantId, LocalFieldId, VariantId,
15+
body::Body, data::adt::VariantData, hir::PatId, AdtId, EnumVariantId, LocalFieldId, VariantId,
1616
};
1717
use hir_expand::name::Name;
1818
use stdx::{always, never};
@@ -125,15 +125,15 @@ impl<'a> PatCtxt<'a> {
125125
let variant = self.infer.variant_resolution_for_pat(pat);
126126

127127
let kind = match self.body[pat] {
128-
hir_def::expr::Pat::Wild => PatKind::Wild,
128+
hir_def::hir::Pat::Wild => PatKind::Wild,
129129

130-
hir_def::expr::Pat::Lit(expr) => self.lower_lit(expr),
130+
hir_def::hir::Pat::Lit(expr) => self.lower_lit(expr),
131131

132-
hir_def::expr::Pat::Path(ref path) => {
132+
hir_def::hir::Pat::Path(ref path) => {
133133
return self.lower_path(pat, path);
134134
}
135135

136-
hir_def::expr::Pat::Tuple { ref args, ellipsis } => {
136+
hir_def::hir::Pat::Tuple { ref args, ellipsis } => {
137137
let arity = match *ty.kind(Interner) {
138138
TyKind::Tuple(arity, _) => arity,
139139
_ => {
@@ -146,7 +146,7 @@ impl<'a> PatCtxt<'a> {
146146
PatKind::Leaf { subpatterns }
147147
}
148148

149-
hir_def::expr::Pat::Bind { id, subpat, .. } => {
149+
hir_def::hir::Pat::Bind { id, subpat, .. } => {
150150
let bm = self.infer.pat_binding_modes[&pat];
151151
let name = &self.body.bindings[id].name;
152152
match (bm, ty.kind(Interner)) {
@@ -161,13 +161,13 @@ impl<'a> PatCtxt<'a> {
161161
PatKind::Binding { name: name.clone(), subpattern: self.lower_opt_pattern(subpat) }
162162
}
163163

164-
hir_def::expr::Pat::TupleStruct { ref args, ellipsis, .. } if variant.is_some() => {
164+
hir_def::hir::Pat::TupleStruct { ref args, ellipsis, .. } if variant.is_some() => {
165165
let expected_len = variant.unwrap().variant_data(self.db.upcast()).fields().len();
166166
let subpatterns = self.lower_tuple_subpats(args, expected_len, ellipsis);
167167
self.lower_variant_or_leaf(pat, ty, subpatterns)
168168
}
169169

170-
hir_def::expr::Pat::Record { ref args, .. } if variant.is_some() => {
170+
hir_def::hir::Pat::Record { ref args, .. } if variant.is_some() => {
171171
let variant_data = variant.unwrap().variant_data(self.db.upcast());
172172
let subpatterns = args
173173
.iter()
@@ -187,12 +187,12 @@ impl<'a> PatCtxt<'a> {
187187
}
188188
}
189189
}
190-
hir_def::expr::Pat::TupleStruct { .. } | hir_def::expr::Pat::Record { .. } => {
190+
hir_def::hir::Pat::TupleStruct { .. } | hir_def::hir::Pat::Record { .. } => {
191191
self.errors.push(PatternError::UnresolvedVariant);
192192
PatKind::Wild
193193
}
194194

195-
hir_def::expr::Pat::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
195+
hir_def::hir::Pat::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
196196

197197
_ => {
198198
self.errors.push(PatternError::Unimplemented);
@@ -279,8 +279,8 @@ impl<'a> PatCtxt<'a> {
279279
}
280280
}
281281

282-
fn lower_lit(&mut self, expr: hir_def::expr::ExprId) -> PatKind {
283-
use hir_def::expr::{Expr, Literal::Bool};
282+
fn lower_lit(&mut self, expr: hir_def::hir::ExprId) -> PatKind {
283+
use hir_def::hir::{Expr, Literal::Bool};
284284

285285
match self.body[expr] {
286286
Expr::Literal(Bool(value)) => PatKind::LiteralBool { value },

0 commit comments

Comments
 (0)