Skip to content

Commit 066be2a

Browse files
committed
rollup merge of #20266: nick29581/dxr-use
r? @huonw
2 parents b1dec37 + 4c4eabf commit 066be2a

File tree

4 files changed

+70
-63
lines changed

4 files changed

+70
-63
lines changed

src/librustc_trans/save/mod.rs

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
636636
item.id);
637637

638638
for field in struct_def.fields.iter() {
639-
self.process_struct_field_def(field, enum_name[], variant.node.id);
639+
self.process_struct_field_def(field, qualname[], variant.node.id);
640640
self.visit_ty(&*field.node.ty);
641641
}
642642
}
@@ -763,37 +763,38 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
763763
}
764764

765765
fn process_path(&mut self,
766-
ex: &ast::Expr,
767-
path: &ast::Path) {
766+
id: NodeId,
767+
span: Span,
768+
path: &ast::Path,
769+
ref_kind: Option<recorder::Row>) {
768770
if generated_code(path.span) {
769771
return
770772
}
771773

772774
let def_map = self.analysis.ty_cx.def_map.borrow();
773-
if !def_map.contains_key(&ex.id) {
774-
self.sess.span_bug(ex.span,
775-
format!("def_map has no key for {} in visit_expr",
776-
ex.id)[]);
775+
if !def_map.contains_key(&id) {
776+
self.sess.span_bug(span,
777+
format!("def_map has no key for {} in visit_expr", id)[]);
777778
}
778-
let def = &(*def_map)[ex.id];
779-
let sub_span = self.span.span_for_last_ident(ex.span);
779+
let def = &(*def_map)[id];
780+
let sub_span = self.span.span_for_last_ident(span);
780781
match *def {
781782
def::DefUpvar(..) |
782783
def::DefLocal(..) |
783784
def::DefStatic(..) |
784785
def::DefConst(..) |
785-
def::DefVariant(..) => self.fmt.ref_str(recorder::VarRef,
786-
ex.span,
786+
def::DefVariant(..) => self.fmt.ref_str(ref_kind.unwrap_or(recorder::VarRef),
787+
span,
787788
sub_span,
788789
def.def_id(),
789790
self.cur_scope),
790791
def::DefStruct(def_id) => self.fmt.ref_str(recorder::StructRef,
791-
ex.span,
792+
span,
792793
sub_span,
793794
def_id,
794-
self.cur_scope),
795+
self.cur_scope),
795796
def::DefStaticMethod(declid, provenence) => {
796-
let sub_span = self.span.sub_span_for_meth_name(ex.span);
797+
let sub_span = self.span.sub_span_for_meth_name(span);
797798
let defid = if declid.krate == ast::LOCAL_CRATE {
798799
let ti = ty::impl_or_trait_item(&self.analysis.ty_cx,
799800
declid);
@@ -828,34 +829,31 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
828829
} else {
829830
None
830831
};
831-
self.fmt.meth_call_str(ex.span,
832+
self.fmt.meth_call_str(span,
832833
sub_span,
833834
defid,
834835
Some(declid),
835836
self.cur_scope);
836837
},
837-
def::DefFn(def_id, _) => self.fmt.fn_call_str(ex.span,
838-
sub_span,
839-
def_id,
840-
self.cur_scope),
841-
_ => self.sess.span_bug(ex.span,
838+
def::DefFn(def_id, _) => self.fmt.fn_call_str(span,
839+
sub_span,
840+
def_id,
841+
self.cur_scope),
842+
_ => self.sess.span_bug(span,
842843
format!("Unexpected def kind while looking up path in '{}'",
843-
self.span.snippet(ex.span))[]),
844+
self.span.snippet(span))[]),
844845
}
845846
// modules or types in the path prefix
846847
match *def {
847-
def::DefStaticMethod(..) => {
848-
self.write_sub_path_trait_truncated(path);
849-
},
848+
def::DefStaticMethod(..) => self.write_sub_path_trait_truncated(path),
850849
def::DefLocal(_) |
851850
def::DefStatic(_,_) |
852851
def::DefConst(..) |
853852
def::DefStruct(_) |
853+
def::DefVariant(..) |
854854
def::DefFn(..) => self.write_sub_paths_truncated(path),
855855
_ => {},
856856
}
857-
858-
visit::walk_path(self, path);
859857
}
860858

861859
fn process_struct_lit(&mut self,
@@ -982,18 +980,19 @@ impl <'l, 'tcx> DxrVisitor<'l, 'tcx> {
982980
}
983981
};
984982
for &Spanned { node: ref field, span } in fields.iter() {
985-
self.visit_pat(&*field.pat);
983+
let sub_span = self.span.span_for_first_ident(span);
986984
let fields = ty::lookup_struct_fields(&self.analysis.ty_cx, struct_def);
987985
for f in fields.iter() {
988986
if f.name == field.ident.name {
989987
self.fmt.ref_str(recorder::VarRef,
990-
p.span,
991-
Some(span),
988+
span,
989+
sub_span,
992990
f.id,
993991
self.cur_scope);
994992
break;
995993
}
996994
}
995+
self.visit_pat(&*field.pat);
997996
}
998997
}
999998
ast::PatEnum(ref path, _) => {
@@ -1162,8 +1161,8 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11621161
}
11631162

