diff --git a/sway-ast/src/path.rs b/sway-ast/src/path.rs index b472426c8d9..c7be1225e87 100644 --- a/sway-ast/src/path.rs +++ b/sway-ast/src/path.rs @@ -110,5 +110,5 @@ impl Spanned for PathTypeSegment { #[derive(Clone, Debug, Serialize)] pub struct QualifiedPathRoot { pub ty: Box, - pub as_trait: Option<(AsToken, Box)>, + pub as_trait: (AsToken, Box), } diff --git a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs index 0cbf326b070..dd5e6303e4c 100644 --- a/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs +++ b/sway-core/src/transform/to_parsed_lang/convert_parse_tree.rs @@ -3333,22 +3333,18 @@ fn path_root_opt_to_bool_and_qualified_path_root( close_angle_bracket_token: _, }), _, - )) => ( - false, - if let Some((_, path_type)) = as_trait { - Some(QualifiedPathType { - ty: ty_to_type_argument(context, handler, engines, *ty)?, - as_trait: engines.te().insert( - engines, - path_type_to_type_info(context, handler, engines, *path_type.clone())?, - path_type.span().source_id(), - ), - as_trait_span: path_type.span(), - }) - } else { - None - }, - ), + )) => (false, { + let (_, path_type) = as_trait; + Some(QualifiedPathType { + ty: ty_to_type_argument(context, handler, engines, *ty)?, + as_trait: engines.te().insert( + engines, + path_type_to_type_info(context, handler, engines, *path_type.clone())?, + path_type.span().source_id(), + ), + as_trait_span: path_type.span(), + }) + }), }) } diff --git a/sway-parse/src/path.rs b/sway-parse/src/path.rs index a9bb8c3826a..657e339747c 100644 --- a/sway-parse/src/path.rs +++ b/sway-parse/src/path.rs @@ -121,10 +121,7 @@ impl Parse for PathTypeSegment { impl Parse for QualifiedPathRoot { fn parse(parser: &mut Parser) -> ParseResult { let ty = parser.parse()?; - let as_trait = match parser.take() { - Some(as_token) => Some((as_token, parser.parse()?)), - None => None, - }; + let as_trait = (parser.parse()?, parser.parse()?); Ok(QualifiedPathRoot { ty, as_trait }) } } diff --git a/swayfmt/src/utils/language/path.rs b/swayfmt/src/utils/language/path.rs index 78711542b7f..f8575f185b0 100644 --- a/swayfmt/src/utils/language/path.rs +++ b/swayfmt/src/utils/language/path.rs @@ -62,10 +62,9 @@ impl Format for QualifiedPathRoot { formatter: &mut Formatter, ) -> Result<(), FormatterError> { self.ty.format(formatted_code, formatter)?; - if let Some((as_token, path_type)) = &self.as_trait { - write!(formatted_code, " {} ", as_token.span().as_str())?; - path_type.format(formatted_code, formatter)?; - } + let (as_token, path_type) = &self.as_trait; + write!(formatted_code, " {} ", as_token.span().as_str())?; + path_type.format(formatted_code, formatter)?; Ok(()) } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.lock new file mode 100644 index 00000000000..e319a387961 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-3A3AB9F18BDA9100" + +[[package]] +name = "parser_generic_turbo_fish_prefix" +source = "member" +dependencies = ["std"] + +[[package]] +name = "std" +source = "path+from-root-3A3AB9F18BDA9100" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.toml new file mode 100644 index 00000000000..22143b9b5eb --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "parser_generic_turbo_fish_prefix" + +[dependencies] +std = { path = "../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/src/main.sw new file mode 100644 index 00000000000..af437cc603e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/src/main.sw @@ -0,0 +1,9 @@ +script; + +struct S { + x: T, +} + +fn main() { + let x: ::S:: = S::{x: 8}; +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/test.toml new file mode 100644 index 00000000000..cfb2e0f1a93 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/parser_generic_turbo_fish_prefix/test.toml @@ -0,0 +1,4 @@ +category = "fail" + +# check: $()let x: ::S:: = S::{x: 8}; +# nextln: $()Expected `as`.