Auto merge of #62816 - estebank:type-ascription-macros, r=petrochenkov
Point at type ascription before macro invocation on expansion parse error Fix https://github.com/rust-lang/rust/issues/47666. Follow up to https://github.com/rust-lang/rust/pull/62791. r? @petrochenkov
This commit is contained in:
@@ -713,6 +713,7 @@ pub struct ExpansionData {
|
||||
pub depth: usize,
|
||||
pub module: Rc<ModuleData>,
|
||||
pub directory_ownership: DirectoryOwnership,
|
||||
pub prior_type_ascription: Option<(Span, bool)>,
|
||||
}
|
||||
|
||||
/// One of these is made during expansion and incrementally updated as we go;
|
||||
@@ -743,6 +744,7 @@ impl<'a> ExtCtxt<'a> {
|
||||
depth: 0,
|
||||
module: Rc::new(ModuleData { mod_path: Vec::new(), directory: PathBuf::new() }),
|
||||
directory_ownership: DirectoryOwnership::Owned { relative: None },
|
||||
prior_type_ascription: None,
|
||||
},
|
||||
expansions: FxHashMap::default(),
|
||||
allow_derive_markers: [sym::rustc_attrs, sym::structural_match][..].into(),
|
||||
|
||||
@@ -517,8 +517,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
result
|
||||
}
|
||||
SyntaxExtensionKind::LegacyBang(expander) => {
|
||||
let prev = self.cx.current_expansion.prior_type_ascription;
|
||||
self.cx.current_expansion.prior_type_ascription =
|
||||
mac.node.prior_type_ascription;
|
||||
let tok_result = expander.expand(self.cx, span, mac.node.stream());
|
||||
if let Some(result) = fragment_kind.make_from(tok_result) {
|
||||
let result = if let Some(result) = fragment_kind.make_from(tok_result) {
|
||||
result
|
||||
} else {
|
||||
let msg = format!("non-{kind} macro in {kind} position: {path}",
|
||||
@@ -526,7 +529,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
|
||||
self.cx.span_err(span, &msg);
|
||||
self.cx.trace_macros_diag();
|
||||
fragment_kind.dummy(span)
|
||||
}
|
||||
};
|
||||
self.cx.current_expansion.prior_type_ascription = prev;
|
||||
result
|
||||
}
|
||||
_ => unreachable!()
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ pub fn placeholder(kind: AstFragmentKind, id: ast::NodeId) -> AstFragment {
|
||||
path: ast::Path { span: DUMMY_SP, segments: Vec::new() },
|
||||
tts: TokenStream::empty().into(),
|
||||
delim: ast::MacDelimiter::Brace,
|
||||
prior_type_ascription: None,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -173,6 +173,7 @@ fn generic_extension<'cx>(
|
||||
let mut p = Parser::new(cx.parse_sess(), tts, Some(directory), true, false, None);
|
||||
p.root_module_name =
|
||||
cx.current_expansion.module.mod_path.last().map(|id| id.as_str().to_string());
|
||||
p.last_type_ascription = cx.current_expansion.prior_type_ascription;
|
||||
|
||||
p.process_potential_macro_variable();
|
||||
// Let the context choose how to interpret the result.
|
||||
|
||||
Reference in New Issue
Block a user