Skip to content

Commit 6dea155

Browse files
No need to validate_alias_bound_self_from_param_env in assemble_alias_bound_candidates
1 parent bf3c6c5 commit 6dea155

File tree

5 files changed

+6
-175
lines changed

5 files changed

+6
-175
lines changed

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

+1-115
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::solve::GoalSource;
55
use crate::traits::coherence;
66
use rustc_hir::def_id::DefId;
77
use rustc_infer::traits::query::NoSolution;
8-
use rustc_infer::traits::Reveal;
98
use rustc_middle::traits::solve::inspect::ProbeKind;
109
use rustc_middle::traits::solve::{
1110
CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
@@ -70,20 +69,6 @@ pub(super) trait GoalKind<'tcx>:
7069
})
7170
}
7271

73-
/// Consider a bound originating from the item bounds of an alias. For this we
74-
/// require that the well-formed requirements of the self type of the goal
75-
/// are "satisfied from the param-env".
76-
/// See [`EvalCtxt::validate_alias_bound_self_from_param_env`].
77-
fn consider_alias_bound_candidate(
78-
ecx: &mut EvalCtxt<'_, 'tcx>,
79-
goal: Goal<'tcx, Self>,
80-
assumption: ty::Clause<'tcx>,
81-
) -> QueryResult<'tcx> {
82-
Self::probe_and_match_goal_against_assumption(ecx, goal, assumption, |ecx| {
83-
ecx.validate_alias_bound_self_from_param_env(goal)
84-
})
85-
}
86-
8772
/// Consider a clause specifically for a `dyn Trait` self type. This requires
8873
/// additionally checking all of the supertraits and object bounds to hold,
8974
/// since they're not implied by the well-formedness of the object type.
@@ -557,7 +542,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
557542
for assumption in
558543
self.tcx().item_bounds(alias_ty.def_id).instantiate(self.tcx(), alias_ty.args)
559544
{
560-
match G::consider_alias_bound_candidate(self, goal, assumption) {
545+
match G::consider_implied_clause(self, goal, assumption, []) {
561546
Ok(result) => {
562547
candidates.push(Candidate { source: CandidateSource::AliasBound, result })
563548
}
@@ -566,105 +551,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
566551
}
567552
}
568553

569-
/// Check that we are allowed to use an alias bound originating from the self
570-
/// type of this goal. This means something different depending on the self type's
571-
/// alias kind.
572-
///
573-
/// * Projection: Given a goal with a self type such as `<Ty as Trait>::Assoc`,
574-
/// we require that the bound `Ty: Trait` can be proven using either a nested alias
575-
/// bound candidate, or a param-env candidate.
576-
///
577-
/// * Opaque: The param-env must be in `Reveal::UserFacing` mode. Otherwise,
578-
/// the goal should be proven by using the hidden type instead.
579-
#[instrument(level = "debug", skip(self), ret)]
580-
pub(super) fn validate_alias_bound_self_from_param_env<G: GoalKind<'tcx>>(
581-
&mut self,
582-
goal: Goal<'tcx, G>,
583-
) -> QueryResult<'tcx> {
584-
match *goal.predicate.self_ty().kind() {
585-
ty::Alias(ty::Projection, projection_ty) => {
586-
let mut param_env_candidates = vec![];
587-
let self_trait_ref = projection_ty.trait_ref(self.tcx());
588-
589-
if self_trait_ref.self_ty().is_ty_var() {
590-
return self
591-
.evaluate_added_goals_and_make_canonical_response(Certainty::AMBIGUOUS);
592-
}
593-
594-
let trait_goal: Goal<'_, ty::TraitPredicate<'tcx>> = goal.with(
595-
self.tcx(),
596-
ty::TraitPredicate {
597-
trait_ref: self_trait_ref,
598-
polarity: ty::ImplPolarity::Positive,
599-
},
600-
);
601-
602-
self.assemble_param_env_candidates(trait_goal, &mut param_env_candidates);
603-
// FIXME: We probably need some sort of recursion depth check here.
604-
// Can't come up with an example yet, though, and the worst case
605-
// we can have is a compiler stack overflow...
606-
self.assemble_alias_bound_candidates(trait_goal, &mut param_env_candidates);
607-
608-
// FIXME: We must also consider alias-bound candidates for a peculiar
609-
// class of built-in candidates that I'll call "defaulted" built-ins.
610-
//
611-
// For example, we always know that `T: Pointee` is implemented, but
612-
// we do not always know what `<T as Pointee>::Metadata` actually is,
613-
// similar to if we had a user-defined impl with a `default type ...`.
614-
// For these traits, since we're not able to always normalize their
615-
// associated types to a concrete type, we must consider their alias bounds
616-
// instead, so we can prove bounds such as `<T as Pointee>::Metadata: Copy`.
617-
self.assemble_alias_bound_candidates_for_builtin_impl_default_items(
618-
trait_goal,
619-
&mut param_env_candidates,
620-
);
621-
622-
self.merge_candidates(param_env_candidates)
623-
}
624-
ty::Alias(ty::Opaque, _opaque_ty) => match goal.param_env.reveal() {
625-
Reveal::UserFacing => {
626-
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
627-
}
628-
Reveal::All => return Err(NoSolution),
629-
},
630-
_ => bug!("only expected to be called on alias tys"),
631-
}
632-
}
633-
634-
/// Assemble a subset of builtin impl candidates for a class of candidates called
635-
/// "defaulted" built-in traits.
636-
///
637-
/// For example, we always know that `T: Pointee` is implemented, but we do not
638-
/// always know what `<T as Pointee>::Metadata` actually is! See the comment in
639-
/// [`EvalCtxt::validate_alias_bound_self_from_param_env`] for more detail.
640-
#[instrument(level = "debug", skip_all)]
641-
fn assemble_alias_bound_candidates_for_builtin_impl_default_items<G: GoalKind<'tcx>>(
642-
&mut self,
643-
goal: Goal<'tcx, G>,
644-
candidates: &mut Vec<Candidate<'tcx>>,
645-
) {
646-
let lang_items = self.tcx().lang_items();
647-
let trait_def_id = goal.predicate.trait_def_id(self.tcx());
648-
649-
// You probably shouldn't add anything to this list unless you
650-
// know what you're doing.
651-
let result = if lang_items.pointee_trait() == Some(trait_def_id) {
652-
G::consider_builtin_pointee_candidate(self, goal)
653-
} else if lang_items.discriminant_kind_trait() == Some(trait_def_id) {
654-
G::consider_builtin_discriminant_kind_candidate(self, goal)
655-
} else {
656-
Err(NoSolution)
657-
};
658-
659-
match result {
660-
Ok(result) => candidates.push(Candidate {
661-
source: CandidateSource::BuiltinImpl(BuiltinImplSource::Misc),
662-
result,
663-
}),
664-
Err(NoSolution) => (),
665-
}
666-
}
667-
668554
#[instrument(level = "debug", skip_all)]
669555
fn assemble_object_bound_candidates<G: GoalKind<'tcx>>(
670556
&mut self,

