Skip to content

Commit a85cfaa

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 0e57277 + ba0fbd7 commit a85cfaa

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(
@@ -433,12 +438,12 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
433438
&access_from!(self.save_ctxt, vis, id),
434439
Def {
435440
kind: DefKind::Const,
436-
id: ::id_from_node_id(id, &self.save_ctxt),
441+
id: id_from_node_id(id, &self.save_ctxt),
437442
span,
438443
name: ident.name.to_string(),
439444
qualname,
440445
value: ty_to_string(&typ),
441-
parent: Some(::id_from_def_id(parent_id)),
446+
parent: Some(id_from_def_id(parent_id)),
442447
children: vec![],
443448
decl_id: None,
444449
docs: self.save_ctxt.docs_for_attrs(attrs),
@@ -495,7 +500,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
495500
value,
496501
fields
497502
.iter()
498-
.map(|f| ::id_from_node_id(f.id, &self.save_ctxt))
503+
.map(|f| id_from_node_id(f.id, &self.save_ctxt))
499504
.collect(),
500505
)
501506
}
@@ -508,7 +513,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
508513
&access_from!(self.save_ctxt, item),
509514
Def {
510515
kind,
511-
id: ::id_from_node_id(item.id, &self.save_ctxt),
516+
id: id_from_node_id(item.id, &self.save_ctxt),
512517
span,
513518
name,
514519
qualname: qualname.clone(),
@@ -564,8 +569,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
564569
let value = format!("{}::{} {{ {} }}", enum_data.name, name, fields_str);
565570
if !self.span.filter_generated(name_span) {
566571
let span = self.span_from_span(name_span);
567-
let id = ::id_from_node_id(variant.node.data.id(), &self.save_ctxt);
568-
let parent = Some(::id_from_node_id(item.id, &self.save_ctxt));
572+
let id = id_from_node_id(variant.node.data.id(), &self.save_ctxt);
573+
let parent = Some(id_from_node_id(item.id, &self.save_ctxt));
569574

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

608613
self.dumper.dump_def(
609614
&access,
@@ -686,11 +691,11 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
686691
val.push_str(&bounds_to_string(trait_refs));
687692
}
688693
if !self.span.filter_generated(item.ident.span) {
689-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
694+
let id = id_from_node_id(item.id, &self.save_ctxt);
690695
let span = self.span_from_span(item.ident.span);
691696
let children = methods
692697
.iter()
693-
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
698+
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
694699
.collect();
695700
self.dumper.dump_def(
696701
&access_from!(self.save_ctxt, item),
@@ -726,14 +731,14 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
726731
self.dumper.dump_ref(Ref {
727732
kind: RefKind::Type,
728733
span: span.clone(),
729-
ref_id: ::id_from_def_id(id),
734+
ref_id: id_from_def_id(id),
730735
});
731736

732737
self.dumper.dump_relation(Relation {
733738
kind: RelationKind::SuperTrait,
734739
span,
735-
from: ::id_from_def_id(id),
736-
to: ::id_from_node_id(item.id, &self.save_ctxt),
740+
from: id_from_def_id(id),
741+
to: id_from_node_id(item.id, &self.save_ctxt),
737742
});
738743
}
739744
}
@@ -873,7 +878,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
873878
self.dumper.dump_ref(Ref {
874879
kind: RefKind::Variable,
875880
span,
876-
ref_id: ::id_from_def_id(variant.fields[index].did),
881+
ref_id: id_from_def_id(variant.fields[index].did),
877882
});
878883
}
879884
}
@@ -912,7 +917,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
912917

