ZhangHanDong / tao-of-rust-codes

《Rust编程之道》随书源码
https://ruststudy.github.io/tao_of_rust_docs/tao_of_rust/
MIT License
1.18k stars 170 forks source link

4.2.3 代码清单4-18链表初始化语句有重复操作,报错信息有更新 #324

Open pkubangbang opened 3 years ago

pkubangbang commented 3 years ago

页码与行数


代码错误

// 看起来,更像是Rc::new(Node { data: 2, next: None })
let second = Rc::new(Node { data: 2, next: Some(first.clone()) });

文本错误

接下来的编译报错信息,(新版本中?)是更友好的cannot assign (不影响上文的改动)

   |
14 |     first.next = Some(second.clone());
   |     ^^^^^^^^^^ cannot assign
   |
   = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `Rc<Node<i32>>`

Rust版本

stable version 1.54.0

rust playground link

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=eb1e39f17f47d3bdfe71df856692a673

pkubangbang commented 3 years ago

另外,代码清单4-19中也有类似的问题:第15行看起来应该是next: None

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ee9f6d708e7cb8cda738cb3efcefc51d

ZhangHanDong commented 3 years ago

感谢反馈!代码之前是没有问题的,我回头再确认下。