diesel-rs/diesel · error
only the `env!` macro is expected here
Error message
only the `env!` macro is expected here
What it means
In the `diesel_for_each_tuple!` macro invocation, the second positional argument for the maximum tuple size may be given either as an integer literal or as `env!(VAR_NAME)`. If a macro-like token appears but its identifier is not `env`, the parser rejects it with this compile error.
Solutions
- Replace the macro call with `env!(YOUR_VAR)`.
- Pass the max tuple size directly as an integer literal instead.
- Fix the capitalization/typo so the identifier is exactly `env`.
Example fix
// before diesel_for_each_tuple!(my_table, getenv!(MAX_TUPLE_SIZE)); // after diesel_for_each_tuple!(my_table, env!(MAX_TUPLE_SIZE));
Defensive patterns
Strategy: validation
Validate before calling
// Only env! is accepted as a macro form for the tuple-size argument
fn validate_size_arg(arg: &str) -> Result<(), String> {
if arg.ends_with('!') && !arg.starts_with("env!") {
return Err(format!("{arg} is not allowed; use env! or a literal"));
}
Ok(())
} Prevention
- Use the literal-integer form unless a build-time env override is genuinely needed
- Copy the exact `env!(VAR)` spelling from the macro docs
- Avoid abstractions like custom wrappers around the size argument
When it happens
Trigger: Writing `diesel_for_each_tuple!(..., other_macro!(SOME_VAR));` — any macro name other than `env` in the max-size position.
Common situations: Typo like `envn!` or `ENV!`, or attempting to reuse a custom macro/environment helper where the grammar only allows `env!`.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- expected attribute `name` help: the correct format looks…
- unknown attribute, expected
- unexpected end of input, expected `=` help: the correct…
- expected type
- unexpected end of input, expected parentheses help: the…
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/57f8a1061f9d1538.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_derives/src/diesel_for_each_tuple.rs:60
#input! {
#(#out)*
}
}
}
pub struct ForEachTupleInput {
inner: Ident,
max_size: u16,
}
impl syn::parse::Parse for ForEachTupleInput {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let inner = input.parse()?;
input.parse::<syn::Token![,]>()?;
let max_size = if input.peek(syn::Ident) {
let macro_ident = input.parse::<syn::Ident>()?;
if macro_ident != "env" {
return Err(syn::Error::new(
macro_ident.span(),
"only the `env!` macro is expected here",
));
}
let _bang = input.parse::<syn::Token![!]>()?;
let name;
syn::parenthesized!(name in input);
let s = name.parse::<syn::LitStr>()?;
std::env::var(s.value())
.map_err(|_| {
syn::Error::new(
s.span(),
format!("Expected `{}` to be set as environment variable", s.value()),
)
})?
.parse::<u16>()
.map_err(|_| {
syn::Error::new(View on GitHub (pinned to 6fa6ed01b2)