mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Auto merge of #33735 - jseyfried:concat_idents_in_ty_positions, r=nrc
Allow `concat_idents!` in type positions as well as in expression positions This allows the `concat_idents!` macro in type positions as well as in expression positions. r? @nrc
This commit is contained in:
commit
1ccada6cd3
@ -52,22 +52,36 @@ pub fn expand_syntax_ext<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[TokenTree])
|
|||||||
}
|
}
|
||||||
let res = str_to_ident(&res_str);
|
let res = str_to_ident(&res_str);
|
||||||
|
|
||||||
let e = P(ast::Expr {
|
struct Result { ident: ast::Ident, span: Span };
|
||||||
id: ast::DUMMY_NODE_ID,
|
|
||||||
node: ast::ExprKind::Path(None,
|
impl Result {
|
||||||
ast::Path {
|
fn path(&self) -> ast::Path {
|
||||||
span: sp,
|
let segment = ast::PathSegment {
|
||||||
global: false,
|
identifier: self.ident,
|
||||||
segments: vec!(
|
parameters: ast::PathParameters::none()
|
||||||
ast::PathSegment {
|
};
|
||||||
identifier: res,
|
ast::Path { span: self.span, global: false, segments: vec![segment] }
|
||||||
parameters: ast::PathParameters::none(),
|
}
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
impl base::MacResult for Result {
|
||||||
),
|
fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> {
|
||||||
span: sp,
|
Some(P(ast::Expr {
|
||||||
attrs: None,
|
id: ast::DUMMY_NODE_ID,
|
||||||
});
|
node: ast::ExprKind::Path(None, self.path()),
|
||||||
MacEager::expr(e)
|
span: self.span,
|
||||||
|
attrs: None,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> {
|
||||||
|
Some(P(ast::Ty {
|
||||||
|
id: ast::DUMMY_NODE_ID,
|
||||||
|
node: ast::TyKind::Path(None, self.path()),
|
||||||
|
span: self.span,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Box::new(Result { ident: res, span: sp })
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,15 @@
|
|||||||
// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
// except according to those terms.
|
// except according to those terms.
|
||||||
|
|
||||||
// this now fails (correctly, I claim) because hygiene prevents
|
#![feature(concat_idents, type_macros)]
|
||||||
// the assembled identifier from being a reference to the binding.
|
|
||||||
#![feature(concat_idents)]
|
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
|
struct Foo;
|
||||||
|
let _: concat_idents!(F, oo) = Foo; // Test that `concat_idents!` can be used in type positions
|
||||||
|
|
||||||
let asdf_fdsa = "<.<".to_string();
|
let asdf_fdsa = "<.<".to_string();
|
||||||
|
// this now fails (correctly, I claim) because hygiene prevents
|
||||||
|
// the assembled identifier from being a reference to the binding.
|
||||||
assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string());
|
assert!(concat_idents!(asd, f_f, dsa) == "<.<".to_string());
|
||||||
//~^ ERROR: unresolved name `asdf_fdsa`
|
//~^ ERROR: unresolved name `asdf_fdsa`
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user