]> git.lizzy.rs Git - rust.git/blob - src/test/auxiliary/regions_bounded_method_type_parameters_cross_crate_lib.rs
rustc: Add support for `extern crate foo as bar`
[rust.git] / src / test / auxiliary / regions_bounded_method_type_parameters_cross_crate_lib.rs
1 // Copyright 2014 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 // Check that method bounds declared on traits/impls in a cross-crate
12 // scenario work. This is the library portion of the test.
13
14 pub enum MaybeOwned<'a> {
15     Owned(int),
16     Borrowed(&'a int)
17 }
18
19 pub struct Inv<'a> { // invariant w/r/t 'a
20     x: &'a mut &'a int
21 }
22
23 // I encountered a bug at some point with encoding the IntoMaybeOwned
24 // trait, so I'll use that as the template for this test.
25 pub trait IntoMaybeOwned<'a> {
26     fn into_maybe_owned(self) -> MaybeOwned<'a>;
27
28     // Note: without this `into_inv` method, the trait is
29     // contravariant w/r/t `'a`, since if you look strictly at the
30     // interface, it only returns `'a`. This complicates the
31     // downstream test since it wants invariance to force an error.
32     // Hence we add this method.
33     fn into_inv(self) -> Inv<'a>;
34
35     fn bigger_region<'b:'a>(self, b: Inv<'b>);
36 }
37
38 impl<'a> IntoMaybeOwned<'a> for Inv<'a> {
39     fn into_maybe_owned(self) -> MaybeOwned<'a> { panic!() }
40     fn into_inv(self) -> Inv<'a> { panic!() }
41     fn bigger_region<'b:'a>(self, b: Inv<'b>) { panic!() }
42 }