-
Notifications
You must be signed in to change notification settings - Fork 526
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
better checking of tag duplicates, avoid discarding invalid variant errs #951
Conversation
31aa6de
to
b30f84b
Compare
prost-derive/src/lib.rs
Outdated
.sorted_unstable() | ||
.tuple_windows() | ||
.find(|(a, b)| a == b) |
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.
it would kinda be preferable to write this as .duplicates().next()
using Itertools
, but that method unfortunately requires use_std
.
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.
As I understand prost_derive will run on the host, so it is not subject to no_std
rules. The code does also use std::fmt;
, so std
must be available. So I think it is safe to use_std
for Itertools. Do you agree?
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.
yeah from what i've seen since i published this that is totally possible. i'll update it
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.
It seems you updated the other case, but not this one. Was that intentional?
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.
it was not.
ef347ff
to
01eaa46
Compare
169f10c
to
b235c8b
Compare
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 fixes the error reporting for duplicate tags, improves the error message and adds tests. I like it.
prost-derive/src/lib.rs
Outdated
.sorted_unstable() | ||
.tuple_windows() | ||
.find(|(a, b)| a == b) |
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.
As I understand prost_derive will run on the host, so it is not subject to no_std
rules. The code does also use std::fmt;
, so std
must be available. So I think it is safe to use_std
for Itertools. Do you agree?
prost-derive/src/lib.rs
Outdated
@@ -412,23 +414,21 @@ fn try_oneof(input: TokenStream) -> Result<TokenStream, Error> { | |||
} | |||
} | |||
|
|||
let mut tags = fields | |||
if fields.iter().any(|(_, field)| field.tags().len() > 1) { | |||
panic!("variant with multiple tags"); // Not clear if this is possible, but good to be safe |
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 error message is a regression, right? The old message was: "invalid oneof variant {}::{}: oneof variants may only have a single tag"
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.
i can re-expand this, sure
prost-derive/src/lib.rs
Outdated
.sorted_unstable() | ||
.tuple_windows() | ||
.find(|(a, b)| a == b) |
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.
It seems you updated the other case, but not this one. Was that intentional?
Co-authored-by: Casper Meijn <casper@meijn.net>
incidentally, most (all? probably, all) of my contributions to
if any of these sound useful to upstream it could be a good project for myself or someone to trace back over my steps in achieving |
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.
Thanks for your contribution
Improvements are welcome. However, review capacity is low, so bringing in a reviewer would be appreciated. Keep in mind that prost is focused on an unopinionated implementation of protobuf. |
Currently it seems that the "invalid oneof variant" Errs are always discarded because they are being passed directly into
flat_map
from a closure, rather than actually propagating the error.This PR also streamlines the checks for duplicated tag numbers and adds some rudimentary tests for the affected code in those proc macros.