Skip to content

Commit 9295454

Browse files
committed
rustdoc: fix fallout from using ptr::P.
1 parent b062128 commit 9295454

File tree

5 files changed

+127
-154
lines changed

5 files changed

+127
-154
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use syntax::attr::{AttributeMethods, AttrMetaMethods};
2020
use syntax::codemap::Pos;
2121
use syntax::parse::token::InternedString;
2222
use syntax::parse::token;
23+
use syntax::ptr::P;
2324

2425
use rustc::back::link;
2526
use rustc::driver::driver;
@@ -34,7 +35,6 @@ use rustc::middle::stability;
3435

3536
use std::rc::Rc;
3637
use std::u32;
37-
use std::gc::{Gc, GC};
3838

3939
use core::DocContext;
4040
use doctree;
@@ -67,7 +67,7 @@ impl<T: Clean<U>, U> Clean<VecPerParamSpace<U>> for VecPerParamSpace<T> {
6767
}
6868
}
6969

70-
impl<T: 'static + Clean<U>, U> Clean<U> for Gc<T> {
70+
impl<T: Clean<U>, U> Clean<U> for P<T> {
7171
fn clean(&self, cx: &DocContext) -> U {
7272
(**self).clean(cx)
7373
}
@@ -408,7 +408,7 @@ impl Clean<Attribute> for ast::MetaItem {
408408

409409
impl Clean<Attribute> for ast::Attribute {
410410
fn clean(&self, cx: &DocContext) -> Attribute {
411-
self.desugar_doc().node.value.clean(cx)
411+
self.with_desugared_doc(|a| a.node.value.clean(cx))
412412
}
413413
}
414414

@@ -430,12 +430,12 @@ impl attr::AttrMetaMethods for Attribute {
430430
_ => None,
431431
}
432432
}
433-
fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
433+
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
434434
}
435435
impl<'a> attr::AttrMetaMethods for &'a Attribute {
436436
fn name(&self) -> InternedString { (**self).name() }
437437
fn value_str(&self) -> Option<InternedString> { (**self).value_str() }
438-
fn meta_item_list<'a>(&'a self) -> Option<&'a [Gc<ast::MetaItem>]> { None }
438+
fn meta_item_list<'a>(&'a self) -> Option<&'a [P<ast::MetaItem>]> { None }
439439
}
440440

