Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,14 @@ vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }
edition = { path = "./crates/edition", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.126", default-features = false }
ra-ap-rustc_parse_format = { version = "0.126", default-features = false }
ra-ap-rustc_index = { version = "0.126", default-features = false }
ra-ap-rustc_abi = { version = "0.126", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.126", default-features = false }
ra-ap-rustc_ast_ir = { version = "0.126", default-features = false }
ra-ap-rustc_type_ir = { version = "0.126", default-features = false }
ra-ap-rustc_next_trait_solver = { version = "0.126", default-features = false }
ra-ap-rustc_lexer = { version = "0.128", default-features = false }
ra-ap-rustc_parse_format = { version = "0.128", default-features = false }
ra-ap-rustc_index = { version = "0.128", default-features = false }
ra-ap-rustc_abi = { version = "0.128", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.128", default-features = false }
ra-ap-rustc_ast_ir = { version = "0.128", default-features = false }
ra-ap-rustc_type_ir = { version = "0.128", default-features = false }
ra-ap-rustc_next_trait_solver = { version = "0.128", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.

Expand Down
13 changes: 13 additions & 0 deletions crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ impl LangItemTarget {
_ => None,
}
}

pub fn as_adt(self) -> Option<AdtId> {
match self {
LangItemTarget::Union(it) => Some(it.into()),
LangItemTarget::EnumId(it) => Some(it.into()),
LangItemTarget::Struct(it) => Some(it.into()),
_ => None,
}
}
}

/// Salsa query. This will look for lang items in a specific crate.
Expand Down Expand Up @@ -289,6 +298,10 @@ impl LangItem {
lang_item(db, start_crate, self).and_then(|t| t.as_trait())
}

pub fn resolve_adt(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<AdtId> {
lang_item(db, start_crate, self).and_then(|t| t.as_adt())
}

pub fn resolve_enum(self, db: &dyn DefDatabase, start_crate: Crate) -> Option<EnumId> {
lang_item(db, start_crate, self).and_then(|t| t.as_enum())
}
Expand Down
43 changes: 12 additions & 31 deletions crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ use crate::{
lt_from_placeholder_idx,
mir::pad16,
next_solver::{
BoundExistentialPredicate, Ctor, DbInterner, GenericArgs, SolverDefId,
BoundExistentialPredicate, DbInterner, GenericArgs, SolverDefId,
mapping::{
ChalkToNextSolver, convert_args_for_result, convert_const_for_result,
convert_region_for_result, convert_ty_for_result,
Expand Down Expand Up @@ -911,14 +911,13 @@ fn render_const_scalar_inner(
f.write_str("&")?;
render_const_scalar_ns(f, bytes, memory_map, t)
}
TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.def_id() {
SolverDefId::AdtId(hir_def::AdtId::StructId(s)) => {
TyKind::Adt(adt, _) if b.len() == 2 * size_of::<usize>() => match adt.def_id().0 {
hir_def::AdtId::StructId(s) => {
let data = f.db.struct_signature(s);
write!(f, "&{}", data.name.display(f.db, f.edition()))?;
Ok(())
}
SolverDefId::AdtId(_) => f.write_str("<unsized-enum-or-union>"),
_ => unreachable!(),
_ => f.write_str("<unsized-enum-or-union>"),
},
_ => {
let addr = usize::from_le_bytes(match b.try_into() {
Expand Down Expand Up @@ -966,10 +965,7 @@ fn render_const_scalar_inner(
f.write_str(")")
}
TyKind::Adt(def, args) => {
let def = match def.def_id() {
SolverDefId::AdtId(def) => def,
_ => unreachable!(),
};
let def = def.def_id().0;
let Ok(layout) = f.db.layout_of_adt(def, args, trait_env.clone()) else {
return f.write_str("<layout-error>");
};
Expand Down Expand Up @@ -1300,12 +1296,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
sig.hir_fmt(f)?;
}
TyKind::FnDef(def, args) => {
let def = match def {
SolverDefId::FunctionId(id) => CallableDefId::FunctionId(id),
SolverDefId::Ctor(Ctor::Enum(e)) => CallableDefId::EnumVariantId(e),
SolverDefId::Ctor(Ctor::Struct(s)) => CallableDefId::StructId(s),
_ => unreachable!(),
};
let def = def.0;
let sig = db
.callable_item_signature(def)
.substitute(Interner, &convert_args_for_result(interner, args.as_slice()));
Expand Down Expand Up @@ -1406,10 +1397,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
}
}
TyKind::Adt(def, parameters) => {
let def_id = match def.def_id() {
SolverDefId::AdtId(id) => id,
_ => unreachable!(),
};
let def_id = def.def_id().0;
f.start_location_link(def_id.into());
match f.display_kind {
DisplayKind::Diagnostics | DisplayKind::Test => {
Expand Down Expand Up @@ -1448,7 +1436,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
hir_fmt_generics(
f,
convert_args_for_result(interner, parameters.as_slice()).as_slice(Interner),
def.def_id().try_into().ok(),
Some(def.def_id().0.into()),
None,
)?;
}
Expand All @@ -1466,13 +1454,9 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {

projection_ty.hir_fmt(f)?;
}
TyKind::Foreign(type_alias) => {
let alias = match type_alias {
SolverDefId::TypeAliasId(id) => id,
_ => unreachable!(),
};
let type_alias = db.type_alias_signature(alias);
f.start_location_link(alias.into());
TyKind::Foreign(alias) => {
let type_alias = db.type_alias_signature(alias.0);
f.start_location_link(alias.0.into());
write!(f, "{}", type_alias.name.display(f.db, f.edition()))?;
f.end_location_link();
}
Expand Down Expand Up @@ -1549,10 +1533,7 @@ impl<'db> HirDisplay for crate::next_solver::Ty<'db> {
}
}
TyKind::Closure(id, substs) => {
let id = match id {
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
let id = id.0;
let substs = convert_args_for_result(interner, substs.as_slice());
if f.display_kind.is_source_code() {
if !f.display_kind.allows_opaque() {
Expand Down
12 changes: 4 additions & 8 deletions crates/hir-ty/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::{
consteval_nextsolver::try_const_usize,
db::HirDatabase,
next_solver::{
DbInterner, GenericArgs, ParamEnv, SolverDefId, Ty, TyKind, TypingMode,
DbInterner, GenericArgs, ParamEnv, Ty, TyKind, TypingMode,
infer::{DbInternerInferExt, traits::ObligationCause},
mapping::{ChalkToNextSolver, convert_args_for_result},
project::solve_normalize::deeply_normalize,
Expand Down Expand Up @@ -323,14 +323,10 @@ pub fn layout_of_ty_query<'db>(
ptr.valid_range_mut().start = 1;
Layout::scalar(dl, ptr)
}
TyKind::Closure(c, args) => {
let id = match c {
SolverDefId::InternedClosureId(id) => id,
_ => unreachable!(),
};
let def = db.lookup_intern_closure(id);
TyKind::Closure(id, args) => {
let def = db.lookup_intern_closure(id.0);
let infer = db.infer(def.0);
let (captures, _) = infer.closure_info(&id.into());
let (captures, _) = infer.closure_info(&id.0.into());
let fields = captures
.iter()
.map(|it| {
Expand Down
5 changes: 1 addition & 4 deletions crates/hir-ty/src/method_resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ impl TyFingerprint {
rustc_ast_ir::Mutability::Mut => TyFingerprint::RawPtr(Mutability::Mut),
rustc_ast_ir::Mutability::Not => TyFingerprint::RawPtr(Mutability::Not),
},
TyKind::Foreign(def) => {
let SolverDefId::TypeAliasId(def) = def else { unreachable!() };
TyFingerprint::ForeignType(crate::to_foreign_def_id(def))
}
TyKind::Foreign(def) => TyFingerprint::ForeignType(crate::to_foreign_def_id(def.0)),
TyKind::Dynamic(bounds, _, _) => {
let trait_ref = bounds
.as_slice()
Expand Down
Loading
Loading