diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-06 21:19:21 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-13 03:45:07 +0000 |
| commit | d0564fda651a9b98539826e9aae05e1f8e7d73ab (patch) | |
| tree | 3728872b74cbd40bc614d296a040a193c72daf9c | |
| parent | 516afd557c521eae3a64882b93d32772f3e2fa45 (diff) | |
| download | rust-d0564fda651a9b98539826e9aae05e1f8e7d73ab.tar.gz rust-d0564fda651a9b98539826e9aae05e1f8e7d73ab.zip | |
Use BikeshedGuaranteedNotDrop in unsafe binder type WF too
| -rw-r--r-- | compiler/rustc_next_trait_solver/src/solve/trait_goals.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/wf.rs | 5 | ||||
| -rw-r--r-- | tests/ui/unsafe-binders/moves.rs | 24 | ||||
| -rw-r--r-- | tests/ui/unsafe-binders/moves.stderr | 93 |
4 files changed, 43 insertions, 81 deletions
diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index beb7f1bf30e..dabfa5cc04c 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -627,7 +627,7 @@ where /// NOTE: This is implemented as a built-in goal and not a set of impls like: /// - /// ``` + /// ```rust,ignore (illustrative) /// impl<T> BikeshedGuaranteedNoDrop for T where T: Copy {} /// impl<T> BikeshedGuaranteedNoDrop for ManuallyDrop<T> {} /// ``` diff --git a/compiler/rustc_trait_selection/src/traits/wf.rs b/compiler/rustc_trait_selection/src/traits/wf.rs index c27bd269b0d..2f72b44f6b6 100644 --- a/compiler/rustc_trait_selection/src/traits/wf.rs +++ b/compiler/rustc_trait_selection/src/traits/wf.rs @@ -881,7 +881,10 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> { ty.map_bound(|ty| { ty::TraitRef::new( self.tcx(), - self.tcx().require_lang_item(LangItem::Copy, Some(self.span)), + self.tcx().require_lang_item( + LangItem::BikeshedGuaranteedNoDrop, + Some(self.span), + ), [ty], ) }), diff --git a/tests/ui/unsafe-binders/moves.rs b/tests/ui/unsafe-binders/moves.rs index 5bfcee62402..9397c2bc20f 100644 --- a/tests/ui/unsafe-binders/moves.rs +++ b/tests/ui/unsafe-binders/moves.rs @@ -1,40 +1,40 @@ -//@ known-bug: unknown - #![feature(unsafe_binders)] -// FIXME(unsafe_binders) ~^ WARN the feature `unsafe_binders` is incomplete +//~^ WARN the feature `unsafe_binders` is incomplete -use std::unsafe_binder::{wrap_binder, unwrap_binder}; -use std::mem::{drop, ManuallyDrop}; +use std::mem::{ManuallyDrop, drop}; +use std::unsafe_binder::{unwrap_binder, wrap_binder}; +#[derive(Default)] struct NotCopyInner; type NotCopy = ManuallyDrop<NotCopyInner>; fn use_after_wrap() { unsafe { - let base = NotCopy; + let base = NotCopy::default(); let binder: unsafe<> NotCopy = wrap_binder!(base); drop(base); - // FIXME(unsafe_binders) ~^ ERROR use of moved value: `base` + //~^ ERROR use of moved value: `base` } } fn move_out_of_wrap() { unsafe { - let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); + let binder: unsafe<> NotCopy = wrap_binder!(NotCopy::default()); drop(unwrap_binder!(binder)); drop(unwrap_binder!(binder)); - // FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder` + //~^ ERROR use of moved value: `binder` } } fn not_conflicting() { unsafe { - let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); + let binder: unsafe<> (NotCopy, NotCopy) = + wrap_binder!((NotCopy::default(), NotCopy::default())); drop(unwrap_binder!(binder).0); drop(unwrap_binder!(binder).1); - // ^ NOT a problem. + // ^ NOT a problem, since the moves are disjoint. drop(unwrap_binder!(binder).0); - // FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder.0` + //~^ ERROR use of moved value: `binder.0` } } diff --git a/tests/ui/unsafe-binders/moves.stderr b/tests/ui/unsafe-binders/moves.stderr index ca507964008..0f976d9e845 100644 --- a/tests/ui/unsafe-binders/moves.stderr +++ b/tests/ui/unsafe-binders/moves.stderr @@ -1,37 +1,5 @@ -error[E0423]: expected value, found type alias `NotCopy` - --> $DIR/moves.rs:14:20 - | -LL | let base = NotCopy; - | ^^^^^^^ - | - = note: can't use a type alias as a constructor - -error[E0423]: expected value, found type alias `NotCopy` - --> $DIR/moves.rs:23:53 - | -LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); - | ^^^^^^^ - | - = note: can't use a type alias as a constructor - -error[E0423]: expected value, found type alias `NotCopy` - --> $DIR/moves.rs:32:65 - | -LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); - | ^^^^^^^ - | - = note: can't use a type alias as a constructor - -error[E0423]: expected value, found type alias `NotCopy` - --> $DIR/moves.rs:32:74 - | -LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); - | ^^^^^^^ - | - = note: can't use a type alias as a constructor - warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes - --> $DIR/moves.rs:3:12 + --> $DIR/moves.rs:1:12 | LL | #![feature(unsafe_binders)] | ^^^^^^^^^^^^^^ @@ -39,47 +7,38 @@ LL | #![feature(unsafe_binders)] = note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information = note: `#[warn(incomplete_features)]` on by default -error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied - --> $DIR/moves.rs:15:21 +error[E0382]: use of moved value: `base` + --> $DIR/moves.rs:15:14 | +LL | let base = NotCopy::default(); + | ---- move occurs because `base` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait LL | let binder: unsafe<> NotCopy = wrap_binder!(base); - | ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` - | - = note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` -help: consider annotating `NotCopyInner` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct NotCopyInner; - | + | ---- value moved here +LL | drop(base); + | ^^^^ value used here after move -error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied - --> $DIR/moves.rs:23:21 +error[E0382]: use of moved value: `binder` + --> $DIR/moves.rs:24:14 | -LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); - | ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` - | - = note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` -help: consider annotating `NotCopyInner` with `#[derive(Copy)]` - | -LL + #[derive(Copy)] -LL | struct NotCopyInner; +LL | drop(unwrap_binder!(binder)); + | ---------------------- value moved here +LL | drop(unwrap_binder!(binder)); + | ^^^^^^^^^^^^^^^^^^^^^^ value used here after move | + = note: move occurs because `binder` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait + = note: this error originates in the macro `unwrap_binder` (in Nightly builds, run with -Z macro-backtrace for more info) -error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied - --> $DIR/moves.rs:32:21 - | -LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` - | - = note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` - = note: required because it appears within the type `(ManuallyDrop<NotCopyInner>, ManuallyDrop<NotCopyInner>)` -help: consider annotating `NotCopyInner` with `#[derive(Copy)]` +error[E0382]: use of moved value: `binder.0` + --> $DIR/moves.rs:36:14 | -LL + #[derive(Copy)] -LL | struct NotCopyInner; +LL | drop(unwrap_binder!(binder).0); + | ------------------------ value moved here +... +LL | drop(unwrap_binder!(binder).0); + | ^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move | + = note: move occurs because `binder.0` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait -error: aborting due to 7 previous errors; 1 warning emitted +error: aborting due to 3 previous errors; 1 warning emitted -Some errors have detailed explanations: E0277, E0423. -For more information about an error, try `rustc --explain E0277`. +For more information about this error, try `rustc --explain E0382`. |
