@@ -226,6 +226,7 @@ pub struct SelectionCache<'tcx> {
226
226
/// parameter environment.
227
227
#[ derive( PartialEq , Eq , Debug , Clone ) ]
228
228
enum SelectionCandidate < ' tcx > {
229
+ /// If has_nested is false, there are no *further* obligations
229
230
BuiltinCandidate { has_nested : bool } ,
230
231
ParamCandidate ( ty:: PolyTraitRef < ' tcx > ) ,
231
232
ImplCandidate ( DefId ) ,
@@ -2039,12 +2040,20 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2039
2040
}
2040
2041
2041
2042
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 ,
2042
2047
ParamCandidate ( ref cand) => match victim. candidate {
2043
2048
AutoImplCandidate ( ..) => {
2044
2049
bug ! (
2045
2050
"default implementations shouldn't be recorded \
2046
2051
when there are other valid candidates") ;
2047
2052
}
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 ,
2048
2057
ImplCandidate ( ..) |
2049
2058
ClosureCandidate |
2050
2059
GeneratorCandidate |
@@ -2072,6 +2081,10 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2072
2081
"default implementations shouldn't be recorded \
2073
2082
when there are other valid candidates") ;
2074
2083
}
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 ,
2075
2088
ImplCandidate ( ..) |
2076
2089
ClosureCandidate |
2077
2090
GeneratorCandidate |
@@ -2115,7 +2128,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
2115
2128
FnPointerCandidate |
2116
2129
BuiltinObjectCandidate |
2117
2130
BuiltinUnsizeCandidate |
2118
- BuiltinCandidate { .. } => {
2131
+ BuiltinCandidate { has_nested : true } => {
2119
2132
match victim. candidate {
2120
2133
ParamCandidate ( ref cand) => {
2121
2134
// Prefer these to a global where-clause bound
0 commit comments