Skip to content

Commit 730b18b

Browse files
committed
Mark static generators as !Unpin
1 parent a3fdee9 commit 730b18b

File tree

5 files changed

+36
-0
lines changed

5 files changed

+36
-0
lines changed

src/libcore/marker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
627627
/// [`Pin`]: ../pin/struct.Pin.html
628628
/// [`pin module`]: ../../std/pin/index.html
629629
#[stable(feature = "pin", since = "1.33.0")]
630+
#[cfg_attr(not(stage0), lang = "unpin")]
630631
pub auto trait Unpin {}
631632

632633
/// A marker type which does not implement `Unpin`.

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ language_item_table! {
299299

300300
GeneratorStateLangItem, "generator_state", gen_state, Target::Enum;
301301
GeneratorTraitLangItem, "generator", gen_trait, Target::Trait;
302+
UnpinTraitLangItem, "unpin", unpin_trait, Target::Trait;
302303

303304
EqTraitLangItem, "eq", eq_trait, Target::Trait;
304305
PartialOrdTraitLangItem, "partial_ord", partial_ord_trait, Target::Trait;

src/librustc/traits/select.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2017,6 +2017,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
20172017
// the auto impl might apply, we don't know
20182018
candidates.ambiguous = true;
20192019
}
2020+
ty::Generator(_, _, hir::GeneratorMovability::Static)
2021+
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
2022+
{
2023+
// Immovable generators are never `Unpin`, so suppress the
2024+
// normal auto-impl candidate for it.
2025+
}
20202026
_ => candidates.vec.push(AutoImplCandidate(def_id.clone())),
20212027
}
20222028
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(generators)]
2+
3+
use std::marker::Unpin;
4+
5+
fn assert_unpin<T: Unpin>(_: T) {
6+
}
7+
8+
fn main() {
9+
let mut generator = static || {
10+
yield;
11+
};
12+
assert_unpin(generator); //~ ERROR std::marker::Unpin` is not satisfied
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0277]: the trait bound `[static generator@$DIR/static-not-unpin.rs:9:25: 11:6 _]: std::marker::Unpin` is not satisfied
2+
--> $DIR/static-not-unpin.rs:12:5
3+
|
4+
LL | assert_unpin(generator); //~ ERROR std::marker::Unpin` is not satisfied
5+
| ^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:9:25: 11:6 _]`
6+
|
7+
note: required by `assert_unpin`
8+
--> $DIR/static-not-unpin.rs:5:1
9+
|
10+
LL | fn assert_unpin<T: Unpin>(_: T) {
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)