Skip to content
Draft
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
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_cranelift/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}
#[lang = "size_of_val"]
pub trait SizeOfVal: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}
pub trait Sized: SizeOfVal {}

#[lang = "destruct"]
pub trait Destruct {}
Expand Down Expand Up @@ -52,14 +52,14 @@ impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U>> for Box<T> {}
impl<T: SizeOfVal + Unsize<U>, U: SizeOfVal> DispatchFromDyn<Box<U>> for Box<T> {}

#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}

impl<T: PointeeSized> LegacyReceiver for &T {}
impl<T: PointeeSized> LegacyReceiver for &mut T {}
impl<T: MetaSized> LegacyReceiver for Box<T> {}
impl<T: SizeOfVal> LegacyReceiver for Box<T> {}

#[lang = "copy"]
pub trait Copy {}
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_codegen_gcc/example/mini_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ unsafe extern "C" fn _Unwind_Resume() {
#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}
#[lang = "size_of_val"]
pub trait SizeOfVal: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}
pub trait Sized: SizeOfVal {}

#[lang = "destruct"]
pub trait Destruct {}
Expand Down Expand Up @@ -56,14 +56,14 @@ impl<'a, T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<&'a mut U
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*const U> for *const T {}
// *mut T -> *mut U
impl<T: PointeeSized + Unsize<U>, U: PointeeSized> DispatchFromDyn<*mut U> for *mut T {}
impl<T: MetaSized + Unsize<U>, U: MetaSized> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}
impl<T: SizeOfVal + Unsize<U>, U: SizeOfVal> DispatchFromDyn<Box<U, ()>> for Box<T, ()> {}

#[lang = "legacy_receiver"]
pub trait LegacyReceiver {}

impl<T: PointeeSized> LegacyReceiver for &T {}
impl<T: PointeeSized> LegacyReceiver for &mut T {}
impl<T: MetaSized> LegacyReceiver for Box<T> {}
impl<T: SizeOfVal> LegacyReceiver for Box<T> {}

