Skip to content

Commit 91a79fb

Browse files
committed
Auto merge of #76985 - hbina:clone_check, r=estebank
Prevent stack overflow in deeply nested types. Related issue #75577 (?) Unfortunately, I am unable to test whether this actually solves the problem because apparently, 12GB RAM + 2GB swap is not enough to compile the (admittedly toy) source file.
2 parents 4437b4b + dc655b2 commit 91a79fb

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

compiler/rustc_ast/src/ast.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::token::{self, CommentKind, DelimToken};
2727
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
2828

2929
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
30+
use rustc_data_structures::stack::ensure_sufficient_stack;
3031
use rustc_data_structures::sync::Lrc;
3132
use rustc_data_structures::thin_vec::ThinVec;
3233
use rustc_macros::HashStable_Generic;
@@ -1864,14 +1865,25 @@ pub enum AssocTyConstraintKind {
18641865
Bound { bounds: GenericBounds },
18651866
}
18661867

1867-
#[derive(Clone, Encodable, Decodable, Debug)]
1868+
#[derive(Encodable, Decodable, Debug)]
18681869
pub struct Ty {
18691870
pub id: NodeId,
18701871
pub kind: TyKind,
18711872
pub span: Span,
18721873
pub tokens: Option<TokenStream>,
18731874
}
18741875

1876+
impl Clone for Ty {
1877+
fn clone(&self) -> Self {
1878+
ensure_sufficient_stack(|| Self {
1879+
id: self.id,
1880+
kind: self.kind.clone(),
1881+
span: self.span,
1882+
tokens: self.tokens.clone(),
1883+
})
1884+
}
1885+
}
1886+
18751887
#[derive(Clone, Encodable, Decodable, Debug)]
18761888
pub struct BareFnTy {
18771889
pub unsafety: Unsafe,

0 commit comments

Comments
 (0)