Skip to content

Commit 2b8ed1e

Browse files
authored
Rollup merge of rust-lang#58233 - taiki-e:librustc_save_analysis-2018, r=Centril
librustc_save_analysis => 2018 Transitions `librustc_save_analysis` to Rust 2018; cc rust-lang#58099 r? @Centril
2 parents 5b4cf9b + ba0fbd7 commit 2b8ed1e

File tree

6 files changed

+79
-82
lines changed

6 files changed

+79
-82
lines changed

src/librustc_save_analysis/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "rustc_save_analysis"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
name = "rustc_save_analysis"

src/librustc_save_analysis/dump_visitor.rs

+39-34
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use rustc::hir::def::Def as HirDef;
1717
use rustc::hir::def_id::DefId;
1818
use rustc::session::config::Input;
19+
use rustc::span_bug;
1920
use rustc::ty::{self, TyCtxt};
2021
use rustc_data_structures::fx::FxHashSet;
2122

@@ -32,16 +33,20 @@ use syntax::print::pprust::{
3233
};
3334
use syntax::ptr::P;
3435
use syntax::source_map::{Spanned, DUMMY_SP, respan};
36+
use syntax::walk_list;
3537
use syntax_pos::*;
3638

37-
use {escape, generated_code, lower_attributes, PathCollector, SaveContext};
38-
use json_dumper::{Access, DumpOutput, JsonDumper};
39-
use span_utils::SpanUtils;
40-
use sig;
39+
use crate::{escape, generated_code, id_from_def_id, id_from_node_id, lower_attributes,
40+
PathCollector, SaveContext};
41+
use crate::json_dumper::{Access, DumpOutput, JsonDumper};
42+
use crate::span_utils::SpanUtils;
43+
use crate::sig;
4144

4245
use rls_data::{CompilationOptions, CratePreludeData, Def, DefKind, GlobalCrateId, Import,
4346
ImportKind, Ref, RefKind, Relation, RelationKind, SpanData};
4447

