]>
git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/impl-trait/auto-trait-leak.rs
1 // Copyright 2016 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.
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.
11 // ignore-tidy-linelength
13 #![feature(conservative_impl_trait)]
18 // Fast path, main can see the concrete type returned.
19 fn before() -> impl Fn(i32) {
20 let p
= Rc
::new(Cell
::new(0));
24 fn send
<T
: Send
>(_
: T
) {}
28 //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
29 //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
30 //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
31 //~| NOTE required because it appears within the type `[closure
32 //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
33 //~| NOTE required by `send`
36 //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
37 //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
38 //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
39 //~| NOTE required because it appears within the type `[closure
40 //~| NOTE required because it appears within the type `impl std::ops::Fn<(i32,)>`
41 //~| NOTE required by `send`
44 // Deferred path, main has to wait until typeck finishes,
45 // to check if the return type of after is Send.
46 fn after() -> impl Fn(i32) {
47 let p
= Rc
::new(Cell
::new(0));
51 // Cycles should work as the deferred obligations are
52 // independently resolved and only require the concrete
53 // return type, which can't depend on the obligation.
54 fn cycle1() -> impl Clone
{
55 send(cycle2().clone());
56 //~^ ERROR the trait bound `std::rc::Rc<std::string::String>: std::marker::Send` is not satisfied
57 //~| NOTE trait `std::rc::Rc<std::string::String>: std::marker::Send` not satisfied
58 //~| NOTE `std::rc::Rc<std::string::String>` cannot be sent between threads safely
59 //~| NOTE required because it appears within the type `impl std::clone::Clone`
60 //~| NOTE required by `send`
65 fn cycle2() -> impl Clone
{
66 send(cycle1().clone());
67 //~^ ERROR the trait bound `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` is not satisfied
68 //~| NOTE trait `std::rc::Rc<std::cell::Cell<i32>>: std::marker::Send` not satisfied
69 //~| NOTE `std::rc::Rc<std::cell::Cell<i32>>` cannot be sent between threads safely
70 //~| NOTE required because it appears within the type `impl std::clone::Clone`
71 //~| NOTE required by `send`
73 Rc
::new(String
::from("foo"))