diff --git a/cranelift/codegen/meta/src/cdsl/operands.rs b/cranelift/codegen/meta/src/cdsl/operands.rs index 1d26ec3624..915b8b6380 100644 --- a/cranelift/codegen/meta/src/cdsl/operands.rs +++ b/cranelift/codegen/meta/src/cdsl/operands.rs @@ -39,12 +39,12 @@ impl Operand { self } - pub fn doc(&self) -> Option<&str> { + pub fn doc(&self) -> &str { if let Some(doc) = &self.doc { - return Some(doc); + return doc; } match &self.kind.fields { - OperandKindFields::TypeVar(tvar) => Some(&tvar.doc), + OperandKindFields::TypeVar(tvar) => &tvar.doc, _ => self.kind.doc(), } } @@ -139,12 +139,14 @@ impl OperandKind { doc: Some(doc), } } - fn doc(&self) -> Option<&str> { + fn doc(&self) -> &str { if let Some(doc) = &self.doc { - return Some(doc); + return doc; } match &self.fields { - OperandKindFields::TypeVar(type_var) => Some(&type_var.doc), + OperandKindFields::TypeVar(type_var) => &type_var.doc, + // The only method to create an OperandKind with `doc` set to None is using a TypeVar, + // so all other options are unreachable here. OperandKindFields::ImmEnum(_) | OperandKindFields::ImmValue | OperandKindFields::EntityRef diff --git a/cranelift/codegen/meta/src/gen_inst.rs b/cranelift/codegen/meta/src/gen_inst.rs index 887ef878ad..5e28e0b24b 100644 --- a/cranelift/codegen/meta/src/gen_inst.rs +++ b/cranelift/codegen/meta/src/gen_inst.rs @@ -946,21 +946,11 @@ fn gen_inst_builder(inst: &Instruction, format: &InstructionFormat, fmt: &mut Fo op.kind.rust_type.to_string() }; args.push(format!("{}: {}", op.name, t)); - args_doc.push(format!( - "- {}: {}", - op.name, - op.doc() - .expect("every instruction's input operand must be documented") - )); + args_doc.push(format!("- {}: {}", op.name, op.doc())); } for op in &inst.operands_out { - rets_doc.push(format!( - "- {}: {}", - op.name, - op.doc() - .expect("every instruction's output operand must be documented") - )); + rets_doc.push(format!("- {}: {}", op.name, op.doc())); } let rtype = match inst.value_results.len() {