Auto merge of #100251 - compiler-errors:tuple-trait-2, r=jackh726
Implement `std::marker::Tuple` Split out from #99943 (https://github.com/rust-lang/rust/pull/99943#pullrequestreview-1064459183). Implements part of rust-lang/compiler-team#537 r? `@jackh726`
This commit is contained in:
commit
3194958217
15 changed files with 181 additions and 11 deletions
|
@ -1751,7 +1751,8 @@ fn assemble_candidates_from_impls<'cx, 'tcx>(
|
|||
super::ImplSource::AutoImpl(..)
|
||||
| super::ImplSource::Builtin(..)
|
||||
| super::ImplSource::TraitUpcasting(_)
|
||||
| super::ImplSource::ConstDestruct(_) => {
|
||||
| super::ImplSource::ConstDestruct(_)
|
||||
| super::ImplSource::Tuple => {
|
||||
// These traits have no associated types.
|
||||
selcx.tcx().sess.delay_span_bug(
|
||||
obligation.cause.span,
|
||||
|
@ -1829,7 +1830,8 @@ fn confirm_select_candidate<'cx, 'tcx>(
|
|||
| super::ImplSource::Builtin(..)
|
||||
| super::ImplSource::TraitUpcasting(_)
|
||||
| super::ImplSource::TraitAlias(..)
|
||||
| super::ImplSource::ConstDestruct(_) => {
|
||||
| super::ImplSource::ConstDestruct(_)
|
||||
| super::ImplSource::Tuple => {
|
||||
// we don't create Select candidates with this kind of resolution
|
||||
span_bug!(
|
||||
obligation.cause.span,
|
||||
|
|
|
@ -309,6 +309,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
// User-defined transmutability impls are permitted.
|
||||
self.assemble_candidates_from_impls(obligation, &mut candidates);
|
||||
self.assemble_candidates_for_transmutability(obligation, &mut candidates);
|
||||
} else if lang_items.tuple_trait() == Some(def_id) {
|
||||
self.assemble_candidate_for_tuple(obligation, &mut candidates);
|
||||
} else {
|
||||
if lang_items.clone_trait() == Some(def_id) {
|
||||
// Same builtin conditions as `Copy`, i.e., every type which has builtin support
|
||||
|
@ -1009,4 +1011,46 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn assemble_candidate_for_tuple(
|
||||
&mut self,
|
||||
obligation: &TraitObligation<'tcx>,
|
||||
candidates: &mut SelectionCandidateSet<'tcx>,
|
||||
) {
|
||||
let self_ty = self.infcx().shallow_resolve(obligation.self_ty().skip_binder());
|
||||
match self_ty.kind() {
|
||||
ty::Tuple(_) => {
|
||||
candidates.vec.push(TupleCandidate);
|
||||
}
|
||||
ty::Infer(ty::TyVar(_)) => {
|
||||
candidates.ambiguous = true;
|
||||
}
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
| ty::Int(_)
|
||||
| ty::Uint(_)
|
||||
| ty::Float(_)
|
||||
| ty::Adt(_, _)
|
||||
| ty::Foreign(_)
|
||||
| ty::Str
|
||||
| ty::Array(_, _)
|
||||
| ty::Slice(_)
|
||||
| ty::RawPtr(_)
|
||||
| ty::Ref(_, _, _)
|
||||
| ty::FnDef(_, _)
|
||||
| ty::FnPtr(_)
|
||||
| ty::Dynamic(_, _)
|
||||
| ty::Closure(_, _)
|
||||
| ty::Generator(_, _, _)
|
||||
| ty::GeneratorWitness(_)
|
||||
| ty::Never
|
||||
| ty::Projection(_)
|
||||
| ty::Opaque(_, _)
|
||||
| ty::Param(_)
|
||||
| ty::Bound(_, _)
|
||||
| ty::Error(_)
|
||||
| ty::Infer(_)
|
||||
| ty::Placeholder(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,6 +126,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let data = self.confirm_const_destruct_candidate(obligation, def_id)?;
|
||||
ImplSource::ConstDestruct(data)
|
||||
}
|
||||
|
||||
TupleCandidate => ImplSource::Tuple,
|
||||
};
|
||||
|
||||
if !obligation.predicate.is_const_if_const() {
|
||||
|
|
|
@ -1609,7 +1609,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
};
|
||||
|
||||
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
|
||||
// `DiscriminantKindCandidate`, and `ConstDestructCandidate` to anything else.
|
||||
// `DiscriminantKindCandidate`, `ConstDestructCandidate`, and `TupleCandidate`
|
||||
// to anything else.
|
||||
//
|
||||
// This is a fix for #53123 and prevents winnowing from accidentally extending the
|
||||
// lifetime of a variable.
|
||||
|
@ -1629,7 +1630,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
BuiltinCandidate { has_nested: false }
|
||||
| DiscriminantKindCandidate
|
||||
| PointeeCandidate
|
||||
| ConstDestructCandidate(_),
|
||||
| ConstDestructCandidate(_)
|
||||
| TupleCandidate,
|
||||
_,
|
||||
) => true,
|
||||
(
|
||||
|
@ -1637,7 +1639,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
BuiltinCandidate { has_nested: false }
|
||||
| DiscriminantKindCandidate
|
||||
| PointeeCandidate
|
||||
| ConstDestructCandidate(_),
|
||||
| ConstDestructCandidate(_)
|
||||
| TupleCandidate,
|
||||
) => false,
|
||||
|
||||
(ParamCandidate(other), ParamCandidate(victim)) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue