Skip to content

Commit 21f754d

Browse files
committed
check Drop specialization of const params
1 parent 3539259 commit 21f754d

File tree

2 files changed

+61
-28
lines changed

2 files changed

+61
-28
lines changed

Diff for: src/test/ui/dropck/reject-specialized-drops-8142.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Issue 8142: Test that Drop impls cannot be specialized beyond the
22
// predicates attached to the type definition itself.
3+
#![feature(min_const_generics)]
34

45
trait Bound { fn foo(&self) { } }
56
struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
@@ -15,6 +16,8 @@ struct T<'t,Ts:'t> { x: &'t Ts }
1516
struct U;
1617
struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
1718
struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
19+
struct X<const Ca: usize>;
20+
struct Y<const Ca: usize, const Cb: usize>;
1821

1922
enum Enum<T> { Variant(T) }
2023
struct TupleStruct<T>(T);
@@ -58,6 +61,12 @@ impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
5861
impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
5962
//~^ ERROR cannot infer an appropriate lifetime for lifetime parameter `'lw`
6063

64+
impl Drop for X<3> { fn drop(&mut self) { } } // REJECT
65+
//~^ ERROR `Drop` impls cannot be specialized
66+
67+
impl<const Ca: usize> Drop for Y<Ca, Ca> { fn drop(&mut self) { } } // REJECT
68+
//~^ ERROR `Drop` impls cannot be specialized
69+
6170
impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
6271
//~^ ERROR `Drop` impl requires `AddsBnd: Bound`
6372

+52-28
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,175 @@
11
error[E0367]: `Drop` impl requires `'adds_bnd: 'al` but the struct it is implemented for does not
2-
--> $DIR/reject-specialized-drops-8142.rs:23:20
2+
--> $DIR/reject-specialized-drops-8142.rs:26:20
33
|
44
LL | impl<'al,'adds_bnd:'al> Drop for K<'al,'adds_bnd> { // REJECT
55
| ^^^
66
|
77
note: the implementor must specify the same requirement
8-
--> $DIR/reject-specialized-drops-8142.rs:5:1
8+
--> $DIR/reject-specialized-drops-8142.rs:6:1
99
|
1010
LL | struct K<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0367]: `Drop` impl requires `'adds_bnd: 'al` but the struct it is implemented for does not
14-
--> $DIR/reject-specialized-drops-8142.rs:27:67
14+
--> $DIR/reject-specialized-drops-8142.rs:30:67
1515
|
1616
LL | impl<'al,'adds_bnd> Drop for L<'al,'adds_bnd> where 'adds_bnd:'al { // REJECT
1717
| ^^^
1818
|
1919
note: the implementor must specify the same requirement
20-
--> $DIR/reject-specialized-drops-8142.rs:6:1
20+
--> $DIR/reject-specialized-drops-8142.rs:7:1
2121
|
2222
LL | struct L<'l1,'l2> { x: &'l1 i8, y: &'l2 u8 }
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2424

2525
error[E0308]: mismatched types
26-
--> $DIR/reject-specialized-drops-8142.rs:33:1
26+
--> $DIR/reject-specialized-drops-8142.rs:36:1
2727
|
2828
LL | impl Drop for N<'static> { fn drop(&mut self) { } } // REJECT
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
3030
|
3131
= note: expected struct `N<'n>`
3232
found struct `N<'static>`
33-
note: the lifetime `'n` as defined on the struct at 8:10...
34-
--> $DIR/reject-specialized-drops-8142.rs:8:10
33+
note: the lifetime `'n` as defined on the struct at 9:10...
34+
--> $DIR/reject-specialized-drops-8142.rs:9:10
3535
|
3636
LL | struct N<'n> { x: &'n i8 }
3737
| ^^
3838
= note: ...does not necessarily outlive the static lifetime
3939

4040
error[E0366]: `Drop` impls cannot be specialized
41-
--> $DIR/reject-specialized-drops-8142.rs:40:1
41+
--> $DIR/reject-specialized-drops-8142.rs:43:1
4242
|
4343
LL | impl Drop for P<i8> { fn drop(&mut self) { } } // REJECT
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4545
|
4646
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
47-
--> $DIR/reject-specialized-drops-8142.rs:10:1
47+
--> $DIR/reject-specialized-drops-8142.rs:11:1
4848
|
4949
LL | struct P<Tp> { x: *const Tp }
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5151

5252
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the struct it is implemented for does not
53-
--> $DIR/reject-specialized-drops-8142.rs:43:14
53+
--> $DIR/reject-specialized-drops-8142.rs:46:14
5454
|
5555
LL | impl<AddsBnd:Bound> Drop for Q<AddsBnd> { fn drop(&mut self) { } } // REJECT
5656
| ^^^^^
5757
|
5858
note: the implementor must specify the same requirement
59-
--> $DIR/reject-specialized-drops-8142.rs:11:1
59+
--> $DIR/reject-specialized-drops-8142.rs:12:1
6060
|
6161
LL | struct Q<Tq> { x: *const Tq }
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6363

6464
error[E0367]: `Drop` impl requires `AddsRBnd: 'rbnd` but the struct it is implemented for does not
65-
--> $DIR/reject-specialized-drops-8142.rs:46:21
65+
--> $DIR/reject-specialized-drops-8142.rs:49:21
6666
|
6767
LL | impl<'rbnd,AddsRBnd:'rbnd> Drop for R<AddsRBnd> { fn drop(&mut self) { } } // REJECT
6868
| ^^^^^
6969
|
7070
note: the implementor must specify the same requirement
71-
--> $DIR/reject-specialized-drops-8142.rs:12:1
71+
--> $DIR/reject-specialized-drops-8142.rs:13:1
7272
|
7373
LL | struct R<Tr> { x: *const Tr }
7474
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7575