48+
use log::{debug, error};
49+
4550
macro_rules! down_cast_data {
4651
($id:ident, $kind:ident, $sp:expr) => {
4752
let $id = if let super::Data::$kind(data) = $id {
@@ -68,7 +73,7 @@ macro_rules! access_from {
6873
};
6974
}
7075

71-
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> {
76+
pub struct DumpVisitor<'l, 'tcx: 'l, 'll, O: DumpOutput> {
7277
save_ctxt: SaveContext<'l, 'tcx>,
7378
tcx: TyCtxt<'l, 'tcx, 'tcx>,
7479
dumper: &'ll mut JsonDumper<O>,
@@ -245,7 +250,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
245250
None => continue,
246251
};
247252
if !self.span.filter_generated(ident.span) {
248-
let id = ::id_from_node_id(id, &self.save_ctxt);
253+
let id = id_from_node_id(id, &self.save_ctxt);
249254
let span = self.span_from_span(ident.span);
250255

251256
self.dumper.dump_def(
@@ -286,7 +291,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
286291
debug!("process_method: {}:{}", id, ident);
287292

288293
if let Some(mut method_data) = self.save_ctxt.get_method_data(id, ident, span) {
289-
let sig_str = ::make_signature(&sig.decl, &generics);
294+
let sig_str = crate::make_signature(&sig.decl, &generics);
290295
if body.is_some() {
291296
self.nest_tables(
292297
id,
@@ -339,7 +344,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
339344
// Append $id to name to make sure each one is unique.
340345
let qualname = format!("{}::{}${}", prefix, name, id);
341346
if !self.span.filter_generated(param_ss) {
342-
let id = ::id_from_node_id(param.id, &self.save_ctxt);
347+
let id = id_from_node_id(param.id, &self.save_ctxt);
343348
let span = self.span_from_span(param_ss);
344349

345350
self.dumper.dump_def(
@@ -434,12 +439,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
434439
&access_from!(self.save_ctxt, vis, id),
435440
Def {
436441
kind: DefKind::Const,
437-
id: ::id_from_node_id(id, &self.save_ctxt),
442+
id: id_from_node_id(id, &self.save_ctxt),
438443
span,
439444
name: ident.name.to_string(),
440445
qualname,
441446
value: ty_to_string(&typ),
442-
parent: Some(::id_from_def_id(parent_id)),
447+
parent: Some(id_from_def_id(parent_id)),
443448
children: vec![],
444449
decl_id: None,
445450
docs: self.save_ctxt.docs_for_attrs(attrs),
@@ -496,7 +501,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
496501
value,
497502
fields
498503
.iter()
499-
.map(|f| ::id_from_node_id(f.id, &self.save_ctxt))
504+
.map(|f| id_from_node_id(f.id, &self.save_ctxt))
500505
.collect(),
501506
)
502507
}
@@ -509,7 +514,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
509514
&access_from!(self.save_ctxt, item),
510515
Def {
511516
kind,
512-
id: ::id_from_node_id(item.id, &self.save_ctxt),
517+
id: id_from_node_id(item.id, &self.save_ctxt),
513518
span,
514519
name,
515520
qualname: qualname.clone(),
@@ -565,8 +570,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
565570
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
566571
if !self.span.filter_generated(name_span) {
567572
let span = self.span_from_span(name_span);
568-
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
569-
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
573+
let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt);
574+
let parent = Some(id_from_node_id(item.id, &self.save_ctxt));
570575

571576
self.dumper.dump_def(
572577
&access,
@@ -603,8 +608,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
603608
}
604609
if !self.span.filter_generated(name_span) {
605610
let span = self.span_from_span(name_span);
606-
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
607-
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
611+
let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt);
612+
let parent = Some(id_from_node_id(item.id, &self.save_ctxt));
608613

609614
self.dumper.dump_def(
610615
&access,
@@ -687,11 +692,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
687692
val.push_str(&bounds_to_string(trait_refs));
688693
}
689694
if !self.span.filter_generated(item.ident.span) {
690-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
695+
let id = id_from_node_id(item.id, &self.save_ctxt);
691696
let span = self.span_from_span(item.ident.span);
692697
let children = methods
693698
.iter()
694-
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
699+
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
695700
.collect();
696701
self.dumper.dump_def(
697702
&access_from!(self.save_ctxt, item),
@@ -727,14 +732,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
727732
self.dumper.dump_ref(Ref {
728733
kind: RefKind::Type,
729734
span: span.clone(),
730-
ref_id: ::id_from_def_id(id),
735+
ref_id: id_from_def_id(id),
731736
});
732737

733738
self.dumper.dump_relation(Relation {
734739
kind: RelationKind::SuperTrait,
735740
span,
736-
from: ::id_from_def_id(id),
737-
to: ::id_from_node_id(item.id, &self.save_ctxt),
741+
from: id_from_def_id(id),
742+
to: id_from_node_id(item.id, &self.save_ctxt),
738743
});
739744
}
740745
}
@@ -874,7 +879,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
874879
self.dumper.dump_ref(Ref {
875880
kind: RefKind::Variable,
876881
span,
877-
ref_id: ::id_from_def_id(variant.fields[index].did),
882+
ref_id: id_from_def_id(variant.fields[index].did),
878883
});
879884
}
880885
}
@@ -913,7 +918,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
913918

914919
if !self.span.filter_generated(ident.span) {
915920
let qualname = format!("{}${}", ident.to_string(), id);
916-
let id = ::id_from_node_id(id, &self.save_ctxt);
921+
let id = id_from_node_id(id, &self.save_ctxt);
917922
let span = self.span_from_span(ident.span);
918923

919924
self.dumper.dump_def(
@@ -989,7 +994,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
989994
// Rust uses the id of the pattern for var lookups, so we'll use it too.
990995
if !self.span.filter_generated(ident.span) {
991996
let qualname = format!("{}${}", ident.to_string(), id);
992-
let id = ::id_from_node_id(id, &self.save_ctxt);
997+
let id = id_from_node_id(id, &self.save_ctxt);
993998
let span = self.span_from_span(ident.span);
994999

9951000
self.dumper.dump_def(
@@ -1092,7 +1097,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10921097

10931098
if !self.span.filter_generated(trait_item.ident.span) {
10941099
let span = self.span_from_span(trait_item.ident.span);
1095-
let id = ::id_from_node_id(trait_item.id, &self.save_ctxt);
1100+
let id = id_from_node_id(trait_item.id, &self.save_ctxt);
10961101

10971102
self.dumper.dump_def(
10981103
&Access {
@@ -1106,7 +1111,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11061111
name,
11071112
qualname,
11081113
value: self.span.snippet(trait_item.span),
1109-
parent: Some(::id_from_def_id(trait_id)),
1114+
parent: Some(id_from_def_id(trait_id)),
11101115
children: vec![],
11111116
decl_id: None,
11121117
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
@@ -1197,7 +1202,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11971202
// The parent def id of a given use tree is always the enclosing item.
11981203
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id)
11991204
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
1200-
.map(::id_from_def_id);
1205+
.map(id_from_def_id);
12011206

12021207
match use_tree.kind {
12031208
ast::UseTreeKind::Simple(alias, ..) => {
@@ -1213,7 +1218,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12131218

12141219
let sub_span = path.segments.last().unwrap().ident.span;
12151220
if !self.span.filter_generated(sub_span) {
1216-
let ref_id = self.lookup_def_id(id).map(|id| ::id_from_def_id(id));
1221+
let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id));
12171222
let alias_span = alias.map(|i| self.span_from_span(i.span));
12181223
let span = self.span_from_span(sub_span);
12191224
self.dumper.import(&access, Import {
@@ -1299,10 +1304,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
12991304

13001305
let cm = self.tcx.sess.source_map();
13011306
let filename = cm.span_to_filename(span);
1302-
let data_id = ::id_from_node_id(id, &self.save_ctxt);
1307+
let data_id = id_from_node_id(id, &self.save_ctxt);
13031308
let children = m.items
13041309
.iter()
1305-
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
1310+
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
13061311
.collect();
13071312
let span = self.span_from_span(span);
13081313

@@ -1346,7 +1351,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13461351
let span = self.span_from_span(name_span);
13471352
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(item.id)
13481353
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
1349-
.map(::id_from_def_id);
1354+
.map(id_from_def_id);
13501355
self.dumper.import(
13511356
&Access {
13521357
public: false,
@@ -1388,7 +1393,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13881393
let value = ty_to_string(&ty);
13891394
if !self.span.filter_generated(item.ident.span) {
13901395
let span = self.span_from_span(item.ident.span);
1391-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
1396+
let id = id_from_node_id(item.id, &self.save_ctxt);
13921397

13931398
self.dumper.dump_def(
13941399
&access_from!(self.save_ctxt, item),
@@ -1418,7 +1423,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14181423
let value = String::new();
14191424
if !self.span.filter_generated(item.ident.span) {
14201425
let span = self.span_from_span(item.ident.span);
1421-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
1426+
let id = id_from_node_id(item.id, &self.save_ctxt);
14221427

14231428
self.dumper.dump_def(
14241429
&access_from!(self.save_ctxt, item),
@@ -1484,7 +1489,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14841489
self.dumper.dump_ref(Ref {
14851490
kind: RefKind::Type,
14861491
span,
1487-
ref_id: ::id_from_def_id(id),
1492+
ref_id: id_from_def_id(id),
14881493
});
14891494
}
14901495

src/librustc_save_analysis/json_dumper.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use rls_data::{self, Analysis, CompilationOptions, CratePreludeData, Def, DefKin
77
MacroRef, Ref, RefKind, Relation};
88
use rls_span::{Column, Row};
99

10+
use log::error;
11+
1012
#[derive(Debug)]
1113
pub struct Access {
1214
pub reachable: bool,
@@ -23,7 +25,7 @@ pub trait DumpOutput {
2325
fn dump(&mut self, result: &Analysis);
2426
}
2527

26-
pub struct WriteOutput<'b, W: Write + 'b> {
28+
pub struct WriteOutput<'b, W: Write> {
2729
output: &'b mut W,
2830
}
2931

src/librustc_save_analysis/lib.rs

+8-22
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,10 @@
11
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
22
#![feature(custom_attribute)]
3-
#![feature(nll)]
3+
#![deny(rust_2018_idioms)]
44
#![allow(unused_attributes)]
55

66
#![recursion_limit="256"]
77

8-
#[macro_use]
9-
extern crate rustc;
10-
11-
#[macro_use]
12-
extern crate log;
13-
extern crate rustc_data_structures;
14-
extern crate rustc_codegen_utils;
15-
extern crate rustc_serialize;
16-
extern crate rustc_target;
17-
extern crate rustc_typeck;
18-
#[macro_use]
19-
extern crate syntax;
20-
extern crate syntax_pos;
21-
22-
extern crate rls_data;
23-
extern crate rls_span;
24-
258

269
mod json_dumper;
2710
mod dump_visitor;
@@ -37,6 +20,7 @@ use rustc::middle::privacy::AccessLevels;
3720
use rustc::middle::cstore::ExternCrate;
3821
use rustc::session::config::{CrateType, Input, OutputType};
3922
use rustc::ty::{self, TyCtxt};
23+
use rustc::{bug, span_bug};
4024
use rustc_typeck::hir_ty_to_ty;
4125
use rustc_codegen_utils::link::{filename_for_metadata, out_filename};
4226
use rustc_data_structures::sync::Lrc;
@@ -64,6 +48,8 @@ use rls_data::{Def, DefKind, ExternalCrateData, GlobalCrateId, MacroRef, Ref, Re
6448
RelationKind, SpanData, Impl, ImplKind};
6549
use rls_data::config::Config;
6650

51+
use log::{debug, error, info};
52+
6753

6854
pub struct SaveContext<'l, 'tcx: 'l> {
6955
tcx: TyCtxt<'l, 'tcx, 'tcx>,
@@ -170,7 +156,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
170156
ast::ForeignItemKind::Static(ref ty, _) => {
171157
filter!(self.span_utils, item.ident.span);
172158

173-
let id = ::id_from_node_id(item.id, self);
159+
let id = id_from_node_id(item.id, self);
174160
let span = self.span_from_span(item.ident.span);
175161

176162
Some(Data::DefData(Def {
@@ -1034,7 +1020,7 @@ impl<'a> DumpHandler<'a> {
10341020
}
10351021
}
10361022

1037-
fn output_file(&self, ctx: &SaveContext) -> File {
1023+
fn output_file(&self, ctx: &SaveContext<'_, '_>) -> File {
10381024
let sess = &ctx.tcx.sess;
10391025
let file_name = match ctx.config.output_file {
10401026
Some(ref s) => PathBuf::from(s),
@@ -1185,7 +1171,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
11851171
}
11861172
}
11871173

1188-
fn id_from_node_id(id: NodeId, scx: &SaveContext) -> rls_data::Id {
1174+
fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
11891175
let def_id = scx.tcx.hir().opt_local_def_id(id);
11901176
def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| {
11911177
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
@@ -1205,7 +1191,7 @@ fn null_id() -> rls_data::Id {
12051191
}
12061192
}
12071193

1208-
fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext) -> Vec<rls_data::Attribute> {
1194+
fn lower_attributes(attrs: Vec<Attribute>, scx: &SaveContext<'_, '_>) -> Vec<rls_data::Attribute> {
12091195
attrs.into_iter()
12101196
// Only retain real attributes. Doc comments are lowered separately.
12111197
.filter(|attr| attr.path != "doc")

0 commit comments

Comments
 (0)