use rustc::ty::{self, DefIdTree};
use rustc::util::nodemap::FxHashSet;
use syntax::ast::{self, Ident, Path};
-use syntax::ext::base::MacroKind;
use syntax::feature_gate::BUILTIN_ATTRIBUTES;
use syntax::source_map::SourceMap;
use syntax::struct_span_err;
use syntax::symbol::{Symbol, kw};
use syntax::util::lev_distance::find_best_match_for_name;
+use syntax_pos::hygiene::MacroKind;
use syntax_pos::{BytePos, Span, MultiSpan};
use crate::resolve_imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
impl_span
}
-crate fn add_typo_suggestion(
- err: &mut DiagnosticBuilder<'_>, suggestion: Option<TypoSuggestion>, span: Span
-) -> bool {
- if let Some(suggestion) = suggestion {
- let msg = format!(
- "{} {} with a similar name exists", suggestion.res.article(), suggestion.res.descr()
- );
- err.span_suggestion(
- span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
- );
- return true;
- }
- false
-}
-
impl<'a> Resolver<'a> {
crate fn add_module_candidates(
&mut self,
names: &mut Vec<TypoSuggestion>,
filter_fn: &impl Fn(Res) -> bool,
) {
- for (&(ident, _), resolution) in self.resolutions(module).borrow().iter() {
+ for (key, resolution) in self.resolutions(module).borrow().iter() {
if let Some(binding) = resolution.borrow().binding {
let res = binding.res();
if filter_fn(res) {
- names.push(TypoSuggestion::from_res(ident.name, res));
+ names.push(TypoSuggestion::from_res(key.ident.name, res));
}
}
}
span, "`Self` in type parameter default".to_string());
err
}
- ResolutionError::ConstParamDependentOnTypeParam => {
- let mut err = struct_span_err!(
- self.session,
- span,
- E0671,
- "const parameters cannot depend on type parameters"
- );
- err.span_label(span, format!("const parameter depends on type parameter"));
- err
- }
}
}
let suggestion = self.early_lookup_typo_candidate(
ScopeSet::Macro(macro_kind), parent_scope, ident, is_expected
);
- add_typo_suggestion(err, suggestion, ident.span);
+ self.add_typo_suggestion(err, suggestion, ident.span);
if macro_kind == MacroKind::Derive &&
(ident.as_str() == "Send" || ident.as_str() == "Sync") {
err.help("have you added the `#[macro_use]` on the module/import?");
}
}
+
+ crate fn add_typo_suggestion(
+ &self,
+ err: &mut DiagnosticBuilder<'_>,
+ suggestion: Option<TypoSuggestion>,
+ span: Span,
+ ) -> bool {
+ if let Some(suggestion) = suggestion {
+ let msg = format!(
+ "{} {} with a similar name exists", suggestion.res.article(), suggestion.res.descr()
+ );
+ err.span_suggestion(
+ span, &msg, suggestion.candidate.to_string(), Applicability::MaybeIncorrect
+ );
+ let def_span = suggestion.res.opt_def_id()
+ .and_then(|def_id| self.definitions.opt_span(def_id));
+ if let Some(span) = def_span {
+ err.span_label(span, &format!(
+ "similarly named {} `{}` defined here",
+ suggestion.res.descr(),
+ suggestion.candidate.as_str(),
+ ));
+ }
+ return true;
+ }
+ false
+ }
}
impl<'a, 'b> ImportResolver<'a, 'b> {
}
let resolutions = self.r.resolutions(crate_module).borrow();
- let resolution = resolutions.get(&(ident, MacroNS))?;
+ let resolution = resolutions.get(&self.r.new_key(ident, MacroNS))?;
let binding = resolution.borrow().binding()?;
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() {
let module_name = crate_module.kind.name().unwrap();