Skip to content

Commit 146abdd

Browse files
committed
Add another test case + fmt
1 parent 49ac725 commit 146abdd

File tree

4 files changed

+94
-14
lines changed

4 files changed

+94
-14
lines changed

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ impl Qualif for NeedsNonConstDrop {
119119
// without having the lang item present.
120120
return false;
121121
};
122-
let trait_ref = ty::TraitRef {
123-
def_id: drop_trait,
124-
substs: cx.tcx.mk_substs_trait(ty, &[]),
125-
};
122+
let trait_ref =
123+
ty::TraitRef { def_id: drop_trait, substs: cx.tcx.mk_substs_trait(ty, &[]) };
126124
let obligation = Obligation::new(
127125
ObligationCause::dummy(),
128126
cx.param_env,
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,59 @@
1+
error: `~const` is not allowed here
2+
--> $DIR/const-drop-fail.rs:27:35
3+
|
4+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
5+
| ^^^^^^^^
6+
|
7+
= note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
8+
19
error[E0277]: the trait bound `NonTrivialDrop: Drop` is not satisfied
2-
--> $DIR/const-drop-fail.rs:30:5
10+
--> $DIR/const-drop-fail.rs:45:5
311
|
412
LL | NonTrivialDrop,
513
| ^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `NonTrivialDrop`
614
|
715
note: required by a bound in `check`
8-
--> $DIR/const-drop-fail.rs:21:19
16+
--> $DIR/const-drop-fail.rs:36:19
917
|
1018
LL | const fn check<T: ~const Drop>(_: T) {}
1119
| ^^^^^^^^^^^ required by this bound in `check`
1220

1321
error[E0277]: the trait bound `ConstImplWithDropGlue: Drop` is not satisfied
14-
--> $DIR/const-drop-fail.rs:32:5
22+
--> $DIR/const-drop-fail.rs:47:5
1523
|
1624
LL | ConstImplWithDropGlue(NonTrivialDrop),
1725
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `ConstImplWithDropGlue`
1826
|
1927
note: required by a bound in `check`
20-
--> $DIR/const-drop-fail.rs:21:19
28+
--> $DIR/const-drop-fail.rs:36:19
2129
|
2230
LL | const fn check<T: ~const Drop>(_: T) {}
2331
| ^^^^^^^^^^^ required by this bound in `check`
2432

25-
error: aborting due to 2 previous errors
33+
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
34+
--> $DIR/const-drop-fail.rs:49:5
35+
|
36+
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
38+
|
39+
note: required by `ConstDropImplWithBounds`
40+
--> $DIR/const-drop-fail.rs:27:1
41+
|
42+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
46+
--> $DIR/const-drop-fail.rs:49:5
47+
|
48+
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
50+
|
51+
note: required by a bound in `ConstDropImplWithBounds`
52+
--> $DIR/const-drop-fail.rs:27:35
53+
|
54+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
55+
| ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
56+
57+
error: aborting due to 5 previous errors
2658

2759
For more information about this error, try `rustc --explain E0277`.

src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs

+18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#![feature(const_fn_trait_bound)]
55
#![cfg_attr(precise, feature(const_precise_live_drops))]
66

7+
use std::marker::PhantomData;
8+
79
struct NonTrivialDrop;
810

911
impl Drop for NonTrivialDrop {
@@ -18,6 +20,19 @@ impl const Drop for ConstImplWithDropGlue {
1820
fn drop(&mut self) {}
1921
}
2022

23+
trait A { fn a() { println!("A"); } }
24+
25+
impl A for NonTrivialDrop {}
26+
27+
struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
28+
//~^ ERROR `~const` is not allowed
29+
30+
impl<T: ~const A> const Drop for ConstDropImplWithBounds<T> {
31+
fn drop(&mut self) {
32+
T::a();
33+
}
34+
}
35+
2136
const fn check<T: ~const Drop>(_: T) {}
2237

2338
macro_rules! check_all {
@@ -31,6 +46,9 @@ check_all! {
3146
//~^ ERROR the trait bound
3247
ConstImplWithDropGlue(NonTrivialDrop),
3348
//~^ ERROR the trait bound
49+
ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
50+
//~^ ERROR the trait bound
51+
//~| ERROR the trait bound
3452
}
3553

3654
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,59 @@
1+
error: `~const` is not allowed here
2+
--> $DIR/const-drop-fail.rs:27:35
3+
|
4+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
5+
| ^^^^^^^^
6+
|
7+
= note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions
8+
19
error[E0277]: the trait bound `NonTrivialDrop: Drop` is not satisfied
2-
--> $DIR/const-drop-fail.rs:30:5
10+
--> $DIR/const-drop-fail.rs:45:5
311
|
412
LL | NonTrivialDrop,
513
| ^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `NonTrivialDrop`
614
|
715
note: required by a bound in `check`
8-
--> $DIR/const-drop-fail.rs:21:19
16+
--> $DIR/const-drop-fail.rs:36:19
917
|
1018
LL | const fn check<T: ~const Drop>(_: T) {}
1119
| ^^^^^^^^^^^ required by this bound in `check`
1220

1321
error[E0277]: the trait bound `ConstImplWithDropGlue: Drop` is not satisfied
14-
--> $DIR/const-drop-fail.rs:32:5
22+
--> $DIR/const-drop-fail.rs:47:5
1523
|
1624
LL | ConstImplWithDropGlue(NonTrivialDrop),
1725
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `ConstImplWithDropGlue`
1826
|
1927
note: required by a bound in `check`
20-
--> $DIR/const-drop-fail.rs:21:19
28+
--> $DIR/const-drop-fail.rs:36:19
2129
|
2230
LL | const fn check<T: ~const Drop>(_: T) {}
2331
| ^^^^^^^^^^^ required by this bound in `check`
2432

25-
error: aborting due to 2 previous errors
33+
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
34+
--> $DIR/const-drop-fail.rs:49:5
35+
|
36+
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
38+
|
39+
note: required by `ConstDropImplWithBounds`
40+
--> $DIR/const-drop-fail.rs:27:1
41+
|
42+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
45+
error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied
46+
--> $DIR/const-drop-fail.rs:49:5
47+
|
48+
LL | ConstDropImplWithBounds::<NonTrivialDrop>(PhantomData),
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop`
50+
|
51+
note: required by a bound in `ConstDropImplWithBounds`
52+
--> $DIR/const-drop-fail.rs:27:35
53+
|
54+
LL | struct ConstDropImplWithBounds<T: ~const A>(PhantomData<T>);
55+
| ^^^^^^^^ required by this bound in `ConstDropImplWithBounds`
56+
57+
error: aborting due to 5 previous errors
2658

2759
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)