@@ -62,6 +62,7 @@ use rustc_span::{self, BytePos, DesugaringKind, Span};
62
62
use rustc_target:: spec:: abi:: Abi ;
63
63
use rustc_trait_selection:: infer:: InferCtxtExt as _;
64
64
use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
65
+ use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
65
66
use rustc_trait_selection:: traits:: {
66
67
self , NormalizeExt , ObligationCause , ObligationCauseCode , ObligationCtxt ,
67
68
} ;
@@ -144,12 +145,28 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
144
145
debug ! ( "unify(a: {:?}, b: {:?}, use_lub: {})" , a, b, self . use_lub) ;
145
146
self . commit_if_ok ( |_| {
146
147
let at = self . at ( & self . cause , self . fcx . param_env ) ;
147
- if self . use_lub {
148
+
149
+ let res = if self . use_lub {
148
150
at. lub ( DefineOpaqueTypes :: Yes , b, a)
149
151
} else {
150
152
at. sup ( DefineOpaqueTypes :: Yes , b, a)
151
153
. map ( |InferOk { value : ( ) , obligations } | InferOk { value : a, obligations } )
154
+ } ;
155
+
156
+ // In the new solver, lazy norm may allow us to shallowly equate
157
+ // more types, but we emit possibly impossible-to-satisfy obligations.
158
+ // Filter these cases out to make sure our coercion is more accurate.
159
+ if self . tcx . trait_solver_next ( ) {
160
+ if let Ok ( res) = & res {
161
+ for obligation in & res. obligations {
162
+ if !self . predicate_may_hold ( & obligation) {
163
+ return Err ( TypeError :: Mismatch ) ;
164
+ }
165
+ }
166
+ }
152
167
}
168
+
169
+ res
153
170
} )
154
171
}
155
172
0 commit comments