{"message":"`x` does not live long enough","code":{"code":"E0597","explanation":"This error occurs because a value was dropped while it was still borrowed.\n\nErroneous code example:\n\n```compile_fail,E0597\nstruct Foo<'a> {\n x: Option<&'a u32>,\n}\n\nlet mut x = Foo { x: None };\n{\n let y = 0;\n x.x = Some(&y); // error: `y` does not live long enough\n}\nprintln!(\"{:?}\", x.x);\n```\n\nHere, `y` is dropped at the end of the inner scope, but it is borrowed by\n`x` until the `println`. To fix the previous example, just remove the scope\nso that `y` isn't dropped until after the println\n\n```\nstruct Foo<'a> {\n x: Option<&'a u32>,\n}\n\nlet mut x = Foo { x: None };\n\nlet y = 0;\nx.x = Some(&y);\n\nprintln!(\"{:?}\", x.x);\n```\n"},"level":"error","spans":[{"file_name":"src/main.rs","byte_start":469,"byte_end":475,"line_start":19,"line_end":19,"column_start":21,"column_end":27,"is_primary":true,"text":[{"text":" pre_ref_x = &mut x;","highlight_start":21,"highlight_end":27}],"label":"borrowed value does not live long enough","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"src/main.rs","byte_start":582,"byte_end":583,"line_start":24,"line_end":24,"column_start":5,"column_end":6,"is_primary":false,"text":[{"text":" }","highlight_start":5,"highlight_end":6}],"label":"`x` dropped here while still borrowed","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"src/main.rs","byte_start":610,"byte_end":619,"line_start":25,"line_end":25,"column_start":27,"column_end":36,"is_primary":false,"text":[{"text":" println!(\"pre_ref_x: {pre_ref_x}\");","highlight_start":27,"highlight_end":36}],"label":"borrow later used here","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4158,"byte_end":4191,"line_start":136,"line_end":136,"column_start":28,"column_end":61,"is_primary":false,"text":[{"text":" $crate::io::_print($crate::format_args_nl!($($arg)*));","highlight_start":28,"highlight_end":61}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"src/main.rs","byte_start":588,"byte_end":622,"line_start":25,"line_end":25,"column_start":5,"column_end":39,"is_primary":false,"text":[{"text":" println!(\"pre_ref_x: {pre_ref_x}\");","highlight_start":5,"highlight_end":39}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"println!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4036,"byte_end":4056,"line_start":131,"line_end":131,"column_start":1,"column_end":21,"is_primary":false,"text":[{"text":"macro_rules! println {","highlight_start":1,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},"macro_decl_name":"$crate::format_args_nl!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs","byte_start":31203,"byte_end":31230,"line_start":907,"line_end":907,"column_start":5,"column_end":32,"is_primary":false,"text":[{"text":" macro_rules! format_args_nl {","highlight_start":5,"highlight_end":32}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0597]\u001b[0m\u001b[0m\u001b[1m: `x` does not live long enough\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:19:21\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m19\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m pre_ref_x = &mut x;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^^^^^^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9mborrowed value does not live long enough\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m...\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m24\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m }\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m-\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m`x` dropped here while still borrowed\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m25\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m println!(\"pre_ref_x: {pre_ref_x}\");\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m---------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mborrow later used here\u001b[0m\n\n"} {"message":"cannot borrow `x` as immutable because it is also borrowed as mutable","code":{"code":"E0502","explanation":"A variable already borrowed as immutable was borrowed as mutable.\n\nErroneous code example:\n\n```compile_fail,E0502\nfn bar(x: &mut i32) {}\nfn foo(a: &mut i32) {\n let y = &a; // a is borrowed as immutable.\n bar(a); // error: cannot borrow `*a` as mutable because `a` is also borrowed\n // as immutable\n println!(\"{}\", y);\n}\n```\n\nTo fix this error, ensure that you don't have any other references to the\nvariable before trying to access it mutably:\n\n```\nfn bar(x: &mut i32) {}\nfn foo(a: &mut i32) {\n bar(a);\n let y = &a; // ok!\n println!(\"{}\", y);\n}\n```\n\nFor more information on Rust's ownership system, take a look at the\n[References & Borrowing][references-and-borrowing] section of the Book.\n\n[references-and-borrowing]: https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html\n"},"level":"error","spans":[{"file_name":"src/main.rs","byte_start":499,"byte_end":500,"line_start":20,"line_end":20,"column_start":23,"column_end":24,"is_primary":true,"text":[{"text":" println!(\"x: {x}\");","highlight_start":23,"highlight_end":24}],"label":"immutable borrow occurs here","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4158,"byte_end":4191,"line_start":136,"line_end":136,"column_start":28,"column_end":61,"is_primary":false,"text":[{"text":" $crate::io::_print($crate::format_args_nl!($($arg)*));","highlight_start":28,"highlight_end":61}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"src/main.rs","byte_start":485,"byte_end":503,"line_start":20,"line_end":20,"column_start":9,"column_end":27,"is_primary":false,"text":[{"text":" println!(\"x: {x}\");","highlight_start":9,"highlight_end":27}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"println!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4036,"byte_end":4056,"line_start":131,"line_end":131,"column_start":1,"column_end":21,"is_primary":false,"text":[{"text":"macro_rules! println {","highlight_start":1,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},"macro_decl_name":"$crate::format_args_nl!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs","byte_start":31203,"byte_end":31230,"line_start":907,"line_end":907,"column_start":5,"column_end":32,"is_primary":false,"text":[{"text":" macro_rules! format_args_nl {","highlight_start":5,"highlight_end":32}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},{"file_name":"src/main.rs","byte_start":469,"byte_end":475,"line_start":19,"line_end":19,"column_start":21,"column_end":27,"is_primary":false,"text":[{"text":" pre_ref_x = &mut x;","highlight_start":21,"highlight_end":27}],"label":"mutable borrow occurs here","suggested_replacement":null,"suggestion_applicability":null,"expansion":null},{"file_name":"src/main.rs","byte_start":610,"byte_end":619,"line_start":25,"line_end":25,"column_start":27,"column_end":36,"is_primary":false,"text":[{"text":" println!(\"pre_ref_x: {pre_ref_x}\");","highlight_start":27,"highlight_end":36}],"label":"mutable borrow later used here","suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4158,"byte_end":4191,"line_start":136,"line_end":136,"column_start":28,"column_end":61,"is_primary":false,"text":[{"text":" $crate::io::_print($crate::format_args_nl!($($arg)*));","highlight_start":28,"highlight_end":61}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":{"span":{"file_name":"src/main.rs","byte_start":588,"byte_end":622,"line_start":25,"line_end":25,"column_start":5,"column_end":39,"is_primary":false,"text":[{"text":" println!(\"pre_ref_x: {pre_ref_x}\");","highlight_start":5,"highlight_end":39}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null},"macro_decl_name":"println!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/macros.rs","byte_start":4036,"byte_end":4056,"line_start":131,"line_end":131,"column_start":1,"column_end":21,"is_primary":false,"text":[{"text":"macro_rules! println {","highlight_start":1,"highlight_end":21}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}},"macro_decl_name":"$crate::format_args_nl!","def_site_span":{"file_name":"/home/vbatts/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/macros/mod.rs","byte_start":31203,"byte_end":31230,"line_start":907,"line_end":907,"column_start":5,"column_end":32,"is_primary":false,"text":[{"text":" macro_rules! format_args_nl {","highlight_start":5,"highlight_end":32}],"label":null,"suggested_replacement":null,"suggestion_applicability":null,"expansion":null}}}],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror[E0502]\u001b[0m\u001b[0m\u001b[1m: cannot borrow `x` as immutable because it is also borrowed as mutable\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m--> \u001b[0m\u001b[0msrc/main.rs:20:23\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m19\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m pre_ref_x = &mut x;\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mmutable borrow occurs here\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m20\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m println!(\"x: {x}\");\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9m^\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;9mimmutable borrow occurs here\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m...\u001b[0m\n\u001b[0m\u001b[1m\u001b[38;5;12m25\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\u001b[0m \u001b[0m\u001b[0m println!(\"pre_ref_x: {pre_ref_x}\");\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m| \u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m---------\u001b[0m\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12mmutable borrow later used here\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m|\u001b[0m\n\u001b[0m \u001b[0m\u001b[0m\u001b[1m\u001b[38;5;12m= \u001b[0m\u001b[0m\u001b[1mnote\u001b[0m\u001b[0m: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)\u001b[0m\n\n"} {"message":"aborting due to 2 previous errors","code":null,"level":"error","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1m\u001b[38;5;9merror\u001b[0m\u001b[0m\u001b[1m: aborting due to 2 previous errors\u001b[0m\n\n"} {"message":"Some errors have detailed explanations: E0502, E0597.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1mSome errors have detailed explanations: E0502, E0597.\u001b[0m\n"} {"message":"For more information about an error, try `rustc --explain E0502`.","code":null,"level":"failure-note","spans":[],"children":[],"rendered":"\u001b[0m\u001b[1mFor more information about an error, try `rustc --explain E0502`.\u001b[0m\n"}