1
Fork 0

Use BikeshedGuaranteedNotDrop in unsafe binder type WF too

This commit is contained in:
Michael Goulet 2025-02-06 21:19:21 +00:00
parent 516afd557c
commit d0564fda65
4 changed files with 43 additions and 81 deletions

View file

@ -627,7 +627,7 @@ where
/// NOTE: This is implemented as a built-in goal and not a set of impls like: /// 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 T where T: Copy {}
/// impl<T> BikeshedGuaranteedNoDrop for ManuallyDrop<T> {} /// impl<T> BikeshedGuaranteedNoDrop for ManuallyDrop<T> {}
/// ``` /// ```

View file

@ -881,7 +881,10 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
ty.map_bound(|ty| { ty.map_bound(|ty| {
ty::TraitRef::new( ty::TraitRef::new(
self.tcx(), self.tcx(),
self.tcx().require_lang_item(LangItem::Copy, Some(self.span)), self.tcx().require_lang_item(
LangItem::BikeshedGuaranteedNoDrop,
Some(self.span),
),
[ty], [ty],
) )
}), }),

View file

@ -1,40 +1,40 @@
//@ known-bug: unknown
#![feature(unsafe_binders)] #![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::{ManuallyDrop, drop};
use std::mem::{drop, ManuallyDrop}; use std::unsafe_binder::{unwrap_binder, wrap_binder};
#[derive(Default)]
struct NotCopyInner; struct NotCopyInner;
type NotCopy = ManuallyDrop<NotCopyInner>; type NotCopy = ManuallyDrop<NotCopyInner>;
fn use_after_wrap() { fn use_after_wrap() {
unsafe { unsafe {
let base = NotCopy; let base = NotCopy::default();
let binder: unsafe<> NotCopy = wrap_binder!(base); let binder: unsafe<> NotCopy = wrap_binder!(base);
drop(base); drop(base);
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `base` //~^ ERROR use of moved value: `base`
} }
} }
fn move_out_of_wrap() { fn move_out_of_wrap() {
unsafe { unsafe {
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); let binder: unsafe<> NotCopy = wrap_binder!(NotCopy::default());
drop(unwrap_binder!(binder)); drop(unwrap_binder!(binder));
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() { fn not_conflicting() {
unsafe { 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).0);
drop(unwrap_binder!(binder).1); drop(unwrap_binder!(binder).1);
// ^ NOT a problem. // ^ NOT a problem, since the moves are disjoint.
drop(unwrap_binder!(binder).0); drop(unwrap_binder!(binder).0);
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder.0` //~^ ERROR use of moved value: `binder.0`
} }
} }

View file

@ -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 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)] 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: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
= note: `#[warn(incomplete_features)]` on by default = note: `#[warn(incomplete_features)]` on by default
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied error[E0382]: use of moved value: `base`
--> $DIR/moves.rs:15:21 --> $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); LL | let binder: unsafe<> NotCopy = wrap_binder!(base);
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ---- value moved here
| LL | drop(base);
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` | ^^^^ value used here after move
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
|
LL + #[derive(Copy)]
LL | struct NotCopyInner;
|
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied error[E0382]: use of moved value: `binder`
--> $DIR/moves.rs:23:21 --> $DIR/moves.rs:24:14
| |
LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy); LL | drop(unwrap_binder!(binder));
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ---------------------- value moved here
| LL | drop(unwrap_binder!(binder));
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` | ^^^^^^^^^^^^^^^^^^^^^^ value used here after move
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
|
LL + #[derive(Copy)]
LL | struct NotCopyInner;
| |
= 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 error[E0382]: use of moved value: `binder.0`
--> $DIR/moves.rs:32:21 --> $DIR/moves.rs:36:14
| |
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy)); LL | drop(unwrap_binder!(binder).0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner` | ------------------------ value moved here
| ...
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy` LL | drop(unwrap_binder!(binder).0);
= note: required because it appears within the type `(ManuallyDrop<NotCopyInner>, ManuallyDrop<NotCopyInner>)` | ^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
|
LL + #[derive(Copy)]
LL | struct NotCopyInner;
| |
= 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 this error, try `rustc --explain E0382`.
For more information about an error, try `rustc --explain E0277`.