-getEqExtra :: TidyEnv -> CtFlavor -> TcType -> TcType -> TcM (TidyEnv, SDoc)
-getEqExtra env (Wanted loc) ty1 ty2 = getWantedEqExtra env (ctLocOrigin loc) ty1 ty2
-getEqExtra env (Derived loc) ty1 ty2 = getWantedEqExtra env (ctLocOrigin loc) ty1 ty2
-getEqExtra env (Given _) _ _ = return (env, empty)
- -- We could print more info, but it seems to be already coming out
-
-getWantedEqExtra :: TidyEnv -> CtOrigin -> TcType -> TcType -> TcM (TidyEnv, SDoc)
-getWantedEqExtra env0 (TypeEqOrigin item) ty1 ty2
+wrapEqErrTcS :: CtFlavor -> TcType -> TcType
+ -> (TidyEnv -> SDoc -> TcM a)
+ -> TcS a
+wrapEqErrTcS fl ty1 ty2 thing_inside
+ = do { ty_binds_var <- getTcSTyBinds
+ ; wrapErrTcS $ setCtFlavorLoc fl $
+ do { env0 <- tcInitTidyEnv
+ ; ty_binds_bag <- readTcRef ty_binds_var
+ ; let subst = mkOpenTvSubst (mkVarEnv (bagToList ty_binds_bag))
+ ; case fl of
+ Wanted loc -> getWantedEqExtra subst env0 (ctLocOrigin loc) ty1 ty2 thing_inside
+ Derived loc -> getWantedEqExtra subst env0 (ctLocOrigin loc) ty1 ty2 thing_inside
+ Given {} -> thing_inside env0 empty -- We could print more info, but it
+ -- seems to be coming out already
+ } }
+
+getWantedEqExtra :: TvSubst -> TidyEnv -> CtOrigin -> TcType -> TcType
+ -> (TidyEnv -> SDoc -> TcM a)
+ -> TcM a
+getWantedEqExtra subst env0 (TypeEqOrigin item) ty1 ty2 thing_inside