Skip to content
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

generator: better macro hygiene #192

Merged
merged 7 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deny.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[licenses]
version = 2
allow = ["Apache-2.0", "BSD-2-Clause", "MIT", "Unicode-DFS-2016"]
allow = ["Apache-2.0", "MIT", "MIT-0", "Unicode-DFS-2016"]
private = { ignore = true }

[[licenses.clarify]]
Expand Down
2 changes: 2 additions & 0 deletions rinja/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ mod html;
use std::{fmt, io};

pub use rinja_derive::Template;
#[doc(hidden)]
pub use {core, std};
Copy link
Contributor

Choose a reason for hiding this comment

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

You can refer to core and std by prepending them with :: in macros. Like ::core::whatever. If not, then add a comment to explain why we want it. Also, it's really not great because it's not rare for users to do use rinja::*;.

Copy link
Collaborator Author

@Kijewski Kijewski Oct 4, 2024

Choose a reason for hiding this comment

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

The current code already does that, but even fully-qualified paths like ::core and ::std can be shadowed. See the example in testing.

But yeah, I didn't recognize the problem that use rinja::* would import the symbol core, too, which might be undesirable. Python is smarter than rust in a way: Symbols with a leading underscore are omitted from glob imports. Would be nice if rust did that, too.

I guess I'll simply move the re-exports into the existing #[doc(hidden)] mod helpers. The name already exists, so it can't introduce a new problem.

Copy link
Contributor

Choose a reason for hiding this comment

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

A new module containing it would be better indeed. 👍


#[doc(hidden)]
pub use crate as shared;
Expand Down
8 changes: 4 additions & 4 deletions rinja_derive/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use proc_macro2::Span;
#[cfg(feature = "config")]
use serde::Deserialize;

use crate::{CRATE, CompileError, FileInfo, OnceMap};
use crate::{CompileError, FileInfo, OnceMap};

#[derive(Debug)]
pub(crate) struct Config {
Expand Down Expand Up @@ -182,7 +182,7 @@ impl Config {
for (extensions, name) in DEFAULT_ESCAPERS {
escapers.push((
str_set(extensions),
format!("{CRATE}::filters::{name}").into(),
format!("rinja::filters::{name}").into(),
));
}

Expand Down Expand Up @@ -682,11 +682,11 @@ mod tests {
str_set(&[
"html", "htm", "j2", "jinja", "jinja2", "rinja", "svg", "xml"
]),
"::rinja::filters::Html".into()
"rinja::filters::Html".into()
),
(
str_set(&["md", "none", "txt", "yml", ""]),
"::rinja::filters::Text".into()
"rinja::filters::Text".into()
),
]);
}
Expand Down
Loading
Loading