@@ -7,6 +7,7 @@ use crate::autoderef::Autoderef;
77use crate :: infer:: InferCtxt ;
88use crate :: traits:: normalize_projection_type;
99
10+ use rustc_data_structures:: stack:: ensure_sufficient_stack;
1011use rustc_errors:: { error_code, struct_span_err, Applicability , DiagnosticBuilder , Style } ;
1112use rustc_hir as hir;
1213use rustc_hir:: def:: DefKind ;
@@ -1912,12 +1913,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19121913
19131914 let parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
19141915 if !self . is_recursive_obligation ( obligated_types, & data. parent_code ) {
1915- self . note_obligation_cause_code (
1916- err,
1917- & parent_predicate,
1918- & data. parent_code ,
1919- obligated_types,
1920- ) ;
1916+ // #74711: avoid a stack overflow
1917+ ensure_sufficient_stack ( || {
1918+ self . note_obligation_cause_code (
1919+ err,
1920+ & parent_predicate,
1921+ & data. parent_code ,
1922+ obligated_types,
1923+ )
1924+ } ) ;
19211925 }
19221926 }
19231927 ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
@@ -1928,22 +1932,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
19281932 parent_trait_ref. skip_binder( ) . self_ty( )
19291933 ) ) ;
19301934 let parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
1931- self . note_obligation_cause_code (
1932- err,
1933- & parent_predicate,
1934- & data. parent_code ,
1935- obligated_types,
1936- ) ;
1935+ // #74711: avoid a stack overflow
1936+ ensure_sufficient_stack ( || {
1937+ self . note_obligation_cause_code (
1938+ err,
1939+ & parent_predicate,
1940+ & data. parent_code ,
1941+ obligated_types,
1942+ )
1943+ } ) ;
19371944 }
19381945 ObligationCauseCode :: DerivedObligation ( ref data) => {
19391946 let parent_trait_ref = self . resolve_vars_if_possible ( & data. parent_trait_ref ) ;
19401947 let parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
1941- self . note_obligation_cause_code (
1942- err,
1943- & parent_predicate,
1944- & data. parent_code ,
1945- obligated_types,
1946- ) ;
1948+ // #74711: avoid a stack overflow
1949+ ensure_sufficient_stack ( || {
1950+ self . note_obligation_cause_code (
1951+ err,
1952+ & parent_predicate,
1953+ & data. parent_code ,
1954+ obligated_types,
1955+ )
1956+ } ) ;
19471957 }
19481958 ObligationCauseCode :: CompareImplMethodObligation { .. } => {
19491959 err. note ( & format ! (
0 commit comments