Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Make is_shadowing_variable() failable#615

Merged
djc merged 1 commit into
askama-rs:mainfrom
Kijewski:pr-is_shadowing_variable-failable
Jan 31, 2022
Merged

Make is_shadowing_variable() failable#615
djc merged 1 commit into
askama-rs:mainfrom
Kijewski:pr-is_shadowing_variable-failable

Conversation

@Kijewski
Copy link
Copy Markdown
Member

Extracted from #612.

Comment thread askama_shared/src/generator.rs Outdated
Comment on lines +820 to +826
Target::Tuple(_, targets) => targets
.iter()
.any(|target| self.is_shadowing_variable(target)),
.find_map(|target| match self.is_shadowing_variable(target) {
Ok(false) => None,
outcome => Some(outcome),
})
.unwrap_or(Ok(false)),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transforming from Ok(false) to None, then back to Ok(false) doesn't seem like a great way to do this. At this point it might be better to just use a for-loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, a loop looks better. Changed.

Comment thread askama_shared/src/generator.rs Outdated
outcome => Some(outcome),
})
.unwrap_or(Ok(false)),
_ => Err("Cannot have literals on the left-hand-side of an assignment.".into()),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably rewrite this as "literals are not allowed on the left-hand side of an assignment" (no capital, no period).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

Copy link
Copy Markdown
Collaborator

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@djc djc merged commit cd744f0 into askama-rs:main Jan 31, 2022
@Kijewski Kijewski deleted the pr-is_shadowing_variable-failable branch January 31, 2022 11:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants