error[E0502]: cannot borrow `foo` as immutable because it is also borrowed as mutable
--> src/main.rs:14:5
|
13 | let loan = foo.mutate_and_share();
| ---------------------- mutable borrow occurs here
14 | foo.share();
| ^^^^^^^^^^^ immutable borrow occurs here
15 | println!("{:?}", loan);
| ---- mutable borrow later used here
It doesn't matter the kind of reference you end up with, but the one you start with, in this case a mutable reference. Allowing downgrading borrows would be unsound when combined with methods like RefCell::get_mut
Hi, your question was a bit hard to read, so I've made some tweaks: For future posts, please make sure to check out how code blocks work in this forum. Also, it's good practice to have your question not only in the title, but to have the topic starting post be understandable on its own, too. And for questions regarding programs that don't compile, attaching the compiler error is always a good idea
This user has been a member of the forum for over two years, and has been asked to format his code snippets in multipleocasions before. At this point, I'm not really sure if he's just trolling.
Well, on the other hand, the top of this topic reminds us they haven't participated in the forum for almost 1 year. One can forget how the syntax works, and the pinned topics are also relatively tricky to find, once you've viewed them once.
Let's appreciate the question did come with a fully working, and easy to understand code example (except for the formatting). Actual trolling seems rather unlikely.
I agree, but I still understand why someone might be frustrated with another user's long-standing unwillingness and/or inability to learn and improve their posts.
I'm often genuinely puzzled by how (supposedly) intelligent adults can think that it's useful to dump a pile of code with no context and a question that's full of errors to the point of being absolutely meaningless. I mean, haven't we got the internet for decades? Anyone who roams around on forums and Q&A sites for a couple of weeks could (and certainly should) notice that there's a significant and very obvious difference between questions that at least make sense and exhibit a minimal effort made by the asker, and those that are entirely useless and impossible to answer. Why people don't get this is beyond my comprehension.