Skip to content

Commit 60ecaca

Browse files
committed
Some stuff
1 parent 8738be6 commit 60ecaca

File tree

9 files changed

+48
-22
lines changed

9 files changed

+48
-22
lines changed

crates/hir-def/src/lang_item.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ impl LangItem {
308308
language_item_table! {
309309
// Variant name, Name, Getter method name, Target Generic requirements;
310310
Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
311+
MetaSized, sym::meta_sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
312+
PointeeSized, sym::pointee_sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
311313
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
312314
/// Trait injected by `#[derive(PartialEq)]`, (i.e. "Partial EQ").
313315
StructuralPeq, sym::structural_peq, structural_peq_trait, Target::Trait, GenericRequirement::None;

crates/hir-ty/src/chalk_db.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ pub(crate) fn associated_ty_data_query(
688688
Arc::new(datum)
689689
}
690690

691+
// FIXME(sized-hierarchy)
691692
pub(crate) fn trait_datum_query(
692693
db: &dyn HirDatabase,
693694
krate: Crate,

crates/hir-ty/src/infer.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ pub use unify::{could_unify, could_unify_deeply};
8686
use cast::{CastCheck, CastError};
8787
pub(crate) use closure::{CaptureKind, CapturedItem, CapturedItemWithoutTy};
8888

89+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
90+
pub(crate) enum SizedTraitKind {
91+
Sized,
92+
MetaSized,
93+
}
94+
8995
/// The entry point of type inference.
9096
pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<InferenceResult> {
9197
let _p = tracing::info_span!("infer_query").entered();

crates/hir-ty/src/infer/cast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl CastCheck {
109109
}
110110

111111
if !self.cast_ty.data(Interner).flags.contains(TypeFlags::HAS_TY_INFER)
112-
&& !table.is_sized(&self.cast_ty)
112+
&& !table.has_trivial_sizedness(&self.cast_ty, super::SizedTraitKind::Sized)
113113
{
114114
return Err(InferenceDiagnostic::CastToUnsized {
115115
expr: self.expr,
@@ -175,7 +175,7 @@ impl CastCheck {
175175
// array-ptr-cast
176176
CastTy::Ptr(t, m) => {
177177
let t = table.eagerly_normalize_and_resolve_shallow_in(t);
178-
if !table.is_sized(&t) {
178+
if !table.has_trivial_sizedness(&t, super::SizedTraitKind::Sized) {
179179
return Err(CastError::IllegalCast);
180180
}
181181
self.check_ref_cast(
@@ -369,7 +369,7 @@ enum PointerKind {
369369
fn pointer_kind(ty: &Ty, table: &mut InferenceTable<'_>) -> Result<Option<PointerKind>, ()> {
370370
let ty = table.eagerly_normalize_and_resolve_shallow_in(ty.clone());
371371

372-
if table.is_sized(&ty) {
372+
if table.has_trivial_sizedness(&ty, super::SizedTraitKind::Sized) {
373373
return Ok(Some(PointerKind::Thin));
374374
}
375375

crates/hir-ty/src/infer/unify.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::{
2323
Lifetime, OpaqueTyId, ParamKind, ProjectionTy, ProjectionTyExt, Scalar, Solution, Substitution,
2424
TraitEnvironment, TraitRef, Ty, TyBuilder, TyExt, TyKind, VariableKind, WhereClause,
2525
consteval::unknown_const, db::HirDatabase, fold_generic_args, fold_tys_and_consts,
26-
to_chalk_trait_id, traits::FnTrait,
26+
infer::SizedTraitKind, to_chalk_trait_id, traits::FnTrait,
2727
};
2828

2929
impl InferenceContext<'_> {
@@ -975,8 +975,8 @@ impl<'a> InferenceTable<'a> {
975975
}
976976

977977
/// Check if given type is `Sized` or not
978-
pub(crate) fn is_sized(&mut self, ty: &Ty) -> bool {
979-
fn short_circuit_trivial_tys(ty: &Ty) -> Option<bool> {
978+
pub(crate) fn has_trivial_sizedness(&mut self, ty: &Ty, sizedness: SizedTraitKind) -> bool {
979+
fn short_circuit_trivial_tys(ty: &Ty, sizedness: SizedTraitKind) -> Option<bool> {
980980
match ty.kind(Interner) {
981981
TyKind::Scalar(..)
982982
| TyKind::Ref(..)
@@ -985,14 +985,20 @@ impl<'a> InferenceTable<'a> {
985985
| TyKind::FnDef(..)
986986
| TyKind::Array(..)
987987
| TyKind::Function(..) => Some(true),
988-
TyKind::Slice(..) | TyKind::Str | TyKind::Dyn(..) => Some(false),
988+
TyKind::Slice(..) | TyKind::Str | TyKind::Dyn(..) => Some(match sizedness {
989+
SizedTraitKind::Sized => false,
990+
SizedTraitKind::MetaSized => true,
991+
}),
992+
TyKind::Foreign(_) => Some(match sizedness {
993+
SizedTraitKind::Sized | SizedTraitKind::MetaSized => false,
994+
}),
989995
_ => None,
990996
}
991997
}
992998

993999
let mut ty = ty.clone();
9941000
ty = self.eagerly_normalize_and_resolve_shallow_in(ty);
995-
if let Some(sized) = short_circuit_trivial_tys(&ty) {
1001+
if let Some(sized) = short_circuit_trivial_tys(&ty, sizedness) {
9961002
return sized;
9971003
}
9981004

@@ -1015,7 +1021,7 @@ impl<'a> InferenceTable<'a> {
10151021
// as unsized by the chalk, so we do this manually.
10161022
ty = last_field_ty;
10171023
ty = self.eagerly_normalize_and_resolve_shallow_in(ty);
1018-
if let Some(sized) = short_circuit_trivial_tys(&ty) {
1024+
if let Some(sized) = short_circuit_trivial_tys(&ty, sizedness) {
10191025
return sized;
10201026
}
10211027
} else {
@@ -1024,6 +1030,7 @@ impl<'a> InferenceTable<'a> {
10241030
}
10251031
}
10261032

1033+
// FIXME(sized-hierarchy):
10271034
let Some(sized) = LangItem::Sized.resolve_trait(self.db, self.trait_env.krate) else {
10281035
return false;
10291036
};

crates/hir-ty/src/lower.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use hir_def::{
4242
use hir_expand::name::Name;
4343
use la_arena::{Arena, ArenaMap};
4444
use rustc_hash::FxHashSet;
45-
use stdx::{impl_from, never};
45+
use stdx::{TupleExt, impl_from, never};
4646
use triomphe::{Arc, ThinArc};
4747

4848
use crate::{
@@ -588,16 +588,28 @@ impl<'a> TyLoweringContext<'a> {
588588
clause = Some(crate::wrap_empty_binders(WhereClause::Implemented(trait_ref)));
589589
}
590590
}
591+
// FIXME(sized-hierarchy)
591592
&TypeBound::Path(path, TraitBoundModifier::Maybe) => {
592593
let sized_trait = LangItem::Sized.resolve_trait(self.db, self.resolver.krate());
593594
// Don't lower associated type bindings as the only possible relaxed trait bound
594595
// `?Sized` has no of them.
595596
// If we got another trait here ignore the bound completely.
596-
let trait_id = self
597-
.lower_trait_ref_from_path(path, self_ty.clone())
598-
.map(|(trait_ref, _)| trait_ref.hir_trait_id());
599-
if trait_id == sized_trait {
597+
let trait_id =
598+
self.lower_trait_ref_from_path(path, self_ty.clone()).map(TupleExt::head);
599+
if trait_id.as_ref().map(|trait_ref| trait_ref.hir_trait_id()) == sized_trait {
600600
self.unsized_types.insert(self_ty);
601+
clause = trait_id
602+
.and_then(|it| {
603+
Some(TraitRef {
604+
trait_id: to_chalk_trait_id(
605+
LangItem::MetaSized
606+
.resolve_trait(self.db, self.resolver.krate())?,
607+
),
608+
substitution: it.substitution,
609+
})
610+
})
611+
.map(WhereClause::Implemented)
612+
.map(crate::wrap_empty_binders)
601613
}
602614
}
603615
&TypeBound::Lifetime(l) => {
@@ -910,6 +922,7 @@ pub(crate) fn field_types_with_diagnostics_query(
910922
(Arc::new(res), create_diagnostics(ctx.diagnostics))
911923
}
912924

925+
// FIXME(sized-hierarchy)
913926
/// This query exists only to be used when resolving short-hand associated types
914927
/// like `T::Item`.
915928
///
@@ -1130,6 +1143,7 @@ pub(crate) fn generic_predicates_without_parent_with_diagnostics_query(
11301143
generic_predicates_filtered_by(db, def, |_, d| d == def)
11311144
}
11321145

1146+
// FIXME(sized-hierarchy)
11331147
/// Resolve the where clause(s) of an item with generics,
11341148
/// except the ones inherited from the parent
11351149
fn generic_predicates_filtered_by<F>(
@@ -1163,7 +1177,6 @@ where
11631177
for pred in maybe_parent_generics.where_predicates() {
11641178
if filter(pred, maybe_parent_generics.def()) {
11651179
// We deliberately use `generics` and not `maybe_parent_generics` here. This is not a mistake!
1166-
// If we use the parent generics
11671180
predicates.extend(
11681181
ctx.lower_where_predicate(pred, false).map(|p| make_binders(db, &generics, p)),
11691182
);
@@ -1190,6 +1203,7 @@ where
11901203
)
11911204
}
11921205

1206+
// FIXME(sized-hierarchy)
11931207
/// Generate implicit `: Sized` predicates for all generics that has no `?Sized` bound.
11941208
/// Exception is Self of a trait def.
11951209
fn implicitly_sized_clauses<'db, 'a, 'subst: 'a>(

crates/intern/src/symbol/symbols.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ define_symbols! {
438438
shr,
439439
simd,
440440
sized,
441+
meta_sized,
442+
pointee_sized,
441443
skip,
442444
slice_len_fn,
443445
Some,

crates/rust-analyzer/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
/// Any toolchain less than this version will likely not work with rust-analyzer built from this revision.
1313
pub const MINIMUM_SUPPORTED_TOOLCHAIN_VERSION: semver::Version = semver::Version {
1414
major: 1,
15-
minor: 78,
15+
minor: 98,
1616
patch: 0,
1717
pre: semver::Prerelease::EMPTY,
1818
build: semver::BuildMetadata::EMPTY,

crates/test-utils/src/minicore.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,18 @@ pub mod marker {
8080
#[lang = "pointee_sized"]
8181
#[fundamental]
8282
#[rustc_specialization_trait]
83-
#[rustc_deny_explicit_impl]
84-
#[rustc_do_not_implement_via_object]
8583
#[rustc_coinductive]
8684
pub trait PointeeSized {}
8785

8886
#[lang = "meta_sized"]
8987
#[fundamental]
9088
#[rustc_specialization_trait]
91-
#[rustc_deny_explicit_impl]
92-
#[rustc_do_not_implement_via_object]
9389
#[rustc_coinductive]
9490
pub trait MetaSized: PointeeSized {}
9591

9692
#[lang = "sized"]
9793
#[fundamental]
9894
#[rustc_specialization_trait]
99-
#[rustc_deny_explicit_impl]
100-
#[rustc_do_not_implement_via_object]
10195
#[rustc_coinductive]
10296
pub trait Sized: MetaSized {}
10397
// endregion:sized

0 commit comments

Comments
 (0)