Skip to content

Commit

Permalink
refactor(wgsl-in): specify more closure ret. types in parsing
Browse files Browse the repository at this point in the history
This resolves ambiguity that will be introduced in the subsequent commit
that adds `impl From<ConflictingDiagnosticRuleError> for naga::Error`.
  • Loading branch information
ErichDonGubler committed Oct 24, 2024
1 parent ca6f6f3 commit 0ebfb1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions naga/src/front/wgsl/lower/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand Down
12 changes: 5 additions & 7 deletions naga/src/front/wgsl/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0ebfb1c

Please sign in to comment.