|
| 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 | +#![feature(no_prelude)] |
| 12 | + |
| 13 | +// Test that things from the prelude aren't in scope. Use many of them |
| 14 | +// so that renaming some things won't magically make this test fail |
| 15 | +// for the wrong reason (e.g. if `Add` changes to `Addition`, and |
| 16 | +// `no_prelude` stops working, then the `impl Add` will still |
| 17 | +// fail with the same error message). |
| 18 | +// |
| 19 | +// Unlike `no_implicit_prelude`, `no_prelude` doesn't cascade into nested |
| 20 | +// modules, this makes the impl in foo::baz work. |
| 21 | + |
| 22 | +#[no_prelude] |
| 23 | +mod foo { |
| 24 | + mod baz { |
| 25 | + struct Test; |
| 26 | + impl From<Test> for Test { fn from(t: Test) { Test }} |
| 27 | + impl Clone for Test { fn clone(&self) { Test } } |
| 28 | + impl Eq for Test {} |
| 29 | + |
| 30 | + fn foo() { |
| 31 | + drop(2) |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + struct Test; |
| 36 | + impl From for Test {} //~ ERROR: not in scope |
| 37 | + impl Clone for Test {} //~ ERROR: not in scope |
| 38 | + impl Iterator for Test {} //~ ERROR: not in scope |
| 39 | + impl ToString for Test {} //~ ERROR: not in scope |
| 40 | + impl Eq for Test {} //~ ERROR: not in scope |
| 41 | + |
| 42 | + fn foo() { |
| 43 | + drop(2) //~ ERROR: unresolved name |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +fn qux() { |
| 48 | + #[no_prelude] |
| 49 | + mod qux_inner { |
| 50 | + struct Test; |
| 51 | + impl From for Test {} //~ ERROR: not in scope |
| 52 | + impl Clone for Test {} //~ ERROR: not in scope |
| 53 | + impl Iterator for Test {} //~ ERROR: not in scope |
| 54 | + impl ToString for Test {} //~ ERROR: not in scope |
| 55 | + impl Eq for Test {} //~ ERROR: not in scope |
| 56 | + |
| 57 | + fn foo() { |
| 58 | + drop(2) //~ ERROR: unresolved name |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | + |
| 64 | +fn main() { |
| 65 | + // these should work fine |
| 66 | + drop(2) |
| 67 | +} |
0 commit comments