@@ -7,6 +7,7 @@ use crate::autoderef::Autoderef;
7
7
use crate :: infer:: InferCtxt ;
8
8
use crate :: traits:: normalize_projection_type;
9
9
10
+ use rustc_data_structures:: stack:: ensure_sufficient_stack;
10
11
use rustc_errors:: { error_code, struct_span_err, Applicability , DiagnosticBuilder , Style } ;
11
12
use rustc_hir as hir;
12
13
use rustc_hir:: def:: DefKind ;
@@ -1912,12 +1913,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1912
1913
1913
1914
let parent_predicate = parent_trait_ref. without_const ( ) . to_predicate ( tcx) ;
1914
1915
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
+ } ) ;
1921
1925
}
1922
1926
}
1923
1927
ObligationCauseCode :: ImplDerivedObligation ( ref data) => {
@@ -1928,22 +1932,28 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
1928
1932
parent_trait_ref. skip_binder( ) . self_ty( )
1929
1933
) ) ;
1930
1934
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
+ } ) ;
1937
1944
}
1938
1945
ObligationCauseCode :: DerivedObligation ( ref data) => {
1939
1946
let parent_trait_ref = self . resolve_vars_if_possible ( & data. parent_trait_ref ) ;
1940
1947
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
+ } ) ;
1947
1957
}
1948
1958
ObligationCauseCode :: CompareImplMethodObligation { .. } => {
1949
1959
err. note ( & format ! (
0 commit comments