+ -- Find the universally quantified type variables
+ -- in the pattern type signatures
+ getLocalNameEnv `thenRn` \ name_env ->
+ let
+ tyvars_in_sigs = rhs_sig_tyvars `unionLists` tyvars_in_pats
+ rhs_sig_tyvars = case maybe_rhs_sig of
+ Nothing -> []
+ Just ty -> extractHsTyRdrNames ty
+ tyvars_in_pats = extractPatsTyVars pats
+ forall_tyvars = filter (not . (`elemFM` name_env)) tyvars_in_sigs
+ doc = text "a pattern type-signature"
+ in
+ bindTyVarsFVRn doc (map UserTyVar forall_tyvars) $ \ sig_tyvars ->
+
+ -- Note that we do a single bindLocalsRn for all the
+ -- matches together, so that we spot the repeated variable in
+ -- f x x = 1
+ bindLocalsFVRn doc (collectPatsBinders pats) $ \ new_binders ->
+
+ mapFvRn rnPat pats `thenRn` \ (pats', pat_fvs) ->
+ rnGRHSs grhss `thenRn` \ (grhss', grhss_fvs) ->
+ (case maybe_rhs_sig of
+ Nothing -> returnRn (Nothing, emptyFVs)
+ Just ty | opt_GlasgowExts -> rnHsType doc ty `thenRn` \ (ty', ty_fvs) ->
+ returnRn (Just ty', ty_fvs)
+ | otherwise -> addErrRn (patSigErr ty) `thenRn_`
+ returnRn (Nothing, emptyFVs)
+ ) `thenRn` \ (maybe_rhs_sig', ty_fvs) ->
+
+ let
+ binder_set = mkNameSet new_binders
+ unused_binders = nameSetToList (binder_set `minusNameSet` grhss_fvs)
+ all_fvs = grhss_fvs `plusFV` pat_fvs `plusFV` ty_fvs
+ in
+ warnUnusedMatches unused_binders `thenRn_`
+
+ returnRn (Match sig_tyvars pats' maybe_rhs_sig' grhss', all_fvs)
+ -- The bindLocals and bindTyVars will remove the bound FVs