@@ -62,6 +62,7 @@ use rustc_span::{self, BytePos, DesugaringKind, Span};
6262use rustc_target:: spec:: abi:: Abi ;
6363use rustc_trait_selection:: infer:: InferCtxtExt as _;
6464use rustc_trait_selection:: traits:: error_reporting:: TypeErrCtxtExt as _;
65+ use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt ;
6566use rustc_trait_selection:: traits:: {
6667 self , NormalizeExt , ObligationCause , ObligationCauseCode , ObligationCtxt ,
6768} ;
@@ -144,12 +145,28 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
144145 debug ! ( "unify(a: {:?}, b: {:?}, use_lub: {})" , a, b, self . use_lub) ;
145146 self . commit_if_ok ( |_| {
146147 let at = self . at ( & self . cause , self . fcx . param_env ) ;
147- if self . use_lub {
148+
149+ let res = if self . use_lub {
148150 at. lub ( DefineOpaqueTypes :: Yes , b, a)
149151 } else {
150152 at. sup ( DefineOpaqueTypes :: Yes , b, a)
151153 . 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+ }
152167 }
168+
169+ res
153170 } )
154171 }
155172
0 commit comments