]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-41936-variance-coerce-unsized-cycle.rs
use equality in the coerce-unsized check
[rust.git] / src / test / run-pass / issue-41936-variance-coerce-unsized-cycle.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.
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 // Regression test for #41936. The coerce-unsized trait check in
12 // coherence was using subtyping, which triggered variance
13 // computation, which failed because it required type info for fields
14 // that had not (yet) been computed.
15
16 #![feature(unsize)]
17 #![feature(coerce_unsized)]
18
19 use std::{marker,ops};
20
21 // Change the array to a non-array, and error disappears
22 // Adding a new field to the end keeps the error
23 struct LogDataBuf([u8;8]);
24
25 struct Aref<T: ?Sized>
26 {
27     // Inner structure triggers the error, removing the inner removes the message.
28     ptr: Box<ArefInner<T>>,
29 }
30 impl<T: ?Sized + marker::Unsize<U>, U: ?Sized> ops::CoerceUnsized<Aref<U>> for Aref<T> {}
31
32 struct ArefInner<T: ?Sized>
33 {
34     // Even with this field commented out, the error is raised.
35     data: T,
36 }
37
38 fn main(){}