Skip to content

Commit 5c67cfa

Browse files
Use BikeshedGuaranteedNotDrop in unsafe binder type WF too
1 parent 8e203fb commit 5c67cfa

File tree

4 files changed

+43
-81
lines changed

4 files changed

+43
-81
lines changed

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ where
624624

625625
/// NOTE: This is implemented as a built-in goal and not a set of impls like:
626626
///
627-
/// ```
627+
/// ```rust,ignore (illustrative)
628628
/// impl<T> BikeshedGuaranteedNoDrop for T where T: Copy {}
629629
/// impl<T> BikeshedGuaranteedNoDrop for ManuallyDrop<T> {}
630630
/// ```

compiler/rustc_trait_selection/src/traits/wf.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,10 @@ impl<'a, 'tcx> TypeVisitor<TyCtxt<'tcx>> for WfPredicates<'a, 'tcx> {
841841
ty.map_bound(|ty| {
842842
ty::TraitRef::new(
843843
self.tcx(),
844-
self.tcx().require_lang_item(LangItem::Copy, Some(self.span)),
844+
self.tcx().require_lang_item(
845+
LangItem::BikeshedGuaranteedNoDrop,
846+
Some(self.span),
847+
),
845848
[ty],
846849
)
847850
}),

tests/ui/unsafe-binders/moves.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
1-
//@ known-bug: unknown
2-
31
#![feature(unsafe_binders)]
4-
// FIXME(unsafe_binders) ~^ WARN the feature `unsafe_binders` is incomplete
2+
//~^ WARN the feature `unsafe_binders` is incomplete
53

6-
use std::unsafe_binder::{wrap_binder, unwrap_binder};
7-
use std::mem::{drop, ManuallyDrop};
4+
use std::mem::{ManuallyDrop, drop};
5+
use std::unsafe_binder::{unwrap_binder, wrap_binder};
86

7+
#[derive(Default)]
98
struct NotCopyInner;
109
type NotCopy = ManuallyDrop<NotCopyInner>;
1110

1211
fn use_after_wrap() {
1312
unsafe {
14-
let base = NotCopy;
13+
let base = NotCopy::default();
1514
let binder: unsafe<> NotCopy = wrap_binder!(base);
1615
drop(base);
17-
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `base`
16+
//~^ ERROR use of moved value: `base`
1817
}
1918
}
2019

