]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/coherence_inherent.rs
New upstream version 1.24.1+dfsg1
[rustc.git] / src / test / compile-fail / coherence_inherent.rs
1 // Copyright 2012 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 // Tests that methods that implement a trait cannot be invoked
12 // unless the trait is imported.
13
14 mod Lib {
15 pub trait TheTrait {
16 fn the_fn(&self);
17 }
18
19 pub struct TheStruct;
20
21 impl TheTrait for TheStruct {
22 fn the_fn(&self) {}
23 }
24 }
25
26 mod Import {
27 // Trait is in scope here:
28 use Lib::TheStruct;
29 use Lib::TheTrait;
30
31 fn call_the_fn(s: &TheStruct) {
32 s.the_fn();
33 }
34 }
35
36 mod NoImport {
37 // Trait is not in scope here:
38 use Lib::TheStruct;
39
40 fn call_the_fn(s: &TheStruct) {
41 s.the_fn(); //~ ERROR no method named `the_fn` found
42 }
43 }
44
45 fn main() {}