rust-marker / design

Apache License 2.0
15 stars 1 forks source link

Question and user story examples for the `time` crate #16

Open xFrednet opened 2 years ago

xFrednet commented 2 years ago

Hey everyone watching this repo. I'm currently working on the basic framework to implement a stable interface. Currently, I'm mostly working with the rust reference, but feel like this isn't ideal when it comes to macro and attribute representations among other things.

To get a feel, what lint authors and library implementors would actually like to have, I would like to collect user storied. Therefore, I would like to select user stories. Would everyone be okay with collecting them in this repo as issues? I believe this is the best place we currently have for something like this. :upside_down_face:

jhpratt commented 2 years ago

Here's a list of lints I could plausibly see myself writing for time as it currently exists:

Happy to provide further explanation on any/all of these as needed. I don't believe the level of a warning is in any way relevant to the design.

xFrednet commented 2 years ago

Thank you for the response! Most of these seam pretty straightforward and would be covered by only having the reference representation. Could you maybe elaborate on these two points:

  • format description containing components that will always error (for the type provided)

  • known invalid format description (e.g. invalid syntax)

A code snipped you would like to lint would be nice. (I haven't worked with the crate yet.) Besides that, do you have any lint ideas that interact with attributes or macros?

jhpratt commented 2 years ago

format description containing components that will always error (for the type provided)

let fd = time::macros::format_description!("[year]");
UtcOffset::UTC.format(fd);
//~^ ERROR `UtcOffset` does not provide the `[year]` component
//~^^ NOTE this method call will always fail

known invalid format description (e.g. invalid syntax)

Any (unescaped) opening bracket has to be closed:

let _ = time::format_description::parse("[");
//~^ ERROR invalid format description
//~^^ NOTE this function call will always fail

This will fail at compile time if you use the macro. I would like to lint the statically known runtime case as well (ignoring the fact that the macro should be suggested).


In theory I would like to be able to know which components are present in a runtime format description, but that would be far more involved. It's certainly not something I would want/need to be present initially.

jhpratt commented 1 year ago

Here's an interesting one: I would like to know whether the crate being analyzed is a binary or a library. This is because a library fundamentally cannot uphold the guarantees that this unsafe fn requires.