Skip to content

Commit

Permalink
Prevent missing idents from causing problems down the line
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Jan 21, 2016
1 parent 0ac8915 commit 585cf6f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -3037,6 +3037,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
check_ribs: bool,
record_used: bool)
-> Option<LocalDef> {
if identifier.name == special_idents::invalid.name {
return Some(LocalDef::from_def(DefErr));
}

// First, check to see whether the name is a primitive type.
if namespace == TypeNS {
if let Some(&prim_ty) = self.primitive_type_table
Expand Down
18 changes: 13 additions & 5 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -121,7 +121,7 @@ use syntax::attr;
use syntax::attr::AttrMetaMethods;
use syntax::codemap::{self, Span, Spanned};
use syntax::errors::DiagnosticBuilder;
use syntax::parse::token::{self, InternedString};
use syntax::parse::token::{self, InternedString, special_idents};
use syntax::ptr::P;
use syntax::util::lev_distance::find_best_match_for_name;

Expand Down Expand Up @@ -2839,8 +2839,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
method_ty
}
Err(error) => {
method::report_error(fcx, method_name.span, expr_t,
method_name.node, Some(rcvr), error);
if method_name.node != special_idents::invalid.name {
method::report_error(fcx, method_name.span, expr_t,
method_name.node, Some(rcvr), error);
}
fcx.write_error(expr.id);
fcx.tcx().types.err
}
Expand Down Expand Up @@ -2938,6 +2940,11 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
None => {}
}

if field.node == special_idents::invalid.name {
fcx.write_error(expr.id);
return;
}

if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
fcx.type_error_struct(field.span,
|actual| {
Expand Down Expand Up @@ -3788,8 +3795,9 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
Some((Some(ty), slice::ref_slice(item_segment), def))
}
Err(error) => {
method::report_error(fcx, span, ty,
item_name, None, error);
if item_name != special_idents::invalid.name {
method::report_error(fcx, span, ty, item_name, None, error);
}
fcx.write_error(node_id);
None
}
Expand Down

0 comments on commit 585cf6f

Please sign in to comment.