Rollup merge of #130633 - eholk:pin-reborrow-self, r=compiler-errors
Add support for reborrowing pinned method receivers This builds on #130526 to add pinned reborrowing for method receivers. This enables the folllowing examples to work: ```rust #![feature(pin_ergonomics)] #![allow(incomplete_features)] use std::pin::Pin; pub struct Foo; impl Foo { fn foo(self: Pin<&mut Self>) { } fn baz(self: Pin<&Self>) { } } pub fn bar(x: Pin<&mut Foo>) { x.foo(); x.foo(); x.baz(); // Pin<&mut Foo> is downgraded to Pin<&Foo> } pub fn baaz(x: Pin<&Foo>) { x.baz(); x.baz(); } ``` This PR includes the original one, which is currently in the commit queue, but the only code changes are in the latest commit (d3c53aaa5c6fcb1018c58d229bc5d92202fa6880). #130494 r? `@compiler-errors`
This commit is contained in:
commit
68de7d11a9
7 changed files with 171 additions and 22 deletions
|
@ -584,6 +584,16 @@ impl<'tcx> Ty<'tcx> {
|
|||
Ty::new_ref(tcx, r, ty, hir::Mutability::Not)
|
||||
}
|
||||
|
||||
pub fn new_pinned_ref(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
r: Region<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
mutbl: ty::Mutability,
|
||||
) -> Ty<'tcx> {
|
||||
let pin = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, None));
|
||||
Ty::new_adt(tcx, pin, tcx.mk_args(&[Ty::new_ref(tcx, r, ty, mutbl).into()]))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn new_ptr(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, mutbl: ty::Mutability) -> Ty<'tcx> {
|
||||
Ty::new(tcx, ty::RawPtr(ty, mutbl))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue