diff --git a/tooling/nargo_cli/build.rs b/tooling/nargo_cli/build.rs index d00cd179789..dcf8b985d13 100644 --- a/tooling/nargo_cli/build.rs +++ b/tooling/nargo_cli/build.rs @@ -173,29 +173,17 @@ const TESTS_WITHOUT_STDOUT_CHECK: [&str; 0] = []; /// These tests are ignored because of existing bugs in `nargo expand`. /// As the bugs are fixed these tests should be removed from this list. /// (some are ignored on purpose for the same reason as `IGNORED_NARGO_EXPAND_EXECUTION_TESTS`) -const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 24] = [ - // bug - "alias_trait_method_call_multiple_candidates", +const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 13] = [ // bug "associated_type_bounds", // bug "enums", // There's no "src/main.nr" here so it's trickier to make this work "overlapping_dep_and_mod", - // bug - "primitive_trait_method_call_multiple_candidates", // this one works, but copying its `Nargo.toml` file to somewhere else doesn't work // because it references another project by a relative path "reexports", // bug - "regression_7038", - // bug - "regression_7038_2", - // bug - "regression_7038_3", - // bug - "regression_7038_4", - // bug "serialize_1", // bug "serialize_2", @@ -204,21 +192,11 @@ const IGNORED_NARGO_EXPAND_COMPILE_SUCCESS_EMPTY_TESTS: [&str; 24] = [ // bug "serialize_4", // bug - "trait_allowed_item_name_matches", - // bug - "trait_default_implementation", - // bug "trait_function_calls", // bug "trait_method_mut_self", // bug - "trait_override_implementation", - // bug "trait_static_methods", - // bug - "type_trait_method_call_multiple_candidates", - // bug - "type_trait_method_call_multiple_candidates_with_turbofish", // There's no "src/main.nr" here so it's trickier to make this work "workspace_reexport_bug", // bug diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/alias_trait_method_call_multiple_candidates/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/alias_trait_method_call_multiple_candidates/execute__tests__expanded.snap new file mode 100644 index 00000000000..0f2fd8c16bb --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/alias_trait_method_call_multiple_candidates/execute__tests__expanded.snap @@ -0,0 +1,38 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +use std::convert::From; + +struct MyU128 { + lo: Field, + hi: Field, +} + +impl MyU128 { + pub fn from_u64s_le(lo: u64, hi: u64) -> Self { + Self { lo: lo as Field, hi: hi as Field } + } +} + +impl From for MyU128 { + fn from(value: u64) -> Self { + Self::from_u64s_le(value, 0_u64) + } +} + +impl From for MyU128 { + fn from(value: u32) -> Self { + Self::from(value as u64) + } +} + +type MyU128Alias = MyU128; + +fn main() { + let x: u64 = 0_u64; + let mut small_int: MyU128 = MyU128::from(x); + assert(small_int.lo == (x as Field)); + let u32_3: u32 = 3_u32; + assert(MyU128::from(u32_3).lo == 3_Field); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics_move_constant_terms/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics_move_constant_terms/execute__tests__expanded.snap index caf6bdf6f6a..9d51be83813 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics_move_constant_terms/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/arithmetic_generics_move_constant_terms/execute__tests__expanded.snap @@ -21,13 +21,13 @@ struct Point { impl FromCallData for Point { fn from_calldata(calldata: [Field; N]) -> (Self, [Field; N - 2]) { - let (x, calldata): (Field, [Field; N - 1]) = FromCallData::from_calldata(calldata); - let (y, calldata): (Field, [Field; N - 2]) = FromCallData::from_calldata(calldata); + let (x, calldata): (Field, [Field; N - 1]) = Field::from_calldata(calldata); + let (y, calldata): (Field, [Field; N - 2]) = Field::from_calldata(calldata); (Self { x: x, y: y }, calldata) } } fn main() { let calldata: [Field; 2] = [1_Field, 2_Field]; - let _: (Point, [Field; 2 - 2]) = FromCallData::from_calldata(calldata); + let _: (Point, [Field; 2 - 2]) = Point::from_calldata(calldata); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types/execute__tests__expanded.snap index d1c24ae38c6..97252563afd 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types/execute__tests__expanded.snap @@ -17,9 +17,9 @@ impl Collection for [T; N] { fn cget(self, index: u32) -> Option { if index < self.len() { - Option::some(self[index]) + Option::::some(self[index]) } else { - Option::none() + Option::::none() } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types_implicit/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types_implicit/execute__tests__expanded.snap index 6bfaa99c636..e560b1d0b39 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types_implicit/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/associated_types_implicit/execute__tests__expanded.snap @@ -28,14 +28,14 @@ where T: Foo, ::Bar: Eq, { - Foo::foo(self.unwrap()) + self.unwrap().foo() } } fn main() { let three: u64 = 3_u64; call_foo(three); - let x: Option> = Option::some(Option::some(0_u64)); + let x: Option> = Option::>::some(Option::::some(0_u64)); let x_foo: u8 = x.foo(); assert(x_foo == x_foo); assert(x.foo() == 0_u8); @@ -46,6 +46,6 @@ where T: Foo, ::Bar: Eq, { - let y: ::Bar = Foo::foo(x); + let y: ::Bar = x.foo(); assert(y == y); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/derive_impl/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/derive_impl/execute__tests__expanded.snap index 2e5ff7c1aca..d02957c1192 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/derive_impl/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/derive_impl/execute__tests__expanded.snap @@ -37,7 +37,7 @@ struct Foo { impl Default for Foo { fn default() -> Self { - Self { x: Default::default(), y: Default::default() } + Self { x: Field::default(), y: Bar::default() } } } @@ -71,5 +71,5 @@ comptime fn join(slice: [Quoted]) -> Quoted { } fn main() { - let _foo: Foo = Default::default(); + let _foo: Foo = Foo::default(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/field_or_integer_static_trait_method/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/field_or_integer_static_trait_method/execute__tests__expanded.snap index ea31136d326..95bdb97d0e5 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/field_or_integer_static_trait_method/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/field_or_integer_static_trait_method/execute__tests__expanded.snap @@ -20,9 +20,9 @@ impl Read for u32 { fn main() { let data: [Field; 1] = [1_Field]; - let value: u32 = Read::read(data); + let value: u32 = u32::read(data); assert(value == 1_u32); - let value: Field = Read::read(data); + let value: Field = Field::read(data); assert(value == 10_Field); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/function_attribute/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/function_attribute/execute__tests__expanded.snap index 2acf93f20ac..a47044bc9c0 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/function_attribute/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/function_attribute/execute__tests__expanded.snap @@ -25,5 +25,5 @@ comptime fn function_attr(_f: FunctionDefinition) -> Quoted { } fn main() { - let _: Foo = Default::default(); + let _: Foo = Foo::default(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/generic_trait_bounds/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/generic_trait_bounds/execute__tests__expanded.snap index 0501f85aeb4..63d32371ad1 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/generic_trait_bounds/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/generic_trait_bounds/execute__tests__expanded.snap @@ -10,7 +10,7 @@ pub fn foo(x: T) where T: Trait, { - Trait::foo(x); + x.foo(); } pub struct Foo {} @@ -20,7 +20,7 @@ impl Foo { where T: Trait, { - Trait::foo(x); + x.foo(); } } @@ -29,7 +29,7 @@ impl Trait2 for Foo { where T: Trait, { - Trait::foo(x); + x.foo(); } } @@ -39,7 +39,7 @@ trait Trait2 { T: Trait, { let _: Self = self; - Trait::foo(x); + x.foo(); } } @@ -50,7 +50,7 @@ impl Bar { where T: Trait, { - Trait::foo(x); + x.foo(); } fn baz(self) @@ -71,7 +71,7 @@ where U: Trait, { self.baz(); - Trait::foo(x); + x.foo(); } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/impl_where_clause/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/impl_where_clause/execute__tests__expanded.snap index c06500dbd00..72ff5d21511 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/impl_where_clause/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/impl_where_clause/execute__tests__expanded.snap @@ -12,7 +12,7 @@ impl MyStruct { where T: MyEq, { - (self.a == other.a) & MyEq::my_eq(self.b, other.b) + (self.a == other.a) & self.b.my_eq(other.b) } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/inject_context_attribute/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/inject_context_attribute/execute__tests__expanded.snap index 88a6012e002..0c2f00fdbbd 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/inject_context_attribute/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/inject_context_attribute/execute__tests__expanded.snap @@ -49,7 +49,7 @@ comptime fn inject_context(f: FunctionDefinition) { comptime fn mapping_function(expr: Expr, f: FunctionDefinition) -> Option { expr.as_function_call().and_then(|(name, arguments): (Expr, [Expr])| -> Option { name - .resolve(Option::some(f)) + .resolve(Option::::some(f)) .as_function_definition() .and_then(|function_definition: FunctionDefinition| -> Option { if function_definition.has_named_attribute("inject_context") { @@ -57,9 +57,9 @@ comptime fn mapping_function(expr: Expr, f: FunctionDefinition) -> Option arguments.push_front(quote { _context }.as_expr().unwrap()); let arguments: Quoted = arguments.map(|arg: Expr| -> Quoted arg.quoted()).join(quote { , }); - Option::some(quote { name(arguments) }.as_expr().unwrap()) + Option::::some(quote { name(arguments) }.as_expr().unwrap()) } else { - Option::none() + Option::::none() } }) }) diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/option/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/option/execute__tests__expanded.snap index 42f7bfa8dd9..4d76cfffeb6 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/option/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/option/execute__tests__expanded.snap @@ -4,8 +4,8 @@ expression: expanded_code --- fn main() { let ten: Field = 10_Field; - let none: Option = Option::none(); - let some: Option = Option::some(3_Field); + let none: Option = Option::::none(); + let some: Option = Option::::some(3_Field); assert(none.is_none()); assert(some.is_some()); assert(some.unwrap() == 3_Field); @@ -32,21 +32,24 @@ fn main() { assert(some.and(none).is_none()); assert(some.and(some).is_some()); let add1_u64: fn(Field) -> Option = - |value: Field| -> Option Option::some((value as u64) + 1_u64); + |value: Field| -> Option Option::::some((value as u64) + 1_u64); assert(none.and_then(|_value: Field| -> Option none).is_none()); assert(none.and_then(add1_u64).is_none()); assert(some.and_then(|_value: Field| -> Option none).is_none()); assert(some.and_then(add1_u64).unwrap() == 4_u64); - assert(some.and_then(|x: Field| -> Option Option::some(x + ten)).unwrap() == 13_Field); + assert( + some.and_then(|x: Field| -> Option Option::::some(x + ten)).unwrap() + == 13_Field, + ); assert(none.or(none).is_none()); assert(none.or(some).is_some()); assert(some.or(none).is_some()); assert(some.or(some).is_some()); - assert(none.or_else(|| -> Option Option::none()).is_none()); - assert(none.or_else(|| -> Option Option::some(5_Field)).is_some()); - assert(some.or_else(|| -> Option Option::none()).is_some()); - assert(some.or_else(|| -> Option Option::some(5_Field)).is_some()); - assert(some.or_else(|| -> Option Option::some(ten)).is_some()); + assert(none.or_else(|| -> Option Option::::none()).is_none()); + assert(none.or_else(|| -> Option Option::::some(5_Field)).is_some()); + assert(some.or_else(|| -> Option Option::::none()).is_some()); + assert(some.or_else(|| -> Option Option::::some(5_Field)).is_some()); + assert(some.or_else(|| -> Option Option::::some(ten)).is_some()); assert(none.xor(none).is_none()); assert(none.xor(some).is_some()); assert(some.xor(none).is_some()); diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/primitive_trait_method_call_multiple_candidates/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/primitive_trait_method_call_multiple_candidates/execute__tests__expanded.snap new file mode 100644 index 00000000000..767291ee70f --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/primitive_trait_method_call_multiple_candidates/execute__tests__expanded.snap @@ -0,0 +1,10 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +fn main() { + let x: u64 = 0_u64; + let f: fn(u64) -> Field = Field::from; + let _: Field = f(x); + let _: str<3> = str::<3>::from([1_u8, 2_u8, 3_u8]); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_4635/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_4635/execute__tests__expanded.snap index 597609fa264..086b027eb65 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_4635/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_4635/execute__tests__expanded.snap @@ -52,13 +52,13 @@ where where T: FromField, { - Self { a: FromField::from_field(fields[0_u32]) } + Self { a: T::from_field(fields[0_u32]) } } } fn main() { let fields: [Field; 1] = [5_Field; 1]; - let foo: MyStruct = Deserialize::<1>::deserialize(fields); + let foo: MyStruct = MyStruct::::deserialize(fields); let bar: AztecAddress = AztecAddress { inner: 5_Field }; assert(foo.a == bar); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_5065/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_5065/execute__tests__expanded.snap index 8a343e08f6c..b339451d79f 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_5065/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_5065/execute__tests__expanded.snap @@ -32,11 +32,11 @@ fn foo() -> T where T: MyTrait, { - MyTrait::new() + T::new() } fn concise_regression() -> MyType { - Wrapper::new_wrapper(foo()).unwrap() + Wrapper::::new_wrapper(foo()).unwrap() } fn main() { diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038/execute__tests__expanded.snap new file mode 100644 index 00000000000..1ef3199fe92 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038/execute__tests__expanded.snap @@ -0,0 +1,50 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait BigNumTrait {} + +pub struct MyBigNum {} + +impl BigNumTrait for MyBigNum {} + +trait CurveParamsTrait +where + BigNum: BigNumTrait, +{ + fn one() + where + BigNum: BigNumTrait; +} + +pub struct BN254Params {} + +impl CurveParamsTrait for BN254Params { + fn one() {} +} + +trait BigCurveTrait { + fn two(); +} + +pub struct BigCurve {} + +impl BigCurveTrait for BigCurve +where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, +{ + fn two() + where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, + { + let _: () = CurveParams::one(); + } +} + +type BN254 = BigCurve; + +fn main() { + let _: () = BigCurve::::two(); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_2/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_2/execute__tests__expanded.snap new file mode 100644 index 00000000000..51d9ac53401 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_2/execute__tests__expanded.snap @@ -0,0 +1,51 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait BigNumTrait {} + +pub struct MyBigNum {} + +impl BigNumTrait for MyBigNum {} + +trait CurveParamsTrait +where + BigNum: BigNumTrait, +{ + fn one() + where + BigNum: BigNumTrait, + {} +} + +pub struct BN254Params {} + +impl CurveParamsTrait for BN254Params { + fn one() {} +} + +trait BigCurveTrait { + fn two(); +} + +pub struct BigCurve {} + +impl BigCurveTrait for BigCurve +where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, +{ + fn two() + where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, + { + let _: () = CurveParams::one(); + } +} + +type BN254 = BigCurve; + +fn main() { + let _: () = BigCurve::::two(); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_3/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_3/execute__tests__expanded.snap new file mode 100644 index 00000000000..f34257898d7 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_3/execute__tests__expanded.snap @@ -0,0 +1,47 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait BigNumTrait {} + +pub struct MyBigNum {} + +impl BigNumTrait for MyBigNum {} + +trait CurveParamsTrait { + fn one() + where + BigNum: BigNumTrait; +} + +pub struct BN254Params {} + +impl CurveParamsTrait for BN254Params { + fn one() {} +} + +trait BigCurveTrait { + fn two(); +} + +pub struct BigCurve {} + +impl BigCurveTrait for BigCurve +where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, +{ + fn two() + where + BigNum: BigNumTrait, + CurveParams: CurveParamsTrait, + { + let _: () = CurveParams::one(); + } +} + +type BN254 = BigCurve; + +fn main() { + let _: () = BigCurve::::two(); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_4/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_4/execute__tests__expanded.snap new file mode 100644 index 00000000000..3631daf0d9f --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/regression_7038_4/execute__tests__expanded.snap @@ -0,0 +1,32 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait BigNumTrait {} + +trait CurveParamsTrait { + fn one() + where + BigNum: BigNumTrait; +} + +pub struct MyBigNum {} + +impl BigNumTrait for MyBigNum {} + +pub struct Params {} + +impl CurveParamsTrait for Params { + fn one() {} +} + +fn foo() +where + C: CurveParamsTrait, +{ + let _: () = C::one(); +} + +fn main() { + foo::(); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/slice_join/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/slice_join/execute__tests__expanded.snap index d9a4fa2d18d..44ca8630861 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/slice_join/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/slice_join/execute__tests__expanded.snap @@ -16,11 +16,5 @@ fn append_three(one: T, two: T, three: T) -> T where T: Append, { - Append::append( - Append::append( - Append::append(Append::append(Append::empty(), one), two), - three, - ), - Append::empty(), - ) + T::empty().append(one).append(two).append(three).append(T::empty()) } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_allowed_item_name_matches/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_allowed_item_name_matches/execute__tests__expanded.snap new file mode 100644 index 00000000000..44a40614e60 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_allowed_item_name_matches/execute__tests__expanded.snap @@ -0,0 +1,29 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +pub trait Trait1 { + type Tralala; + + let Tralala: u32; +} + +pub trait Trait2 { + let Tralala: u32; + + type Tralala; +} + +pub trait Trait3 { + type Tralala; + + fn Tralala(); +} + +pub trait Trait4 { + type Tralala; + + fn Tralala(); +} + +fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_call_full_path/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_call_full_path/execute__tests__expanded.snap index d0f2a0fe7e5..7b41e5e08d8 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_call_full_path/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_call_full_path/execute__tests__expanded.snap @@ -17,7 +17,7 @@ mod foo { } fn main(x: Field) { - let _: Field = Trait::me(x); - let _: Field = Trait::me(x); - let _: Field = Trait::me(x); + let _: Field = x.me(); + let _: Field = x.me(); + let _: Field = x.me(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_default_implementation/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_default_implementation/execute__tests__expanded.snap new file mode 100644 index 00000000000..636c014b57f --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_default_implementation/execute__tests__expanded.snap @@ -0,0 +1,31 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait MyDefault { + fn my_default(x: Field, y: Field) -> Self; + + fn method2(x: Field) -> Field { + x + } +} + +struct Foo { + bar: Field, + array: [Field; 2], +} + +impl MyDefault for Foo { + fn my_default(x: Field, y: Field) -> Self { + Self { bar: x, array: [x, y] } + } + + fn method2(x: Field) -> Field { + x + } +} + +fn main(x: Field) { + let first: Field = Foo::method2(x); + assert(first == x); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_generics/execute__tests__expanded.snap index f240ee2a57e..9ba6d73b07e 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_generics/execute__tests__expanded.snap @@ -15,7 +15,7 @@ where T: MyInto, U: Eq, { - assert(MyInto::into(x) == u); + assert(x.into() == u); } trait MyInto { @@ -30,7 +30,7 @@ where where T: MyInto, { - self.map(|x: T| -> U MyInto::into(x)) + self.map(|x: T| -> U x.into()) } } @@ -60,7 +60,7 @@ fn sum(data: T) -> Field where T: Serializable, { - let serialized: [Field; M] = Serializable::serialize(data); + let serialized: [Field; M] = data.serialize(); serialized.fold(0_Field, |acc: Field, elem: Field| -> Field { acc + elem }) } @@ -68,6 +68,6 @@ fn sum_static(data: T) -> Field where T: Serializable, { - let serialized: [Field; M] = Serializable::serialize(data); + let serialized: [Field; M] = data.serialize(); serialized.fold(0_Field, |acc: Field, elem: Field| -> Field { acc + elem }) } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_impl_with_where_clause/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_impl_with_where_clause/execute__tests__expanded.snap index ba21bd299a9..a849c9aa5a1 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_impl_with_where_clause/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_impl_with_where_clause/execute__tests__expanded.snap @@ -23,7 +23,7 @@ where { let mut ret: bool = true; for i in 0_u32..self.len() { - ret = ret & MyEq::my_eq(self[i], other[i]); + ret = ret & self[i].my_eq(other[i]); } ret } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_override_implementation/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_override_implementation/execute__tests__expanded.snap new file mode 100644 index 00000000000..5c90d2aa6ea --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_override_implementation/execute__tests__expanded.snap @@ -0,0 +1,87 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +trait MyDefault { + fn my_default(x: Field, y: Field) -> Self; + + fn method2(x: Field) -> Field { + x + } +} + +struct Foo { + bar: Field, + array: [Field; 2], +} + +impl MyDefault for Foo { + fn my_default(x: Field, y: Field) -> Self { + Self { bar: x, array: [x, y] } + } + + fn method2(x: Field) -> Field { + x * 3_Field + } +} + +trait F { + fn f1(self) -> Field; + + fn f2(_self: Self) -> Field { + 2_Field + } + + fn f3(_self: Self) -> Field { + 3_Field + } + + fn f4(_self: Self) -> Field { + 4_Field + } + + fn f5(_self: Self) -> Field { + 5_Field + } +} + +struct Bar {} + +impl F for Bar { + fn f1(_self: Self) -> Field { + 10_Field + } + + fn f2(_self: Self) -> Field { + 2_Field + } + + fn f3(_self: Self) -> Field { + 30_Field + } + + fn f4(_self: Self) -> Field { + 4_Field + } + + fn f5(_self: Self) -> Field { + 50_Field + } +} + +fn main(x: Field) { + let first: Field = Foo::method2(x); + assert(first == (3_Field * x)); + let bar: Bar = Bar {}; + assert(bar.f1() == 10_Field, "1"); + assert(bar.f2() == 2_Field, "2"); + assert(bar.f3() == 30_Field, "3"); + assert(bar.f4() == 4_Field, "4"); + assert(bar.f5() == 50_Field, "5"); + let mut bar_mut: Bar = Bar {}; + assert(bar_mut.f1() == 10_Field, "10"); + assert(bar_mut.f2() == 2_Field, "12"); + assert(bar_mut.f3() == 30_Field, "13"); + assert(bar_mut.f4() == 4_Field, "14"); + assert(bar_mut.f5() == 50_Field, "15"); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_where_clause/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_where_clause/execute__tests__expanded.snap index b9eafdc26cd..24e244cc356 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_where_clause/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/trait_where_clause/execute__tests__expanded.snap @@ -67,7 +67,7 @@ fn assert_asd_eq_100(t: T) where T: Asd, { - assert(Asd::asd(t) == 100_Field); + assert(t.asd() == 100_Field); } fn add_one_to_static_function(t: T) -> Field diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/traits/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/traits/execute__tests__expanded.snap index 3a44ae04080..b79aabe433f 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/traits/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/traits/execute__tests__expanded.snap @@ -18,6 +18,6 @@ impl MyDefault for Foo { } fn main(x: Field, y: Field) { - let first: Foo = MyDefault::my_default(x, y); + let first: Foo = Foo::my_default(x, y); assert(first.bar == x); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/turbofish_call_func_diff_types/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/turbofish_call_func_diff_types/execute__tests__expanded.snap index d9bc997865c..a1bf435b76b 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/turbofish_call_func_diff_types/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/turbofish_call_func_diff_types/execute__tests__expanded.snap @@ -6,12 +6,12 @@ use poseidon::{poseidon2::Poseidon2Hasher, poseidon::PoseidonHasher}; use std::hash::Hasher; fn main(x: Field, y: pub Field) { - let mut hasher: PoseidonHasher = Default::default(); + let mut hasher: PoseidonHasher = PoseidonHasher::default(); hasher.write(x); hasher.write(y); let poseidon_expected_hash: Field = hasher.finish(); assert(hash_simple_array::([x, y]) == poseidon_expected_hash); - let mut hasher: Poseidon2Hasher = Default::default(); + let mut hasher: Poseidon2Hasher = Poseidon2Hasher::default(); hasher.write(x); hasher.write(y); let poseidon2_expected_hash: Field = hasher.finish(); @@ -23,8 +23,8 @@ where H: Hasher, H: Default, { - let mut hasher: H = Default::default(); - Hasher::write(&mut hasher, input[0_u32]); - Hasher::write(&mut hasher, input[1_u32]); - Hasher::finish(hasher) + let mut hasher: H = H::default(); + hasher.write(input[0_u32]); + hasher.write(input[1_u32]); + hasher.finish() } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_path/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_path/execute__tests__expanded.snap index b6266cf0453..4a8d9485037 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_path/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_path/execute__tests__expanded.snap @@ -5,8 +5,8 @@ expression: expanded_code fn main() { { Foo::static() }; let _: Field = Field::from_be_bytes([1_u8]); - let _: () = Trait::method(); - let _: [i32; 3] = Trait::method(); + let _: () = <()>::method(); + let _: [i32; 3] = <[i32; 3]>::method(); } pub struct Foo {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates/execute__tests__expanded.snap new file mode 100644 index 00000000000..ef56e9f9563 --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates/execute__tests__expanded.snap @@ -0,0 +1,36 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +use std::convert::From; + +struct MyU128 { + lo: Field, + hi: Field, +} + +impl MyU128 { + pub fn from_u64s_le(lo: u64, hi: u64) -> Self { + Self { lo: lo as Field, hi: hi as Field } + } +} + +impl From for MyU128 { + fn from(value: u64) -> Self { + Self::from_u64s_le(value, 0_u64) + } +} + +impl From for MyU128 { + fn from(value: u32) -> Self { + Self::from(value as u64) + } +} + +fn main() { + let x: u64 = 0_u64; + let mut small_int: MyU128 = MyU128::from(x); + assert(small_int.lo == (x as Field)); + let u32_3: u32 = 3_u32; + assert(MyU128::from(u32_3).lo == 3_Field); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates_with_turbofish/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates_with_turbofish/execute__tests__expanded.snap new file mode 100644 index 00000000000..e7c4042800d --- /dev/null +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/type_trait_method_call_multiple_candidates_with_turbofish/execute__tests__expanded.snap @@ -0,0 +1,29 @@ +--- +source: tooling/nargo_cli/tests/execute.rs +expression: expanded_code +--- +pub struct Struct { + x: T, +} + +impl From2 for Struct { + fn from2(_: u64) -> Self { + Self { x: 0_u64 } + } +} + +impl From2 for Struct { + fn from2(_: u32) -> Self { + Self { x: 0_u32 } + } +} + +pub trait From2 { + fn from2(input: T) -> Self; +} + +fn main() { + let x: u32 = 1_u32; + let f: fn(u32) -> Struct = Struct::::from2; + let _: Struct = f(x); +} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_empty/vectors/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_empty/vectors/execute__tests__expanded.snap index beaf13b138e..ca8ec82fbd4 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_empty/vectors/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_empty/vectors/execute__tests__expanded.snap @@ -5,7 +5,7 @@ expression: expanded_code use std::collections::vec::Vec; fn main(x: Field, y: pub Field) { - let mut vector: Vec = Vec::new(); + let mut vector: Vec = Vec::::new(); assert(vector.len() == 0_u32); for i in 0_u32..5_u32 { vector.push(i); @@ -25,7 +25,7 @@ fn main(x: Field, y: pub Field) { assert(removed_elem == 2_u32); assert(vector.get(3_u32) == 3_u32); assert(vector.len() == 4_u32); - let mut inputs_vector: Vec = Vec::from_slice(&[x, y]); + let mut inputs_vector: Vec = Vec::::from_slice(&[x, y]); assert(inputs_vector.get(0_u32) == x); assert(inputs_vector.get(1_u32) == y); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/databus_mapping_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/databus_mapping_regression/execute__tests__expanded.snap index 72c1bdca352..bb6911da3fe 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/databus_mapping_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/databus_mapping_regression/execute__tests__expanded.snap @@ -17,7 +17,7 @@ where T: Empty, T: Eq, { - Eq::eq(item, Empty::empty()) + item.eq(T::empty()) } pub fn array_to_bounded_vec(array: [T; N]) -> BoundedVec @@ -37,7 +37,7 @@ where } } }; - BoundedVec::from_parts_unchecked(array, len) + BoundedVec::::from_parts_unchecked(array, len) } global TX_SIZE: u32 = 5; diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_aliases_double_generic_alias_in_path/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_aliases_double_generic_alias_in_path/execute__tests__expanded.snap index d66f31e6696..7389959416f 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_aliases_double_generic_alias_in_path/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_aliases_double_generic_alias_in_path/execute__tests__expanded.snap @@ -15,5 +15,5 @@ type FooAlias1 = Foo; type FooAlias2 = FooAlias1; fn main() { - let _: Foo = Foo::new(); + let _: Foo = Foo::::new(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_check_trait_implemented_for_all_t/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_check_trait_implemented_for_all_t/execute__tests__expanded.snap index 470600dd493..a7c307fbaef 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_check_trait_implemented_for_all_t/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_check_trait_implemented_for_all_t/execute__tests__expanded.snap @@ -30,7 +30,7 @@ where Self: Default2, Self: Eq2, { - Eq2::eq2(self, Default2::default2()) + self.eq2(Self::default2()) } } @@ -46,7 +46,7 @@ impl Eq2 for Foo { impl Default2 for Foo { fn default2() -> Self { - Self { a: Default2::default2() } + Self { a: u64::default2() } } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_numeric_generic_in_trait_impl_with_extra_impl_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_numeric_generic_in_trait_impl_with_extra_impl_generics/execute__tests__expanded.snap index f29b6634a7d..7d3ed133b6a 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_numeric_generic_in_trait_impl_with_extra_impl_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_numeric_generic_in_trait_impl_with_extra_impl_generics/execute__tests__expanded.snap @@ -21,7 +21,7 @@ where where T: Default2, { - Self { a: fields[0_u32], b: fields[1_u32], c: fields[2_u32], d: Default2::default2() } + Self { a: fields[0_u32], b: fields[1_u32], c: fields[2_u32], d: T::default2() } } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_regression_7088/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_regression_7088/execute__tests__expanded.snap index 546668be17c..f4609a642d1 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_regression_7088/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_regression_7088/execute__tests__expanded.snap @@ -12,5 +12,5 @@ impl U60Repr { fn main() { let input: [Field; 6] = [0_Field; 6]; - let _: U60Repr<3, 6> = U60Repr::new(input); + let _: U60Repr<3, 6> = U60Repr::<6 / 2, 6>::new(input); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_function_types_with_turbofish/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_function_types_with_turbofish/execute__tests__expanded.snap index 2ae79decdc2..8a5d866592d 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_function_types_with_turbofish/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_function_types_with_turbofish/execute__tests__expanded.snap @@ -23,7 +23,7 @@ where T: Default2, U: Default2, { - (Default2::default2(), Default2::default2()) + (T::default2(), U::default2()) } fn main() { diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_method_types_with_turbofish/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_method_types_with_turbofish/execute__tests__expanded.snap index ec68fc52dbd..037d8c15742 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_method_types_with_turbofish/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_specify_method_types_with_turbofish/execute__tests__expanded.snap @@ -21,7 +21,7 @@ impl Foo { where U: Default2, { - Default2::default2() + U::default2() } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type/execute__tests__expanded.snap index 4cb16c2bf4d..331fe8ffed4 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type/execute__tests__expanded.snap @@ -10,7 +10,7 @@ pub fn bar(x: (T, U), y: V) -> bool where (T, U): Foo, { - Foo::foo(x, y) + x.foo(y) } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type_pub_crate/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type_pub_crate/execute__tests__expanded.snap index 2f16051f3f3..0df8a4e36b8 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type_pub_crate/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_constraint_on_tuple_type_pub_crate/execute__tests__expanded.snap @@ -10,7 +10,7 @@ pub fn bar(x: (T, U), y: V) -> bool where (T, U): Foo, { - Foo::foo(x, y) + x.foo(y) } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait/execute__tests__expanded.snap index da33287d2cf..0ca8a424207 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait/execute__tests__expanded.snap @@ -24,7 +24,7 @@ where where Self: One, { - One::one(self) + 1_i32 + self.one() + 1_i32 } } @@ -32,7 +32,7 @@ pub fn use_it(t: T) -> i32 where T: Two, { - Two::two(t) + t.two() } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait_with_another_impl_used/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait_with_another_impl_used/execute__tests__expanded.snap index ff45df3e3c5..a4911459690 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait_with_another_impl_used/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_trait_impl_for_a_type_that_implements_another_trait_with_another_impl_used/execute__tests__expanded.snap @@ -25,7 +25,7 @@ where where Self: One, { - One::one(self) + 1_i32 + self.one() + 1_i32 } } @@ -37,7 +37,7 @@ impl Two for u32 { } pub fn use_it(t: u32) -> i32 { - Two::two(t) + t.two() } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_allows_renaming_trait_during_import/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_allows_renaming_trait_during_import/execute__tests__expanded.snap index 4e09455005c..995ce76f051 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_allows_renaming_trait_during_import/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_allows_renaming_trait_during_import/execute__tests__expanded.snap @@ -15,5 +15,5 @@ mod trait_mod { } fn main(x: Field) { - x.foo(); + Field::foo(x); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_calls_trait_method_if_it_is_in_scope_with_multiple_candidates_but_only_one_decided_by_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_calls_trait_method_if_it_is_in_scope_with_multiple_candidates_but_only_one_decided_by_generics/execute__tests__expanded.snap index de9bd914d67..a271a52fe68 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_calls_trait_method_if_it_is_in_scope_with_multiple_candidates_but_only_one_decided_by_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_calls_trait_method_if_it_is_in_scope_with_multiple_candidates_but_only_one_decided_by_generics/execute__tests__expanded.snap @@ -24,5 +24,5 @@ trait Converter { fn main() { let foo: Foo = Foo { inner: 42_Field }; - let _: u32 = Converter::convert(foo); + let _: u32 = foo.convert(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_concrete_type/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_concrete_type/execute__tests__expanded.snap index 83435db7640..3eca4a865ee 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_concrete_type/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_concrete_type/execute__tests__expanded.snap @@ -15,7 +15,7 @@ where U: Greeter, T: Greeter, { - Greeter::greet(object); + object.greet(); } } @@ -32,7 +32,7 @@ impl Foo for Bar { where U: Greeter, { - Greeter::greet(object); + object.greet(); } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_type_variable/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_type_variable/execute__tests__expanded.snap index f7952e246d5..bed68c2397d 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_type_variable/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_does_not_error_if_impl_trait_constraint_is_satisfied_for_type_variable/execute__tests__expanded.snap @@ -14,7 +14,7 @@ where where T: Greeter, { - Greeter::greet(object); + object.greet(); } } @@ -28,7 +28,7 @@ where where T: Greeter, { - Greeter::greet(object); + object.greet(); } } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6314_double_inheritance/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6314_double_inheritance/execute__tests__expanded.snap index 75464230adf..5788f84ab5a 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6314_double_inheritance/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6314_double_inheritance/execute__tests__expanded.snap @@ -34,7 +34,7 @@ fn baz(x: T) -> T where T: Baz, { - Bar::bar(Foo::foo(x)) + x.foo().bar() } fn main() { diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6530/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6530/execute__tests__expanded.snap index d153b16f4bf..22b03833c9d 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6530/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_regression_6530/execute__tests__expanded.snap @@ -34,6 +34,6 @@ impl Into2 for Foo { fn main() { let foo: Foo = Foo { inner: 0_Field }; - let _: Field = Into2::into2(foo); + let _: Field = foo.into2(); let _: Field = foo.into2(); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_renaming_trait_avoids_name_collisions/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_renaming_trait_avoids_name_collisions/execute__tests__expanded.snap index 2010f6a7676..fdccad1352b 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_renaming_trait_avoids_name_collisions/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_renaming_trait_avoids_name_collisions/execute__tests__expanded.snap @@ -17,5 +17,5 @@ mod trait_mod { pub struct Foo {} fn main(x: Field) { - x.foo(); + Field::foo(x); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance/execute__tests__expanded.snap index e526ccda73e..b320bd31c5b 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance/execute__tests__expanded.snap @@ -18,7 +18,7 @@ pub fn foo(baz: T) -> (Field, Field, Field) where T: Baz, { - (Foo::foo(baz), Bar::bar(baz), Baz::baz(baz)) + (baz.foo(), baz.bar(), baz.baz()) } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics/execute__tests__expanded.snap index 54e2ab69b59..2546ce5f2c0 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics/execute__tests__expanded.snap @@ -14,7 +14,7 @@ pub fn foo(x: T) -> i32 where T: Bar, { - Foo::foo(x) + x.foo() } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics_2/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics_2/execute__tests__expanded.snap index 7da16c700e7..b2a2c973dbd 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics_2/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_traits_trait_inheritance_with_generics_2/execute__tests__expanded.snap @@ -14,7 +14,7 @@ pub fn foo(x: T) -> i32 where T: Bar, { - Foo::foo(x) + x.foo() } fn main() {} diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_turbofish_in_type_before_call_does_not_error/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_turbofish_in_type_before_call_does_not_error/execute__tests__expanded.snap index 4fe33a9351e..81af2dc466c 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_turbofish_in_type_before_call_does_not_error/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_turbofish_in_type_before_call_does_not_error/execute__tests__expanded.snap @@ -13,5 +13,5 @@ impl Foo { } fn main() { - let _: Foo = Foo::new(1_i32); + let _: Foo = Foo::::new(1_i32); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_partial_generics_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_partial_generics_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap index 6611750da6c..620635e426a 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_partial_generics_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_partial_generics_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap @@ -16,5 +16,5 @@ impl Foo { type Bar = Foo; fn main() { - let _: Foo = Foo::new(true, 1_i32); + let _: Foo = Foo::::new(true, 1_i32); } diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap index 1a81494fba1..b7f4bc7e549 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_turbofish_use_generic_type_alias_with_turbofish_in_method_call_does_not_error/execute__tests__expanded.snap @@ -13,7 +13,7 @@ impl Foo { type Bar = Foo; fn foo() -> Foo { - Foo::new() + Foo::::new() } fn main() { diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_use_type_alias_to_generic_concrete_type_in_method_call/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_use_type_alias_to_generic_concrete_type_in_method_call/execute__tests__expanded.snap index 30e9b6857ee..ea2fca4c3eb 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_use_type_alias_to_generic_concrete_type_in_method_call/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_use_type_alias_to_generic_concrete_type_in_method_call/execute__tests__expanded.snap @@ -15,7 +15,7 @@ impl Foo { type Bar = Foo; fn foo() -> Bar { - Foo::new(1_i32) + Foo::::new(1_i32) } fn main() { diff --git a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap index ebd258700c5..d74d0f9ea82 100644 --- a/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/compile_success_no_bug/noirc_frontend_tests_uses_self_type_inside_trait/execute__tests__expanded.snap @@ -21,5 +21,5 @@ impl Foo for Field { } fn main() { - let _: Field = Foo::foo(); + let _: Field = Field::foo(); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/a_1327_concrete_in_generic/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/a_1327_concrete_in_generic/execute__tests__expanded.snap index 4539c8413fd..f4719f8d671 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/a_1327_concrete_in_generic/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/a_1327_concrete_in_generic/execute__tests__expanded.snap @@ -4,7 +4,7 @@ expression: expanded_code --- fn new_concrete_c_over_d() -> C { let d_method_interface: MethodInterface = get_d_method_interface(); - C::new(d_method_interface) + C::::new(d_method_interface) } struct B { @@ -54,7 +54,7 @@ fn get_d_method_interface() -> MethodInterface { } fn main(input: Field) -> pub Field { - let b: B> = B::new(new_concrete_c_over_d); + let b: B> = B::>::new(new_concrete_c_over_d); let c: C = b.get_t_c(); let d: D = D { d: input }; let output: Field = c.call_method_of_t_d(d); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_loop_size_regression/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_loop_size_regression/execute__tests__expanded.snap index 5e95cb83880..008aae7a71d 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_loop_size_regression/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_loop_size_regression/execute__tests__expanded.snap @@ -9,11 +9,14 @@ struct EnumEmulation { } unconstrained fn main() -> pub Field { - let mut emulated_enum: EnumEmulation = - EnumEmulation { a: Option::some(1_Field), b: Option::none(), c: Option::none() }; + let mut emulated_enum: EnumEmulation = EnumEmulation { + a: Option::::some(1_Field), + b: Option::::none(), + c: Option::::none(), + }; for _ in 0_u32..1_u32 { assert(emulated_enum.a.unwrap() == 1_Field); } - emulated_enum.a = Option::some(2_Field); + emulated_enum.a = Option::::some(2_Field); emulated_enum.a.unwrap() } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_rc_regression_6123/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_rc_regression_6123/execute__tests__expanded.snap index a482a1e3645..636b210d319 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/brillig_rc_regression_6123/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/brillig_rc_regression_6123/execute__tests__expanded.snap @@ -29,8 +29,10 @@ fn swap_items(vec: &mut BoundedVec, from_index: u32, to_ind } unconstrained fn main() { - let mut builder: Builder = - Builder { note_hashes: BoundedVec::new(), nullifiers: BoundedVec::new() }; + let mut builder: Builder = Builder { + note_hashes: BoundedVec::::new(), + nullifiers: BoundedVec::::new(), + }; builder.append_note_hashes_with_logs(2_u32); builder.nullifiers.set_unchecked(1_u32, 27_Field); let note_hashes: [Field; 2] = builder.note_hashes.storage(); diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/derive/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/derive/execute__tests__expanded.snap index e8755878aa8..ca1e131ec6c 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/derive/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/derive/execute__tests__expanded.snap @@ -44,7 +44,7 @@ where where T: Default, { - Self { x: Default::default() } + Self { x: T::default() } } } @@ -69,7 +69,7 @@ where H: Hasher, T: Hash, { - Hash::hash(_self.x, _state); + _self.x.hash(_state); } } @@ -83,7 +83,7 @@ where { let mut result: std::cmp::Ordering = std::cmp::Ordering::equal(); if result == std::cmp::Ordering::equal() { - result = Ord::cmp(_self.x, _other.x); + result = _self.x.cmp(_other.x); }; result } @@ -105,7 +105,11 @@ where A: Default, B: Default, { - Self { field1: Default::default(), field2: Default::default(), field3: Default::default() } + Self { + field1: A::default(), + field2: B::default(), + field3: MyOtherOtherStruct::::default(), + } } } @@ -135,8 +139,8 @@ where A: Hash, B: Hash, { - Hash::hash(_self.field1, _state); - Hash::hash(_self.field2, _state); + _self.field1.hash(_state); + _self.field2.hash(_state); _self.field3.hash(_state); } } @@ -153,10 +157,10 @@ where { let mut result: std::cmp::Ordering = std::cmp::Ordering::equal(); if result == std::cmp::Ordering::equal() { - result = Ord::cmp(_self.field1, _other.field1); + result = _self.field1.cmp(_other.field1); }; if result == std::cmp::Ordering::equal() { - result = Ord::cmp(_self.field2, _other.field2); + result = _self.field2.cmp(_other.field2); }; if result == std::cmp::Ordering::equal() { result = _self.field3.cmp(_other.field3); @@ -196,9 +200,9 @@ impl Ord for EmptyStruct { fn main() { let s: MyStruct = MyStruct { my_field: 1_u32 }; s.do_nothing(); - let o: MyOtherStruct = Default::default(); + let o: MyOtherStruct = MyOtherStruct::::default(); assert(o == o); - let o: MyOtherStruct]> = Default::default(); + let o: MyOtherStruct]> = MyOtherStruct::]>::default(); assert(o == o); let o1: MyOtherStruct = MyOtherStruct:: { field1: 12_u32, diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/generics/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/generics/execute__tests__expanded.snap index fe8668b7f6f..fd98c8df8b7 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/generics/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/generics/execute__tests__expanded.snap @@ -47,7 +47,8 @@ fn main(x: Field, y: Field) { foo(bar2); let int1: BigInt<1> = BigInt::<1> { limbs: [1_u32] }; let int2: BigInt<1> = BigInt::<1> { limbs: [2_u32] }; - let BigInt::<1> { limbs }: BigInt<1> = int1.second(int2).first(int1); + let BigInt::<1> { limbs }: BigInt<1> = + BigInt::<1>::first(BigInt::<1>::second(int1, int2), int1); assert(limbs == int2.limbs); assert(bar1.get_other() == bar1.other); let one: Field = x; diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/hashmap/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/hashmap/execute__tests__expanded.snap index 60dac8b3c9d..d5d50f51b71 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/hashmap/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/hashmap/execute__tests__expanded.snap @@ -27,8 +27,9 @@ global V_CMP: fn(Field, Field) -> bool = |a: Field, b: Field| -> bool a.lt(b); global KV_CMP: fn((K, V), (K, V)) -> bool = |a: (K, V), b: (K, V)| -> bool a.0.lt(b.0); -global ALLOCATE_HASHMAP: fn() -> HashMap> = - || -> HashMap> Default::default(); +global ALLOCATE_HASHMAP: fn() -> HashMap> = || -> HashMap> { + HashMap::>::default() +}; fn main(input: [Entry; 6]) { test_sequential(input[0_u32].key, input[0_u32].value); @@ -202,13 +203,16 @@ type MyMap = HashMap>; /// Tests examples from the stdlib hashmap documentation fn doc_tests() { - let hashmap: HashMap> = Default::default(); + let hashmap: HashMap> = + HashMap::>::default(); assert(hashmap.is_empty()); - let my_hasher: BuildHasherDefault = Default::default(); + let my_hasher: BuildHasherDefault = + BuildHasherDefault::::default(); let hashmap: HashMap> = - HashMap::with_hasher(my_hasher); + HashMap::>::with_hasher(my_hasher); assert(hashmap.is_empty()); - let mut map: HashMap> = Default::default(); + let mut map: HashMap> = + HashMap::>::default(); map.insert(12_Field, 42_Field); assert(map.len() == 1_u32); get_example(map); @@ -231,7 +235,7 @@ fn doc_tests() { map.remove(1_Field); assert(map.len() == 2_u32); let empty_map: HashMap> = - Default::default(); + HashMap::>::default(); assert(empty_map.len() == 0_u32); assert(empty_map.capacity() == 42_u32); assert(!map.is_empty()); @@ -246,8 +250,10 @@ fn doc_tests() { entries_examples(map); iter_examples(map); map.retain(|k: Field, v: Field| -> bool { (k != 0_Field) & (v != 0_Field) }); - let mut map1: HashMap> = Default::default(); - let mut map2: HashMap> = Default::default(); + let mut map1: HashMap> = + HashMap::>::default(); + let mut map2: HashMap> = + HashMap::>::default(); map1.insert(1_Field, 2_u64); map1.insert(3_Field, 4_u64); map2.insert(3_Field, 4_u64); @@ -296,7 +302,7 @@ fn iter_examples(mut map: HashMap(input: BoundedVec) -> [T; M] { assert(M < N, "M should be less than N."); - let mut new: BoundedVec = BoundedVec::new(); + let mut new: BoundedVec = BoundedVec::::new(); for i in 0_u32..M { new.push(input.get(i)); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/prelude/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/prelude/execute__tests__expanded.snap index 6465c4e92b2..d0e3bf08c2d 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/prelude/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/prelude/execute__tests__expanded.snap @@ -3,8 +3,8 @@ source: tooling/nargo_cli/tests/execute.rs expression: expanded_code --- fn main() { - let _xs: Vec = Vec::new(); - let _option: Option = Option::none(); + let _xs: Vec = Vec::::new(); + let _option: Option = Option::::none(); print("42\n"); println("42"); } @@ -13,8 +13,8 @@ mod a { use std::{collections::vec::Vec, option::Option}; fn main() { - let _xs: Vec = Vec::new(); - let _option: Option = Option::none(); + let _xs: Vec = Vec::::new(); + let _option: Option = Option::::none(); print("42\n"); println("42"); } @@ -22,8 +22,8 @@ mod a { mod b { fn main() { - let _xs: Vec = Vec::new(); - let _option: Option = Option::none(); + let _xs: Vec = Vec::::new(); + let _option: Option = Option::::none(); print("42\n"); println("42"); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/reference_only_used_as_alias/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/reference_only_used_as_alias/execute__tests__expanded.snap index fe6d3cf08b5..57202ab420e 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/reference_only_used_as_alias/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/reference_only_used_as_alias/execute__tests__expanded.snap @@ -84,7 +84,8 @@ unconstrained fn func(input: u32) { fn main(input: [Field; 4], randomness: Field, context_input: u32) { let b: [u32; 3] = [context_input, context_input, context_input]; - let mut context: Context = Context { a: context_input, b: b, log_hashes: BoundedVec::new() }; + let mut context: Context = + Context { a: context_input, b: b, log_hashes: BoundedVec::::new() }; let event0: ExampleEvent0 = ExampleEvent0 { value0: input[0_u32], value1: input[1_u32] }; event0.emit(encode_event_with_randomness(&mut context, randomness)); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_11294/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_11294/execute__tests__expanded.snap index b95478a4df8..60b343bdec8 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_11294/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_11294/execute__tests__expanded.snap @@ -61,7 +61,9 @@ impl PrivateKernelCircuitPublicInputsComposer { previous_kernel_public_inputs: PrivateKernelCircuitPublicInputs, ) -> Self { let mut public_inputs: PrivateKernelCircuitPublicInputsBuilder = PrivateKernelCircuitPublicInputsBuilder { - end: PrivateAccumulatedDataBuilder { private_call_stack: BoundedVec::new() }, + end: PrivateAccumulatedDataBuilder { + private_call_stack: BoundedVec::::new(), + }, }; let start: PrivateAccumulatedData = previous_kernel_public_inputs.end; public_inputs.end.private_call_stack = array_to_bounded_vec(start.private_call_stack); @@ -137,7 +139,7 @@ where T: Empty, T: Eq, { - Eq::eq(item, Empty::empty()) + item.eq(T::empty()) } pub fn array_length(array: [T; N]) -> u32 @@ -169,5 +171,5 @@ where T: Eq, { let len: u32 = array_length(array); - BoundedVec::from_parts_unchecked(array, len) + BoundedVec::::from_parts_unchecked(array, len) } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_4124/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_4124/execute__tests__expanded.snap index e1bb6caeb0c..978323a0f7d 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_4124/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_4124/execute__tests__expanded.snap @@ -41,6 +41,6 @@ impl PublicMutable { } fn main(value: Field) { - let ps: PublicMutable = PublicMutable::new(27_Field); + let ps: PublicMutable = PublicMutable::::new(27_Field); assert(ps.read() == value); } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_3/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_3/execute__tests__expanded.snap index 3f428e09570..ab5d3b4f63f 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_3/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/regression_6674_3/execute__tests__expanded.snap @@ -76,7 +76,7 @@ impl FixtureBuilder2 { } pub fn add_public_call_request(&mut self) { - self.public_call_requests.push(Counted::new(zeroed(), self.next_counter())); + self.public_call_requests.push(Counted::::new(zeroed(), self.next_counter())); } pub fn append_public_call_requests(&mut self, num: u32) { @@ -126,11 +126,11 @@ pub struct PrivateKernelCircuitPublicInputsComposer { impl PrivateKernelCircuitPublicInputsComposer { pub unconstrained fn sort_ordered_values(&mut self) { - self.public_inputs.end.l2_to_l1_msgs = BoundedVec::from_parts_unchecked( + self.public_inputs.end.l2_to_l1_msgs = BoundedVec::::from_parts_unchecked( sort_by_counter_desc(self.public_inputs.end.l2_to_l1_msgs.storage()), self.public_inputs.end.l2_to_l1_msgs.len(), ); - self.public_inputs.end.public_call_requests = BoundedVec::from_parts_unchecked( + self.public_inputs.end.public_call_requests = BoundedVec::, 4>::from_parts_unchecked( sort_by_counter_desc(self.public_inputs.end.public_call_requests.storage()), self.public_inputs.end.public_call_requests.len(), ); @@ -141,8 +141,10 @@ impl PrivateKernelCircuitPublicInputsComposer { ) -> Self { let mut public_inputs: PrivateKernelCircuitPublicInputsBuilder = zeroed(); let start: PrivateAccumulatedData = previous_kernel_public_inputs.end; - public_inputs.end.public_call_requests = - BoundedVec::from_parts(start.public_call_requests, start.public_call_requests.len()); + public_inputs.end.public_call_requests = BoundedVec::, 4>::from_parts( + start.public_call_requests, + start.public_call_requests.len(), + ); Self { public_inputs: public_inputs } } } @@ -152,7 +154,7 @@ pub struct PrivateKernelCircuitPublicInputsBuilder { } fn vec_reverse(vec: BoundedVec) -> BoundedVec { - let mut reversed: BoundedVec = BoundedVec::new(); + let mut reversed: BoundedVec = BoundedVec::::new(); let len: u32 = vec.len(); for i in 0_u32..N { if i < len { diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/slice_regex/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/slice_regex/execute__tests__expanded.snap index 626d03e8e70..71445fb08b9 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/slice_regex/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/slice_regex/execute__tests__expanded.snap @@ -68,9 +68,9 @@ where T: Regex, U: Regex, { - let lhs_result: Match = Regex::find_match(self.0, input); + let lhs_result: Match = self.0.find_match(input); if lhs_result.succeeded { - let rhs_result: Match = Regex::find_match(self.1, lhs_result.leftover); + let rhs_result: Match = self.1.find_match(lhs_result.leftover); if rhs_result.succeeded { Match { succeeded: true, @@ -101,7 +101,7 @@ where let mut result: Match = Match::empty(input); for _ in 0_u32..N { if result.succeeded { - let next_result: Match = Regex::find_match(self.inner, result.leftover); + let next_result: Match = self.inner.find_match(result.leftover); result = Match { succeeded: next_result.succeeded, match_ends: result.match_ends + next_result.match_ends, @@ -128,11 +128,11 @@ where T: Regex, U: Regex, { - let lhs_result: Match = Regex::find_match(self.lhs, input); + let lhs_result: Match = self.lhs.find_match(input); if lhs_result.succeeded { lhs_result } else { - Regex::find_match(self.rhs, input) + self.rhs.find_match(input) } } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/struct/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/struct/execute__tests__expanded.snap index 41bc3ebdbfe..2ea9de02058 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/struct/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/struct/execute__tests__expanded.snap @@ -24,7 +24,7 @@ impl Pair { } fn bar(self) -> Field { - self.foo().bar + Self::foo(self).bar } } diff --git a/tooling/nargo_cli/tests/snapshots/execution_success/uhashmap/execute__tests__expanded.snap b/tooling/nargo_cli/tests/snapshots/execution_success/uhashmap/execute__tests__expanded.snap index ff2f5640c8c..cdccfc8fcfa 100644 --- a/tooling/nargo_cli/tests/snapshots/execution_success/uhashmap/execute__tests__expanded.snap +++ b/tooling/nargo_cli/tests/snapshots/execution_success/uhashmap/execute__tests__expanded.snap @@ -24,8 +24,9 @@ global V_CMP: fn(Field, Field) -> bool = |a: Field, b: Field| -> bool a.lt(b); global KV_CMP: fn((K, V), (K, V)) -> bool = |a: (K, V), b: (K, V)| -> bool a.0.lt(b.0); -global ALLOCATE_HASHMAP: fn() -> UHashMap> = - || -> UHashMap> Default::default(); +global ALLOCATE_HASHMAP: fn() -> UHashMap> = || -> UHashMap> { + UHashMap::>::default() +}; unconstrained fn main(input: [Entry; 6]) { test_sequential(input[0_u32].key, input[0_u32].value); @@ -201,13 +202,16 @@ type MyMap = UHashMap>; /// Tests examples from the stdlib cthashmap documentation unconstrained fn doc_tests() { - let hashmap: UHashMap> = Default::default(); + let hashmap: UHashMap> = + UHashMap::>::default(); assert(hashmap.is_empty()); - let my_hasher: BuildHasherDefault = Default::default(); + let my_hasher: BuildHasherDefault = + BuildHasherDefault::::default(); let hashmap: UHashMap> = - UHashMap::with_hasher(my_hasher); + UHashMap::>::with_hasher(my_hasher); assert(hashmap.is_empty()); - let mut map: UHashMap> = Default::default(); + let mut map: UHashMap> = + UHashMap::>::default(); map.insert(12_Field, 42_Field); assert(map.len() == 1_u32); get_example(map); @@ -229,7 +233,8 @@ unconstrained fn doc_tests() { assert(map.len() == 3_u32); map.remove(1_Field); assert(map.len() == 2_u32); - let empty_map: UHashMap> = Default::default(); + let empty_map: UHashMap> = + UHashMap::>::default(); assert(empty_map.len() == 0_u32); println(empty_map.capacity()); assert(!map.is_empty()); @@ -244,8 +249,10 @@ unconstrained fn doc_tests() { entries_examples(map); iter_examples(map); map.retain(|k: Field, v: Field| -> bool { (k != 0_Field) & (v != 0_Field) }); - let mut map1: UHashMap> = Default::default(); - let mut map2: UHashMap> = Default::default(); + let mut map1: UHashMap> = + UHashMap::>::default(); + let mut map2: UHashMap> = + UHashMap::>::default(); map1.insert(1_Field, 2_u64); map1.insert(3_Field, 4_u64); map2.insert(3_Field, 4_u64); diff --git a/tooling/nargo_expand/src/printer.rs b/tooling/nargo_expand/src/printer.rs index 62df33565e1..18d9d111b0b 100644 --- a/tooling/nargo_expand/src/printer.rs +++ b/tooling/nargo_expand/src/printer.rs @@ -1119,6 +1119,17 @@ impl<'context, 'string> ItemPrinter<'context, 'string> { } } + fn pattern_is_self_or_underscore_self(&self, pattern: &HirPattern) -> bool { + match pattern { + HirPattern::Identifier(ident) => { + let definition = self.interner.definition(ident.id); + definition.name == "self" || definition.name == "_self" + } + HirPattern::Mutable(pattern, _) => self.pattern_is_self(pattern), + HirPattern::Tuple(..) | HirPattern::Struct(..) => false, + } + } + fn module_def_id_name(&self, module_def_id: ModuleDefId) -> String { match module_def_id { ModuleDefId::ModuleId(module_id) => { diff --git a/tooling/nargo_expand/src/printer/hir.rs b/tooling/nargo_expand/src/printer/hir.rs index de38fd63589..9209030f222 100644 --- a/tooling/nargo_expand/src/printer/hir.rs +++ b/tooling/nargo_expand/src/printer/hir.rs @@ -64,7 +64,7 @@ impl ItemPrinter<'_, '_> { pub(super) fn show_hir_expression(&mut self, hir_expr: HirExpression, expr_id: ExprId) { match hir_expr { HirExpression::Ident(hir_ident, generics) => { - self.show_hir_ident(hir_ident); + self.show_hir_ident(hir_ident, Some(expr_id)); if let Some(generics) = generics { let use_colons = true; self.show_generic_types(&generics, use_colons); @@ -386,19 +386,19 @@ impl ItemPrinter<'_, '_> { return false; }; - // Is this `self.foo()` where `self` is currently a trait? - // If so, show it as `self.foo()` instead of `Self::foo(self)`. - let mut method_on_trait_self = false; - // Special case: assumed trait method if let ImplKind::TraitMethod(trait_method) = hir_ident.impl_kind { if trait_method.assumed { - if let Type::NamedGeneric(NamedGeneric { name, .. }) = &trait_method.constraint.typ - { - if name.to_string() == "Self" { - method_on_trait_self = true; - } - } + // Is this `self.foo()` where `self` is currently a trait? + // If so, show it as `self.foo()` instead of `Self::foo(self)`. + let method_on_trait_self = + if let Type::NamedGeneric(NamedGeneric { name, .. }) = + &trait_method.constraint.typ + { + name.to_string() == "Self" + } else { + false + }; if !method_on_trait_self { self.show_type(&trait_method.constraint.typ); @@ -419,11 +419,6 @@ impl ItemPrinter<'_, '_> { // The function must have a self type let func_meta = self.interner.function_meta(&func_id); - // Don't do this for trait methods (refer to the trait name instead) - if func_meta.trait_id.is_some() && !method_on_trait_self { - return false; - } - let Some(self_type) = &func_meta.self_type else { return false; }; @@ -433,12 +428,20 @@ impl ItemPrinter<'_, '_> { return false; } + let (first_param_patten, first_param_type, _) = &func_meta.parameters.0[0]; + + // The first parameter must be `self` or `_self` + if !self.pattern_is_self_or_underscore_self(first_param_patten) { + return false; + } + // The first parameter must unify with the self type (as-is or after removing `&mut`) - let param_type = func_meta.parameters.0[0].1.follow_bindings(); - let param_type = if let Type::Reference(typ, ..) = param_type { *typ } else { param_type }; + let first_param_type = first_param_type.follow_bindings(); + let first_param_type = + if let Type::Reference(typ, ..) = first_param_type { *typ } else { first_param_type }; let mut bindings = TypeBindings::default(); - if self_type.try_unify(¶m_type, &mut bindings).is_err() { + if self_type.try_unify(&first_param_type, &mut bindings).is_err() { return false; } @@ -518,7 +521,7 @@ impl ItemPrinter<'_, '_> { } HirStatement::For(hir_for_statement) => { self.push_str("for "); - self.show_hir_ident(hir_for_statement.identifier); + self.show_hir_ident(hir_for_statement.identifier, None); self.push_str(" in "); self.show_hir_expression_id(hir_for_statement.start_range); self.push_str(".."); @@ -622,7 +625,7 @@ impl ItemPrinter<'_, '_> { fn show_hir_lvalue(&mut self, lvalue: HirLValue) { match lvalue { HirLValue::Ident(hir_ident, _) => { - self.show_hir_ident(hir_ident); + self.show_hir_ident(hir_ident, None); } HirLValue::MemberAccess { object, field_name, field_index: _, typ: _, location: _ } => { self.show_hir_lvalue(*object); @@ -651,7 +654,7 @@ impl ItemPrinter<'_, '_> { fn show_hir_pattern(&mut self, pattern: HirPattern) { match pattern { - HirPattern::Identifier(hir_ident) => self.show_hir_ident(hir_ident), + HirPattern::Identifier(hir_ident) => self.show_hir_ident(hir_ident, None), HirPattern::Mutable(hir_pattern, _) => { self.push_str("mut "); self.show_hir_pattern(*hir_pattern); @@ -687,28 +690,55 @@ impl ItemPrinter<'_, '_> { fn show_definition_id(&mut self, definition_id: DefinitionId) { let location = self.interner.definition(definition_id).location; let ident = HirIdent::non_trait_method(definition_id, location); - self.show_hir_ident(ident); + self.show_hir_ident(ident, None); } - fn show_hir_ident(&mut self, ident: HirIdent) { + fn show_hir_ident(&mut self, ident: HirIdent, expr_id: Option) { let definition = self.interner.definition(ident.id); match definition.kind { DefinitionKind::Function(func_id) => { let func_meta = self.interner.function_meta(&func_id); - if func_meta.self_type.is_some() && func_meta.self_type == self.self_type { + let self_type = &func_meta.self_type; + + if let Some(self_type) = self_type { // No need to fully-qualify the function name if its self type is the current self type - let name = self.interner.function_name(&func_id); - self.push_str("Self::"); - self.push_str(name); - } else { - let use_import = true; - let visibility = self.interner.function_visibility(func_id); - self.show_reference_to_module_def_id( - ModuleDefId::FunctionId(func_id), - visibility, - use_import, - ); + if Some(self_type) == self.self_type.as_ref() { + let name = self.interner.function_name(&func_id); + self.push_str("Self::"); + self.push_str(name); + return; + } + + // See if we can show this as `Self::method` by substitution instantiation type bindings for self_type + if let Some(expr_id) = expr_id { + if let Some(instantiation_bindings) = + self.interner.try_get_instantiation_bindings(expr_id) + { + let self_type = self_type.substitute(instantiation_bindings); + let unbound = if let Type::TypeVariable(type_var) = &self_type { + type_var.borrow().is_unbound() + } else { + false + }; + + if !unbound { + self.show_type_as_expression(&self_type); + self.push_str("::"); + let name = self.interner.function_name(&func_id); + self.push_str(name); + return; + } + } + } } + + let use_import = true; + let visibility = self.interner.function_visibility(func_id); + self.show_reference_to_module_def_id( + ModuleDefId::FunctionId(func_id), + visibility, + use_import, + ); } DefinitionKind::Global(global_id) => { let global_info = self.interner.get_global(global_id); diff --git a/tooling/nargo_expand/src/printer/types.rs b/tooling/nargo_expand/src/printer/types.rs index 9ba0570dd7f..46d9e379520 100644 --- a/tooling/nargo_expand/src/printer/types.rs +++ b/tooling/nargo_expand/src/printer/types.rs @@ -10,6 +10,14 @@ impl ItemPrinter<'_, '_> { } pub(super) fn show_type(&mut self, typ: &Type) { + self.show_type_impl(typ, false /* as expression */); + } + + pub(super) fn show_type_as_expression(&mut self, typ: &Type) { + self.show_type_impl(typ, true /* as expression */); + } + + fn show_type_impl(&mut self, typ: &Type, as_expression: bool) { if self.self_type.as_ref() == Some(typ) { self.push_str("Self"); return; @@ -17,25 +25,58 @@ impl ItemPrinter<'_, '_> { match typ { Type::Array(length, typ) => { + if as_expression { + self.push('<'); + } + self.push('['); self.show_type(typ); self.push_str("; "); self.show_type(length); self.push(']'); + + if as_expression { + self.push('>'); + } } Type::Slice(typ) => { + if as_expression { + self.push('<'); + } + self.push('['); self.show_type(typ); self.push(']'); + + if as_expression { + self.push('>'); + } + } + Type::String(length) => { + self.push_str("str"); + if as_expression { + self.push_str("::"); + } + self.push('<'); + self.show_type(length); + self.push('>'); } Type::FmtString(length, typ) => { - self.push_str("fmtstr<"); + self.push_str("fmtstr"); + if as_expression { + self.push_str("::"); + } + self.push('<'); self.show_type(length); self.push_str(", "); self.show_type(typ); self.push('>'); } Type::Tuple(types) => { + if as_expression { + self.push('<'); + } + let len = types.len(); self.push('('); self.show_types_separated_by_comma(types); @@ -43,6 +84,10 @@ impl ItemPrinter<'_, '_> { self.push(','); } self.push(')'); + + if as_expression { + self.push('>'); + } } Type::DataType(data_type, generics) => { let data_type = data_type.borrow(); @@ -53,6 +98,9 @@ impl ItemPrinter<'_, '_> { use_import, ); if !generics.is_empty() { + if as_expression { + self.push_str("::"); + } self.push_str("<"); self.show_types_separated_by_comma(generics); self.push('>'); @@ -67,6 +115,9 @@ impl ItemPrinter<'_, '_> { use_import, ); if !generics.is_empty() { + if as_expression { + self.push_str("::"); + } self.push_str("<"); self.show_types_separated_by_comma(generics); self.push('>'); @@ -74,7 +125,7 @@ impl ItemPrinter<'_, '_> { } Type::TypeVariable(type_variable) => match &*type_variable.borrow() { TypeBinding::Bound(typ) => { - self.show_type(typ); + self.show_type_impl(typ, as_expression); } TypeBinding::Unbound(..) => { self.push('_'); @@ -88,15 +139,19 @@ impl ItemPrinter<'_, '_> { } Type::NamedGeneric(NamedGeneric { name, type_var, .. }) => { if let TypeBinding::Bound(typ) = &*type_var.borrow() { - self.show_type(typ); + self.show_type_impl(typ, as_expression); } else { self.push_str(name); } } Type::CheckedCast { from: _, to } => { - self.show_type(to); + self.show_type_impl(to, as_expression); } Type::Function(args, ret, env, unconstrained) => { + if as_expression { + self.push('<'); + } + if *unconstrained { self.push_str("unconstrained "); } @@ -113,6 +168,10 @@ impl ItemPrinter<'_, '_> { self.push_str(" -> "); self.show_type(ret); } + + if as_expression { + self.push('>'); + } } Type::Reference(typ, mutable) => { if *mutable { @@ -120,7 +179,7 @@ impl ItemPrinter<'_, '_> { } else { self.push('&'); } - self.show_type(typ); + self.show_type_impl(typ, as_expression); } Type::Forall(..) => { panic!("Should not need to print Type::Forall") @@ -135,11 +194,16 @@ impl ItemPrinter<'_, '_> { self.push(' '); self.show_type_maybe_in_parentheses(rhs); } - Type::Unit - | Type::Bool + Type::Unit => { + if as_expression { + self.push_str("<()>"); + } else { + self.push_str("()"); + } + } + Type::Bool | Type::Integer(..) | Type::FieldElement - | Type::String(_) | Type::Quoted(..) | Type::Error => self.push_str(&typ.to_string()), }