Skip to content

Commit c7d5a52

Browse files
committed
auto merge of #10189 : alexcrichton/rust/inner-statics, r=cmr
Closes #9186
2 parents 55eed05 + 0db5005 commit c7d5a52

File tree

3 files changed

+62
-23
lines changed

3 files changed

+62
-23
lines changed

src/libextra/treemap.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
145145
pub fn iter<'a>(&'a self) -> TreeMapIterator<'a, K, V> {
146146
TreeMapIterator {
147147
stack: ~[],
148-
node: &self.root,
148+
node: deref(&self.root),
149149
remaining_min: self.length,
150150
remaining_max: self.length
151151
}
@@ -162,7 +162,7 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
162162
fn iter_for_traversal<'a>(&'a self) -> TreeMapIterator<'a, K, V> {
163163
TreeMapIterator {
164164
stack: ~[],
165-
node: &self.root,
165+
node: deref(&self.root),
166166
remaining_min: 0,
167167
remaining_max: self.length
168168
}
@@ -173,8 +173,8 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
173173
pub fn lower_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
174174
let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal();
175175
loop {
176-
match *iter.node {
177-
Some(ref r) => {
176+
match iter.node {
177+
Some(r) => {
178178
match k.cmp(&r.key) {
179179
Less => iter_traverse_left(&mut iter),
180180
Greater => iter_traverse_right(&mut iter),
@@ -197,8 +197,8 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
197197
pub fn upper_bound_iter<'a>(&'a self, k: &K) -> TreeMapIterator<'a, K, V> {
198198
let mut iter: TreeMapIterator<'a, K, V> = self.iter_for_traversal();
199199
loop {
200-
match *iter.node {
201-
Some(ref r) => {
200+
match iter.node {
201+
Some(r) => {
202202
match k.cmp(&r.key) {
203203
Less => iter_traverse_left(&mut iter),
204204
Greater => iter_traverse_right(&mut iter),
@@ -229,24 +229,34 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
229229

230230
/// Lazy forward iterator over a map
231231
pub struct TreeMapIterator<'self, K, V> {
232-
priv stack: ~[&'self ~TreeNode<K, V>],
233-
priv node: &'self Option<~TreeNode<K, V>>,
232+
priv stack: ~[&'self TreeNode<K, V>],
233+
priv node: Option<&'self TreeNode<K, V>>,
234234
priv remaining_min: uint,
235235
priv remaining_max: uint
236236
}
237237

238+
fn deref<'a, K, V>(node: &'a Option<~TreeNode<K, V>>) -> Option<&'a TreeNode<K, V>> {
239+
match *node {
240+
Some(ref n) => {
241+
let n: &TreeNode<K, V> = *n;
242+
Some(n)
243+
}
244+
None => None
245+
}
246+
}
247+
238248
impl<'self, K, V> TreeMapIterator<'self, K, V> {
239249
#[inline(always)]
240250
fn next_(&mut self, forward: bool) -> Option<(&'self K, &'self V)> {
241251
while !self.stack.is_empty() || self.node.is_some() {
242-
match *self.node {
243-
Some(ref x) => {
252+
match self.node {
253+
Some(x) => {
244254
self.stack.push(x);
245-
self.node = if forward { &x.left } else { &x.right };
255+
self.node = deref(if forward { &x.left } else { &x.right });
246256
}
247257
None => {
248258
let res = self.stack.pop();
249-
self.node = if forward { &res.right } else { &res.left };
259+
self.node = deref(if forward { &res.right } else { &res.left });
250260
self.remaining_max -= 1;
251261
if self.remaining_min > 0 {
252262
self.remaining_min -= 1;
@@ -302,14 +312,14 @@ impl<'self, K, V> Iterator<(&'self K, &'self V)> for TreeMapRevIterator<'self, K
302312
/// - complete initialization with `iter_traverse_complete`
303313
#[inline]
304314
fn iter_traverse_left<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) {
305-
let node = it.node.get_ref();
315+
let node = it.node.unwrap();
306316
it.stack.push(node);
307-
it.node = &node.left;
317+
it.node = deref(&node.left);
308318
}
309319

310320
#[inline]
311321
fn iter_traverse_right<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) {
312-
it.node = &(it.node.get_ref().right);
322+
it.node = deref(&it.node.get_ref().right);
313323
}
314324

315325
/// iter_traverse_left, iter_traverse_right and iter_traverse_complete are used to
@@ -321,11 +331,10 @@ fn iter_traverse_right<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) {
321331
/// traversed left.
322332
#[inline]
323333
fn iter_traverse_complete<'a, K, V>(it: &mut TreeMapIterator<'a, K, V>) {
324-
static none: Option<~TreeNode<K, V>> = None;
325-
match *it.node {
326-
Some(ref n) => {
334+
match it.node {
335+
Some(n) => {
327336
it.stack.push(n);
328-
it.node = &none;
337+
it.node = None;
329338
}
330339
None => ()
331340
}

src/librustc/middle/resolve.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3488,10 +3488,17 @@ impl Resolver {
34883488
return None;
34893489
}
34903490
ConstantItemRibKind => {
3491-
// Still doesn't deal with upvars
3492-
self.resolve_error(span,
3493-
"attempt to use a non-constant \
3494-
value in a constant");
3491+
if is_ty_param {
3492+
// see #9186
3493+
self.resolve_error(span,
3494+
"cannot use an outer type \
3495+
parameter in this context");
3496+
} else {
3497+
// Still doesn't deal with upvars
3498+
self.resolve_error(span,
3499+
"attempt to use a non-constant \
3500+
value in a constant");
3501+
}
34953502

34963503
}
34973504
}
@@ -3764,7 +3771,9 @@ impl Resolver {
37643771

37653772
fn with_constant_rib(&mut self, f: &fn(&mut Resolver)) {
37663773
self.value_ribs.push(@Rib::new(ConstantItemRibKind));
3774+
self.type_ribs.push(@Rib::new(ConstantItemRibKind));
37673775
f(self);
3776+
self.type_ribs.pop();
37683777
self.value_ribs.pop();
37693778
}
37703779

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2013 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+
// see #9186
12+
13+
enum Bar<T> { What }
14+
15+
fn foo<T>() {
16+
static a: Bar<T> = What;
17+
//~^ ERROR: cannot use an outer type parameter in this context
18+
}
19+
20+
fn main() {
21+
}

0 commit comments

Comments
 (0)