tests/ui/for/issue-20605.next.stderr

+2-40
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,12 @@ error[E0277]: the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is
44
LL | for item in *things { *item = 0 }
55
| ^^^^^^^ the trait `IntoIterator` is not implemented for `dyn Iterator<Item = &'a mut u8>`
66

7-
error[E0277]: the size for values of type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` cannot be known at compilation time
8-
--> $DIR/issue-20605.rs:5:17
9-
|
10-
LL | for item in *things { *item = 0 }
11-
| ^^^^^^^ doesn't have a size known at compile-time
12-
|
13-
= help: the trait `Sized` is not implemented for `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter`
14-
= note: all local variables must have a statically known size
15-
= help: unsized locals are gated as an unstable feature
16-
177
error: the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
188
--> $DIR/issue-20605.rs:5:17
199
|
2010
LL | for item in *things { *item = 0 }
2111
| ^^^^^^^
2212

23-
error[E0277]: `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not an iterator
24-
--> $DIR/issue-20605.rs:5:17
25-
|
26-
LL | for item in *things { *item = 0 }
27-
| ^^^^^^^ `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not an iterator
28-
|
29-
= help: the trait `Iterator` is not implemented for `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter`
30-
3113
error: the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
3214
--> $DIR/issue-20605.rs:5:17
3315
|
@@ -40,33 +22,13 @@ error: the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::Into
4022
LL | for item in *things { *item = 0 }
4123
| ^^^^^^^
4224

43-
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
44-
--> $DIR/issue-20605.rs:5:5
45-
|
46-
LL | for item in *things { *item = 0 }
47-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
48-
|
49-
= help: the trait `Sized` is not implemented for `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item`
50-
note: required by a bound in `None`
51-
--> $SRC_DIR/core/src/option.rs:LL:COL
52-
53-
error[E0277]: the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
54-
--> $DIR/issue-20605.rs:5:9
55-
|
56-
LL | for item in *things { *item = 0 }
57-
| ^^^^ doesn't have a size known at compile-time
58-
|
59-
= help: the trait `Sized` is not implemented for `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item`
60-
= note: all local variables must have a statically known size
61-
= help: unsized locals are gated as an unstable feature
62-
63-
error[E0614]: type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
25+
error[E0614]: type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::Item` cannot be dereferenced
6426
--> $DIR/issue-20605.rs:5:27
6527
|
6628
LL | for item in *things { *item = 0 }
6729
| ^^^^^
6830