2120
fn move_out_of_wrap() {
2221
unsafe {
23-
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy);
22+
let binder: unsafe<> NotCopy = wrap_binder!(NotCopy::default());
2423
drop(unwrap_binder!(binder));
2524
drop(unwrap_binder!(binder));
26-
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder`
25+
//~^ ERROR use of moved value: `binder`
2726
}
2827
}
2928

3029
fn not_conflicting() {
3130
unsafe {
32-
let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy));
31+
let binder: unsafe<> (NotCopy, NotCopy) =
32+
wrap_binder!((NotCopy::default(), NotCopy::default()));
3333
drop(unwrap_binder!(binder).0);
3434
drop(unwrap_binder!(binder).1);
35-
// ^ NOT a problem.
35+
// ^ NOT a problem, since the moves are disjoint.
3636
drop(unwrap_binder!(binder).0);
37-
// FIXME(unsafe_binders) ~^ ERROR use of moved value: `binder.0`
37+
//~^ ERROR use of moved value: `binder.0`
3838
}
3939
}
4040

tests/ui/unsafe-binders/moves.stderr

+26-67
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,44 @@
1-
error[E0423]: expected value, found type alias `NotCopy`
2-
--> $DIR/moves.rs:14:20
3-
|
4-
LL | let base = NotCopy;
5-
| ^^^^^^^
6-
|
7-
= note: can't use a type alias as a constructor
8-
9-
error[E0423]: expected value, found type alias `NotCopy`
10-
--> $DIR/moves.rs:23:53
11-
|
12-
LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy);
13-
| ^^^^^^^
14-
|
15-
= note: can't use a type alias as a constructor
16-
17-
error[E0423]: expected value, found type alias `NotCopy`
18-
--> $DIR/moves.rs:32:65
19-
|
20-
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy));
21-
| ^^^^^^^
22-
|
23-
= note: can't use a type alias as a constructor
24-
25-
error[E0423]: expected value, found type alias `NotCopy`
26-
--> $DIR/moves.rs:32:74
27-
|
28-
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy));
29-
| ^^^^^^^
30-
|
31-
= note: can't use a type alias as a constructor
32-
331
warning: the feature `unsafe_binders` is incomplete and may not be safe to use and/or cause compiler crashes
34-
--> $DIR/moves.rs:3:12
2+
--> $DIR/moves.rs:1:12
353
|
364
LL | #![feature(unsafe_binders)]
375
| ^^^^^^^^^^^^^^
386
|
397
= note: see issue #130516 <https://github.com/rust-lang/rust/issues/130516> for more information
408
= note: `#[warn(incomplete_features)]` on by default
419

42-
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied
43-
--> $DIR/moves.rs:15:21
10+
error[E0382]: use of moved value: `base`
11+
--> $DIR/moves.rs:15:14
4412
|
13+
LL | let base = NotCopy::default();
14+
| ---- move occurs because `base` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait
4515
LL | let binder: unsafe<> NotCopy = wrap_binder!(base);
46-
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner`
47-
|
48-
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy`
49-
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
50-
|
51-
LL + #[derive(Copy)]
52-
LL | struct NotCopyInner;
53-
|
16+
| ---- value moved here
17+
LL | drop(base);
18+
| ^^^^ value used here after move
5419

55-
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied
56-
--> $DIR/moves.rs:23:21
20+
error[E0382]: use of moved value: `binder`
21+
--> $DIR/moves.rs:24:14
5722
|
58-
LL | let binder: unsafe<> NotCopy = wrap_binder!(NotCopy);
59-
| ^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner`
60-
|
61-
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy`
62-
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
63-
|
64-
LL + #[derive(Copy)]
65-
LL | struct NotCopyInner;
23+
LL | drop(unwrap_binder!(binder));
24+
| ---------------------- value moved here
25+
LL | drop(unwrap_binder!(binder));
26+
| ^^^^^^^^^^^^^^^^^^^^^^ value used here after move
6627
|
28+
= note: move occurs because `binder` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait
29+
= note: this error originates in the macro `unwrap_binder` (in Nightly builds, run with -Z macro-backtrace for more info)
6730

68-
error[E0277]: the trait bound `NotCopyInner: Copy` is not satisfied
69-
--> $DIR/moves.rs:32:21
70-
|
71-
LL | let binder: unsafe<> (NotCopy, NotCopy) = wrap_binder!((NotCopy, NotCopy));
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `NotCopyInner`
73-
|
74-
= note: required for `ManuallyDrop<NotCopyInner>` to implement `Copy`
75-
= note: required because it appears within the type `(ManuallyDrop<NotCopyInner>, ManuallyDrop<NotCopyInner>)`
76-
help: consider annotating `NotCopyInner` with `#[derive(Copy)]`
31+
error[E0382]: use of moved value: `binder.0`
32+
--> $DIR/moves.rs:36:14
7733
|
78-
LL + #[derive(Copy)]
79-
LL | struct NotCopyInner;
34+
LL | drop(unwrap_binder!(binder).0);
35+
| ------------------------ value moved here
36+
...
37+
LL | drop(unwrap_binder!(binder).0);
38+
| ^^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
8039
|
40+
= note: move occurs because `binder.0` has type `ManuallyDrop<NotCopyInner>`, which does not implement the `Copy` trait
8141

82-
error: aborting due to 7 previous errors; 1 warning emitted
42+
error: aborting due to 3 previous errors; 1 warning emitted
8343

84-
Some errors have detailed explanations: E0277, E0423.
85-
For more information about an error, try `rustc --explain E0277`.
44+
For more information about this error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)