Skip to content

Commit 5656ea2

Browse files
authored
Rollup merge of rust-lang#96968 - cjgillot:codegen-fulfill-nice, r=oli-obk
Add tests for rust-lang#96806 I messed up the rebase in rust-lang#96806. I took the opportunity to add an extra mir-opt test from rust-lang#91743. r? `@oli-obk`
2 parents 47e4c9e + bd41874 commit 5656ea2

9 files changed

+346
-0
lines changed

src/test/mir-opt/inline/dyn-trait.rs

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![crate_type = "lib"]
2+
3+
use std::fmt::Debug;
4+
5+
pub trait Cache {
6+
type V: Debug;
7+
8+
fn store_nocache(&self);
9+
}
10+
11+
pub trait Query {
12+
type V;
13+
type C: Cache<V = Self::V>;
14+
15+
fn cache<T>(s: &T) -> &Self::C;
16+
}
17+
18+
// EMIT_MIR dyn_trait.mk_cycle.Inline.diff
19+
#[inline(always)]
20+
pub fn mk_cycle<V: Debug>(c: &dyn Cache<V = V>) {
21+
c.store_nocache()
22+
}
23+
24+
// EMIT_MIR dyn_trait.try_execute_query.Inline.diff
25+
#[inline(always)]
26+
pub fn try_execute_query<C: Cache>(c: &C) {
27+
mk_cycle(c)
28+
}
29+
30+
// EMIT_MIR dyn_trait.get_query.Inline.diff
31+
#[inline(always)]
32+
pub fn get_query<Q: Query, T>(t: &T) {
33+
let c = Q::cache(t);
34+
try_execute_query(c)
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
- // MIR for `get_query` before Inline
2+
+ // MIR for `get_query` after Inline
3+
4+
fn get_query(_1: &T) -> () {
5+
debug t => _1; // in scope 0 at $DIR/dyn-trait.rs:32:31: 32:32
6+
let mut _0: (); // return place in scope 0 at $DIR/dyn-trait.rs:32:38: 32:38
7+
let _2: &<Q as Query>::C; // in scope 0 at $DIR/dyn-trait.rs:33:9: 33:10
8+
let mut _3: &T; // in scope 0 at $DIR/dyn-trait.rs:33:22: 33:23
9+
let mut _4: &<Q as Query>::C; // in scope 0 at $DIR/dyn-trait.rs:34:23: 34:24
10+
scope 1 {
11+
debug c => _2; // in scope 1 at $DIR/dyn-trait.rs:33:9: 33:10
12+
+ scope 2 (inlined try_execute_query::<<Q as Query>::C>) { // at $DIR/dyn-trait.rs:34:5: 34:25
13+
+ debug c => _4; // in scope 2 at $DIR/dyn-trait.rs:26:36: 26:37
14+
+ let mut _5: &dyn Cache<V = <Q as Query>::V>; // in scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
15+
+ let mut _6: &<Q as Query>::C; // in scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
16+
+ scope 3 (inlined mk_cycle::<<Q as Query>::V>) { // at $DIR/dyn-trait.rs:27:5: 27:16
17+
+ debug c => _5; // in scope 3 at $DIR/dyn-trait.rs:20:27: 20:28
18+
+ let mut _7: &dyn Cache<V = <Q as Query>::V>; // in scope 3 at $DIR/dyn-trait.rs:21:5: 21:22
19+
+ }
20+
+ }
21+
}
22+
23+
bb0: {
24+
StorageLive(_2); // scope 0 at $DIR/dyn-trait.rs:33:9: 33:10
25+
StorageLive(_3); // scope 0 at $DIR/dyn-trait.rs:33:22: 33:23
26+
_3 = &(*_1); // scope 0 at $DIR/dyn-trait.rs:33:22: 33:23
27+
_2 = <Q as Query>::cache::<T>(move _3) -> bb1; // scope 0 at $DIR/dyn-trait.rs:33:13: 33:24
28+
// mir::Constant
29+
// + span: $DIR/dyn-trait.rs:33:13: 33:21
30+
// + user_ty: UserType(0)
31+
// + literal: Const { ty: for<'r> fn(&'r T) -> &'r <Q as Query>::C {<Q as Query>::cache::<T>}, val: Value(Scalar(<ZST>)) }
32+
}
33+
34+
bb1: {
35+
StorageDead(_3); // scope 0 at $DIR/dyn-trait.rs:33:23: 33:24
36+
StorageLive(_4); // scope 1 at $DIR/dyn-trait.rs:34:23: 34:24
37+
_4 = &(*_2); // scope 1 at $DIR/dyn-trait.rs:34:23: 34:24
38+
- _0 = try_execute_query::<<Q as Query>::C>(move _4) -> bb2; // scope 1 at $DIR/dyn-trait.rs:34:5: 34:25
39+
+ StorageLive(_5); // scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
40+
+ StorageLive(_6); // scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
41+
+ _6 = _4; // scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
42+
+ _5 = move _6 as &dyn Cache<V = <Q as Query>::V> (Pointer(Unsize)); // scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
43+
+ StorageDead(_6); // scope 2 at $DIR/dyn-trait.rs:27:14: 27:15
44+
+ StorageLive(_7); // scope 3 at $DIR/dyn-trait.rs:21:5: 21:22
45+
+ _7 = _5; // scope 3 at $DIR/dyn-trait.rs:21:5: 21:22
46+
+ _0 = <dyn Cache<V = <Q as Query>::V> as Cache>::store_nocache(move _7) -> bb2; // scope 3 at $DIR/dyn-trait.rs:21:5: 21:22
47+
// mir::Constant
48+
- // + span: $DIR/dyn-trait.rs:34:5: 34:22
49+
- // + literal: Const { ty: for<'r> fn(&'r <Q as Query>::C) {try_execute_query::<<Q as Query>::C>}, val: Value(Scalar(<ZST>)) }
50+
+ // + span: $DIR/dyn-trait.rs:21:7: 21:20
51+
+ // + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = <Q as Query>::V>) {<dyn Cache<V = <Q as Query>::V> as Cache>::store_nocache}, val: Value(Scalar(<ZST>)) }
52+
}
53+
54+
bb2: {
55+
+ StorageDead(_7); // scope 3 at $DIR/dyn-trait.rs:21:21: 21:22
56+
+ StorageDead(_5); // scope 2 at $DIR/dyn-trait.rs:27:15: 27:16
57+
StorageDead(_4); // scope 1 at $DIR/dyn-trait.rs:34:24: 34:25
58+
StorageDead(_2); // scope 0 at $DIR/dyn-trait.rs:35:1: 35:2
59+
return; // scope 0 at $DIR/dyn-trait.rs:35:2: 35:2
60+
}
61+
}
62+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
- // MIR for `mk_cycle` before Inline
2+
+ // MIR for `mk_cycle` after Inline
3+
4+
fn mk_cycle(_1: &dyn Cache<V = V>) -> () {
5+
debug c => _1; // in scope 0 at $DIR/dyn-trait.rs:20:27: 20:28
6+
let mut _0: (); // return place in scope 0 at $DIR/dyn-trait.rs:20:49: 20:49
7+
let mut _2: &dyn Cache<V = V>; // in scope 0 at $DIR/dyn-trait.rs:21:5: 21:22
8+
9+
bb0: {
10+
StorageLive(_2); // scope 0 at $DIR/dyn-trait.rs:21:5: 21:22
11+
_2 = &(*_1); // scope 0 at $DIR/dyn-trait.rs:21:5: 21:22
12+
_0 = <dyn Cache<V = V> as Cache>::store_nocache(move _2) -> bb1; // scope 0 at $DIR/dyn-trait.rs:21:5: 21:22
13+
// mir::Constant
14+
// + span: $DIR/dyn-trait.rs:21:7: 21:20
15+
// + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = V>) {<dyn Cache<V = V> as Cache>::store_nocache}, val: Value(Scalar(<ZST>)) }
16+
}
17+
18+
bb1: {
19+
StorageDead(_2); // scope 0 at $DIR/dyn-trait.rs:21:21: 21:22
20+
return; // scope 0 at $DIR/dyn-trait.rs:22:2: 22:2
21+
}
22+
}
23+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
- // MIR for `try_execute_query` before Inline
2+
+ // MIR for `try_execute_query` after Inline
3+
4+
fn try_execute_query(_1: &C) -> () {
5+
debug c => _1; // in scope 0 at $DIR/dyn-trait.rs:26:36: 26:37
6+
let mut _0: (); // return place in scope 0 at $DIR/dyn-trait.rs:26:43: 26:43
7+
let mut _2: &dyn Cache<V = <C as Cache>::V>; // in scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
8+
let mut _3: &C; // in scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
9+
+ scope 1 (inlined mk_cycle::<<C as Cache>::V>) { // at $DIR/dyn-trait.rs:27:5: 27:16
10+
+ debug c => _2; // in scope 1 at $DIR/dyn-trait.rs:20:27: 20:28
11+
+ let mut _4: &dyn Cache<V = <C as Cache>::V>; // in scope 1 at $DIR/dyn-trait.rs:21:5: 21:22
12+
+ }
13+
14+
bb0: {
15+
StorageLive(_2); // scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
16+
StorageLive(_3); // scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
17+
_3 = &(*_1); // scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
18+
_2 = move _3 as &dyn Cache<V = <C as Cache>::V> (Pointer(Unsize)); // scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
19+
StorageDead(_3); // scope 0 at $DIR/dyn-trait.rs:27:14: 27:15
20+
- _0 = mk_cycle::<<C as Cache>::V>(move _2) -> bb1; // scope 0 at $DIR/dyn-trait.rs:27:5: 27:16
21+
+ StorageLive(_4); // scope 1 at $DIR/dyn-trait.rs:21:5: 21:22
22+
+ _4 = _2; // scope 1 at $DIR/dyn-trait.rs:21:5: 21:22
23+
+ _0 = <dyn Cache<V = <C as Cache>::V> as Cache>::store_nocache(move _4) -> bb1; // scope 1 at $DIR/dyn-trait.rs:21:5: 21:22
24+
// mir::Constant
25+
- // + span: $DIR/dyn-trait.rs:27:5: 27:13
26+
- // + literal: Const { ty: for<'r> fn(&'r (dyn Cache<V = <C as Cache>::V> + 'r)) {mk_cycle::<<C as Cache>::V>}, val: Value(Scalar(<ZST>)) }
27+
+ // + span: $DIR/dyn-trait.rs:21:7: 21:20
28+
+ // + literal: Const { ty: for<'r> fn(&'r dyn Cache<V = <C as Cache>::V>) {<dyn Cache<V = <C as Cache>::V> as Cache>::store_nocache}, val: Value(Scalar(<ZST>)) }
29+
}
30+
31+
bb1: {
32+
+ StorageDead(_4); // scope 1 at $DIR/dyn-trait.rs:21:21: 21:22
33+
StorageDead(_2); // scope 0 at $DIR/dyn-trait.rs:27:15: 27:16
34+
return; // scope 0 at $DIR/dyn-trait.rs:28:2: 28:2
35+
}
36+
}
37+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// check-pass
2+
#![feature(generic_const_exprs)]
3+
#![allow(incomplete_features)]
4+
5+
pub trait First {
6+
const CONST: usize;
7+
}
8+
pub trait Second {}
9+
10+
impl<'a> First for dyn Second
11+
where
12+
&'a Self: First,
13+
{
14+
const CONST: usize = <&Self>::CONST;
15+
}
16+
17+
trait Third: First
18+
where
19+
[u8; Self::CONST]:
20+
{
21+
const VAL: [u8; Self::CONST] = [0; Self::CONST];
22+
}
23+
24+
fn main() {}

src/test/ui/issues/issue-37725.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// build-pass
2+
// compiler-opts: -Zmir-opt-level=2
3+
24
#![allow(dead_code)]
35
trait Foo {
46
fn foo(&self);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
warning: trait bound for<'any> &'any mut (): Clone does not depend on any type or lifetime parameters
2+
--> $DIR/issue-73021-impossible-inline.rs:20:29
3+
|
4+
LL | for<'any> &'any mut (): Clone,
5+
| ^^^^^
6+
|
7+
= note: `#[warn(trivial_bounds)]` on by default
8+
9+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
10+
--> $DIR/issue-73021-impossible-inline.rs:28:21
11+
|
12+
LL | struct S where i32: Foo;
13+
| ^^^
14+
15+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
16+
--> $DIR/issue-73021-impossible-inline.rs:31:28
17+
|
18+
LL | impl Foo for () where i32: Foo {
19+
| ^^^
20+
21+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
22+
--> $DIR/issue-73021-impossible-inline.rs:40:19
23+
|
24+
LL | fn f() where i32: Foo {
25+
| ^^^
26+
27+
warning: trait bound &'static str: Foo does not depend on any type or lifetime parameters
28+
--> $DIR/issue-73021-impossible-inline.rs:48:28
29+
|
30+
LL | fn g() where &'static str: Foo {
31+
| ^^^
32+
33+
warning: trait bound String: Neg does not depend on any type or lifetime parameters
34+
--> $DIR/issue-73021-impossible-inline.rs:57:13
35+
|
36+
LL | String: ::std::ops::Neg<Output = String>,
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
warning: trait bound i32: Iterator does not depend on any type or lifetime parameters
40+
--> $DIR/issue-73021-impossible-inline.rs:65:10
41+
|
42+
LL | i32: Iterator,
43+
| ^^^^^^^^
44+
45+
warning: 7 warnings emitted
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
warning: trait bound for<'any> &'any mut (): Clone does not depend on any type or lifetime parameters
2+
--> $DIR/issue-73021-impossible-inline.rs:20:29
3+
|
4+
LL | for<'any> &'any mut (): Clone,
5+
| ^^^^^
6+
|
7+
= note: `#[warn(trivial_bounds)]` on by default
8+
9+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
10+
--> $DIR/issue-73021-impossible-inline.rs:28:21
11+
|
12+
LL | struct S where i32: Foo;
13+
| ^^^
14+
15+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
16+
--> $DIR/issue-73021-impossible-inline.rs:31:28
17+
|
18+
LL | impl Foo for () where i32: Foo {
19+
| ^^^
20+
21+
warning: trait bound i32: Foo does not depend on any type or lifetime parameters
22+
--> $DIR/issue-73021-impossible-inline.rs:40:19
23+
|
24+
LL | fn f() where i32: Foo {
25+
| ^^^
26+
27+
warning: trait bound &'static str: Foo does not depend on any type or lifetime parameters
28+
--> $DIR/issue-73021-impossible-inline.rs:48:28
29+
|
30+
LL | fn g() where &'static str: Foo {
31+
| ^^^
32+
33+
warning: trait bound String: Neg does not depend on any type or lifetime parameters
34+
--> $DIR/issue-73021-impossible-inline.rs:57:13
35+
|
36+
LL | String: ::std::ops::Neg<Output = String>,
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
warning: trait bound i32: Iterator does not depend on any type or lifetime parameters
40+
--> $DIR/issue-73021-impossible-inline.rs:65:10
41+
|
42+
LL | i32: Iterator,
43+
| ^^^^^^^^
44+
45+
warning: 7 warnings emitted
46+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// build-pass
2+
// revisions: no-opt inline
3+
// [inline]compile-flags: -Zmir-opt-level=3 --emit=mir
4+
#![feature(trivial_bounds)]
5+
#![allow(unused)]
6+
7+
trait Foo {
8+
fn test(&self);
9+
}
10+
11+
fn foo<'a>(s: &'a mut ())
12+
where
13+
&'a mut (): Foo,
14+
{
15+
s.test();
16+
}
17+
18+
fn clone(it: &mut ()) -> &mut ()
19+
where
20+
for<'any> &'any mut (): Clone,
21+
//~^ WARN trait bound for<'any> &'any mut (): Clone does not depend on any type or lifetime parameters
22+
{
23+
it.clone()
24+
}
25+
26+
fn generic_function<X: Foo>(x: X) {}
27+
28+
struct S where i32: Foo;
29+
//~^ WARN trait bound i32: Foo does not depend on any type or lifetime parameters
30+
31+
impl Foo for () where i32: Foo {
32+
//~^ WARN trait bound i32: Foo does not depend on any type or lifetime parameters
33+
fn test(&self) {
34+
3i32.test();
35+
Foo::test(&4i32);
36+
generic_function(5i32);
37+
}
38+
}
39+
40+
fn f() where i32: Foo {
41+
//~^ WARN trait bound i32: Foo does not depend on any type or lifetime parameters
42+
let s = S;
43+
3i32.test();
44+
Foo::test(&4i32);
45+
generic_function(5i32);
46+
}
47+
48+
fn g() where &'static str: Foo {
49+
//~^ WARN trait bound &'static str: Foo does not depend on any type or lifetime parameters
50+
"Foo".test();
51+
Foo::test(&"Foo");
52+
generic_function("Foo");
53+
}
54+
55+
fn use_op(s: String) -> String
56+
where
57+
String: ::std::ops::Neg<Output = String>,
58+
//~^ WARN trait bound String: Neg does not depend on any type or lifetime parameters
59+
{
60+
-s
61+
}
62+
63+
fn use_for()
64+
where
65+
i32: Iterator,
66+
//~^ WARN trait bound i32: Iterator does not depend on any type or lifetime parameters
67+
{
68+
for _ in 2i32 {}
69+
}
70+
71+
fn main() {}

0 commit comments

Comments
 (0)