Skip to content

Commit

Permalink
[review] joshtriplett
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Feb 27, 2021
1 parent 797ef60 commit 68b9cdf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/ui/resolve/module-in-block-compile-fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
fn module_in_function_cannot_access_variables() {
let x: i32 = 5;

mod inner {
use super::x; //~ ERROR unresolved import `super::x`
fn get_x() -> i32 {
x
}
}
}

fn main() { }
9 changes: 9 additions & 0 deletions src/test/ui/resolve/module-in-block-compile-fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0432]: unresolved import `super::x`
--> $DIR/module-in-block-compile-fail.rs:5:13
|
LL | use super::x;
| ^^^^^^^^ no `x` in `<opaque>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
33 changes: 33 additions & 0 deletions src/test/ui/resolve/module-in-block-run-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,36 @@ fn module_in_block_prefer_inner_glob() {
assert_eq!(inner::get_const(), "INNER");
}
}

#[test]
fn module_in_block_does_not_use_variables() {
#[allow(unused_variables)]
let bar = || "inner_block";


// anonymous block
mod inner {
use super::bar;
pub fn call_bar() -> &'static str {
bar()
}
}

assert_eq!(inner::call_bar(), "outer");
}

#[test]
fn module_in_block_does_not_use_variables_glob() {
#[allow(unused_variables)]
let bar = || "inner_block";

// anonymous block
mod inner {
use super::*;
pub fn call_bar() -> &'static str {
bar()
}
}

assert_eq!(inner::call_bar(), "outer");
}

0 comments on commit 68b9cdf

Please sign in to comment.