-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Implement parsing of pinned borrows #135731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -479,6 +479,55 @@ impl<'tcx> ThirBuildCx<'tcx> { | |
| ExprKind::RawBorrow { mutability, arg: self.mirror_expr(arg) } | ||
| } | ||
|
|
||
| // Make `&pin mut $expr` and `&pin const $expr` into | ||
| // `Pin { __pointer: &mut { $expr } }` and `Pin { __pointer: &$expr }`. | ||
| hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr) => match expr_ty.kind() { | ||
| &ty::Adt(adt_def, args) if tcx.is_lang_item(adt_def.did(), hir::LangItem::Pin) => { | ||
| let ty = args.type_at(0); | ||
| let arg_ty = self.typeck_results.expr_ty(arg_expr); | ||
| let mut arg = self.mirror_expr(arg_expr); | ||
| // For `&pin mut $place` where `$place` is not `Unpin`, move the place | ||
| // `$place` to ensure it will not be used afterwards. | ||
| if mutbl.is_mut() && !arg_ty.is_unpin(self.tcx, self.typing_env) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FWIW, using
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a working around. By design, The checking process is not implemented yet, so this just a work around to avoid the soundness issue. |
||
| let block = self.thir.blocks.push(Block { | ||
| targeted_by_break: false, | ||
| region_scope: region::Scope { | ||
| local_id: arg_expr.hir_id.local_id, | ||
| data: region::ScopeData::Node, | ||
| }, | ||
| span: arg_expr.span, | ||
| stmts: Box::new([]), | ||
| expr: Some(arg), | ||
| safety_mode: BlockSafety::Safe, | ||
| }); | ||
| let (temp_lifetime, backwards_incompatible) = self | ||
| .rvalue_scopes | ||
| .temporary_scope(self.region_scope_tree, arg_expr.hir_id.local_id); | ||
| arg = self.thir.exprs.push(Expr { | ||
| temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, | ||
| ty: arg_ty, | ||
| span: arg_expr.span, | ||
| kind: ExprKind::Block { block }, | ||
| }); | ||
| } | ||
| let expr = self.thir.exprs.push(Expr { | ||
| temp_lifetime: TempLifetime { temp_lifetime, backwards_incompatible }, | ||
| ty, | ||
| span: expr.span, | ||
| kind: ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg }, | ||
| }); | ||
| ExprKind::Adt(Box::new(AdtExpr { | ||
| adt_def, | ||
| variant_index: FIRST_VARIANT, | ||
| args, | ||
| fields: Box::new([FieldExpr { name: FieldIdx::from(0u32), expr }]), | ||
| user_ty: None, | ||
| base: AdtExprBase::None, | ||
| })) | ||
| } | ||
| _ => span_bug!(expr.span, "unexpected type for pinned borrow: {:?}", expr_ty), | ||
| }, | ||
|
|
||
| hir::ExprKind::Block(blk, _) => ExprKind::Block { block: self.mirror_block(blk) }, | ||
|
|
||
| hir::ExprKind::Assign(lhs, rhs, _) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| //@ pretty-compare-only | ||
| //@ pretty-mode:hir | ||
| //@ pp-exact:pin-ergonomics-hir.pp | ||
|
|
||
| #![feature(pin_ergonomics)] | ||
| #![allow(dead_code, incomplete_features)] | ||
| #[prelude_import] | ||
| use ::std::prelude::rust_2015::*; | ||
| #[macro_use] | ||
| extern crate std; | ||
|
|
||
| use std::pin::Pin; | ||
|
|
||
| struct Foo; | ||
|
|
||
| impl Foo { | ||
| fn baz(&mut self) { } | ||
|
|
||
| fn baz_const(&self) { } | ||
|
|
||
| fn baz_lt<'a>(&mut self) { } | ||
|
|
||
| fn baz_const_lt(&self) { } | ||
| } | ||
|
|
||
| fn foo(_: Pin<&'_ mut Foo>) { } | ||
| fn foo_lt<'a>(_: Pin<&'a mut Foo>) { } | ||
|
|
||
| fn foo_const(_: Pin<&'_ Foo>) { } | ||
| fn foo_const_lt(_: Pin<&'_ Foo>) { } | ||
|
|
||
| fn bar() { | ||
| let mut x: Pin<&mut _> = &pin mut Foo; | ||
| foo(x.as_mut()); | ||
| foo(x.as_mut()); | ||
| foo_const(x); | ||
|
|
||
| let x: Pin<&_> = &pin const Foo; | ||
|
|
||
| foo_const(x); | ||
| foo_const(x); | ||
| } | ||
|
|
||
| fn main() { } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| //@ pretty-compare-only | ||
| //@ pretty-mode:hir | ||
| //@ pp-exact:pin-ergonomics-hir.pp | ||
|
|
||
| #![feature(pin_ergonomics)] | ||
| #![allow(dead_code, incomplete_features)] | ||
|
|
||
| use std::pin::Pin; | ||
|
|
||
| struct Foo; | ||
|
|
||
| impl Foo { | ||
| fn baz(&mut self) { } | ||
|
|
||
| fn baz_const(&self) { } | ||
|
|
||
| fn baz_lt<'a>(&mut self) { } | ||
|
|
||
| fn baz_const_lt(&self) { } | ||
| } | ||
|
|
||
| fn foo(_: Pin<&'_ mut Foo>) { } | ||
| fn foo_lt<'a>(_: Pin<&'a mut Foo>) { } | ||
|
|
||
| fn foo_const(_: Pin<&'_ Foo>) { } | ||
| fn foo_const_lt(_: Pin<&'_ Foo>) { } | ||
|
|
||
| fn bar() { | ||
| let mut x: Pin<&mut _> = &pin mut Foo; | ||
| foo(x.as_mut()); | ||
| foo(x.as_mut()); | ||
| foo_const(x); | ||
|
|
||
| let x: Pin<&_> = &pin const Foo; | ||
|
|
||
| foo_const(x); | ||
| foo_const(x); | ||
| } | ||
|
|
||
| fn main() { } |
Uh oh!
There was an error while loading. Please reload this page.