Add a test for issue 110457
This commit is contained in:
parent
99ff5afeb8
commit
8d406b8459
2 changed files with 137 additions and 0 deletions
|
@ -0,0 +1,90 @@
|
||||||
|
// force-host
|
||||||
|
// no-prefer-dynamic
|
||||||
|
#![crate_type = "proc-macro"]
|
||||||
|
|
||||||
|
extern crate proc_macro;
|
||||||
|
|
||||||
|
use proc_macro::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
|
||||||
|
|
||||||
|
#[proc_macro]
|
||||||
|
pub fn expand(_: TokenStream) -> TokenStream {
|
||||||
|
// Hand expansion/rewriting of
|
||||||
|
// ```
|
||||||
|
// quote! {
|
||||||
|
// output_mut(|o| o.copied_text = "".into());
|
||||||
|
// output_mut(|o| o.copied_text = format!("{:?}", self.tile_db));
|
||||||
|
// }.into()
|
||||||
|
// ```
|
||||||
|
stream([
|
||||||
|
ident("output_mut"),
|
||||||
|
group(
|
||||||
|
Delimiter::Parenthesis,
|
||||||
|
[
|
||||||
|
or(),
|
||||||
|
ident("o"),
|
||||||
|
or(),
|
||||||
|
ident("o"),
|
||||||
|
dot(),
|
||||||
|
ident("copied_text"),
|
||||||
|
eq(),
|
||||||
|
string(""),
|
||||||
|
dot(),
|
||||||
|
ident("into"),
|
||||||
|
group(Delimiter::Parenthesis, []),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
semi(),
|
||||||
|
ident("output_mut"),
|
||||||
|
group(
|
||||||
|
Delimiter::Parenthesis,
|
||||||
|
[
|
||||||
|
or(),
|
||||||
|
ident("o"),
|
||||||
|
or(),
|
||||||
|
ident("o"),
|
||||||
|
dot(),
|
||||||
|
ident("copied_text"),
|
||||||
|
eq(),
|
||||||
|
ident("format"),
|
||||||
|
bang(),
|
||||||
|
group(
|
||||||
|
Delimiter::Parenthesis,
|
||||||
|
[string("{:?}"), comma(), ident("self"), dot(), ident("tile_db")],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
semi(),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
fn stream(s: impl IntoIterator<Item = TokenTree>) -> TokenStream {
|
||||||
|
s.into_iter().collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn ident(i: &str) -> TokenTree {
|
||||||
|
TokenTree::Ident(Ident::new(i, Span::call_site()))
|
||||||
|
}
|
||||||
|
fn group(d: Delimiter, s: impl IntoIterator<Item = TokenTree>) -> TokenTree {
|
||||||
|
TokenTree::Group(Group::new(d, s.into_iter().collect()))
|
||||||
|
}
|
||||||
|
fn semi() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new(';', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn or() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new('|', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn dot() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new('.', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn eq() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new('=', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn bang() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new('!', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn comma() -> TokenTree {
|
||||||
|
TokenTree::Punct(Punct::new(',', Spacing::Alone))
|
||||||
|
}
|
||||||
|
fn string(s: &str) -> TokenTree {
|
||||||
|
TokenTree::Literal(Literal::string(s))
|
||||||
|
}
|
47
tests/incremental/issue-110457-same-span-closures/main.rs
Normal file
47
tests/incremental/issue-110457-same-span-closures/main.rs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
// aux-build: egui_inspect_derive.rs
|
||||||
|
// revisions: cpass1 cpass2
|
||||||
|
|
||||||
|
extern crate egui_inspect_derive;
|
||||||
|
|
||||||
|
pub struct TileDef {
|
||||||
|
pub layer: (),
|
||||||
|
#[cfg(cpass2)]
|
||||||
|
pub blend_graphic: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct GameState {
|
||||||
|
pub(crate) tile_db: TileDb,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl GameState {
|
||||||
|
fn inspect_mut(&mut self) {
|
||||||
|
egui_inspect_derive::expand! {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new() -> GameState {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut app = new();
|
||||||
|
app.inspect_mut();
|
||||||
|
}
|
||||||
|
// this is actually used
|
||||||
|
pub struct TileDb {
|
||||||
|
unknown_bg: TileDef,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Debug for TileDb {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct PlatformOutput {
|
||||||
|
pub copied_text: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn output_mut<R>(writer: impl FnOnce(&mut PlatformOutput) -> R) -> R {
|
||||||
|
loop {}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue