diff --git a/tool/src/c/mod.rs b/tool/src/c/mod.rs index a4ddca00a..6482fd421 100644 --- a/tool/src/c/mod.rs +++ b/tool/src/c/mod.rs @@ -107,6 +107,7 @@ fn gen_struct_header<'a>( } writeln!(out, "}} {};", enm.name)?; } + &_ => unreachable!("unknown AST/HIR variant"), } writeln!(out, "#ifdef __cplusplus")?; @@ -286,6 +287,7 @@ pub fn gen_includes( (ast::CustomType::Opaque(_), false) => { panic!("Cannot pass opaque types by value") } + (&_, _) => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Box(underlying) => { @@ -333,6 +335,7 @@ pub fn gen_includes( ast::TypeName::StrReference(..) => {} ast::TypeName::PrimitiveSlice(..) => {} ast::TypeName::Unit => {} + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) diff --git a/tool/src/c/structs.rs b/tool/src/c/structs.rs index 744465911..0ec997cf3 100644 --- a/tool/src/c/structs.rs +++ b/tool/src/c/structs.rs @@ -31,6 +31,7 @@ pub fn gen_struct( } ast::CustomType::Enum(_) => {} + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) diff --git a/tool/src/c/types.rs b/tool/src/c/types.rs index 25cba35fa..5a86c40f0 100644 --- a/tool/src/c/types.rs +++ b/tool/src/c/types.rs @@ -19,6 +19,7 @@ pub fn gen_type( ast::CustomType::Enum(enm) => { write!(out, "{}", enm.name)?; } + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -62,6 +63,7 @@ pub fn gen_type( write!(out, "Diplomat{prim}View")?; } ast::TypeName::Unit => write!(out, "void")?, + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) @@ -103,6 +105,7 @@ pub fn name_for_type(typ: &ast::TypeName) -> ast::Ident { ast::Ident::from(format!("ref_prim_slice_{}", c_type_for_prim(prim))) } ast::TypeName::Unit => ast::Ident::from("void"), + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/c2/formatter.rs b/tool/src/c2/formatter.rs index 892922ebb..f5a0ef431 100644 --- a/tool/src/c2/formatter.rs +++ b/tool/src/c2/formatter.rs @@ -115,6 +115,7 @@ impl<'tcx> CFormatter<'tcx> { let prim = self.fmt_primitive_as_c(*p); format!("ref_{constness}prim_slice_{prim}").into() } + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/c2/ty.rs b/tool/src/c2/ty.rs index c8c9ac2b2..5dd6f24a4 100644 --- a/tool/src/c2/ty.rs +++ b/tool/src/c2/ty.rs @@ -27,6 +27,7 @@ impl<'tcx> super::CContext<'tcx> { TypeDef::Opaque(o) => context.gen_opaque_def(o, id), TypeDef::Struct(s) => context.gen_struct_def(s, id), TypeDef::OutStruct(s) => context.gen_struct_def(s, id), + _ => unreachable!("unknown AST/HIR variant"), } for method in ty.methods() { if method.attrs.disable { @@ -139,6 +140,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { "void".into() } SuccessType::OutType(o) => self.gen_ty_name(o, false), + &_ => unreachable!("unknown AST/HIR variant"), }, ReturnType::Fallible(ref ok, ref err) => { let (ok_type_name, ok_ty) = match ok { @@ -150,6 +152,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { Some(SuccessType::OutType(o)) => { (self.cx.formatter.fmt_type_name_uniquely(o), Some(o)) } + &Some(_) => unreachable!("unknown AST/HIR variant"), }; let err_type_name = match err { Some(o) => self.cx.formatter.fmt_type_name_uniquely(o), @@ -313,12 +316,14 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { let ptr_ty = match s { hir::Slice::Str(..) => "char".into(), hir::Slice::Primitive(_, prim) => self.cx.formatter.fmt_primitive_as_c(*prim), + &_ => unreachable!("unknown AST/HIR variant"), }; ( None, format!("struct {{ const {ptr_ty}* data; size_t len; }}").into(), ) } + _ => unreachable!("unknown AST/HIR variant"), }; // Todo(breaking): We can remove this requirement // and users will be forced to import more types diff --git a/tool/src/cpp/conversions.rs b/tool/src/cpp/conversions.rs index de7d35511..017d73c9f 100644 --- a/tool/src/cpp/conversions.rs +++ b/tool/src/cpp/conversions.rs @@ -31,9 +31,10 @@ pub fn gen_rust_to_cpp( // TODO(#59): should emit a unique_ptr todo!("Receiving boxes of enums is not yet supported") } + &_ => unreachable!("unknown AST/HIR variant"), } } - _o => todo!(), + _o => unreachable!("unknown AST/HIR variant"), }, ast::TypeName::Named(path_type) | ast::TypeName::SelfType(path_type) => { match path_type.resolve_with_path(in_path, env) { @@ -67,6 +68,7 @@ pub fn gen_rust_to_cpp( (_, ast::CustomType::Enum(enm)) => { format!("static_cast<{}>({})", enm.name, cpp) } + (_, &_) => unreachable!("unknown AST/HIR variant"), } } @@ -129,7 +131,7 @@ pub fn gen_rust_to_cpp( wrapped_value_id } - _ => todo!(), + _ => unreachable!("unknown AST/HIR variant"), }, ast::TypeName::Result(ok, err, _) => { @@ -229,6 +231,7 @@ pub fn gen_rust_to_cpp( "slice".into() } ast::TypeName::Unit => cpp.to_string(), + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -333,6 +336,7 @@ pub fn gen_cpp_to_rust( } ast::CustomType::Enum(enm) => format!("static_cast({})", enm.name, cpp), + &_ => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Writeable => { diff --git a/tool/src/cpp/docs.rs b/tool/src/cpp/docs.rs index 369aedb39..c386a5680 100644 --- a/tool/src/cpp/docs.rs +++ b/tool/src/cpp/docs.rs @@ -101,6 +101,7 @@ pub fn gen_custom_type_docs( ast::CustomType::Struct(_) => writeln!(out, ".. cpp:struct:: {}", typ.name())?, ast::CustomType::Enum(_) => writeln!(out, ".. cpp:enum-struct:: {}", typ.name())?, ast::CustomType::Opaque(_) => writeln!(out, ".. cpp:class:: {}", typ.name())?, + &_ => unreachable!("unknown AST/HIR variant"), } let mut class_indented = indented(out).with_str(" "); diff --git a/tool/src/cpp/mod.rs b/tool/src/cpp/mod.rs index ea52247be..f7a2e38c2 100644 --- a/tool/src/cpp/mod.rs +++ b/tool/src/cpp/mod.rs @@ -132,6 +132,7 @@ pub fn gen_bindings( )?; } } + &&_ => unreachable!("unknown AST/HIR variant"), } for method in typ.methods() { @@ -174,6 +175,7 @@ pub fn gen_bindings( writeln!(out)?; gen_struct(typ, in_path, true, env, &library_config, docs_url_gen, out)?; } + &&_ => unreachable!("unknown AST/HIR variant"), } writeln!(out)?; @@ -218,6 +220,7 @@ pub fn gen_bindings( writeln!(out)?; gen_struct(typ, in_path, false, env, &library_config, docs_url_gen, out)?; } + &&_ => unreachable!("unknown AST/HIR variant"), } writeln!(out, "#endif")? @@ -280,6 +283,7 @@ fn gen_includes( seen_includes.insert(include); } } + &_ => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Box(underlying) => { @@ -346,6 +350,7 @@ fn gen_includes( ast::TypeName::StrReference(..) => {} ast::TypeName::PrimitiveSlice(..) => {} ast::TypeName::Unit => {} + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) diff --git a/tool/src/cpp/structs.rs b/tool/src/cpp/structs.rs index 115ffabbc..ed816cc2b 100644 --- a/tool/src/cpp/structs.rs +++ b/tool/src/cpp/structs.rs @@ -158,6 +158,7 @@ pub fn gen_struct( } ast::CustomType::Enum(_) => {} + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) diff --git a/tool/src/cpp/types.rs b/tool/src/cpp/types.rs index 135f0d57f..c22652059 100644 --- a/tool/src/cpp/types.rs +++ b/tool/src/cpp/types.rs @@ -66,6 +66,7 @@ fn gen_type_inner( ast::CustomType::Enum(enm) => { write!(out, "{}", enm.name)?; } + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -126,7 +127,7 @@ fn gen_type_inner( )?; } - _ => todo!(), + _ => unreachable!("unknown AST/HIR variant"), }, ast::TypeName::Result(ok, err, _) => { @@ -180,6 +181,7 @@ fn gen_type_inner( ast::TypeName::Unit => { write!(out, "void")?; } + &_ => unreachable!("unknown AST/HIR variant"), } if !handled_ref { diff --git a/tool/src/cpp2/ty.rs b/tool/src/cpp2/ty.rs index 605b6cf45..3cda5a95b 100644 --- a/tool/src/cpp2/ty.rs +++ b/tool/src/cpp2/ty.rs @@ -31,6 +31,7 @@ impl<'tcx> super::Cpp2Context<'tcx> { TypeDef::Opaque(o) => context.gen_opaque_def(o, id), TypeDef::Struct(s) => context.gen_struct_def(s, id), TypeDef::OutStruct(s) => context.gen_struct_def(s, id), + _ => unreachable!("unknown AST/HIR variant"), } drop(guard); @@ -459,6 +460,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { let ret = self.cx.formatter.fmt_borrowed_slice(&ret, b.mutability); ret.into_owned().into() } + _ => unreachable!("unknown AST/HIR variant"), } } @@ -468,6 +470,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { SelfType::Opaque(..) => "this->AsFFI()".into(), SelfType::Struct(..) => "this->AsFFI()".into(), SelfType::Enum(..) => "this->AsFFI()".into(), + _ => unreachable!("unknown AST/HIR variant"), } } @@ -560,6 +563,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { }, ] } + _ => unreachable!("unknown AST/HIR variant"), } } @@ -570,12 +574,14 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { ReturnType::Infallible(Some(ref ty)) => match ty { SuccessType::Writeable => self.cx.formatter.fmt_owned_str(), SuccessType::OutType(o) => self.gen_type_name(o), + &_ => unreachable!("unknown AST/HIR variant"), }, ReturnType::Fallible(ref ok, ref err) => { let ok_type_name = match ok { Some(SuccessType::Writeable) => self.cx.formatter.fmt_owned_str(), None => "std::monostate".into(), Some(SuccessType::OutType(o)) => self.gen_type_name(o), + &Some(_) => unreachable!("unknown AST/HIR variant"), }; let err_type_name = match err { Some(o) => self.gen_type_name(o), @@ -661,6 +667,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { .fmt_borrowed_slice(&prim_name, b.mutability); format!("{span}({var_name}_data, {var_name}_size)").into() } + _ => unreachable!("unknown AST/HIR variant"), } } @@ -685,6 +692,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { Some(SuccessType::Writeable) => self.cx.formatter.fmt_owned_str(), None => "std::monostate".into(), Some(SuccessType::OutType(o)) => self.gen_type_name(o), + &Some(_) => unreachable!("unknown AST/HIR variant"), }; let err_type_name = match err { Some(o) => self.gen_type_name(o), @@ -695,6 +703,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { Some(SuccessType::Writeable) => "std::move(output)".into(), None => "".into(), Some(SuccessType::OutType(o)) => self.gen_c_to_cpp_for_type(o, ok_path.into()), + &Some(_) => unreachable!("unknown AST/HIR variant"), }; let err_conversion = match err { Some(o) => self.gen_c_to_cpp_for_type(o, err_path.into()), @@ -704,6 +713,7 @@ impl<'ccx, 'tcx: 'ccx, 'header> TyGenContext<'ccx, 'tcx, 'header> { format!("{var_name}.is_ok ? diplomat::result<{ok_type_name}, {err_type_name}>(diplomat::Ok<{ok_type_name}>({ok_conversion})) : diplomat::result<{ok_type_name}, {err_type_name}>(diplomat::Err<{err_type_name}>({err_conversion}))").into() ) } + ReturnType::Infallible(Some(_)) => unreachable!("unknown AST/HIR variant"), } } } diff --git a/tool/src/docs_util.rs b/tool/src/docs_util.rs index 8a2d6ab3c..207fbcec2 100644 --- a/tool/src/docs_util.rs +++ b/tool/src/docs_util.rs @@ -108,6 +108,7 @@ impl FromMarkdown for CppRst { ast::CustomType::Struct(strct) => write!(out, ":cpp:struct:`{}`", strct.name), ast::CustomType::Enum(enm) => write!(out, ":cpp:enum-struct:`{}`", enm.name), ast::CustomType::Opaque(opaque) => write!(out, ":cpp:class:`{}`", opaque.name), + &_ => unreachable!("unknown AST/HIR variant"), } } } diff --git a/tool/src/dotnet/conversions.rs b/tool/src/dotnet/conversions.rs index 2446676de..288db82cc 100644 --- a/tool/src/dotnet/conversions.rs +++ b/tool/src/dotnet/conversions.rs @@ -77,6 +77,7 @@ pub fn to_idiomatic_object( ast::CustomType::Enum(_) => { write!(out, "({name}){input_var_name}") } + &_ => unreachable!("unknown AST/HIR variant"), } } other => panic!("expected named type name, found `{}`", other), @@ -119,6 +120,7 @@ pub fn to_raw_object( ast::CustomType::Enum(_) => { write!(out, "(Raw.{name}){input_var_name}") } + &_ => unreachable!("unknown AST/HIR variant"), } } other => panic!("expected named type name, found `{}`", other), diff --git a/tool/src/dotnet/idiomatic.rs b/tool/src/dotnet/idiomatic.rs index 74031af82..710639408 100644 --- a/tool/src/dotnet/idiomatic.rs +++ b/tool/src/dotnet/idiomatic.rs @@ -185,6 +185,7 @@ pub fn gen( Ok(()) })?; } + &_ => unreachable!("unknown AST/HIR variant"), } Ok(()) @@ -212,6 +213,7 @@ fn gen_property_for_field( return Ok(()); } ast::CustomType::Enum(_) => {} + &_ => unreachable!("unknown AST/HIR variant"), } } _ => { @@ -723,6 +725,7 @@ fn gen_raw_conversion_type_name_decl_position( ast::CustomType::Enum(_) | ast::CustomType::Struct(_) => { gen_raw_type_name_decl_position(typ, in_path, env, out) } + &_ => unreachable!("unknown AST/HIR variant"), } } _ => gen_raw_type_name_decl_position(typ, in_path, env, out), @@ -790,6 +793,7 @@ fn requires_null_check(typ: &ast::TypeName, in_path: &ast::Path, env: &Env) -> b match path_type.resolve(in_path, env) { ast::CustomType::Opaque(_) => true, ast::CustomType::Struct(_) | ast::CustomType::Enum(_) => false, + &_ => unreachable!("unknown AST/HIR variant"), } } other => panic!("expected named type name, found `{}`", other), diff --git a/tool/src/dotnet/raw.rs b/tool/src/dotnet/raw.rs index 0430b3936..052c1cee1 100644 --- a/tool/src/dotnet/raw.rs +++ b/tool/src/dotnet/raw.rs @@ -144,6 +144,7 @@ pub fn gen<'ast>( Ok(()) }) } + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/dotnet/types.rs b/tool/src/dotnet/types.rs index fcbb57135..596486950 100644 --- a/tool/src/dotnet/types.rs +++ b/tool/src/dotnet/types.rs @@ -60,6 +60,7 @@ pub fn gen_type_name( ast::TypeName::Unit => { write!(out, "void") } + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -115,5 +116,6 @@ pub fn name_for_type(typ: &ast::TypeName) -> ast::Ident { format!("RefPrimSlice{}", prim.to_string().to_upper_camel_case()), ), ast::TypeName::Unit => ast::Ident::from("Void"), + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/dotnet/util.rs b/tool/src/dotnet/util.rs index 84e5b4fc9..861f2447c 100644 --- a/tool/src/dotnet/util.rs +++ b/tool/src/dotnet/util.rs @@ -63,6 +63,7 @@ pub fn collect_results<'ast>( | ast::TypeName::Named(_) | ast::TypeName::SelfType(_) | ast::TypeName::Primitive(_) => {} + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -124,5 +125,6 @@ fn collect_errors_impl<'ast>( | ast::TypeName::Writeable | ast::TypeName::StrReference(..) | ast::TypeName::PrimitiveSlice(..) => {} + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/js/conversions.rs b/tool/src/js/conversions.rs index a4ea21998..b6820ea56 100644 --- a/tool/src/js/conversions.rs +++ b/tool/src/js/conversions.rs @@ -207,6 +207,7 @@ pub fn gen_value_js_to_rust<'env>( ast::CustomType::Opaque(_) => { panic!("Opaque types cannot be sent as values"); } + &_ => unreachable!("unknown AST/HIR variant"), } } _ => invocation_params.push(param_name.to_string()), @@ -420,7 +421,8 @@ impl fmt::Display for InvocationIntoJs<'_> { } ast::CustomType::Enum(enm) => { write!(f, "{}_rust_to_js[{}]", enm.name, self.invocation.scalar()) - } + }, + &_ => unreachable!("unknown AST/HIR variant") } } ast::TypeName::Reference(.., inner) => Pointer { @@ -508,8 +510,9 @@ impl fmt::Display for InvocationIntoJs<'_> { ast::TypeName::PrimitiveSlice(.., prim) => { self.display_slice(SliceKind::Primitive(prim.into())).fmt(f) } - ast::TypeName::Writeable => todo!(), + ast::TypeName::Writeable => unreachable!("unknown AST/HIR variant"), ast::TypeName::Unit => self.invocation.scalar().fmt(f), + &_ => unreachable!("unknown AST/HIR variant"), } } } @@ -728,6 +731,7 @@ impl fmt::Display for UnderlyingIntoJs<'_> { "{}_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, {})]", enm.name, self.underlying, ), + &_ => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Reference(.., typ) => Pointer { @@ -780,6 +784,7 @@ impl fmt::Display for UnderlyingIntoJs<'_> { self.display_slice(SliceKind::Primitive(prim.into())).fmt(f) } ast::TypeName::Unit => "{}".fmt(f), + &_ => unreachable!("unknown AST/HIR variant"), } } } diff --git a/tool/src/js/mod.rs b/tool/src/js/mod.rs index cc60b6f0d..5cf821caf 100644 --- a/tool/src/js/mod.rs +++ b/tool/src/js/mod.rs @@ -237,6 +237,7 @@ impl<'env> Imports<'env> { self.collect_usages(typ, &ty_in_path, env, TypePosition::Inner) } } + &_ => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Reference(.., typ) diff --git a/tool/src/js/structs.rs b/tool/src/js/structs.rs index 95f42546c..c50a0f543 100644 --- a/tool/src/js/structs.rs +++ b/tool/src/js/structs.rs @@ -182,6 +182,7 @@ pub fn gen_struct( }) ) } + &_ => unreachable!("unknown AST/HIR variant"), } } @@ -521,6 +522,7 @@ pub fn gen_ts_type( ast::TypeName::Unit => { out.write_str("void")?; } + &_ => unreachable!("unknown AST/HIR variant"), } Ok(false) } diff --git a/tool/src/js/types.rs b/tool/src/js/types.rs index a3fb9ed87..96b207113 100644 --- a/tool/src/js/types.rs +++ b/tool/src/js/types.rs @@ -50,6 +50,7 @@ pub fn return_type_form(typ: &ast::TypeName, in_path: &ast::Path, env: &Env) -> (_, ast::CustomType::Opaque(_)) | (_, ast::CustomType::Enum(_)) => { ReturnTypeForm::Scalar } + (_, &_) => unreachable!("unknown AST/HIR variant"), } } @@ -79,6 +80,7 @@ pub fn return_type_form(typ: &ast::TypeName, in_path: &ast::Path, env: &Env) -> ast::TypeName::Primitive(_) => ReturnTypeForm::Scalar, ast::TypeName::Writeable => panic!("Cannot return writeable"), + &_ => unreachable!("unknown AST/HIR variant"), } } diff --git a/tool/src/layout.rs b/tool/src/layout.rs index b7b064d8e..ccb3bbe25 100644 --- a/tool/src/layout.rs +++ b/tool/src/layout.rs @@ -96,6 +96,7 @@ pub fn type_size_alignment(typ: &ast::TypeName, in_path: &ast::Path, env: &Env) (_, ast::CustomType::Opaque(_)) => { panic!("Size of opaque types is unknown") } + (_, &_) => unreachable!("unknown AST/HIR variant"), } } ast::TypeName::Primitive(p) => primitive_size_alignment(*p), @@ -108,6 +109,7 @@ pub fn type_size_alignment(typ: &ast::TypeName, in_path: &ast::Path, env: &Env) ast::TypeName::PrimitiveSlice(..) => Layout::new::<(usize_target, usize_target)>(), ast::TypeName::Writeable => panic!(), ast::TypeName::Unit => Layout::new::<()>(), + &_ => unreachable!("unknown AST/HIR variant"), } }