-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed as not planned
Labels
Description
rust-analyzer version: 0.3.1489-standalone
rustc version: rustc 1.71.0-nightly (f5559e338 2023-04-24)
relevant settings: probably none
Given the following macro:
macro_rules! get {
($list:ident; ) => (
None
);
($list:ident; (Marker)) => (
Some($list[0])
);
($list:ident; (Marker) $(($tail:ty))*) => (
Some($list[0])
);
($list:ident; ($head:ty) $(($tail:ty))*) => (
get!($list; $(($tail))*)
);
}
The output of the following snippet will be None
:
fn main() {
let test = &["test"];
let v: Option<&'static str> = get!(test; (Test) (Marker));
println!("{v:?}");
}
But rust-analyzer
's expansion outputs Some(test[0])
, which should print Some("test")
.
For more context, cargo-expand
expands the above snippet to:
fn main() {
let test = &["test"];
let v: Option<&'static str> = None;
{
::std::io::_print(format_args!("{0:?}\n", v));
};
}
If the designator of $tail
is changed from ty
to ident
:
macro_rules! get {
($list:ident; ) => (
None
);
($list:ident; (Marker)) => (
Some($list[0])
);
($list:ident; (Marker) $(($tail:ident))*) => (
Some($list[0])
);
($list:ident; ($head:ident) $(($tail:ident))*) => (
get!($list; $(($tail))*)
);
}
Then rustc
, cargo-expand
, and rust-analyzer
all agree that the expansion of the macro is Some(test[0])
, which will print Some("test")
.