Look up macro names as well when suggesting replacements for function resolve errors
fixes #5780
This commit is contained in:
@@ -27,7 +27,7 @@ use util::small_vector::SmallVector;
|
||||
use ext::mtwt;
|
||||
use fold::Folder;
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::rc::Rc;
|
||||
use std::default::Default;
|
||||
|
||||
@@ -856,7 +856,10 @@ pub fn get_exprs_from_tts(cx: &mut ExtCtxt,
|
||||
///
|
||||
/// This environment maps Names to SyntaxExtensions.
|
||||
pub struct SyntaxEnv {
|
||||
chain: Vec<MapChainFrame> ,
|
||||
chain: Vec<MapChainFrame>,
|
||||
/// All bang-style macro/extension names
|
||||
/// encountered so far; to be used for diagnostics in resolve
|
||||
pub names: HashSet<Name>,
|
||||
}
|
||||
|
||||
// impl question: how to implement it? Initially, the
|
||||
@@ -876,7 +879,7 @@ struct MapChainFrame {
|
||||
|
||||
impl SyntaxEnv {
|
||||
fn new() -> SyntaxEnv {
|
||||
let mut map = SyntaxEnv { chain: Vec::new() };
|
||||
let mut map = SyntaxEnv { chain: Vec::new() , names: HashSet::new()};
|
||||
map.push_frame();
|
||||
map
|
||||
}
|
||||
@@ -913,6 +916,9 @@ impl SyntaxEnv {
|
||||
}
|
||||
|
||||
pub fn insert(&mut self, k: Name, v: SyntaxExtension) {
|
||||
if let NormalTT(..) = v {
|
||||
self.names.insert(k);
|
||||
}
|
||||
self.find_escape_frame().map.insert(k, Rc::new(v));
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ast::{Block, Crate, DeclLocal, ExprMac, PatMac};
|
||||
use ast::{Local, Ident, Mac_};
|
||||
use ast::{Local, Ident, Mac_, Name};
|
||||
use ast::{ItemMac, MacStmtWithSemicolon, Mrk, Stmt, StmtDecl, StmtMac};
|
||||
use ast::{StmtExpr, StmtSemi};
|
||||
use ast::TokenTree;
|
||||
@@ -32,6 +32,8 @@ use visit;
|
||||
use visit::Visitor;
|
||||
use std_inject;
|
||||
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
||||
pub fn expand_expr(e: P<ast::Expr>, fld: &mut MacroExpander) -> P<ast::Expr> {
|
||||
let expr_span = e.span;
|
||||
@@ -1261,7 +1263,7 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
|
||||
imported_macros: Vec<ast::MacroDef>,
|
||||
user_exts: Vec<NamedSyntaxExtension>,
|
||||
feature_gated_cfgs: &mut Vec<GatedCfg>,
|
||||
c: Crate) -> Crate {
|
||||
c: Crate) -> (Crate, HashSet<Name>) {
|
||||
let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg,
|
||||
feature_gated_cfgs);
|
||||
if std_inject::no_core(&c) {
|
||||
@@ -1271,21 +1273,23 @@ pub fn expand_crate<'feat>(parse_sess: &parse::ParseSess,
|
||||
} else {
|
||||
cx.crate_root = Some("std");
|
||||
}
|
||||
let ret = {
|
||||
let mut expander = MacroExpander::new(&mut cx);
|
||||
|
||||
let mut expander = MacroExpander::new(&mut cx);
|
||||
for def in imported_macros {
|
||||
expander.cx.insert_macro(def);
|
||||
}
|
||||
|
||||
for def in imported_macros {
|
||||
expander.cx.insert_macro(def);
|
||||
}
|
||||
for (name, extension) in user_exts {
|
||||
expander.cx.syntax_env.insert(name, extension);
|
||||
}
|
||||
|
||||
for (name, extension) in user_exts {
|
||||
expander.cx.syntax_env.insert(name, extension);
|
||||
}
|
||||
|
||||
let mut ret = expander.fold_crate(c);
|
||||
ret.exported_macros = expander.cx.exported_macros.clone();
|
||||
parse_sess.span_diagnostic.handler().abort_if_errors();
|
||||
return ret;
|
||||
let mut ret = expander.fold_crate(c);
|
||||
ret.exported_macros = expander.cx.exported_macros.clone();
|
||||
parse_sess.span_diagnostic.handler().abort_if_errors();
|
||||
ret
|
||||
};
|
||||
return (ret, cx.syntax_env.names);
|
||||
}
|
||||
|
||||
// HYGIENIC CONTEXT EXTENSION:
|
||||
@@ -1480,7 +1484,7 @@ mod tests {
|
||||
let ps = parse::ParseSess::new();
|
||||
let crate_ast = panictry!(string_to_parser(&ps, crate_str).parse_crate_mod());
|
||||
// the cfg argument actually does matter, here...
|
||||
expand_crate(&ps,test_ecfg(),vec!(),vec!(), &mut vec![], crate_ast)
|
||||
expand_crate(&ps,test_ecfg(),vec!(),vec!(), &mut vec![], crate_ast).0
|
||||
}
|
||||
|
||||
// find the pat_ident paths in a crate
|
||||
|
||||
Reference in New Issue
Block a user