I get different results on puzzle 15

Rust Brain Teasers: description (Puzzle15: To Infinity)

On this line:

  fn fmt(&self, f: &mut fmt::Formatter<`_>) -> fmt::Result {

Formatter<`_> is flagged as an error (“this struct takes 0 generic arguments but 1 generic argument was supplied”).

When I “correct” it to f: &mut fmt::Formatter then the program runs just fine) only spits out one line and exits normally. It does not spit out node after node until it gets a stack overflow.

I do get a “dead code” warning on the prev property of Node, so maybe that’s being optimized out, thus avoiding your error?

Full source for reference:

use std::cell::RefCell;
use std::rc::Rc;

type Link = Option<Rc<RefCell<Node>>>;

// #[derive(Debug)]
struct Node {
    elem: i32,
    next: Link,
    prev: Link,

impl Node {}

use std::fmt;
impl fmt::Debug for Node {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "elem: {}", self.elem)

fn main() {
    let mut head = Some(Rc::new(RefCell::new(Node {
        elem: 1,
        next: None,
        prev: None,
    head.as_mut().unwrap().borrow_mut().next = Some(Rc::new(RefCell::new(Node {
        elem: 2,
        next: None,
        prev: head.clone(),
    println!("{:?}", head);

also for reference:

rustup show
Default host: x86_64-apple-darwin
rustup home:  /Users/mike/.rustup

installed toolchains

stable-x86_64-apple-darwin (default)

installed targets for active toolchain


active toolchain

stable-x86_64-apple-darwin (default)
rustc 1.55.0 (c8dfcfe04 2021-09-06)

Thanks! I’ve added that to the tracker. This is an odd one, I think an update changed some behavior - because I’m now getting a different result on my travel laptop (I’m taking a short holiday) and remote controlling my work setup. I’ll investigate further for B2. I’m leaning towards a source control merge issue, it looks like I have a branch merged on my work setup and not on the travel laptop - the source isn’t quite the same.

I just realized that I used (backtick) instead of ’ (tick/apostrophe) infmt::Formatter<’ >`, so that explains the compile error I was getting (sorry, guess I should be using your source instead of typing it in myself (though, admittedly, the error I got when I used backtick was somewhat misleading (that’s my story… sticking to it)

I did, however, still just get one line of output (Some(RefCell { value: elem: 1 })) and a clean exit.

I’ve been playing with this a bit, and it does look like I wrote a puzzle around something that’s been improved - as well as SCM merge issues on my end (in one version, that whole puzzle was marked “to be provided later” even!). I’m getting the feeling that puzzle will be very different in beta 2.