about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>2020-09-21 04:19:51 +0800
committerHanif Bin Ariffin <hanif.ariffin.4326@gmail.com>2020-09-21 04:20:41 +0800
commitdc655b28424549a4775bc2e8c9021d44482bccb1 (patch)
tree81fcc6026a69f5969907ed3424e2fd97fdc9ea62
parent2e0edc0f28c5647141bedba02e7a222d3a5dc9c3 (diff)
downloadrust-dc655b28424549a4775bc2e8c9021d44482bccb1.tar.gz
rust-dc655b28424549a4775bc2e8c9021d44482bccb1.zip
Prevent stackoverflow
-rw-r--r--compiler/rustc_ast/src/ast.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs
index 95abf552915..0399c4829a1 100644
--- a/compiler/rustc_ast/src/ast.rs
+++ b/compiler/rustc_ast/src/ast.rs
@@ -27,6 +27,7 @@ use crate::token::{self, CommentKind, DelimToken};
 use crate::tokenstream::{DelimSpan, TokenStream, TokenTree};
 
 use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stack::ensure_sufficient_stack;
 use rustc_data_structures::sync::Lrc;
 use rustc_data_structures::thin_vec::ThinVec;
 use rustc_macros::HashStable_Generic;
@@ -1864,7 +1865,7 @@ pub enum AssocTyConstraintKind {
     Bound { bounds: GenericBounds },
 }
 
-#[derive(Clone, Encodable, Decodable, Debug)]
+#[derive(Encodable, Decodable, Debug)]
 pub struct Ty {
     pub id: NodeId,
     pub kind: TyKind,
@@ -1872,6 +1873,17 @@ pub struct Ty {
     pub tokens: Option<TokenStream>,
 }
 
+impl Clone for Ty {
+    fn clone(&self) -> Self {
+        ensure_sufficient_stack(|| Self {
+            id: self.id,
+            kind: self.kind.clone(),
+            span: self.span,
+            tokens: self.tokens.clone(),
+        })
+    }
+}
+
 #[derive(Clone, Encodable, Decodable, Debug)]
 pub struct BareFnTy {
     pub unsafety: Unsafe,