mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-05 03:23:25 +00:00
Mark static generators as !Unpin
This commit is contained in:
parent
a3fdee9a75
commit
730b18b6e5
@ -627,6 +627,7 @@ unsafe impl<T: ?Sized> Freeze for &mut T {}
|
|||||||
/// [`Pin`]: ../pin/struct.Pin.html
|
/// [`Pin`]: ../pin/struct.Pin.html
|
||||||
/// [`pin module`]: ../../std/pin/index.html
|
/// [`pin module`]: ../../std/pin/index.html
|
||||||
#[stable(feature = "pin", since = "1.33.0")]
|
#[stable(feature = "pin", since = "1.33.0")]
|
||||||
|
#[cfg_attr(not(stage0), lang = "unpin")]
|
||||||
pub auto trait Unpin {}
|
pub auto trait Unpin {}
|
||||||
|
|
||||||
/// A marker type which does not implement `Unpin`.
|
/// A marker type which does not implement `Unpin`.
|
||||||
|
@ -299,6 +299,7 @@ language_item_table! {
|
|||||||
|
|
||||||
GeneratorStateLangItem, "generator_state", gen_state, Target::Enum;
|
GeneratorStateLangItem, "generator_state", gen_state, Target::Enum;
|
||||||
GeneratorTraitLangItem, "generator", gen_trait, Target::Trait;
|
GeneratorTraitLangItem, "generator", gen_trait, Target::Trait;
|
||||||
|
UnpinTraitLangItem, "unpin", unpin_trait, Target::Trait;
|
||||||
|
|
||||||
EqTraitLangItem, "eq", eq_trait, Target::Trait;
|
EqTraitLangItem, "eq", eq_trait, Target::Trait;
|
||||||
PartialOrdTraitLangItem, "partial_ord", partial_ord_trait, Target::Trait;
|
PartialOrdTraitLangItem, "partial_ord", partial_ord_trait, Target::Trait;
|
||||||
|
@ -2017,6 +2017,12 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
|
|||||||
// the auto impl might apply, we don't know
|
// the auto impl might apply, we don't know
|
||||||
candidates.ambiguous = true;
|
candidates.ambiguous = true;
|
||||||
}
|
}
|
||||||
|
ty::Generator(_, _, hir::GeneratorMovability::Static)
|
||||||
|
if self.tcx().lang_items().unpin_trait() == Some(def_id) =>
|
||||||
|
{
|
||||||
|
// Immovable generators are never `Unpin`, so suppress the
|
||||||
|
// normal auto-impl candidate for it.
|
||||||
|
}
|
||||||
_ => candidates.vec.push(AutoImplCandidate(def_id.clone())),
|
_ => candidates.vec.push(AutoImplCandidate(def_id.clone())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
13
src/test/ui/generator/static-not-unpin.rs
Normal file
13
src/test/ui/generator/static-not-unpin.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#![feature(generators)]
|
||||||
|
|
||||||
|
use std::marker::Unpin;
|
||||||
|
|
||||||
|
fn assert_unpin<T: Unpin>(_: T) {
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut generator = static || {
|
||||||
|
yield;
|
||||||
|
};
|
||||||
|
assert_unpin(generator); //~ ERROR std::marker::Unpin` is not satisfied
|
||||||
|
}
|
15
src/test/ui/generator/static-not-unpin.stderr
Normal file
15
src/test/ui/generator/static-not-unpin.stderr
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
error[E0277]: the trait bound `[static generator@$DIR/static-not-unpin.rs:9:25: 11:6 _]: std::marker::Unpin` is not satisfied
|
||||||
|
--> $DIR/static-not-unpin.rs:12:5
|
||||||
|
|
|
||||||
|
LL | assert_unpin(generator); //~ ERROR std::marker::Unpin` is not satisfied
|
||||||
|
| ^^^^^^^^^^^^ the trait `std::marker::Unpin` is not implemented for `[static generator@$DIR/static-not-unpin.rs:9:25: 11:6 _]`
|
||||||
|
|
|
||||||
|
note: required by `assert_unpin`
|
||||||
|
--> $DIR/static-not-unpin.rs:5:1
|
||||||
|
|
|
||||||
|
LL | fn assert_unpin<T: Unpin>(_: T) {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user