r/learnrust • u/dmills_00 • 6d ago
E0308 when assigning an Option<Enum....>?
Hi everyone.
I have this bit of code (Extracted from something much larger) that is throwing up an error as follows:
#[derive(Clone, Debug)]
pub enum CutterComp {
CompOff,
LeftFromTool(Option<Expr>),
RightFromTool(Option<Expr>),
}
Then in a structure definition :
#[derive(Debug, Default)]
struct StateUpdate {
.
.
.
radius_compensation: Option<CutterComp>,
.
.
}
Then in an impl of Stateupdate :
fn intepret_block(&mut self) -> Result<(), ErrType> {
.
.
.
if let Some (c) = self.grouped_gcodes[GCodeGroups::GRadiusComp as usize] {
match c.0 {
GCodes::G40 => {
trace!("Cutter compensation off");
self.radius_compensation = Some<CutterComp::CompOff>;
}
GCodes::G41 => {
trace!("Cutter compensation left");
self.radius_compensation = Some<CutterComp::LeftFromTool((self.axis.get(&"d")))>;
}Where the thing blows up with
error: comparison operators cannot be chained
--> src/main.rs:259:52
|
259 | self.radius_compensation = Some<CutterComp::CompOff>;
| ^ ^Any ideas?
Rust usually gets types right almost by magic (Old C hand here), but it seems to think that I have a bool or something.
Rust analyser is saying "expected Option<CutterComp>, found bool" which I do not understand.
1
Upvotes
12
u/Sharlinator 6d ago edited 6d ago
Some(…)notSome<…>If rustc doesn’t have a warning about this it probably should because the error message is not informative, it tries to parse the < > as comparison operators (even though this one can't possibly be parsed as an attempted chained comparison).
4
u/This_Growth2898 6d ago
2
u/projct 6d ago
Some(CutterComp::CompOff)andself.radius_compensation = Some(CutterComp::LeftFromTool(self.axis.get(&"d").cloned()));7
u/Sharlinator 6d ago
Opened #166133 because the error message is super unhelpful.