@@ -226,6 +226,7 @@ pub struct SelectionCache<'tcx> {
226226/// parameter environment.
227227#[ derive( PartialEq , Eq , Debug , Clone ) ]
228228enum SelectionCandidate < ' tcx > {
229+ /// If has_nested is false, there are no *further* obligations
229230 BuiltinCandidate { has_nested : bool } ,
230231 ParamCandidate ( ty:: PolyTraitRef < ' tcx > ) ,
231232 ImplCandidate ( DefId ) ,
@@ -2039,12 +2040,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20392040 }
20402041
20412042 match other. candidate {
2043+ // Prefer BuiltinCandidate { has_nested: false } to anything else.
2044+ // This is a fix for #53123 and prevents winnowing from accidentally extending the
2045+ // lifetime of a variable.
2046+ BuiltinCandidate { has_nested : false } => true ,
20422047 ParamCandidate ( ref cand) => match victim. candidate {
20432048 AutoImplCandidate ( ..) => {
20442049 bug ! (
20452050 "default implementations shouldn't be recorded \
20462051 when there are other valid candidates") ;
20472052 }
2053+ // Prefer BuiltinCandidate { has_nested: false } to anything else.
2054+ // This is a fix for #53123 and prevents winnowing from accidentally extending the
2055+ // lifetime of a variable.
2056+ BuiltinCandidate { has_nested : false } => false ,
20482057 ImplCandidate ( ..) |
20492058 ClosureCandidate |
20502059 GeneratorCandidate |
@@ -2072,6 +2081,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20722081 "default implementations shouldn't be recorded \
20732082 when there are other valid candidates") ;
20742083 }
2084+ // Prefer BuiltinCandidate { has_nested: false } to anything else.
2085+ // This is a fix for #53123 and prevents winnowing from accidentally extending the
2086+ // lifetime of a variable.
2087+ BuiltinCandidate { has_nested : false } => false ,
20752088 ImplCandidate ( ..) |
20762089 ClosureCandidate |
20772090 GeneratorCandidate |
@@ -2115,7 +2128,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
21152128 FnPointerCandidate |
21162129 BuiltinObjectCandidate |
21172130 BuiltinUnsizeCandidate |
2118- BuiltinCandidate { .. } => {
2131+ BuiltinCandidate { has_nested : true } => {
21192132 match victim. candidate {
21202133 ParamCandidate ( ref cand) => {
21212134 // Prefer these to a global where-clause bound
0 commit comments