Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 98db52d

Browse files
authoredNov 8, 2021
Rollup merge of rust-lang#90578 - lcnr:add-test, r=Mark-Simulacrum
add const generics test cc rust-lang#89829 (comment) r? rust-lang/project-const-generics
2 parents 8cbe7a8 + 084b232 commit 98db52d

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
 
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#![feature(generic_const_exprs)]
2+
#![allow(incomplete_features)]
3+
use std::marker::PhantomData;
4+
5+
trait SadBee {
6+
const ASSOC: usize;
7+
}
8+
// fn(&'static ())` is a supertype of `for<'a> fn(&'a ())` while
9+
// we allow two different impls for these types, leading
10+
// to different const eval results.
11+
impl SadBee for for<'a> fn(&'a ()) {
12+
const ASSOC: usize = 0;
13+
}
14+
impl SadBee for fn(&'static ()) {
15+
//~^ WARNING conflicting implementations of trait
16+
//~| WARNING this was previously accepted
17+
const ASSOC: usize = 100;
18+
}
19+
20+
struct Foo<T: SadBee>([u8; <T as SadBee>::ASSOC], PhantomData<T>)
21+
where
22+
[(); <T as SadBee>::ASSOC]: ;
23+
24+
fn covariant(
25+
v: &'static Foo<for<'a> fn(&'a ())>
26+
) -> &'static Foo<fn(&'static ())> {
27+
v //~ ERROR mismatched types
28+
}
29+
30+
fn main() {
31+
let y = covariant(&Foo([], PhantomData));
32+
println!("{:?}", y.0);
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
warning: conflicting implementations of trait `SadBee` for type `for<'a> fn(&'a ())`
2+
--> $DIR/invariant.rs:14:1
3+
|
4+
LL | impl SadBee for for<'a> fn(&'a ()) {
5+
| ---------------------------------- first implementation here
6+
...
7+
LL | impl SadBee for fn(&'static ()) {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a> fn(&'a ())`
9+
|
10+
= note: `#[warn(coherence_leak_check)]` on by default
11+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
12+
= note: for more information, see issue #56105 <https://github.com/rust-lang/rust/issues/56105>
13+
= note: this behavior recently changed as a result of a bug fix; see rust-lang/rust#56105 for details
14+
15+
error[E0308]: mismatched types
16+
--> $DIR/invariant.rs:27:5
17+
|
18+
LL | v
19+
| ^ one type is more general than the other
20+
|
21+
= note: expected reference `&'static Foo<fn(&'static ())>`
22+
found reference `&'static Foo<for<'a> fn(&'a ())>`
23+
24+
error: aborting due to previous error; 1 warning emitted
25+
26+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)
Please sign in to comment.