diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-03 14:25:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-03 14:25:17 +0100 |
| commit | 98ca09b7b1ff3b82e3bb4de728417b176d56d4e7 (patch) | |
| tree | 66c2c90f0415a5d482bfdc77b3a3a5cef71a5312 /src | |
| parent | f70794a17a357c93014059f23db53fae4fcc578c (diff) | |
Qualify global paths
Diffstat (limited to 'src')
4 files changed, 8 insertions, 13 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java index 5d777ea..b2a5009 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rust/RustGeneratorConfig.java @@ -53,9 +53,9 @@ public record RustGeneratorConfig( private static final Map<SimpleNativeType, RustNativeTypeConfig> DEFAULT_NATIVE_TYPE_CONFIGS = Map.ofEntries( Map.entry(NativeTypes.INT_32, new RustNativeTypeConfig(RustTypePath.primitive("i32"))), Map.entry(NativeTypes.INT_64, new RustNativeTypeConfig(RustTypePath.primitive("i64"))), - Map.entry(NativeTypes.STRING, new RustNativeTypeConfig(RustTypePath.of("std", "string", "String"))), - Map.entry(NativeTypes.LIST_INNER, new RustNativeTypeConfig(RustTypePath.of("std", "vec", "Vec"))), - Map.entry(NativeTypes.OPTION_INNER, new RustNativeTypeConfig(RustTypePath.of("std", "option", "Option"))) + Map.entry(NativeTypes.STRING, new RustNativeTypeConfig(RustTypePath.global("std", "string", "String"))), + Map.entry(NativeTypes.LIST_INNER, new RustNativeTypeConfig(RustTypePath.global("std", "vec", "Vec"))), + Map.entry(NativeTypes.OPTION_INNER, new RustNativeTypeConfig(RustTypePath.global("std", "option", "Option"))) ); public Optional<RustNativeTypeConfig> nativeTypeConfig(SimpleNativeType type) { diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttypes/RustTypesGenerator.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttypes/RustTypesGenerator.java index d4e7fd1..2e8b244 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttypes/RustTypesGenerator.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/generators/rusttypes/RustTypesGenerator.java @@ -156,7 +156,7 @@ public class RustTypesGenerator implements Generator { var variantType = generateRustTypeExpression(variant.type(), context); if (variant.isBox()) { - variantType = RustTypePath.of("std", "boxed", "Box") + variantType = RustTypePath.global("std", "boxed", "Box") .withArgs(List.of(variantType)); } diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java index 6b51792..8b0adf0 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/output/lang/rust/ast/RustTypePath.java @@ -42,12 +42,7 @@ public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output. // Custom area start: org.zwobble.hobgoblin.compiler.output.lang.rust.ast.RustTypePath body public static RustTypePath primitive(String name) { - return new RustTypePath(List.of( - new RustTypePathSegment( - new RustPathIdentSegmentIdentifier(new RustIdentifier(name)), - Optional.empty() - ) - )); + return global("core", "primitive", name); } public static RustTypePath of(String... names) { @@ -83,7 +78,7 @@ public record RustTypePath(java.util.List<org.zwobble.hobgoblin.compiler.output. return new RustTypePath(segments); } - public static RustType global(String... names) { + public static RustTypePath global(String... names) { var segments = Stream.concat( Stream.of(RustTypePathSegment.global()), Arrays.stream(names) diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java index a7bf391..476a876 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/output/lang/rust/RustWriterTests.java @@ -228,8 +228,8 @@ public class RustWriterTests { var rust = RustStructStruct.arbitrary() .withName(new RustIdentifier("Rectangle")) .withFields(List.of( - new RustStructField(new RustIdentifier("width"), RustTypePath.primitive("i32")), - new RustStructField(new RustIdentifier("height"), RustTypePath.primitive("i32")) + new RustStructField(new RustIdentifier("width"), RustTypePath.of("i32")), + new RustStructField(new RustIdentifier("height"), RustTypePath.of("i32")) )) .build(); |