11641163
match i.node {
1165-
ast::ViewItemUse(ref path) => {
1166-
match path.node {
1164+
ast::ViewItemUse(ref item) => {
1165+
match item.node {
11671166
ast::ViewPathSimple(ident, ref path, id) => {
11681167
let sub_span = self.span.span_for_last_ident(path.span);
11691168
let mod_id = match self.lookup_type_ref(id) {
@@ -1184,7 +1183,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
11841183
// 'use' always introduces an alias, if there is not an explicit
11851184
// one, there is an implicit one.
11861185
let sub_span =
1187-
match self.span.sub_span_before_token(path.span, token::Eq) {
1186+
match self.span.sub_span_after_keyword(item.span, keywords::As) {
11881187
Some(sub_span) => Some(sub_span),
11891188
None => sub_span,
11901189
};
@@ -1308,7 +1307,10 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
13081307
// because just walking the callee path does what we want.
13091308
visit::walk_expr(self, ex);
13101309
},
1311-
ast::ExprPath(ref path) => self.process_path(ex, path),
1310+
ast::ExprPath(ref path) => {
1311+
self.process_path(ex.id, ex.span, path, None);
1312+
visit::walk_path(self, path);
1313+
}
13121314
ast::ExprStruct(ref path, ref fields, ref base) =>
13131315
self.process_struct_lit(ex, path, fields, base),
13141316
ast::ExprMethodCall(_, _, ref args) => self.process_method_call(ex, args),
@@ -1405,46 +1407,50 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
14051407
fn visit_arm(&mut self, arm: &ast::Arm) {
14061408
assert!(self.collected_paths.len() == 0 && !self.collecting);
14071409
self.collecting = true;
1408-
14091410
for pattern in arm.pats.iter() {
14101411
// collect paths from the arm's patterns
14111412
self.visit_pat(&**pattern);
14121413
}
1413-
self.collecting = false;
1414+
1415+
// This is to get around borrow checking, because we need mut self to call process_path.
1416+
let mut paths_to_process = vec![];
14141417
// process collected paths
14151418
for &(id, ref p, ref immut, ref_kind) in self.collected_paths.iter() {
1416-
let value = if *immut {
1417-
self.span.snippet(p.span).to_string()
1418-
} else {
1419-
"<mutable>".to_string()
1420-
};
1421-
let sub_span = self.span.span_for_first_ident(p.span);
14221419
let def_map = self.analysis.ty_cx.def_map.borrow();
14231420
if !def_map.contains_key(&id) {
14241421
self.sess.span_bug(p.span,
1425-
format!("def_map has no key for {} in visit_arm",
1426-
id)[]);
1422+
format!("def_map has no key for {} in visit_arm", id)[]);
14271423
}
14281424
let def = &(*def_map)[id];
14291425
match *def {
1430-
def::DefLocal(id) => self.fmt.variable_str(p.span,
1431-
sub_span,
1432-
id,
1433-
path_to_string(p)[],
1434-
value[],
1435-
""),
1436-
def::DefVariant(_,id,_) => self.fmt.ref_str(ref_kind,
1437-
p.span,
1438-
sub_span,
1439-
id,
1440-
self.cur_scope),
1441-
// FIXME(nrc) what is this doing here?
1426+
def::DefLocal(id) => {
1427+
let value = if *immut {
1428+
self.span.snippet(p.span).to_string()
1429+
} else {
1430+
"<mutable>".to_string()
1431+
};
1432+
1433+
assert!(p.segments.len() == 1, "qualified path for local variable def in arm");
1434+
self.fmt.variable_str(p.span,
1435+
Some(p.span),
1436+
id,
1437+
path_to_string(p)[],
1438+
value[],
1439+
"")
1440+
}
1441+
def::DefVariant(..) => {
1442+
paths_to_process.push((id, p.span, p.clone(), Some(ref_kind)))
1443+
}
1444+
// FIXME(nrc) what are these doing here?
14421445
def::DefStatic(_, _) => {}
14431446
def::DefConst(..) => {}
1444-
_ => error!("unexpected definition kind when processing collected paths: {}",
1445-
*def)
1447+
_ => error!("unexpected definition kind when processing collected paths: {}", *def)
14461448
}
14471449
}
1450+
for &(id, span, ref path, ref_kind) in paths_to_process.iter() {
1451+
self.process_path(id, span, path, ref_kind);
1452+
}
1453+
self.collecting = false;
14481454
self.collected_paths.clear();
14491455
visit::walk_expr_opt(self, &arm.guard);
14501456
self.visit_expr(&*arm.body);

src/librustc_trans/save/recorder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ macro_rules! svec {
6161
})
6262
}
6363

64-
#[deriving(Copy)]
64+
#[deriving(Copy,Show)]
6565
pub enum Row {
6666
Variable,
6767
Enum,

src/librustc_trans/save/span_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ impl<'a> SpanUtils<'a> {
294294
}
295295

296296
pub fn sub_span_after_keyword(&self,
297-
span: Span,
298-
keyword: keywords::Keyword) -> Option<Span> {
297+
span: Span,
298+
keyword: keywords::Keyword) -> Option<Span> {
299299
let mut toks = self.retokenise_span(span);
300300
loop {
301301
let ts = toks.real_token();

src/libsyntax/parse/parser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5977,7 +5977,7 @@ impl<'a> Parser<'a> {
59775977
}
59785978

59795979

5980-
/// Matches view_path : MOD? IDENT EQ non_global_path
5980+
/// Matches view_path : MOD? non_global_path as IDENT
59815981
/// | MOD? non_global_path MOD_SEP LBRACE RBRACE
59825982
/// | MOD? non_global_path MOD_SEP LBRACE ident_seq RBRACE
59835983
/// | MOD? non_global_path MOD_SEP STAR
@@ -6089,7 +6089,7 @@ impl<'a> Parser<'a> {
60896089
}
60906090
let mut rename_to = path[path.len() - 1u];
60916091
let path = ast::Path {
6092-
span: mk_sp(lo, self.span.hi),
6092+
span: mk_sp(lo, self.last_span.hi),
60936093
global: false,
60946094
segments: path.into_iter().map(|identifier| {
60956095
ast::PathSegment {
@@ -6101,7 +6101,8 @@ impl<'a> Parser<'a> {
61016101
if self.eat_keyword(keywords::As) {
61026102
rename_to = self.parse_ident()
61036103
}
6104-
P(spanned(lo, self.last_span.hi,
6104+
P(spanned(lo,
6105+
self.last_span.hi,
61056106
ViewPathSimple(rename_to, path, ast::DUMMY_NODE_ID)))
61066107
}
61076108

0 commit comments

Comments
 (0)