Rust: Add unit type

This commit is contained in:
Simon Friis Vindum
2025-05-21 13:00:28 +02:00
parent 0dcf15bf77
commit fafae89502

View File

@@ -9,6 +9,7 @@ private import codeql.rust.elements.internal.generated.Synth
cached
newtype TType =
TUnit() or
TStruct(Struct s) { Stages::TypeInferenceStage::ref() } or
TEnum(Enum e) or
TTrait(Trait t) or
@@ -48,6 +49,21 @@ abstract class Type extends TType {
abstract Location getLocation();
}
/** The unit type `()`. */
class UnitType extends Type, TUnit {
UnitType() { this = TUnit() }
override StructField getStructField(string name) { none() }
override TupleField getTupleField(int i) { none() }
override TypeParameter getTypeParameter(int i) { none() }
override string toString() { result = "()" }
override Location getLocation() { result instanceof EmptyLocation }
}
abstract private class StructOrEnumType extends Type {
abstract ItemNode asItemNode();
}