From 146abdd1198d25541b19ce7e17c588f041d88518 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Fri, 3 Sep 2021 10:04:43 +0000 Subject: [PATCH] Add another test case + fmt --- .../src/transform/check_consts/qualifs.rs | 6 +-- .../const-drop-fail.precise.stderr | 42 ++++++++++++++++--- .../const-drop-fail.rs | 18 ++++++++ .../const-drop-fail.stock.stderr | 42 ++++++++++++++++--- 4 files changed, 94 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs index c6f786ca538..dc3927ed85b 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs @@ -119,10 +119,8 @@ impl Qualif for NeedsNonConstDrop { // without having the lang item present. return false; }; - let trait_ref = ty::TraitRef { - def_id: drop_trait, - substs: cx.tcx.mk_substs_trait(ty, &[]), - }; + let trait_ref = + ty::TraitRef { def_id: drop_trait, substs: cx.tcx.mk_substs_trait(ty, &[]) }; let obligation = Obligation::new( ObligationCause::dummy(), cx.param_env, diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr index acfa03a6175..1ac62f0bfec 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.precise.stderr @@ -1,27 +1,59 @@ +error: `~const` is not allowed here + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + error[E0277]: the trait bound `NonTrivialDrop: Drop` is not satisfied - --> $DIR/const-drop-fail.rs:30:5 + --> $DIR/const-drop-fail.rs:45:5 | LL | NonTrivialDrop, | ^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `NonTrivialDrop` | note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:21:19 + --> $DIR/const-drop-fail.rs:36:19 | LL | const fn check(_: T) {} | ^^^^^^^^^^^ required by this bound in `check` error[E0277]: the trait bound `ConstImplWithDropGlue: Drop` is not satisfied - --> $DIR/const-drop-fail.rs:32:5 + --> $DIR/const-drop-fail.rs:47:5 | LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `ConstImplWithDropGlue` | note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:21:19 + --> $DIR/const-drop-fail.rs:36:19 | LL | const fn check(_: T) {} | ^^^^^^^^^^^ required by this bound in `check` -error: aborting due to 2 previous errors +error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied + --> $DIR/const-drop-fail.rs:49:5 + | +LL | ConstDropImplWithBounds::(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop` + | +note: required by `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:1 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied + --> $DIR/const-drop-fail.rs:49:5 + | +LL | ConstDropImplWithBounds::(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop` + | +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs index 3d505c70086..3d4de088f55 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.rs @@ -4,6 +4,8 @@ #![feature(const_fn_trait_bound)] #![cfg_attr(precise, feature(const_precise_live_drops))] +use std::marker::PhantomData; + struct NonTrivialDrop; impl Drop for NonTrivialDrop { @@ -18,6 +20,19 @@ impl const Drop for ConstImplWithDropGlue { fn drop(&mut self) {} } +trait A { fn a() { println!("A"); } } + +impl A for NonTrivialDrop {} + +struct ConstDropImplWithBounds(PhantomData); +//~^ ERROR `~const` is not allowed + +impl const Drop for ConstDropImplWithBounds { + fn drop(&mut self) { + T::a(); + } +} + const fn check(_: T) {} macro_rules! check_all { @@ -31,6 +46,9 @@ check_all! { //~^ ERROR the trait bound ConstImplWithDropGlue(NonTrivialDrop), //~^ ERROR the trait bound + ConstDropImplWithBounds::(PhantomData), + //~^ ERROR the trait bound + //~| ERROR the trait bound } fn main() {} diff --git a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr index acfa03a6175..1ac62f0bfec 100644 --- a/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr +++ b/src/test/ui/rfc-2632-const-trait-impl/const-drop-fail.stock.stderr @@ -1,27 +1,59 @@ +error: `~const` is not allowed here + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^ + | + = note: only allowed on bounds on traits' associated types and functions, const fns, const impls and its associated functions + error[E0277]: the trait bound `NonTrivialDrop: Drop` is not satisfied - --> $DIR/const-drop-fail.rs:30:5 + --> $DIR/const-drop-fail.rs:45:5 | LL | NonTrivialDrop, | ^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `NonTrivialDrop` | note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:21:19 + --> $DIR/const-drop-fail.rs:36:19 | LL | const fn check(_: T) {} | ^^^^^^^^^^^ required by this bound in `check` error[E0277]: the trait bound `ConstImplWithDropGlue: Drop` is not satisfied - --> $DIR/const-drop-fail.rs:32:5 + --> $DIR/const-drop-fail.rs:47:5 | LL | ConstImplWithDropGlue(NonTrivialDrop), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Drop` is not implemented for `ConstImplWithDropGlue` | note: required by a bound in `check` - --> $DIR/const-drop-fail.rs:21:19 + --> $DIR/const-drop-fail.rs:36:19 | LL | const fn check(_: T) {} | ^^^^^^^^^^^ required by this bound in `check` -error: aborting due to 2 previous errors +error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied + --> $DIR/const-drop-fail.rs:49:5 + | +LL | ConstDropImplWithBounds::(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop` + | +note: required by `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:1 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error[E0277]: the trait bound `NonTrivialDrop: A` is not satisfied + --> $DIR/const-drop-fail.rs:49:5 + | +LL | ConstDropImplWithBounds::(PhantomData), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `A` is not implemented for `NonTrivialDrop` + | +note: required by a bound in `ConstDropImplWithBounds` + --> $DIR/const-drop-fail.rs:27:35 + | +LL | struct ConstDropImplWithBounds(PhantomData); + | ^^^^^^^^ required by this bound in `ConstDropImplWithBounds` + +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0277`.