Skip to content

Commit 0cda12e

Browse files
committed
Add compile-fail tests for no_prelude
1 parent cb4bdd2 commit 0cda12e

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

src/test/compile-fail/no-prelude.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
#![no_prelude]
13+
14+
// Test that things from the prelude aren't in scope. Use many of them
15+
// so that renaming some things won't magically make this test fail
16+
// for the wrong reason (e.g. if `Add` changes to `Addition`, and
17+
// `no_prelude` stops working, then the `impl Add` will still
18+
// fail with the same error message).
19+
20+
struct Test;
21+
impl Add for Test {} //~ ERROR: not in scope
22+
impl Clone for Test {} //~ ERROR: not in scope
23+
impl Iterator for Test {} //~ ERROR: not in scope
24+
impl ToString for Test {} //~ ERROR: not in scope
25+
impl Writer for Test {} //~ ERROR: not in scope
26+
27+
fn main() {
28+
drop(2) //~ ERROR: unresolved name
29+
}

0 commit comments

Comments
 (0)