Skip to content

Commit 68b9cdf

Browse files
committed
[review] joshtriplett
1 parent 797ef60 commit 68b9cdf

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
fn module_in_function_cannot_access_variables() {
2+
let x: i32 = 5;
3+
4+
mod inner {
5+
use super::x; //~ ERROR unresolved import `super::x`
6+
fn get_x() -> i32 {
7+
x
8+
}
9+
}
10+
}
11+
12+
fn main() { }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0432]: unresolved import `super::x`
2+
--> $DIR/module-in-block-compile-fail.rs:5:13
3+
|
4+
LL | use super::x;
5+
| ^^^^^^^^ no `x` in `<opaque>`
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0432`.

src/test/ui/resolve/module-in-block-run-pass.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,36 @@ fn module_in_block_prefer_inner_glob() {
9999
assert_eq!(inner::get_const(), "INNER");
100100
}
101101
}
102+
103+
#[test]
104+
fn module_in_block_does_not_use_variables() {
105+
#[allow(unused_variables)]
106+
let bar = || "inner_block";
107+
108+
109+
// anonymous block
110+
mod inner {
111+
use super::bar;
112+
pub fn call_bar() -> &'static str {
113+
bar()
114+
}
115+
}
116+
117+
assert_eq!(inner::call_bar(), "outer");
118+
}
119+
120+
#[test]
121+
fn module_in_block_does_not_use_variables_glob() {
122+
#[allow(unused_variables)]
123+
let bar = || "inner_block";
124+
125+
// anonymous block
126+
mod inner {
127+
use super::*;
128+
pub fn call_bar() -> &'static str {
129+
bar()
130+
}
131+
}
132+
133+
assert_eq!(inner::call_bar(), "outer");
134+
}

0 commit comments

Comments
 (0)