File: sugar-self.rs

package info (click to toggle)
rustc 1.88.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 934,128 kB
  • sloc: xml: 158,127; python: 36,062; javascript: 19,855; sh: 19,700; cpp: 18,947; ansic: 12,993; asm: 4,792; makefile: 690; lisp: 29; perl: 29; ruby: 19; sql: 11
file content (46 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//@ check-pass

#![feature(pin_ergonomics)]
#![allow(dead_code, incomplete_features)]

// Makes sure we can handle `&pin mut self` and `&pin const self` as sugar for
// `self: Pin<&mut Self>` and `self: Pin<&Self>`.

use std::pin::Pin;

struct Foo;

impl Foo {
    fn baz(&pin mut self) {}

    fn baz_const(&pin const self) {}

    fn baz_lt<'a>(&'a pin mut self) {}

    fn baz_const_lt(&'_ pin const self) {}
}

fn foo(_: &pin mut Foo) {}

fn foo_const(_: &pin const Foo) {}

fn bar(x: &pin mut Foo) {
    // For the calls below to work we need to automatically reborrow,
    // as if the user had written `foo(x.as_mut())`.
    foo(x);
    foo(x);

    Foo::baz(x);
    Foo::baz(x);

    // make sure we can reborrow &mut as &.
    foo_const(x);
    Foo::baz_const(x);

    let x: &pin const _ = Pin::new(&Foo);

    foo_const(x); // make sure reborrowing from & to & works.
    foo_const(x);
}

fn main() {}