913918
if !self.span.filter_generated(ident.span) {
914919
let qualname = format!("{}${}", ident.to_string(), id);
915-
let id = ::id_from_node_id(id, &self.save_ctxt);
920+
let id = id_from_node_id(id, &self.save_ctxt);
916921
let span = self.span_from_span(ident.span);
917922

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

994999
self.dumper.dump_def(
@@ -1091,7 +1096,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
10911096

10921097
if !self.span.filter_generated(trait_item.ident.span) {
10931098
let span = self.span_from_span(trait_item.ident.span);
1094-
let id = ::id_from_node_id(trait_item.id, &self.save_ctxt);
1099+
let id = id_from_node_id(trait_item.id, &self.save_ctxt);
10951100

10961101
self.dumper.dump_def(
10971102
&Access {
@@ -1105,7 +1110,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11051110
name,
11061111
qualname,
11071112
value: self.span.snippet(trait_item.span),
1108-
parent: Some(::id_from_def_id(trait_id)),
1113+
parent: Some(id_from_def_id(trait_id)),
11091114
children: vec![],
11101115
decl_id: None,
11111116
docs: self.save_ctxt.docs_for_attrs(&trait_item.attrs),
@@ -1196,7 +1201,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
11961201
// The parent def id of a given use tree is always the enclosing item.
11971202
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(id)
11981203
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
1199-
.map(::id_from_def_id);
1204+
.map(id_from_def_id);
12001205

12011206
match use_tree.kind {
12021207
ast::UseTreeKind::Simple(alias, ..) => {
@@ -1212,7 +1217,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12121217

12131218
let sub_span = path.segments.last().unwrap().ident.span;
12141219
if !self.span.filter_generated(sub_span) {
1215-
let ref_id = self.lookup_def_id(id).map(|id| ::id_from_def_id(id));
1220+
let ref_id = self.lookup_def_id(id).map(|id| id_from_def_id(id));
12161221
let alias_span = alias.map(|i| self.span_from_span(i.span));
12171222
let span = self.span_from_span(sub_span);
12181223
self.dumper.import(&access, Import {
@@ -1298,10 +1303,10 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
12981303

12991304
let cm = self.tcx.sess.source_map();
13001305
let filename = cm.span_to_filename(span);
1301-
let data_id = ::id_from_node_id(id, &self.save_ctxt);
1306+
let data_id = id_from_node_id(id, &self.save_ctxt);
13021307
let children = m.items
13031308
.iter()
1304-
.map(|i| ::id_from_node_id(i.id, &self.save_ctxt))
1309+
.map(|i| id_from_node_id(i.id, &self.save_ctxt))
13051310
.collect();
13061311
let span = self.span_from_span(span);
13071312

@@ -1345,7 +1350,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13451350
let span = self.span_from_span(name_span);
13461351
let parent = self.save_ctxt.tcx.hir().opt_local_def_id(item.id)
13471352
.and_then(|id| self.save_ctxt.tcx.parent_def_id(id))
1348-
.map(::id_from_def_id);
1353+
.map(id_from_def_id);
13491354
self.dumper.import(
13501355
&Access {
13511356
public: false,
@@ -1387,7 +1392,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13871392
let value = ty_to_string(&ty);
13881393
if !self.span.filter_generated(item.ident.span) {
13891394
let span = self.span_from_span(item.ident.span);
1390-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
1395+
let id = id_from_node_id(item.id, &self.save_ctxt);
13911396

13921397
self.dumper.dump_def(
13931398
&access_from!(self.save_ctxt, item),
@@ -1417,7 +1422,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14171422
let value = String::new();
14181423
if !self.span.filter_generated(item.ident.span) {
14191424
let span = self.span_from_span(item.ident.span);
1420-
let id = ::id_from_node_id(item.id, &self.save_ctxt);
1425+
let id = id_from_node_id(item.id, &self.save_ctxt);
14211426

14221427
self.dumper.dump_def(
14231428
&access_from!(self.save_ctxt, item),
@@ -1476,7 +1481,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14761481
self.dumper.dump_ref(Ref {
14771482
kind: RefKind::Type,
14781483
span,
1479-
ref_id: ::id_from_def_id(id),
1484+
ref_id: id_from_def_id(id),
14801485
});
14811486
}
14821487

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 {
@@ -1027,7 +1013,7 @@ impl<'a> DumpHandler<'a> {
10271013
}
10281014
}
10291015

1030-
fn output_file(&self, ctx: &SaveContext) -> File {
1016+
fn output_file(&self, ctx: &SaveContext<'_, '_>) -> File {
10311017
let sess = &ctx.tcx.sess;
10321018
let file_name = match ctx.config.output_file {
10331019
Some(ref s) => PathBuf::from(s),
@@ -1178,7 +1164,7 @@ fn id_from_def_id(id: DefId) -> rls_data::Id {
11781164
}
11791165
}
11801166

1181-
fn id_from_node_id(id: NodeId, scx: &SaveContext) -> rls_data::Id {
1167+
fn id_from_node_id(id: NodeId, scx: &SaveContext<'_, '_>) -> rls_data::Id {
11821168
let def_id = scx.tcx.hir().opt_local_def_id(id);
11831169
def_id.map(|id| id_from_def_id(id)).unwrap_or_else(|| {
11841170
// Create a *fake* `DefId` out of a `NodeId` by subtracting the `NodeId`
@@ -1198,7 +1184,7 @@ fn null_id() -> rls_data::Id {
11981184
}
11991185
}
12001186

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

0 commit comments

Comments
 (0)