use errors::{Applicability, DiagnosticBuilder};
use rustc_data_structures::sync::Lrc;
use rustc::hir::{self, ExprKind, Node, QPath};
-use rustc::hir::def::Def;
+use rustc::hir::def::{Def, DefKind};
use rustc::hir::def_id::{CRATE_DEF_INDEX, LOCAL_CRATE, DefId};
use rustc::hir::map as hir_map;
use rustc::hir::print;
use super::probe::Mode;
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
- fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
+ fn is_fn_ty(&self, ty: Ty<'tcx>, span: Span) -> bool {
let tcx = self.tcx;
match ty.sty {
// Not all of these (e.g., unsafe fns) implement `FnOnce`,
ExprKind::Path(ref qpath) => {
// local binding
if let &QPath::Resolved(_, ref path) = &qpath {
- if let hir::def::Def::Local(node_id) = path.def {
- let span = tcx.hir().span(node_id);
+ if let hir::def::Def::Local(hir_id) = path.def {
+ let span = tcx.hir().span_by_hir_id(hir_id);
let snippet = tcx.sess.source_map().span_to_snippet(span)
.unwrap();
let filename = tcx.sess.source_map().span_to_filename(span);
- let parent_node = self.tcx.hir().get(
- self.tcx.hir().get_parent_node(node_id),
+ let parent_node = self.tcx.hir().get_by_hir_id(
+ self.tcx.hir().get_parent_node_by_hir_id(hir_id),
);
let msg = format!(
"you must specify a type for this binding, like `{}`",
return;
} else {
span = item_name.span;
- struct_span_err!(
+ let mut err = struct_span_err!(
tcx.sess,
span,
E0599,
item_kind,
item_name,
ty_str
- )
+ );
+ if let Some(span) = tcx.sess.confused_type_with_std_module.borrow()
+ .get(&span)
+ {
+ if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*span) {
+ err.span_suggestion(
+ *span,
+ "you are looking for the module in `std`, \
+ not the primitive type",
+ format!("std::{}", snippet),
+ Applicability::MachineApplicable,
+ );
+ }
+ }
+ err
}
} else {
tcx.sess.diagnostic().struct_dummy()
}
if let Some(lev_candidate) = lev_candidate {
- let def = lev_candidate.def();
+ let def_kind = lev_candidate.def_kind();
err.span_suggestion(
span,
&format!(
"there is {} {} with a similar name",
- def.article(),
- def.kind_name(),
+ def_kind.article(),
+ def_kind.descr(),
),
lev_candidate.ident.to_string(),
Applicability::MaybeIncorrect,
err.emit();
}
- MethodError::PrivateMatch(def, out_of_scope_traits) => {
+ MethodError::PrivateMatch(kind, _, out_of_scope_traits) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0624,
- "{} `{}` is private", def.kind_name(), item_name);
+ "{} `{}` is private", kind.descr(), item_name);
self.suggest_valid_traits(&mut err, out_of_scope_traits);
err.emit();
}
external_mods: &mut FxHashSet<DefId>,
def: Def) {
match def {
- Def::Trait(def_id) |
- Def::TraitAlias(def_id) => {
+ Def::Def(DefKind::Trait, def_id) |
+ Def::Def(DefKind::TraitAlias, def_id) => {
traits.push(def_id);
}
- Def::Mod(def_id) => {
+ Def::Def(DefKind::Mod, def_id) => {
if !external_mods.insert(def_id) {
return;
}
krate: cnum,
index: CRATE_DEF_INDEX,
};
- handle_external_def(tcx, &mut traits, &mut external_mods, Def::Mod(def_id));
+ handle_external_def(tcx, &mut traits, &mut external_mods, Def::Def(DefKind::Mod, def_id));
}
traits