69-
error: aborting due to 9 previous errors
31+
error: aborting due to 5 previous errors
7032

7133
Some errors have detailed explanations: E0277, E0614.
7234
For more information about an error, try `rustc --explain E0277`.

tests/ui/for/issue-20605.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ fn changer<'a>(mut things: Box<dyn Iterator<Item=&'a mut u8>>) {
55
for item in *things { *item = 0 }
66
//[current]~^ ERROR the size for values of type
77
//[next]~^^ ERROR the trait bound `dyn Iterator<Item = &'a mut u8>: IntoIterator` is not satisfied
8-
//[next]~| ERROR the size for values of type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` cannot be known at compilation time
98
//[next]~| ERROR the type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
10-
//[next]~| ERROR `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not an iterator
119
//[next]~| ERROR the type `&mut <dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter` is not well-formed
12-
//[next]~| ERROR the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
1310
//[next]~| ERROR the type `Option<<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item>` is not well-formed
14-
//[next]~| ERROR the size for values of type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be known at compilation time
15-
//[next]~| ERROR type `<<dyn Iterator<Item = &'a mut u8> as IntoIterator>::IntoIter as Iterator>::Item` cannot be dereferenced
11+
//[next]~| ERROR type `<dyn Iterator<Item = &'a mut u8> as IntoIterator>::Item` cannot be dereferenced
12+
1613
// FIXME(-Znext-solver): these error messages are horrible and have to be
1714
// improved before we stabilize the new solver.
1815
}

tests/ui/traits/next-solver/object-unsafety.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ pub fn copy_any<T>(t: &T) -> T {
1414
//~| ERROR the trait bound `dyn Setup<From = T>: Setup` is not satisfied
1515
//~| ERROR mismatched types
1616
//~| ERROR the type `<dyn Setup<From = T> as Setup>::From` is not well-formed
17-
//~| ERROR the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
1817

1918
// FIXME(-Znext-solver): These error messages are horrible and some of them
2019
// are even simple fallout from previous error.

tests/ui/traits/next-solver/object-unsafety.stderr

+1-14
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,7 @@ error: the type `<dyn Setup<From = T> as Setup>::From` is not well-formed
4242
LL | copy::<dyn Setup<From=T>>(t)
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4444

45-
error[E0277]: the size for values of type `<dyn Setup<From = T> as Setup>::From` cannot be known at compilation time
46-
--> $DIR/object-unsafety.rs:12:5
47-
|
48-
LL | copy::<dyn Setup<From=T>>(t)
49-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
50-
|
51-
= help: the trait `Sized` is not implemented for `<dyn Setup<From = T> as Setup>::From`
52-
= note: the return type of a function must have a statically known size
53-
help: consider further restricting the associated type
54-
|
55-
LL | pub fn copy_any<T>(t: &T) -> T where <dyn Setup<From = T> as Setup>::From: Sized {
56-
| +++++++++++++++++++++++++++++++++++++++++++++++++
57-
58-
error: aborting due to 5 previous errors
45+
error: aborting due to 4 previous errors
5946

6047
Some errors have detailed explanations: E0277, E0308.
6148
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)