441441
#[deriving(Clone, Encodable, Decodable, PartialEq)]
@@ -758,10 +758,10 @@ impl Clean<SelfTy> for ast::ExplicitSelf_ {
758758
match *self {
759759
ast::SelfStatic => SelfStatic,
760760
ast::SelfValue(_) => SelfValue,
761-
ast::SelfRegion(lt, mt, _) => {
761+
ast::SelfRegion(ref lt, ref mt, _) => {
762762
SelfBorrowed(lt.clean(cx), mt.clean(cx))
763763
}
764-
ast::SelfExplicit(typ, _) => SelfExplicit(typ.clean(cx)),
764+
ast::SelfExplicit(ref typ, _) => SelfExplicit(typ.clean(cx)),
765765
}
766766
}
767767
}
@@ -1189,11 +1189,11 @@ impl Clean<Type> for ast::Ty {
11891189
TyRptr(ref l, ref m) =>
11901190
BorrowedRef {lifetime: l.clean(cx), mutability: m.mutbl.clean(cx),
11911191
type_: box m.ty.clean(cx)},
1192-
TyBox(ty) => Managed(box ty.clean(cx)),
1193-
TyUniq(ty) => Unique(box ty.clean(cx)),
1194-
TyVec(ty) => Vector(box ty.clean(cx)),
1195-
TyFixedLengthVec(ty, ref e) => FixedVector(box ty.clean(cx),
1196-
e.span.to_src(cx)),
1192+
TyBox(ref ty) => Managed(box ty.clean(cx)),
1193+
TyUniq(ref ty) => Unique(box ty.clean(cx)),
1194+
TyVec(ref ty) => Vector(box ty.clean(cx)),
1195+
TyFixedLengthVec(ref ty, ref e) => FixedVector(box ty.clean(cx),
1196+
e.span.to_src(cx)),
11971197
TyTup(ref tys) => Tuple(tys.clean(cx)),
11981198
TyPath(ref p, ref tpbs, id) => {
11991199
resolve_type(cx, p.clean(cx), tpbs.clean(cx), id)
@@ -1799,7 +1799,7 @@ impl Clean<Vec<Item>> for ast::ViewItem {
17991799
remaining,
18001800
b.clone());
18011801
let path = syntax::codemap::dummy_spanned(path);
1802-
ret.push(convert(&ast::ViewItemUse(box(GC) path)));
1802+
ret.push(convert(&ast::ViewItemUse(P(path))));
18031803
}
18041804
}
18051805
ast::ViewPathSimple(ident, _, id) => {
@@ -1985,8 +1985,8 @@ fn name_from_pat(p: &ast::Pat) -> String {
19851985
},
19861986
PatTup(ref elts) => format!("({})", elts.iter().map(|p| name_from_pat(&**p))
19871987
.collect::<Vec<String>>().connect(", ")),
1988-
PatBox(p) => name_from_pat(&*p),
1989-
PatRegion(p) => name_from_pat(&*p),
1988+
PatBox(ref p) => name_from_pat(&**p),
1989+
PatRegion(ref p) => name_from_pat(&**p),
19901990
PatLit(..) => {
19911991
warn!("tried to get argument name from PatLit, \
19921992
which is silly in function arguments");

src/librustdoc/core.rs

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc;
12-
use rustc::{driver, middle};
11+
use rustc::driver::{config, driver, session};
1312
use rustc::middle::{privacy, ty};
1413
use rustc::lint;
1514
use rustc::back::link;
1615

17-
use syntax::ast;
16+
use syntax::{ast, ast_map, codemap, diagnostic};
1817
use syntax::parse::token;
19-
use syntax;
18+
use syntax::ptr::P;
2019

2120
use std::cell::RefCell;
22-
use std::gc::GC;
2321
use std::os;
2422
use std::collections::{HashMap, HashSet};
2523
use arena::TypedArena;
@@ -30,15 +28,15 @@ use clean::Clean;
3028

3129
/// Are we generating documentation (`Typed`) or tests (`NotTyped`)?
3230
pub enum MaybeTyped<'tcx> {
33-
Typed(middle::ty::ctxt<'tcx>),
34-
NotTyped(driver::session::Session)
31+
Typed(ty::ctxt<'tcx>),
32+
NotTyped(session::Session)
3533
}
3634

3735
pub type ExternalPaths = RefCell<Option<HashMap<ast::DefId,
3836
(Vec<String>, clean::TypeKind)>>>;
3937

4038
pub struct DocContext<'tcx> {
41-
pub krate: ast::Crate,
39+
pub krate: &'tcx ast::Crate,
4240
pub maybe_typed: MaybeTyped<'tcx>,
4341
pub src: Path,
4442
pub external_paths: ExternalPaths,
@@ -49,7 +47,7 @@ pub struct DocContext<'tcx> {
4947
}
5048

5149
impl<'tcx> DocContext<'tcx> {
52-
pub fn sess<'a>(&'a self) -> &'a driver::session::Session {
50+
pub fn sess<'a>(&'a self) -> &'a session::Session {
5351
match self.maybe_typed {
5452
Typed(ref tcx) => &tcx.sess,
5553
NotTyped(ref sess) => sess
@@ -80,91 +78,82 @@ pub struct CrateAnalysis {
8078

8179
pub type Externs = HashMap<String, Vec<String>>;
8280

83-
/// Parses, resolves, and typechecks the given crate
84-
fn get_ast_and_resolve<'tcx>(cpath: &Path, libs: Vec<Path>, cfgs: Vec<String>,
85-
externs: Externs, triple: Option<String>,
86-
type_arena: &'tcx TypedArena<ty::t_box_>)
87-
-> (DocContext<'tcx>, CrateAnalysis) {
88-
use syntax::codemap::dummy_spanned;
89-
use rustc::driver::driver::{FileInput,
90-
phase_1_parse_input,
91-
phase_2_configure_and_expand,
92-
phase_3_run_analysis_passes};
93-
use rustc::driver::config::build_configuration;
81+
pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
82+
cpath: &Path, triple: Option<String>)
83+
-> (clean::Crate, CrateAnalysis) {
9484

95-
let input = FileInput(cpath.clone());
85+
// Parse, resolve, and typecheck the given crate.
86+
87+
let input = driver::FileInput(cpath.clone());
9688

9789
let warning_lint = lint::builtin::WARNINGS.name_lower();
9890

99-
let sessopts = driver::config::Options {
91+
let sessopts = config::Options {
10092
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
10193
addl_lib_search_paths: RefCell::new(libs),
102-
crate_types: vec!(driver::config::CrateTypeRlib),
94+
crate_types: vec!(config::CrateTypeRlib),
10395
lint_opts: vec!((warning_lint, lint::Allow)),
10496
externs: externs,
105-
target_triple: triple.unwrap_or(driver::driver::host_triple().to_string()),
106-
..rustc::driver::config::basic_options().clone()
97+
target_triple: triple.unwrap_or(driver::host_triple().to_string()),
98+
..config::basic_options().clone()
10799
};
108100

109101

110-
let codemap = syntax::codemap::CodeMap::new();
111-
let diagnostic_handler = syntax::diagnostic::default_handler(syntax::diagnostic::Auto, None);
102+
let codemap = codemap::CodeMap::new();
103+
let diagnostic_handler = diagnostic::default_handler(diagnostic::Auto, None);
112104
let span_diagnostic_handler =
113-
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);
105+
diagnostic::mk_span_handler(diagnostic_handler, codemap);
114106

115-
let sess = driver::session::build_session_(sessopts,
116-
Some(cpath.clone()),
117-
span_diagnostic_handler);
107+
let sess = session::build_session_(sessopts,
108+
Some(cpath.clone()),
109+
span_diagnostic_handler);
118110

119-
let mut cfg = build_configuration(&sess);
111+
let mut cfg = config::build_configuration(&sess);
120112
for cfg_ in cfgs.move_iter() {
121113
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
122-
cfg.push(box(GC) dummy_spanned(ast::MetaWord(cfg_)));
114+
cfg.push(P(codemap::dummy_spanned(ast::MetaWord(cfg_))));
123115
}
124116

125-
let krate = phase_1_parse_input(&sess, cfg, &input);
117+
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
126118

127119
let name = link::find_crate_name(Some(&sess), krate.attrs.as_slice(),
128120
&input);
129121

130-
let (krate, ast_map)
131-
= phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
132-
.expect("phase_2_configure_and_expand aborted in rustdoc!");
122+
let krate = driver::phase_2_configure_and_expand(&sess, krate, name.as_slice(), None)
123+
.expect("phase_2_configure_and_expand aborted in rustdoc!");
124+
125+
let mut forest = ast_map::Forest::new(krate);
126+
let ast_map = driver::assign_node_ids_and_map(&sess, &mut forest);
133127

134-
let driver::driver::CrateAnalysis {
128+
let type_arena = TypedArena::new();
129+
let driver::CrateAnalysis {
135130
exported_items, public_items, ty_cx, ..
136-
} = phase_3_run_analysis_passes(sess, &krate, ast_map, type_arena, name);
131+
} = driver::phase_3_run_analysis_passes(sess, ast_map, &type_arena, name);
137132

138-
debug!("crate: {:?}", krate);
139-
(DocContext {
140-
krate: krate,
133+
let ctxt = DocContext {
134+
krate: ty_cx.map.krate(),
141135
maybe_typed: Typed(ty_cx),
142136
src: cpath.clone(),
143137
external_traits: RefCell::new(Some(HashMap::new())),
144138
external_typarams: RefCell::new(Some(HashMap::new())),
145139
external_paths: RefCell::new(Some(HashMap::new())),
146140
inlined: RefCell::new(Some(HashSet::new())),
147141
populated_crate_impls: RefCell::new(HashSet::new()),
148-
}, CrateAnalysis {
142+
};
143+
debug!("crate: {:?}", ctxt.krate);
144+
145+
let analysis = CrateAnalysis {
149146
exported_items: exported_items,
150147
public_items: public_items,
151148
external_paths: RefCell::new(None),
152149
external_traits: RefCell::new(None),
153150
external_typarams: RefCell::new(None),
154151
inlined: RefCell::new(None),
155-
})
156-
}
157-
158-
pub fn run_core(libs: Vec<Path>, cfgs: Vec<String>, externs: Externs,
159-
path: &Path, triple: Option<String>)
160-
-> (clean::Crate, CrateAnalysis) {
161-
let type_arena = TypedArena::new();
162-
let (ctxt, analysis) = get_ast_and_resolve(path, libs, cfgs, externs,
163-
triple, &type_arena);
152+
};
164153

165154
let krate = {
166155
let mut v = RustdocVisitor::new(&ctxt, Some(&analysis));
167-
v.visit(&ctxt.krate);
156+
v.visit(ctxt.krate);
168157
v.clean(&ctxt)
169158
};
170159

src/librustdoc/doctree.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ use syntax::codemap::Span;
1616
use syntax::ast;
1717
use syntax::attr;
1818
use syntax::ast::{Ident, NodeId};
19-
20-
use std::gc::Gc;
19+
use syntax::ptr::P;
2120

2221
pub struct Module {
2322
pub name: Option<Ident>,
@@ -130,7 +129,7 @@ pub struct Function {
130129
}
131130

132131
pub struct Typedef {
133-
pub ty: ast::P<ast::Ty>,
132+
pub ty: P<ast::Ty>,
134133
pub gen: ast::Generics,
135134
pub name: Ident,
136135
pub id: ast::NodeId,
@@ -141,9 +140,9 @@ pub struct Typedef {
141140
}
142141

143142
pub struct Static {
144-
pub type_: ast::P<ast::Ty>,
143+
pub type_: P<ast::Ty>,
145144
pub mutability: ast::Mutability,
146-
pub expr: Gc<ast::Expr>,
145+
pub expr: P<ast::Expr>,
147146
pub name: Ident,
148147
pub attrs: Vec<ast::Attribute>,
149148
pub vis: ast::Visibility,
@@ -167,7 +166,7 @@ pub struct Trait {
167166
pub struct Impl {
168167
pub generics: ast::Generics,
169168
pub trait_: Option<ast::TraitRef>,
170-
pub for_: ast::P<ast::Ty>,
169+
pub for_: P<ast::Ty>,
171170
pub items: Vec<ast::ImplItem>,
172171
pub attrs: Vec<ast::Attribute>,
173172
pub whence: Span,

src/librustdoc/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use std::cell::RefCell;
1212
use std::char;
1313
use std::dynamic_lib::DynamicLibrary;
14-
use std::gc::GC;
1514
use std::io::{Command, TempDir};
1615
use std::io;
1716
use std::os;
@@ -28,6 +27,7 @@ use syntax::ast;
2827
use syntax::codemap::{CodeMap, dummy_spanned};
2928
use syntax::diagnostic;
3029
use syntax::parse::token;
30+
use syntax::ptr::P;
3131

3232
use core;
3333
use clean;
@@ -67,15 +67,15 @@ pub fn run(input: &str,
6767
let mut cfg = config::build_configuration(&sess);
6868
cfg.extend(cfgs.move_iter().map(|cfg_| {
6969
let cfg_ = token::intern_and_get_ident(cfg_.as_slice());
70-
box(GC) dummy_spanned(ast::MetaWord(cfg_))
70+
P(dummy_spanned(ast::MetaWord(cfg_)))
7171
}));
7272
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
73-
let (krate, _) = driver::phase_2_configure_and_expand(&sess, krate,
74-
"rustdoc-test", None)
73+
let krate = driver::phase_2_configure_and_expand(&sess, krate,
74+
"rustdoc-test", None)
7575
.expect("phase_2_configure_and_expand aborted in rustdoc!");
7676

7777
let ctx = core::DocContext {
78-
krate: krate,
78+
krate: &krate,
7979
maybe_typed: core::NotTyped(sess),
8080
src: input_path,
8181
external_paths: RefCell::new(Some(HashMap::new())),
@@ -86,7 +86,7 @@ pub fn run(input: &str,
8686
};
8787

8888
let mut v = RustdocVisitor::new(&ctx, None);
89-
v.visit(&ctx.krate);
89+
v.visit(ctx.krate);
9090
let mut krate = v.clean(&ctx);
9191
match crate_name {
9292
Some(name) => krate.name = name,

0 commit comments

Comments
 (0)