7676
error[E0366]: `Drop` impls cannot be specialized
77-
--> $DIR/reject-specialized-drops-8142.rs:55:1
77+
--> $DIR/reject-specialized-drops-8142.rs:58:1
7878
|
7979
LL | impl<One> Drop for V<One,One> { fn drop(&mut self) { } } // REJECT
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8181
|
8282
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
83-
--> $DIR/reject-specialized-drops-8142.rs:16:1
83+
--> $DIR/reject-specialized-drops-8142.rs:17:1
8484
|
8585
LL | struct V<Tva, Tvb> { x: *const Tva, y: *const Tvb }
8686
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8787

8888
error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'lw` due to conflicting requirements
89-
--> $DIR/reject-specialized-drops-8142.rs:58:1
89+
--> $DIR/reject-specialized-drops-8142.rs:61:1
9090
|
9191
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
9292
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9393
|
94-
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 17:10...
95-
--> $DIR/reject-specialized-drops-8142.rs:17:10
94+
note: first, the lifetime cannot outlive the lifetime `'l1` as defined on the struct at 18:10...
95+
--> $DIR/reject-specialized-drops-8142.rs:18:10
9696
|
9797
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
9898
| ^^^
99-
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 17:15...
100-
--> $DIR/reject-specialized-drops-8142.rs:17:15
99+
note: ...but the lifetime must also be valid for the lifetime `'l2` as defined on the struct at 18:15...
100+
--> $DIR/reject-specialized-drops-8142.rs:18:15
101101
|
102102
LL | struct W<'l1, 'l2> { x: &'l1 i8, y: &'l2 u8 }
103103
| ^^^
104104
note: ...so that the types are compatible
105-
--> $DIR/reject-specialized-drops-8142.rs:58:1
105+
--> $DIR/reject-specialized-drops-8142.rs:61:1
106106
|
107107
LL | impl<'lw> Drop for W<'lw,'lw> { fn drop(&mut self) { } } // REJECT
108108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109109
= note: expected `W<'l1, 'l2>`
110110
found `W<'_, '_>`
111111

112+
error[E0366]: `Drop` impls cannot be specialized
113+
--> $DIR/reject-specialized-drops-8142.rs:64:1
114+
|
115+
LL | impl Drop for X<3> { fn drop(&mut self) { } } // REJECT
116+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117+
|
118+
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
119+
--> $DIR/reject-specialized-drops-8142.rs:19:1
120+
|
121+
LL | struct X<const Ca: usize>;
122+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
123+
124+
error[E0366]: `Drop` impls cannot be specialized
125+
--> $DIR/reject-specialized-drops-8142.rs:67:1
126+
|
127+
LL | impl<const Ca: usize> Drop for Y<Ca, Ca> { fn drop(&mut self) { } } // REJECT
128+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
129+
|
130+
note: use the same sequence of generic type, lifetime and const parameters as the struct definition
131+
--> $DIR/reject-specialized-drops-8142.rs:20:1
132+
|
133+
LL | struct Y<const Ca: usize, const Cb: usize>;
134+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
135+
112136
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the enum it is implemented for does not
113-
--> $DIR/reject-specialized-drops-8142.rs:61:14
137+
--> $DIR/reject-specialized-drops-8142.rs:70:14
114138
|
115139
LL | impl<AddsBnd:Bound> Drop for Enum<AddsBnd> { fn drop(&mut self) { } } // REJECT
116140
| ^^^^^
117141
|
118142
note: the implementor must specify the same requirement
119-
--> $DIR/reject-specialized-drops-8142.rs:19:1
143+
--> $DIR/reject-specialized-drops-8142.rs:22:1
120144
|
121145
LL | enum Enum<T> { Variant(T) }
122146
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
123147

124148
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the struct it is implemented for does not
125-
--> $DIR/reject-specialized-drops-8142.rs:64:14
149+
--> $DIR/reject-specialized-drops-8142.rs:73:14
126150
|
127151
LL | impl<AddsBnd:Bound> Drop for TupleStruct<AddsBnd> { fn drop(&mut self) { } } // REJECT
128152
| ^^^^^
129153
|
130154
note: the implementor must specify the same requirement
131-
--> $DIR/reject-specialized-drops-8142.rs:20:1
155+
--> $DIR/reject-specialized-drops-8142.rs:23:1
132156
|
133157
LL | struct TupleStruct<T>(T);
134158
| ^^^^^^^^^^^^^^^^^^^^^^^^^
135159

136160
error[E0367]: `Drop` impl requires `AddsBnd: Bound` but the union it is implemented for does not
137-
--> $DIR/reject-specialized-drops-8142.rs:67:21
161+
--> $DIR/reject-specialized-drops-8142.rs:76:21
138162
|
139163
LL | impl<AddsBnd:Copy + Bound> Drop for Union<AddsBnd> { fn drop(&mut self) { } } // REJECT
140164
| ^^^^^
141165
|
142166
note: the implementor must specify the same requirement
143-
--> $DIR/reject-specialized-drops-8142.rs:21:1
167+
--> $DIR/reject-specialized-drops-8142.rs:24:1
144168
|
145169
LL | union Union<T: Copy> { f: T }
146170
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
147171

148-
error: aborting due to 11 previous errors
172+
error: aborting due to 13 previous errors
149173

150174
Some errors have detailed explanations: E0308, E0366, E0367, E0495.
151175
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)