-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add context for more "strict undefined behavior" cases #627
Add context for more "strict undefined behavior" cases #627
Conversation
0d428c9
to
a7b0df9
Compare
minijinja/src/vm/mod.rs
Outdated
@@ -306,7 +318,7 @@ impl<'env> Vm<'env> { | |||
Instruction::EmitRaw(val) => { | |||
// this only produces a format error, no need to attach | |||
// location information. | |||
ok!(out.write_str(val).map_err(Error::from)); | |||
ctx_ok!(out.write_str(val).map_err(Error::from)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case is intentionally bypassing ctx_ok!
as you can see from the comment. This is done for performance reasons.
minijinja/src/vm/mod.rs
Outdated
@@ -279,6 +279,18 @@ impl<'env> Vm<'env> { | |||
}; | |||
} | |||
|
|||
#[allow(unused_macros)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I think this is a nice idea, at least the raw case should be allowed to use the ok!
macro as mentioned. I would probably just not do the ok!
macro here. Particularly with the fixes to ?
this codebase will avoid the ok!
and some!
macros in the future anyways.
...and make it hard to forget to add context again
a7b0df9
to
3b9ff86
Compare
@mitsuhiko Thanks for the review! I removed the ok-shadowing and let EmitRaw use it — it's now just 3 occurences of ok=>ctx_ok |
For now, this depends on a branch of minijinja, until <mitsuhiko/minijinja#627> lands
For now, this depends on a branch of minijinja, until <mitsuhiko/minijinja#627> lands
For now, this depends on a branch of minijinja, until <mitsuhiko/minijinja#627> lands
For now, this depends on a branch of minijinja, until <mitsuhiko/minijinja#627> lands
...and make it hard to forget to add context again.
This hit us in https://github.com/axodotdev/cargo-dist when trying to enable strict undefined behavior.
The change I do care about is using
ctx_ok!
in all branches of the vm evaluation.I added a little trick where the
ok!
macro is shadowed, so if you accidentally use it again, rustc will yell at you:Other ideas include.. shadowing
ok!
in the first place and changing everyctx_ok!
invocation back took!
, but eh, I had to pick one. Feel free to pick your favorite / take over this PR / do whatever it takes to get this merged, all I care is that our errors have debug info :) Thanks!