From 334d36d07023b773fa6786000136eb2d38943f86 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Tue, 1 Oct 2024 07:27:33 -0400 Subject: [PATCH] refactor(wgsl-in): specify more closure ret. types in parsing This resolves ambiguity that will be introduced in the subsequent commit that adds `impl From for naga::Error`. --- naga/src/front/wgsl/lower/mod.rs | 4 ++-- naga/src/front/wgsl/parse/mod.rs | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 78e81350b4..e800796587 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -1244,7 +1244,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { .arguments .iter() .enumerate() - .map(|(i, arg)| { + .map(|(i, arg)| -> Result<_, Error<'_>> { let ty = self.resolve_ast_type(arg.ty, ctx)?; let expr = expressions .append(crate::Expression::FunctionArgument(i as u32), arg.name.span); @@ -1263,7 +1263,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let result = f .result .as_ref() - .map(|res| { + .map(|res| -> Result<_, Error<'_>> { let ty = self.resolve_ast_type(res.ty, ctx)?; Ok(crate::FunctionResult { ty, diff --git a/naga/src/front/wgsl/parse/mod.rs b/naga/src/front/wgsl/parse/mod.rs index fcfcc37750..e91541e767 100644 --- a/naga/src/front/wgsl/parse/mod.rs +++ b/naga/src/front/wgsl/parse/mod.rs @@ -1906,10 +1906,8 @@ impl Parser { let _ = lexer.next(); let mut body = ast::Block::default(); - let (condition, span) = lexer.capture_span(|lexer| { - let condition = self.general_expression(lexer, ctx)?; - Ok(condition) - })?; + let (condition, span) = + lexer.capture_span(|lexer| self.general_expression(lexer, ctx))?; let mut reject = ast::Block::default(); reject.stmts.push(ast::Statement { kind: ast::StatementKind::Break, @@ -1966,9 +1964,9 @@ impl Parser { let mut body = ast::Block::default(); if !lexer.skip(Token::Separator(';')) { let (condition, span) = lexer.capture_span(|lexer| { - let condition = self.general_expression(lexer, ctx)?; - lexer.expect(Token::Separator(';'))?; - Ok(condition) + self.general_expression(lexer, ctx).and_then(|condition| { + lexer.expect(Token::Separator(';')).map(|()| condition) + }) })?; let mut reject = ast::Block::default(); reject.stmts.push(ast::Statement {