Skip to content

Commit ef4982f

Browse files
committed
auto merge of #19466 : nikomatsakis/rust/recursion-limit, r=eddyb
This is particularly important for deeply nested types, which generate deeply nested impls. This is a fix for #19318. It's possible we could also improve this particular case not to increment the recursion count, but it's worth being able to adjust the recursion limit anyhow. cc @jdm r? @pcwalton
2 parents cafe296 + 34812b8 commit ef4982f

File tree

8 files changed

+126
-294
lines changed

8 files changed

+126
-294
lines changed

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ pub mod middle {
8888
pub mod privacy;
8989
pub mod reachable;
9090
pub mod region;
91+
pub mod recursion_limit;
9192
pub mod resolve;
9293
pub mod resolve_lifetime;
9394
pub mod stability;
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Recursion limit.
12+
//
13+
// There are various parts of the compiler that must impose arbitrary limits
14+
// on how deeply they recurse to prevent stack overflow. Users can override
15+
// this via an attribute on the crate like `#![recursion_limit(22)]`. This pass
16+
// just peeks and looks for that attribute.
17+
18+
use session::Session;
19+
use syntax::ast;
20+
use syntax::attr::AttrMetaMethods;
21+
use std::str::FromStr;
22+
23+
pub fn update_recursion_limit(sess: &Session, krate: &ast::Crate) {
24+
for attr in krate.attrs.iter() {
25+
if !attr.check_name("recursion_limit") {
26+
continue;
27+
}
28+
29+
if let Some(s) = attr.value_str() {
30+
if let Some(n) = FromStr::from_str(s.get()) {
31+
sess.recursion_limit.set(n);
32+
return;
33+
}
34+
}
35+
36+
sess.span_err(attr.span, "malformed recursion limit attribute, \
37+
expected #![recursion_limit(\"N\")]");
38+
}
39+
}

0 commit comments

Comments
 (0)