Skip to content

Commit

Permalink
Avoid spurious rust warnings if interfaces unused
Browse files Browse the repository at this point in the history
  • Loading branch information
robertgoss committed Sep 26, 2023
1 parent 8a4ff6a commit 3c13291
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
15 changes: 11 additions & 4 deletions Source/buildimplementationrust.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,21 @@ func writeRustTraitFn(method ComponentDefinitionMethod, w LanguageWriter, hasSel
return err
}
RustParam := RustParams[0]
paramName := RustParam.ParamName
if hasImpl && !hasImplParent {
// For stubed out methods avoid warning about unued parameters
paramName = "_" + RustParam.ParamName
}
if param.ParamPass != "return" {
if parameterString == "" {
parameterString += fmt.Sprintf("%s : %s", RustParam.ParamName, RustParam.ParamType)
parameterString += fmt.Sprintf("%s : %s", paramName, RustParam.ParamType)
} else {
parameterString += fmt.Sprintf(", %s : %s", RustParam.ParamName, RustParam.ParamType)
parameterString += fmt.Sprintf(", %s : %s", paramName, RustParam.ParamType)
}
if parameterNames == "" {
parameterNames += RustParam.ParamName
parameterNames += paramName
} else {
parameterNames += fmt.Sprintf(", %s", RustParam.ParamName)
parameterNames += fmt.Sprintf(", %s", paramName)
}
} else {
returnType = RustParam.ParamType
Expand Down Expand Up @@ -557,6 +562,7 @@ func buildRustHandle(component ComponentDefinition, w LanguageWriter, InterfaceM
w.Writeln("")
w.Writeln("use %s::*;", InterfaceMod)
w.Writeln("")
w.Writeln("#[allow(dead_code)]")
w.Writeln("impl HandleImpl {")
w.AddIndentationLevel(1)
for i := 0; i < len(component.Classes); i++ {
Expand Down Expand Up @@ -660,6 +666,7 @@ func writeRustMethodWrapper(method ComponentDefinitionMethod, optclass *Componen
}
}
}
w.Writeln("#[no_mangle]")
w.Writeln("pub fn %s%s(%s) -> i32 {", cprefix, strings.ToLower(method.MethodName), parameterString)
w.AddIndentationLevel(1)
// Convert self parameter if non global
Expand Down
11 changes: 10 additions & 1 deletion Source/languagerust.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ func writeRustBaseTypeDefinitions(componentdefinition ComponentDefinition, w Lan
w.Writeln(" Version definition for %s", NameSpace)
w.Writeln("**************************************************************************************************************************/")
w.Writeln("")
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_VERSION_MAJOR : usize = %d;", strings.ToUpper(NameSpace), majorVersion(componentdefinition.Version))
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_VERSION_MINOR : usize = %d;", strings.ToUpper(NameSpace), minorVersion(componentdefinition.Version))
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_VERSION_MICRO : usize= %d;", strings.ToUpper(NameSpace), microVersion(componentdefinition.Version))
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_VERSION_PRERELEASEINFO : &str = \"%s\";", strings.ToUpper(NameSpace), preReleaseInfo(componentdefinition.Version))
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_VERSION_BUILDINFO : &str = \"%s\";", strings.ToUpper(NameSpace), buildInfo(componentdefinition.Version))

w.Writeln("")
Expand All @@ -67,9 +72,11 @@ func writeRustBaseTypeDefinitions(componentdefinition ComponentDefinition, w Lan
w.Writeln(" Error constants for %s", NameSpace)
w.Writeln("**************************************************************************************************************************/")
w.Writeln("")
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub const %s_SUCCESS : i32 = 0;", strings.ToUpper(NameSpace))
for i := 0; i < len(componentdefinition.Errors.Errors); i++ {
errorcode := componentdefinition.Errors.Errors[i]
w.Writeln("#[allow(dead_code)]")
if errorcode.Description != "" {
w.Writeln("pub const %s_ERROR_%s : i32 = %d; /** %s */", strings.ToUpper(NameSpace), errorcode.Name, errorcode.Code, errorcode.Description)
} else {
Expand All @@ -85,6 +92,8 @@ func writeRustBaseTypeDefinitions(componentdefinition ComponentDefinition, w Lan
w.Writeln("**************************************************************************************************************************/")
w.Writeln("")
w.Writeln("// Enum of all traits - this acts as a handle as we pass trait pointers through the interface")
w.Writeln("")
w.Writeln("#[allow(dead_code)]")
w.Writeln("pub enum HandleImpl {")
w.AddIndentationLevel(1)
for i := 0; i < len(componentdefinition.Classes); i++ {
Expand All @@ -101,7 +110,7 @@ func writeRustBaseTypeDefinitions(componentdefinition ComponentDefinition, w Lan
w.Writeln("pub type Handle = *mut HandleImpl;")
for i := 0; i < len(componentdefinition.Classes); i++ {
class := componentdefinition.Classes[i]
w.Writeln("pub type %sHandle = *mut HandleImpl;", class.ClassName)
w.Writeln("pub type %sHandle =Handle;", class.ClassName)
}

if len(componentdefinition.Enums) > 0 {
Expand Down

0 comments on commit 3c13291

Please sign in to comment.