Skip to content

Commit

Permalink
[wgsl-in] Delete {ExpressionContext,RuntimeContext}::reborrow.
Browse files Browse the repository at this point in the history
Remove `front::wgsl::lower::ExpressionContext::reborrow` and
`front::wgsl::lower::RuntimeExpressionContext::reborrow` in favor of
Rust's automatic reborrowing of `&mut` references.
  • Loading branch information
jimblandy authored and teoxoy committed Oct 23, 2023
1 parent a647c64 commit d038506
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 160 deletions.
16 changes: 8 additions & 8 deletions src/front/wgsl/lower/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ enum ConcreteConstructor<'a> {
}

impl ConcreteConstructorHandle {
fn to_error_string(&self, ctx: ExpressionContext) -> String {
fn to_error_string(&self, ctx: &mut ExpressionContext) -> String {
match *self {
Self::PartialVector { size } => {
format!("vec{}<?>", size as u32,)
Expand Down Expand Up @@ -143,15 +143,15 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
constructor: &ast::ConstructorType<'source>,
ty_span: Span,
components: &[Handle<ast::Expression<'source>>],
mut ctx: ExpressionContext<'source, '_, '_>,
ctx: &mut ExpressionContext<'source, '_, '_>,
) -> Result<Handle<crate::Expression>, Error<'source>> {
let constructor_h = self.constructor(constructor, ctx.reborrow())?;
let constructor_h = self.constructor(constructor, ctx)?;

let components_h = match *components {
[] => ComponentsHandle::None,
[component] => {
let span = ctx.ast_expressions.get_span(component);
let component = self.expression(component, ctx.reborrow())?;
let component = self.expression(component, ctx)?;
let ty = super::resolve!(ctx, component);

ComponentsHandle::One {
Expand All @@ -162,12 +162,12 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
}
[component, ref rest @ ..] => {
let span = ctx.ast_expressions.get_span(component);
let component = self.expression(component, ctx.reborrow())?;
let component = self.expression(component, ctx)?;

let components = std::iter::once(Ok(component))
.chain(
rest.iter()
.map(|&component| self.expression(component, ctx.reborrow())),
.map(|&component| self.expression(component, ctx)),
)
.collect::<Result<_, _>>()?;
let spans = std::iter::once(span)
Expand Down Expand Up @@ -488,7 +488,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
return Err(Error::BadTypeCast {
span,
from_type,
to_type: constructor_h.to_error_string(ctx.reborrow()),
to_type: constructor_h.to_error_string(ctx),
});
}

Expand Down Expand Up @@ -545,7 +545,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
fn constructor<'out>(
&mut self,
constructor: &ast::ConstructorType<'source>,
mut ctx: ExpressionContext<'source, '_, 'out>,
ctx: &mut ExpressionContext<'source, '_, 'out>,
) -> Result<ConcreteConstructorHandle, Error<'source>> {
let c = match *constructor {
ast::ConstructorType::Scalar { width, kind } => {
Expand Down
Loading

0 comments on commit d038506

Please sign in to comment.