about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-01-22 09:55:29 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-01-26 04:16:58 +0000
commitfaf0852fc1d01aef18fe8098a0f2f601dbfebd9b (patch)
tree476dad97e14b84d094c8ae97bc9de7813e2db37a /src/test
parent54475e950cf3db909c4dec4a30c72f7636ab4e07 (diff)
downloadrust-faf0852fc1d01aef18fe8098a0f2f601dbfebd9b.tar.gz
rust-faf0852fc1d01aef18fe8098a0f2f601dbfebd9b.zip
Resolve: fix #23880, a scoping bug
This fixes a bug in which items in a block are shadowed by local variables and type parameters that are in scope.
It is a [breaking-change]. For example, the following code breaks:

```rust
fn foo() {
    let mut f = 1;
    {
        fn f() {}
        f += 1; // This will now resolve to the function instead of the local variable
    }
}
```

Any breakage can be fixed by renaming the item that is no longer shadowed.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/lexical-scoping.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/test/run-pass/lexical-scoping.rs b/src/test/run-pass/lexical-scoping.rs
new file mode 100644
index 00000000000..36604042d0f
--- /dev/null
+++ b/src/test/run-pass/lexical-scoping.rs
@@ -0,0 +1,28 @@
+// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// Tests that items in subscopes can shadow type parameters and local variables (see issue #23880).
+
+#![allow(unused)]
+struct Foo<X> { x: Box<X> }
+impl<Bar> Foo<Bar> {
+    fn foo(&self) {
+        type Bar = i32;
+        let _: Bar = 42;
+    }
+}
+
+fn main() {
+    let f = 1;
+    {
+        fn f() {}
+        f();
+    }
+}