-
-
Save ubnt-intrepid/3cd3d3910b775e003dbe3de9eb0e1ff8 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// WARNING: This output format is intended for human consumers only | |
// and is subject to change without notice. Knock yourself out. | |
static <impl at <anon>:11:1: 33:2>::display::__STATIC_FMTSTR: &[&str] = { | |
let mut _0: &[&str]; // return pointer | |
let mut _1: &[&str; 2]; | |
let mut _2: &[&str; 2]; | |
let mut _3: [&str; 2]; | |
bb0: { | |
_3 = [const "", const "\n"]; // scope 0 at <println macros>:3:18: 3:43 | |
_2 = &_3; // scope 0 at <println macros>:3:18: 3:43 | |
_1 = _2; // scope 0 at <println macros>:3:18: 3:43 | |
_0 = _1 as &[&str] (Unsize); // scope 0 at <println macros>:3:18: 3:43 | |
return; // scope 0 at <println macros>:3:18: 3:43 | |
} | |
} | |
fn <impl at <anon>:11:1: 33:2>::bar(_1: &mut Hoge) -> &str { | |
let mut _0: &str; // return pointer | |
scope 1 { | |
let _2: &mut Hoge; // "self" in scope 1 at <anon>:25:16: 25:28 | |
} | |
bb0: { | |
StorageLive(_2); // scope 0 at <anon>:25:16: 25:28 | |
_2 = _1; // scope 0 at <anon>:25:16: 25:28 | |
_0 = ((*_2).0: &str); // scope 1 at <anon>:26:9: 26:18 | |
StorageDead(_2); // scope 0 at <anon>:27:6: 27:6 | |
return; // scope 1 at <anon>:27:6: 27:6 | |
} | |
} | |
fn <impl at <anon>:11:1: 33:2>::new(_1: &str) -> Hoge { | |
let mut _0: Hoge; // return pointer | |
scope 1 { | |
let _2: &str; // "s" in scope 1 at <anon>:12:12: 12:13 | |
} | |
let mut _3: &str; | |
bb0: { | |
StorageLive(_2); // scope 0 at <anon>:12:12: 12:13 | |
_2 = _1; // scope 0 at <anon>:12:12: 12:13 | |
StorageLive(_3); // scope 1 at <anon>:13:22: 13:23 | |
_3 = _2; // scope 1 at <anon>:13:22: 13:23 | |
_0 = Hoge { hoge: _3 }; // scope 1 at <anon>:13:9: 13:25 | |
StorageDead(_3); // scope 1 at <anon>:13:25: 13:25 | |
StorageDead(_2); // scope 0 at <anon>:14:6: 14:6 | |
return; // scope 1 at <anon>:14:6: 14:6 | |
} | |
} | |
fn main() -> () { | |
let mut _0: (); // return pointer | |
scope 1 { | |
let _1: std::string::String; // "s" in scope 1 at <anon>:54:13: 54:14 | |
scope 2 { | |
let mut _4: Hoge; // "hoge" in scope 2 at <anon>:55:13: 55:21 | |
scope 3 { | |
let _9: &str; // "_borrow" in scope 3 at <anon>:56:13: 56:20 | |
} | |
} | |
} | |
let mut _2: &str; | |
let mut _3: &str; | |
let mut _5: &str; | |
let mut _6: &str; | |
let mut _7: &std::string::String; | |
let mut _8: &std::string::String; | |
let mut _10: &mut Hoge; | |
let mut _11: (); | |
let mut _12: &Hoge; | |
bb0: { | |
StorageLive(_1); // scope 0 at <anon>:54:13: 54:14 | |
StorageLive(_2); // scope 0 at <anon>:54:17: 54:23 | |
StorageLive(_3); // scope 0 at <anon>:54:17: 54:23 | |
_3 = const "TEST"; // scope 0 at <anon>:54:17: 54:23 | |
_2 = _3; // scope 0 at <anon>:54:17: 54:23 | |
_1 = const std::borrow::ToOwned::to_owned(_2) -> bb1; // scope 0 at <anon>:54:17: 54:34 | |
} | |
bb1: { | |
StorageDead(_2); // scope 0 at <anon>:54:34: 54:34 | |
StorageDead(_3); // scope 0 at <anon>:54:35: 54:35 | |
StorageLive(_4); // scope 1 at <anon>:55:13: 55:21 | |
StorageLive(_5); // scope 1 at <anon>:55:34: 55:36 | |
StorageLive(_6); // scope 1 at <anon>:55:34: 55:36 | |
StorageLive(_7); // scope 1 at <anon>:55:34: 55:36 | |
StorageLive(_8); // scope 1 at <anon>:55:34: 55:36 | |
_8 = &_1; // scope 1 at <anon>:55:34: 55:36 | |
_7 = _8; // scope 1 at <anon>:55:34: 55:36 | |
_6 = const std::ops::Deref::deref(_7) -> [return: bb4, unwind: bb3]; // scope 1 at <anon>:55:34: 55:36 | |
} | |
bb2: { | |
resume; // scope 0 at <anon>:35:1: 65:2 | |
} | |
bb3: { | |
drop(_1) -> bb2; // scope 0 at <anon>:58:6: 58:6 | |
} | |
bb4: { | |
_5 = _6; // scope 1 at <anon>:55:34: 55:36 | |
StorageDead(_7); // scope 1 at <anon>:55:36: 55:36 | |
_4 = const Hoge::new(_5) -> [return: bb5, unwind: bb3]; // scope 1 at <anon>:55:24: 55:37 | |
} | |
bb5: { | |
StorageDead(_5); // scope 1 at <anon>:55:37: 55:37 | |
StorageDead(_6); // scope 1 at <anon>:55:38: 55:38 | |
StorageDead(_8); // scope 1 at <anon>:55:38: 55:38 | |
StorageLive(_9); // scope 2 at <anon>:56:13: 56:20 | |
StorageLive(_10); // scope 2 at <anon>:56:23: 56:27 | |
_10 = &mut _4; // scope 2 at <anon>:56:23: 56:27 | |
_9 = const Hoge::baz(_10) -> [return: bb6, unwind: bb3]; // scope 2 at <anon>:56:23: 56:33 | |
} | |
bb6: { | |
StorageDead(_10); // scope 2 at <anon>:56:33: 56:33 | |
StorageLive(_12); // scope 3 at <anon>:57:9: 57:13 | |
_12 = &_4; // scope 3 at <anon>:57:9: 57:13 | |
_11 = const Hoge::display(_12) -> [return: bb7, unwind: bb3]; // scope 3 at <anon>:57:9: 57:23 | |
} | |
bb7: { | |
StorageDead(_12); // scope 3 at <anon>:57:23: 57:23 | |
_0 = (); // scope 3 at <anon>:53:5: 58:6 | |
StorageDead(_9); // scope 2 at <anon>:58:6: 58:6 | |
StorageDead(_4); // scope 1 at <anon>:58:6: 58:6 | |
drop(_1) -> bb8; // scope 0 at <anon>:58:6: 58:6 | |
} | |
bb8: { | |
StorageDead(_1); // scope 0 at <anon>:58:6: 58:6 | |
return; // scope 0 at <anon>:65:2: 65:2 | |
} | |
} | |
fn <impl at <anon>:11:1: 33:2>::foo(_1: &mut Hoge) -> &str { | |
let mut _0: &str; // return pointer | |
scope 1 { | |
let _2: &mut Hoge; // "self" in scope 1 at <anon>:20:12: 20:24 | |
} | |
let mut _3: &str; | |
bb0: { | |
StorageLive(_2); // scope 0 at <anon>:20:12: 20:24 | |
_2 = _1; // scope 0 at <anon>:20:12: 20:24 | |
StorageLive(_3); // scope 1 at <anon>:21:9: 21:18 | |
_3 = ((*_2).0: &str); // scope 1 at <anon>:21:9: 21:18 | |
_0 = _3; // scope 1 at <anon>:21:9: 21:18 | |
StorageDead(_3); // scope 1 at <anon>:21:18: 21:18 | |
StorageDead(_2); // scope 0 at <anon>:22:6: 22:6 | |
return; // scope 1 at <anon>:22:6: 22:6 | |
} | |
} | |
fn <impl at <anon>:11:1: 33:2>::baz(_1: &mut Hoge) -> &str { | |
let mut _0: &str; // return pointer | |
scope 1 { | |
let _2: &mut Hoge; // "self" in scope 1 at <anon>:30:16: 30:28 | |
} | |
let mut _3: &str; | |
bb0: { | |
StorageLive(_2); // scope 0 at <anon>:30:16: 30:28 | |
_2 = _1; // scope 0 at <anon>:30:16: 30:28 | |
StorageLive(_3); // scope 1 at <anon>:31:9: 31:18 | |
_3 = ((*_2).0: &str); // scope 1 at <anon>:31:9: 31:18 | |
_0 = _3; // scope 1 at <anon>:31:9: 31:18 | |
StorageDead(_3); // scope 1 at <anon>:31:18: 31:18 | |
StorageDead(_2); // scope 0 at <anon>:32:6: 32:6 | |
return; // scope 1 at <anon>:32:6: 32:6 | |
} | |
} | |
fn <impl at <anon>:11:1: 33:2>::display(_1: &Hoge) -> () { | |
let mut _0: (); // return pointer | |
scope 1 { | |
let _2: &Hoge; // "self" in scope 1 at <anon>:15:16: 15:21 | |
scope 2 { | |
let _11: &&str; // "__arg0" in scope 2 at <anon>:1:1: 1:1 | |
} | |
} | |
let mut _3: std::fmt::Arguments; | |
let mut _4: &[&str]; | |
let mut _5: &[std::fmt::ArgumentV1]; | |
let mut _6: &[std::fmt::ArgumentV1; 1]; | |
let mut _7: &[std::fmt::ArgumentV1; 1]; | |
let mut _8: [std::fmt::ArgumentV1; 1]; | |
let mut _9: (&&str,); | |
let mut _10: &&str; | |
let mut _12: std::fmt::ArgumentV1; | |
let mut _13: &&str; | |
let mut _14: fn(&&str, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error>; | |
bb0: { | |
StorageLive(_2); // scope 0 at <anon>:15:16: 15:21 | |
_2 = _1; // scope 0 at <anon>:15:16: 15:21 | |
StorageLive(_3); // scope 1 at <print macros>:2:27: 2:58 | |
StorageLive(_4); // scope 1 at <println macros>:3:18: 3:43 | |
_4 = (Hoge::display::__STATIC_FMTSTR: &[&str]); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_5); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_6); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_7); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_8); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_9); // scope 1 at <println macros>:3:18: 3:43 | |
StorageLive(_10); // scope 1 at <anon>:16:24: 16:33 | |
_10 = &((*_2).0: &str); // scope 1 at <anon>:16:24: 16:33 | |
_9 = (_10,); // scope 1 at <println macros>:3:18: 3:43 | |
StorageDead(_10); // scope 1 at <println macros>:3:43: 3:43 | |
StorageLive(_11); // scope 1 at <anon>:1:1: 1:1 | |
_11 = (_9.0: &&str); // scope 1 at <anon>:1:1: 1:1 | |
StorageLive(_12); // scope 2 at <print macros>:2:27: 2:58 | |
StorageLive(_13); // scope 2 at <anon>:16:24: 16:33 | |
_13 = _11; // scope 2 at <anon>:16:24: 16:33 | |
StorageLive(_14); // scope 2 at <anon>:16:24: 16:33 | |
_14 = const std::fmt::Display::fmt as fn(&&str, &mut std::fmt::Formatter<'_>) -> std::result::Result<(), std::fmt::Error> (ReifyFnPointer); // scope 2 at <anon>:16:24: 16:33 | |
_12 = const std::fmt::ArgumentV1::new(_13, _14) -> bb1; // scope 2 at <print macros>:2:27: 2:58 | |
} | |
bb1: { | |
StorageDead(_14); // scope 2 at <print macros>:2:58: 2:58 | |
StorageDead(_13); // scope 2 at <print macros>:2:58: 2:58 | |
_8 = [_12]; // scope 2 at <println macros>:3:18: 3:43 | |
StorageDead(_12); // scope 2 at <println macros>:3:43: 3:43 | |
StorageDead(_11); // scope 1 at <println macros>:3:43: 3:43 | |
_7 = &_8; // scope 1 at <println macros>:3:18: 3:43 | |
_6 = _7; // scope 1 at <println macros>:3:18: 3:43 | |
_5 = _6 as &[std::fmt::ArgumentV1] (Unsize); // scope 1 at <println macros>:3:18: 3:43 | |
StorageDead(_6); // scope 1 at <println macros>:3:43: 3:43 | |
_3 = const std::fmt::Arguments::new_v1(_4, _5) -> bb2; // scope 1 at <print macros>:2:27: 2:58 | |
} | |
bb2: { | |
StorageDead(_5); // scope 1 at <print macros>:2:58: 2:58 | |
StorageDead(_4); // scope 1 at <print macros>:2:58: 2:58 | |
_0 = const std::io::_print(_3) -> bb3; // scope 1 at <print macros>:2:1: 2:60 | |
} | |
bb3: { | |
StorageDead(_3); // scope 1 at <print macros>:2:60: 2:60 | |
StorageDead(_7); // scope 1 at <anon>:17:6: 17:6 | |
StorageDead(_8); // scope 1 at <anon>:17:6: 17:6 | |
StorageDead(_9); // scope 1 at <anon>:17:6: 17:6 | |
StorageDead(_2); // scope 0 at <anon>:17:6: 17:6 | |
return; // scope 1 at <anon>:17:6: 17:6 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![allow(dead_code)] | |
// ※主な変更点 | |
// 1. foo(), bar() の第一引数を &self から &mut self に変更 | |
// 2. baz() を追加 | |
struct Hoge<'s> { | |
hoge: &'s str, | |
} | |
impl<'s> Hoge<'s> { | |
fn new(s: &'s str) -> Hoge<'s> { | |
Hoge { hoge: s } | |
} | |
fn display(&self) { | |
println!("{}", self.hoge) | |
} | |
// (1) &mut self, &self.hoge の lifetime が 's の場合 | |
fn foo(&'s mut self) -> &'s str { | |
self.hoge | |
} | |
// (2) &mut self, &self.hoge の lifetime をパラメータにとる場合 | |
fn bar<'f>(&'f mut self) -> &'f str { | |
self.hoge | |
} | |
// (3) &mut self の lifetime のみをパラメータにとる場合 | |
fn baz<'f>(&'f mut self) -> &'s str { | |
self.hoge | |
} | |
} | |
fn main() { | |
// (1') foo() | |
/* { | |
let s = "TEST".to_owned(); | |
let mut hoge = Hoge::new(&s); | |
let _borrow = hoge.foo(); | |
hoge.display(); | |
} */ | |
// (2') bar() | |
/* { | |
let s = "TEST".to_owned(); | |
let mut hoge = Hoge::new(&s); | |
let _borrow = hoge.bar(); | |
hoge.display(); | |
} */ | |
// (3') baz() | |
{ | |
let s = "TEST".to_owned(); | |
let mut hoge = Hoge::new(&s); | |
let _borrow = hoge.baz(); | |
hoge.display(); | |
} | |
// (1'), (2') は borrow checker により弾かれてコンパイルに失敗する | |
// ※ hoge.display() を呼び出す際,その前に読んだ時の mutable な借用が解放されていないと言われる | |
// (3') では borrow checker によるチェックをパスする | |
// ※ hoge.display() の呼び出し時には baz() で作られた &mut hoge が開放済みになる | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment