Skip to content

Commit 92742a5

Browse files
author
Lukas Markeffsky
committed
stash
1 parent 15ffe83 commit 92742a5

File tree

3 files changed

+37
-50
lines changed

3 files changed

+37
-50
lines changed

compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -409,21 +409,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
409409
.instantiate(tcx, &[ty::GenericArg::from(goal.predicate.self_ty())])
410410
}
411411

412-
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
413-
// This is the "fallback impl" for type parameters, unnormalizable projections
414-
// and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
415-
// FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
416-
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
417-
let sized_predicate = ty::TraitRef::from_lang_item(
418-
tcx,
419-
LangItem::Sized,
420-
DUMMY_SP,
421-
[ty::GenericArg::from(goal.predicate.self_ty())],
422-
);
423-
// FIXME(-Znext-solver=coinductive): Should this be `GoalSource::ImplWhereBound`?
424-
ecx.add_goal(GoalSource::Misc, goal.with(tcx, sized_predicate));
425-
tcx.types.unit
426-
}
412+
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => return Err(NoSolution),
427413

428414
ty::Adt(def, args) if def.is_struct() => match def.non_enum_variant().tail_opt() {
429415
None => tcx.types.unit,

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use crate::errors::InherentProjectionNormalizationOverflow;
2020
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
2121
use crate::infer::{BoundRegionConversionTime, InferCtxt, InferOk};
2222
use crate::traits::error_reporting::TypeErrCtxtExt as _;
23-
use crate::traits::query::evaluate_obligation::InferCtxtExt as _;
2423
use crate::traits::select::ProjectionMatchesProjection;
2524
use rustc_data_structures::sso::SsoHashSet;
2625
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -1791,9 +1790,12 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
17911790
//
17921791
// NOTE: This should be kept in sync with the similar code in
17931792
// `rustc_ty_utils::instance::resolve_associated_item()`.
1794-
let node_item =
1795-
specialization_graph::assoc_def(selcx.tcx(), impl_data.impl_def_id, obligation.predicate.def_id)
1796-
.map_err(|ErrorGuaranteed { .. }| ())?;
1793+
let node_item = specialization_graph::assoc_def(
1794+
selcx.tcx(),
1795+
impl_data.impl_def_id,
1796+
obligation.predicate.def_id,
1797+
)
1798+
.map_err(|ErrorGuaranteed { .. }| ())?;
17971799

17981800
if node_item.is_final() {
17991801
// Non-specializable items are always projectable.
@@ -1833,10 +1835,11 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
18331835
lang_items.fn_trait(),
18341836
lang_items.fn_mut_trait(),
18351837
lang_items.fn_once_trait(),
1836-
].contains(&Some(trait_ref.def_id))
1838+
]
1839+
.contains(&Some(trait_ref.def_id))
18371840
{
18381841
true
1839-
}else if lang_items.discriminant_kind_trait() == Some(trait_ref.def_id) {
1842+
} else if lang_items.discriminant_kind_trait() == Some(trait_ref.def_id) {
18401843
match self_ty.kind() {
18411844
ty::Bool
18421845
| ty::Char
@@ -1871,9 +1874,16 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
18711874
| ty::Error(_) => false,
18721875
}
18731876
} else if lang_items.pointee_trait() == Some(trait_ref.def_id) {
1877+
let metadata_def_id = selcx.tcx().require_lang_item(LangItem::Metadata, None);
1878+
let self_project = Ty::new_projection(selcx.tcx(), metadata_def_id, [self_ty]);
1879+
18741880
let tail = selcx.tcx().struct_tail_with_normalize(
18751881
self_ty,
18761882
|ty| {
1883+
if ty == self_project {
1884+
return ty;
1885+
}
1886+
18771887
// We throw away any obligations we get from this, since we normalize
18781888
// and confirm these obligations once again during confirmation
18791889
normalize_with_depth(
@@ -1917,23 +1927,10 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
19171927
| ty::Infer(ty::InferTy::IntVar(_) | ty::InferTy::FloatVar(..)) => true,
19181928

19191929
// We normalize from `Wrapper<Tail>::Metadata` to `Tail::Metadata` if able.
1920-
// Otherwise, type parameters, opaques, and unnormalized projections have
1921-
// unit metadata if they're known (e.g. by the param_env) to be sized.
1922-
ty::Param(_) | ty::Alias(..)
1923-
if self_ty != tail || selcx.infcx.predicate_must_hold_modulo_regions(
1924-
&obligation.with(
1925-
selcx.tcx(),
1926-
ty::TraitRef::from_lang_item(selcx.tcx(), LangItem::Sized, obligation.cause.span(),[self_ty]),
1927-
),
1928-
) =>
1929-
{
1930-
true
1931-
}
1930+
ty::Param(_) | ty::Alias(..) => self_ty != tail,
19321931

19331932
// FIXME(compiler-errors): are Bound and Placeholder types ever known sized?
1934-
ty::Param(_)
1935-
| ty::Alias(..)
1936-
| ty::Bound(..)
1933+
ty::Bound(..)
19371934
| ty::Placeholder(..)
19381935
| ty::Infer(..)
19391936
| ty::Error(_) => {
@@ -2302,23 +2299,14 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
23022299
};
23032300
let metadata_ty = self_ty.ptr_metadata_ty_or_tail(tcx, normalize).unwrap_or_else(|tail| {
23042301
if tail == self_ty {
2305-
// This is the "fallback impl" for type parameters, unnormalizable projections
2306-
// and opaque types: If the `self_ty` is `Sized`, then the metadata is `()`.
2307-
// FIXME(ptr_metadata): This impl overlaps with the other impls and shouldn't
2308-
// exist. Instead, `Pointee<Metadata = ()>` should be a supertrait of `Sized`.
2309-
let sized_predicate = ty::TraitRef::from_lang_item(
2310-
tcx,
2311-
LangItem::Sized,
2302+
span_bug!(
23122303
obligation.cause.span(),
2313-
[self_ty],
2304+
"Pointee projection candidate assembled, but we cannot project further",
23142305
);
2315-
obligations.push(obligation.with(tcx, sized_predicate));
2316-
tcx.types.unit
2317-
} else {
2318-
// We know that `self_ty` has the same metadata as `tail`. This allows us
2319-
// to prove predicates like `Wrapper<Tail>::Metadata == Tail::Metadata`.
2320-
Ty::new_projection(tcx, metadata_def_id, [tail])
23212306
}
2307+
// We know that `self_ty` has the same metadata as `tail`. This allows us
2308+
// to prove predicates like `Wrapper<Tail>::Metadata == Tail::Metadata`.
2309+
Ty::new_projection(tcx, metadata_def_id, [tail])
23222310
});
23232311
(metadata_ty.into(), obligations)
23242312
} else {

library/core/src/marker.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,19 @@ unsafe impl<T: Sync + ?Sized> Send for &T {}
142142
#[rustc_specialization_trait]
143143
#[rustc_deny_explicit_impl(implement_via_object = false)]
144144
#[rustc_coinductive]
145+
#[cfg(not(bootstrap))]
146+
pub trait Sized: crate::ptr::Thin {
147+
// Empty.
148+
}
149+
150+
#[stable(feature = "rust1", since = "1.0.0")]
151+
#[lang = "sized"]
152+
#[fundamental]
153+
#[rustc_specialization_trait]
154+
#[rustc_deny_explicit_impl(implement_via_object = false)]
155+
#[rustc_coinductive]
156+
#[cfg(bootstrap)]
157+
#[allow(missing_docs)]
145158
pub trait Sized {
146159
// Empty.
147160
}

0 commit comments

Comments
 (0)