about summary refs log tree commit diff
path: root/tests/ui/traits/default_auto_traits/maybe-bounds-in-dyn-traits.rs
blob: 5069cd256b277077d08d452f06e2d74a50fd8619 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//@ compile-flags: -Zexperimental-default-bounds

#![feature(
    auto_traits,
    lang_items,
    more_maybe_bounds,
    negative_impls,
    no_core,
    rustc_attrs
)]
#![allow(internal_features)]
#![no_std]
#![no_core]

#[lang = "pointee_sized"]
trait PointeeSized {}

#[lang = "meta_sized"]
trait MetaSized: PointeeSized {}

#[lang = "sized"]
trait Sized: MetaSized {}

#[lang = "copy"]
pub trait Copy {}
impl<'a, T: ?Sized> Copy for &'a T {}

#[lang = "legacy_receiver"]
trait Receiver {}
impl<T: ?Sized + ?Leak> Receiver for &T {}

#[lang = "unsize"]
trait Unsize<T: ?Sized + ?Leak> {}

#[lang = "coerce_unsized"]
trait CoerceUnsized<T: ?Leak + ?Sized> {}
impl<'a, 'b: 'a, T: ?Sized + ?Leak + Unsize<U>, U: ?Sized + ?Leak> CoerceUnsized<&'a U> for &'b T {}

#[lang = "dispatch_from_dyn"]
trait DispatchFromDyn<T: ?Leak> {}
impl<'a, T: ?Sized + ?Leak + Unsize<U>, U: ?Sized + ?Leak> DispatchFromDyn<&'a U> for &'a T {}

#[lang = "default_trait1"]
auto trait Leak {}

struct NonLeakS;
impl !Leak for NonLeakS {}
struct LeakS;

trait Trait {
    fn leak_foo(&self) {}
    fn maybe_leak_foo(&self) where Self: ?Leak {}
}

impl Trait for NonLeakS {}
impl Trait for LeakS {}

fn main() {
    let _: &dyn Trait = &NonLeakS;
    //~^ ERROR the trait bound `NonLeakS: Leak` is not satisfied
    let _: &dyn Trait = &LeakS;
    let _: &(dyn Trait + ?Leak) = &LeakS;
    let x: &(dyn Trait + ?Leak) = &NonLeakS;
    x.leak_foo();
    //~^ ERROR the trait bound `dyn Trait: Leak` is not satisfied
    x.maybe_leak_foo();
}