#[lang = "receiver"]
trait Receiver {}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_gcc/tests/run/simd-ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub fn bar(a: i32x4, b: i32x4) -> i32x4 {
#[lang = "pointee_sized"]
pub trait PointeeSized {}

#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}
#[lang = "size_of_val"]
pub trait SizeOfVal: PointeeSized {}

#[lang = "sized"]
pub trait Sized: MetaSized {}
pub trait Sized: SizeOfVal {}

#[lang = "copy"]
pub trait Copy {}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl<CTX> HashStable<CTX> for LangItem {
language_item_table! {
// Variant name, Name, Getter method name, Target Generic requirements;
Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
MetaSized, sym::meta_sized, meta_sized_trait, Target::Trait, GenericRequirement::Exact(0);
SizeOfVal, sym::size_of_val, size_of_val_trait, Target::Trait, GenericRequirement::Exact(0);
PointeeSized, sym::pointee_sized, pointee_sized_trait, Target::Trait, GenericRequirement::Exact(0);
Unsize, sym::unsize, unsize_trait, Target::Trait, GenericRequirement::Minimum(1);
AlignOf, sym::mem_align_const, align_const, Target::AssocConst, GenericRequirement::Exact(0);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ fn bounds_from_generic_predicates<'tcx>(
projections_str.push(format!("{} = {}", name, p.term));
}
}
let bound_def_path = if tcx.is_lang_item(bound, LangItem::MetaSized) {
let bound_def_path = if tcx.is_lang_item(bound, LangItem::SizeOfVal) {
String::from("?Sized")
} else {
tcx.def_path_str(bound)
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ impl CollectedBound {
struct CollectedSizednessBounds {
// Collected `Sized` bounds
sized: CollectedBound,
// Collected `MetaSized` bounds
meta_sized: CollectedBound,
// Collected `SizeOfVal` bounds
size_of_val: CollectedBound,
// Collected `PointeeSized` bounds
pointee_sized: CollectedBound,
}

impl CollectedSizednessBounds {
/// Returns `true` if any of `Trait`, `?Trait` or `!Trait` were encountered for `Sized`,
/// `MetaSized` or `PointeeSized`.
/// `SizeOfVal` or `PointeeSized`.
fn any(&self) -> bool {
self.sized.any() || self.meta_sized.any() || self.pointee_sized.any()
self.sized.any() || self.size_of_val.any() || self.pointee_sized.any()
}
}

Expand Down Expand Up @@ -127,13 +127,13 @@ fn collect_sizedness_bounds<'tcx>(
let sized_did = tcx.require_lang_item(hir::LangItem::Sized, span);
let sized = collect_bounds(hir_bounds, context, sized_did);

let meta_sized_did = tcx.require_lang_item(hir::LangItem::MetaSized, span);
let meta_sized = collect_bounds(hir_bounds, context, meta_sized_did);
let size_of_val_did = tcx.require_lang_item(hir::LangItem::SizeOfVal, span);
let size_of_val = collect_bounds(hir_bounds, context, size_of_val_did);

let pointee_sized_did = tcx.require_lang_item(hir::LangItem::PointeeSized, span);
let pointee_sized = collect_bounds(hir_bounds, context, pointee_sized_did);

CollectedSizednessBounds { sized, meta_sized, pointee_sized }
CollectedSizednessBounds { sized, size_of_val, pointee_sized }
}

/// Add a trait bound for `did`.
Expand All @@ -155,9 +155,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
///
/// - On parameters, opaque type and associated types, add default `Sized` bound if no explicit
/// sizedness bounds are present.
/// - On traits and trait aliases, add default `MetaSized` supertrait if no explicit sizedness
/// - On traits and trait aliases, add default `SizeOfVal` supertrait if no explicit sizedness
/// bounds are present.
/// - On parameters, opaque type, associated types and trait aliases, add a `MetaSized` bound if
/// - On parameters, opaque type, associated types and trait aliases, add a `SizeOfVal` bound if
/// a `?Sized` bound is present.
pub(crate) fn add_implicit_sizedness_bounds(
&self,
Expand All @@ -174,7 +174,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
return;
}

let meta_sized_did = tcx.require_lang_item(hir::LangItem::MetaSized, span);
let size_of_val_did = tcx.require_lang_item(hir::LangItem::SizeOfVal, span);
let pointee_sized_did = tcx.require_lang_item(hir::LangItem::PointeeSized, span);

// If adding sizedness bounds to a trait, then there are some relevant early exits
Expand Down Expand Up @@ -210,18 +210,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
let collected = collect_sizedness_bounds(tcx, hir_bounds, context, span);
if (collected.sized.maybe || collected.sized.negative)
&& !collected.sized.positive
&& !collected.meta_sized.any()
&& !collected.size_of_val.any()
&& !collected.pointee_sized.any()
{
// `?Sized` is equivalent to `MetaSized` (but only add the bound if there aren't any
// `?Sized` is equivalent to `SizeOfVal` (but only add the bound if there aren't any
// other explicit ones) - this can happen for trait aliases as well as bounds.
add_trait_bound(tcx, bounds, self_ty, meta_sized_did, span);
add_trait_bound(tcx, bounds, self_ty, size_of_val_did, span);
} else if !collected.any() {
match context {
ImpliedBoundsContext::TraitDef(..) => {
// If there are no explicit sizedness bounds on a trait then add a default
// `MetaSized` supertrait.
add_trait_bound(tcx, bounds, self_ty, meta_sized_did, span);
// `SizeOfVal` supertrait.
add_trait_bound(tcx, bounds, self_ty, size_of_val_did, span);
}
ImpliedBoundsContext::TyParam(..)
| ImpliedBoundsContext::AssociatedTypeOrImplTrait => {
Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {

// FIXME(sized-hierarchy): https://github.com/rust-lang/rust/pull/142712#issuecomment-3013231794
debug!(?user_written_bounds, ?elaborated_trait_bounds);
let meta_sized_did = tcx.require_lang_item(LangItem::MetaSized, span);
// Don't strip out `MetaSized` when the user wrote it explicitly, only when it was
let size_of_val_did = tcx.require_lang_item(LangItem::SizeOfVal, span);
// Don't strip out `SizeOfVal` when the user wrote it explicitly, only when it was
// elaborated
if user_written_bounds
.iter()
.all(|(clause, _)| clause.as_trait_clause().map(|p| p.def_id()) != Some(meta_sized_did))
{
elaborated_trait_bounds.retain(|(pred, _)| pred.def_id() != meta_sized_did);
if user_written_bounds.iter().all(|(clause, _)| {
clause.as_trait_clause().map(|p| p.def_id()) != Some(size_of_val_did)
}) {
elaborated_trait_bounds.retain(|(pred, _)| pred.def_id() != size_of_val_did);
}
debug!(?user_written_bounds, ?elaborated_trait_bounds);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::{NoVariantNamed, check_c_variadic_abi};
#[derive(Clone, Copy)]
pub(crate) enum ImpliedBoundsContext<'tcx> {
/// An implied bound is added to a trait definition (i.e. a new supertrait), used when adding
/// a default `MetaSized` supertrait
/// a default `SizeOfVal` supertrait
TraitDef(LocalDefId),
/// An implied bound is added to a type parameter
TyParam(LocalDefId, &'tcx [hir::WherePredicate<'tcx>]),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/multiple_supertrait_upcastable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
.explicit_super_predicates_of(def_id)
.iter_identity_copied()
.filter_map(|(pred, _)| pred.as_trait_clause())
.filter(|pred| !cx.tcx.is_lang_item(pred.def_id(), hir::LangItem::MetaSized))
.filter(|pred| !cx.tcx.is_lang_item(pred.def_id(), hir::LangItem::SizeOfVal))
.filter(|pred| !cx.tcx.is_default_trait(pred.def_id()));
if direct_super_traits_iter.count() > 1 {
cx.emit_span_lint(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

pub fn is_sizedness_trait(self, def_id: DefId) -> bool {
matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::MetaSized))
matches!(self.as_lang_item(def_id), Some(LangItem::Sized | LangItem::SizeOfVal))
}

/// Returns a range of the start/end indices specified with the
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/context/impl_interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,9 @@ bidirectional_lang_item_map! {
FusedIterator,
Future,
Iterator,
MetaSized,
PointeeSized,
PointeeTrait,
SizeOfVal,
Sized,
TransmuteTrait,
TrivialClone,
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,15 +1078,15 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {

let mut has_sized_bound = false;
let mut has_negative_sized_bound = false;
let mut has_meta_sized_bound = false;
let mut has_size_of_val_bound = false;

for (predicate, _) in bounds.iter_instantiated_copied(tcx, args) {
let bound_predicate = predicate.kind();

match bound_predicate.skip_binder() {
ty::ClauseKind::Trait(pred) => {
// With `feature(sized_hierarchy)`, don't print `?Sized` as an alias for
// `MetaSized`, and skip sizedness bounds to be added at the end.
// `SizeOfVal`, and skip sizedness bounds to be added at the end.
match tcx.as_lang_item(pred.def_id()) {
Some(LangItem::Sized) => match pred.polarity {
ty::PredicatePolarity::Positive => {
Expand All @@ -1095,8 +1095,8 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
}
ty::PredicatePolarity::Negative => has_negative_sized_bound = true,
},
Some(LangItem::MetaSized) => {
has_meta_sized_bound = true;
Some(LangItem::SizeOfVal) => {
has_size_of_val_bound = true;
continue;
}
Some(LangItem::PointeeSized) => {
Expand Down Expand Up @@ -1248,10 +1248,10 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
let using_sized_hierarchy = self.tcx().features().sized_hierarchy();
let add_sized = has_sized_bound && (first || has_negative_sized_bound);
let add_maybe_sized =
has_meta_sized_bound && !has_negative_sized_bound && !using_sized_hierarchy;
// Set `has_pointee_sized_bound` if there were no `Sized` or `MetaSized` bounds.
has_size_of_val_bound && !has_negative_sized_bound && !using_sized_hierarchy;
// Set `has_pointee_sized_bound` if there were no `Sized` or `SizeOfVal` bounds.
let has_pointee_sized_bound =
!has_sized_bound && !has_meta_sized_bound && !has_negative_sized_bound;
!has_sized_bound && !has_size_of_val_bound && !has_negative_sized_bound;
if add_sized || add_maybe_sized {
if !first {
write!(self, " + ")?;
Expand All @@ -1260,11 +1260,11 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
write!(self, "?")?;
}
write!(self, "Sized")?;
} else if has_meta_sized_bound && using_sized_hierarchy {
} else if has_size_of_val_bound && using_sized_hierarchy {
if !first {
write!(self, " + ")?;
}
write!(self, "MetaSized")?;
write!(self, "SizeOfVal")?;
} else if has_pointee_sized_bound && using_sized_hierarchy {
if !first {
write!(self, " + ")?;
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1890,7 +1890,7 @@ impl<'tcx> Ty<'tcx> {
}
}

/// Fast path helper for testing if a type is `Sized` or `MetaSized`.
/// Fast path helper for testing if a type is `Sized` or `SizeOfVal`.
///
/// Returning true means the type is known to implement the sizedness trait. Returning `false`
/// means nothing -- could be sized, might not be.
Expand Down Expand Up @@ -1924,11 +1924,11 @@ impl<'tcx> Ty<'tcx> {

ty::Str | ty::Slice(_) | ty::Dynamic(_, _) => match sizedness {
SizedTraitKind::Sized => false,
SizedTraitKind::MetaSized => true,
SizedTraitKind::SizeOfVal => true,
},

ty::Foreign(..) => match sizedness {
SizedTraitKind::Sized | SizedTraitKind::MetaSized => false,
SizedTraitKind::Sized | SizedTraitKind::SizeOfVal => false,
},

ty::Tuple(tys) => tys.last().is_none_or(|ty| ty.has_trivial_sizedness(tcx, sizedness)),
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ where
goal: Goal<I, Self>,
) -> Result<Candidate<I>, NoSolution>;

/// A type is `Sized` if its tail component is `Sized` and a type is `MetaSized` if its tail
/// component is `MetaSized`.
/// A type is `Sized` if its tail component is `Sized` and a type is `SizeOfVal` if its tail
/// component is `SizeOfVal`.
///
/// These components are given by built-in rules from
/// [`structural_traits::instantiate_constituent_tys_for_sizedness_trait`].
Expand Down Expand Up @@ -551,8 +551,8 @@ where
Some(SolverTraitLangItem::Sized) => {
G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::Sized)
}
Some(SolverTraitLangItem::MetaSized) => {
G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::MetaSized)
Some(SolverTraitLangItem::SizeOfVal) => {
G::consider_builtin_sizedness_candidates(self, goal, SizedTraitKind::SizeOfVal)
}
Some(SolverTraitLangItem::PointeeSized) => {
unreachable!("`PointeeSized` is removed during lowering");
Expand Down Expand Up @@ -802,7 +802,7 @@ where
) {
let cx = self.cx();
if cx.is_sizedness_trait(goal.predicate.trait_def_id(cx)) {
// `dyn MetaSized` is valid, but should get its `MetaSized` impl from
// `dyn SizeOfVal` is valid, but should get its `SizeOfVal` impl from
// being `dyn` (SizedCandidate), not from the object candidate.
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ where
// impl {Meta,}Sized for str, [T], dyn Trait
ty::Str | ty::Slice(_) | ty::Dynamic(..) => match sizedness {
SizedTraitKind::Sized => Err(NoSolution),
SizedTraitKind::MetaSized => Ok(ty::Binder::dummy(vec![])),
SizedTraitKind::SizeOfVal => Ok(ty::Binder::dummy(vec![])),
},

// impl {} for extern type
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ where
_goal: Goal<I, Self>,
_sizedness: SizedTraitKind,
) -> Result<Candidate<I>, NoSolution> {
unreachable!("Sized/MetaSized is never const")
unreachable!("Sized/SizeOfVal is never const")
}

fn consider_builtin_copy_clone_candidate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ where
goal: Goal<I, Self>,
_sizedness: SizedTraitKind,
) -> Result<Candidate<I>, NoSolution> {
panic!("`Sized`/`MetaSized` does not have an associated type: {:?}", goal);
panic!("`Sized`/`SizeOfVal` does not have an associated type: {:?}", goal);
}

fn consider_builtin_copy_clone_candidate(
Expand Down
Loading
Loading