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