Skip to content

Commit 585cf6f

Browse files
committed
Prevent missing idents from causing problems down the line
1 parent 0ac8915 commit 585cf6f

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/librustc_resolve/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,6 +3037,10 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
30373037
check_ribs: bool,
30383038
record_used: bool)
30393039
-> Option<LocalDef> {
3040+
if identifier.name == special_idents::invalid.name {
3041+
return Some(LocalDef::from_def(DefErr));
3042+
}
3043+
30403044
// First, check to see whether the name is a primitive type.
30413045
if namespace == TypeNS {
30423046
if let Some(&prim_ty) = self.primitive_type_table

src/librustc_typeck/check/mod.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ use syntax::attr;
121121
use syntax::attr::AttrMetaMethods;
122122
use syntax::codemap::{self, Span, Spanned};
123123
use syntax::errors::DiagnosticBuilder;
124-
use syntax::parse::token::{self, InternedString};
124+
use syntax::parse::token::{self, InternedString, special_idents};
125125
use syntax::ptr::P;
126126
use syntax::util::lev_distance::find_best_match_for_name;
127127

@@ -2839,8 +2839,10 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
28392839
method_ty
28402840
}
28412841
Err(error) => {
2842-
method::report_error(fcx, method_name.span, expr_t,
2843-
method_name.node, Some(rcvr), error);
2842+
if method_name.node != special_idents::invalid.name {
2843+
method::report_error(fcx, method_name.span, expr_t,
2844+
method_name.node, Some(rcvr), error);
2845+
}
28442846
fcx.write_error(expr.id);
28452847
fcx.tcx().types.err
28462848
}
@@ -2938,6 +2940,11 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
29382940
None => {}
29392941
}
29402942

2943+
if field.node == special_idents::invalid.name {
2944+
fcx.write_error(expr.id);
2945+
return;
2946+
}
2947+
29412948
if method::exists(fcx, field.span, field.node, expr_t, expr.id) {
29422949
fcx.type_error_struct(field.span,
29432950
|actual| {
@@ -3788,8 +3795,9 @@ pub fn resolve_ty_and_def_ufcs<'a, 'b, 'tcx>(fcx: &FnCtxt<'b, 'tcx>,
37883795
Some((Some(ty), slice::ref_slice(item_segment), def))
37893796
}
37903797
Err(error) => {
3791-
method::report_error(fcx, span, ty,
3792-
item_name, None, error);
3798+
if item_name != special_idents::invalid.name {
3799+
method::report_error(fcx, span, ty, item_name, None, error);
3800+
}
37933801
fcx.write_error(node_id);
37943802
None
37953803
}

0 commit comments

Comments
 (0)