Skip to content

Commit e2ebc8f

Browse files
committed
Fix rustdoc and tests.
1 parent e02aa72 commit e2ebc8f

File tree

13 files changed

+71
-103
lines changed

13 files changed

+71
-103
lines changed

src/librustc/driver/driver.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ mod test {
12341234
};
12351235
let sessopts = build_session_options(matches);
12361236
let sess = build_session(sessopts, None);
1237-
let cfg = build_configuration(sess);
1237+
let cfg = build_configuration(&sess);
12381238
assert!((attr::contains_name(cfg.as_slice(), "test")));
12391239
}
12401240

@@ -1253,7 +1253,7 @@ mod test {
12531253
};
12541254
let sessopts = build_session_options(matches);
12551255
let sess = build_session(sessopts, None);
1256-
let cfg = build_configuration(sess);
1256+
let cfg = build_configuration(&sess);
12571257
let mut test_items = cfg.iter().filter(|m| m.name().equiv(&("test")));
12581258
assert!(test_items.next().is_some());
12591259
assert!(test_items.next().is_none());

src/librustc/middle/astencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ fn test_more() {
15171517
#[test]
15181518
fn test_simplification() {
15191519
let cx = mk_ctxt();
1520-
let item = quote_item!(cx,
1520+
let item = quote_item!(&cx,
15211521
fn new_int_alist<B>() -> alist<int, B> {
15221522
fn eq_int(a: int, b: int) -> bool { a == b }
15231523
return alist {eq_fn: eq_int, data: Vec::new()};

src/librustdoc/clean.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl Clean<Type> for ast::Ty {
684684
fn clean(&self) -> Type {
685685
use syntax::ast::*;
686686
debug!("cleaning type `{:?}`", self);
687-
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
687+
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
688688
debug!("span corresponds to `{}`", codemap.span_to_str(self.span));
689689
match self.node {
690690
TyNil => Unit,
@@ -866,7 +866,7 @@ pub struct Span {
866866

867867
impl Clean<Span> for syntax::codemap::Span {
868868
fn clean(&self) -> Span {
869-
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
869+
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
870870
let filename = cm.span_to_filename(*self);
871871
let lo = cm.lookup_char_pos(self.lo);
872872
let hi = cm.lookup_char_pos(self.hi);
@@ -1180,7 +1180,7 @@ trait ToSource {
11801180
impl ToSource for syntax::codemap::Span {
11811181
fn to_src(&self) -> ~str {
11821182
debug!("converting span {:?} to snippet", self.clean());
1183-
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap.clone();
1183+
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap().clone();
11841184
let sn = match cm.span_to_snippet(*self) {
11851185
Some(x) => x,
11861186
None => ~""

src/librustdoc/core.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc::middle::privacy;
1515

1616
use syntax::ast;
1717
use syntax::parse::token;
18-
use syntax::parse;
1918
use syntax;
2019

2120
use std::cell::RefCell;
@@ -60,24 +59,23 @@ fn get_ast_and_resolve(cpath: &Path,
6059
phase_2_configure_and_expand,
6160
phase_3_run_analysis_passes};
6261

63-
let parsesess = parse::new_parse_sess();
6462
let input = FileInput(cpath.clone());
6563

66-
let sessopts = @driver::session::Options {
64+
let sessopts = driver::session::Options {
6765
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
6866
addl_lib_search_paths: RefCell::new(libs),
6967
crate_types: vec!(driver::session::CrateTypeDylib),
70-
.. (*rustc::driver::session::basic_options()).clone()
68+
..rustc::driver::session::basic_options().clone()
7169
};
7270

7371

72+
let codemap = syntax::codemap::CodeMap::new();
7473
let diagnostic_handler = syntax::diagnostic::default_handler();
7574
let span_diagnostic_handler =
76-
syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
75+
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);
7776

7877
let sess = driver::driver::build_session_(sessopts,
7978
Some(cpath.clone()),
80-
parsesess.cm,
8179
span_diagnostic_handler);
8280

8381
let mut cfg = build_configuration(&sess);
@@ -87,7 +85,7 @@ fn get_ast_and_resolve(cpath: &Path,
8785
}
8886

8987
let krate = phase_1_parse_input(&sess, cfg, &input);
90-
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(sess),
88+
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(&sess),
9189
krate, &from_str("rustdoc").unwrap());
9290
let driver::driver::CrateAnalysis {
9391
exported_items, public_items, ty_cx, ..

src/librustdoc/html/highlight.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use std::io;
1818

1919
use syntax::parse;
2020
use syntax::parse::lexer;
21-
use syntax::diagnostic;
2221
use syntax::codemap::{BytePos, Span};
2322

2423
use html::escape::Escape;
@@ -28,13 +27,11 @@ use t = syntax::parse::token;
2827
/// Highlights some source code, returning the HTML output.
2928
pub fn highlight(src: &str, class: Option<&str>) -> ~str {
3029
let sess = parse::new_parse_sess();
31-
let handler = diagnostic::default_handler();
32-
let span_handler = diagnostic::mk_span_handler(handler, sess.cm);
3330
let fm = parse::string_to_filemap(&sess, src.to_owned(), ~"<stdin>");
3431
3532
let mut out = io::MemWriter::new();
3633
doit(&sess,
37-
lexer::new_string_reader(span_handler, fm),
34+
lexer::new_string_reader(&sess.span_diagnostic, fm),
3835
class,
3936
&mut out).unwrap();
4037
str::from_utf8_lossy(out.unwrap()).into_owned()
@@ -68,7 +65,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
6865
// comment. This will classify some whitespace as a comment, but that
6966
// doesn't matter too much for syntax highlighting purposes.
7067
if test > last {
71-
let snip = sess.cm.span_to_snippet(Span {
68+
let snip = sess.span_diagnostic.cm.span_to_snippet(Span {
7269
lo: last,
7370
hi: test,
7471
expn_info: None,
@@ -172,7 +169,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
172169

173170
// as mentioned above, use the original source code instead of
174171
// stringifying this token
175-
let snip = sess.cm.span_to_snippet(next.sp).unwrap();
172+
let snip = sess.span_diagnostic.cm.span_to_snippet(next.sp).unwrap();
176173
if klass == "" {
177174
try!(write!(out, "{}", Escape(snip)));
178175
} else {

src/librustdoc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ extern crate time;
2828
#[phase(syntax, link)]
2929
extern crate log;
3030

31-
use std::cell::RefCell;
3231
use std::local_data;
3332
use std::io;
3433
use std::io::{File, MemWriter};

src/librustdoc/markdown.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::{str, io};
12-
use std::cell::RefCell;
1312
use std::vec_ng::Vec;
1413

1514
use collections::HashSet;

src/librustdoc/test.rs

+9-14
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc::driver::driver;
2323
use rustc::driver::session;
2424
use rustc::metadata::creader::Loader;
2525
use syntax::diagnostic;
26-
use syntax::parse;
2726
use syntax::codemap::CodeMap;
2827

2928
use core;
@@ -38,29 +37,26 @@ pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
3837
let input_path = Path::new(input);
3938
let input = driver::FileInput(input_path.clone());
4039

41-
let sessopts = @session::Options {
40+
let sessopts = session::Options {
4241
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
4342
addl_lib_search_paths: RefCell::new(libs.clone()),
4443
crate_types: vec!(session::CrateTypeDylib),
45-
.. (*session::basic_options()).clone()
44+
..session::basic_options().clone()
4645
};
4746

4847

49-
let cm = @CodeMap::new();
48+
let codemap = CodeMap::new();
5049
let diagnostic_handler = diagnostic::default_handler();
5150
let span_diagnostic_handler =
52-
diagnostic::mk_span_handler(diagnostic_handler, cm);
53-
let parsesess = parse::new_parse_sess_special_handler(span_diagnostic_handler,
54-
cm);
51+
diagnostic::mk_span_handler(diagnostic_handler, codemap);
5552

5653
let sess = driver::build_session_(sessopts,
5754
Some(input_path),
58-
parsesess.cm,
5955
span_diagnostic_handler);
6056

6157
let cfg = driver::build_configuration(&sess);
6258
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
63-
let (krate, _) = driver::phase_2_configure_and_expand(sess, &mut Loader::new(sess), krate,
59+
let (krate, _) = driver::phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), krate,
6460
&from_str("rustdoc-test").unwrap());
6561

6662
let ctx = @core::DocContext {
@@ -88,10 +84,9 @@ pub fn run(input: &str, libs: HashSet<Path>, mut test_args: ~[~str]) -> int {
8884
fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
8985
no_run: bool, loose_feature_gating: bool) {
9086
let test = maketest(test, cratename, loose_feature_gating);
91-
let parsesess = parse::new_parse_sess();
9287
let input = driver::StrInput(test);
9388

94-
let sessopts = @session::Options {
89+
let sessopts = session::Options {
9590
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
9691
addl_lib_search_paths: RefCell::new(libs),
9792
crate_types: vec!(session::CrateTypeExecutable),
@@ -100,7 +95,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
10095
prefer_dynamic: true,
10196
.. session::basic_codegen_options()
10297
},
103-
.. (*session::basic_options()).clone()
98+
..session::basic_options().clone()
10499
};
105100

106101
// Shuffle around a few input and output handles here. We're going to pass
@@ -126,13 +121,13 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
126121
let emitter = diagnostic::EmitterWriter::new(~w2);
127122

128123
// Compile the code
124+
let codemap = CodeMap::new();
129125
let diagnostic_handler = diagnostic::mk_handler(~emitter);
130126
let span_diagnostic_handler =
131-
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
127+
diagnostic::mk_span_handler(diagnostic_handler, codemap);
132128

133129
let sess = driver::build_session_(sessopts,
134130
None,
135-
parsesess.cm,
136131
span_diagnostic_handler);
137132

138133
let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");

src/libsyntax/ext/expand.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1044,15 +1044,15 @@ mod test {
10441044
let crate_ast = parse::parse_crate_from_source_str(
10451045
~"<test>",
10461046
src,
1047-
Vec::new(),sess);
1047+
Vec::new(), &sess);
10481048
// should fail:
10491049
let mut loader = ErrLoader;
10501050
let cfg = ::syntax::ext::expand::ExpansionConfig {
10511051
loader: &mut loader,
10521052
deriving_hash_type_parameter: false,
10531053
crate_id: from_str("test").unwrap(),
10541054
};
1055-
expand_crate(sess,cfg,crate_ast);
1055+
expand_crate(&sess,cfg,crate_ast);
10561056
}
10571057

10581058
// make sure that macros can leave scope for modules
@@ -1064,15 +1064,15 @@ mod test {
10641064
let crate_ast = parse::parse_crate_from_source_str(
10651065
~"<test>",
10661066
src,
1067-
Vec::new(),sess);
1067+
Vec::new(), &sess);
10681068
// should fail:
10691069
let mut loader = ErrLoader;
10701070
let cfg = ::syntax::ext::expand::ExpansionConfig {
10711071
loader: &mut loader,
10721072
deriving_hash_type_parameter: false,
10731073
crate_id: from_str("test").unwrap(),
10741074
};
1075-
expand_crate(sess,cfg,crate_ast);
1075+
expand_crate(&sess,cfg,crate_ast);
10761076
}
10771077

10781078
// macro_escape modules shouldn't cause macros to leave scope
@@ -1083,15 +1083,15 @@ mod test {
10831083
let crate_ast = parse::parse_crate_from_source_str(
10841084
~"<test>",
10851085
src,
1086-
Vec::new(), sess);
1086+
Vec::new(), &sess);
10871087
// should fail:
10881088
let mut loader = ErrLoader;
10891089
let cfg = ::syntax::ext::expand::ExpansionConfig {
10901090
loader: &mut loader,
10911091
deriving_hash_type_parameter: false,
10921092
crate_id: from_str("test").unwrap(),
10931093
};
1094-
expand_crate(sess, cfg, crate_ast);
1094+
expand_crate(&sess, cfg, crate_ast);
10951095
}
10961096

10971097
#[test] fn test_contains_flatten (){
@@ -1127,7 +1127,7 @@ mod test {
11271127

11281128
fn expand_crate_str(crate_str: ~str) -> ast::Crate {
11291129
let ps = parse::new_parse_sess();
1130-
let crate_ast = string_to_parser(&ps, source_str).parse_crate_mod();
1130+
let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod();
11311131
// the cfg argument actually does matter, here...
11321132
let mut loader = ErrLoader;
11331133
let cfg = ::syntax::ext::expand::ExpansionConfig {

src/libsyntax/fold.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -880,9 +880,9 @@ mod test {
880880
use super::*;
881881

882882
// this version doesn't care about getting comments or docstrings in.
883-
fn fake_print_crate(s: &mut pprust::State,
884-
krate: &ast::Crate) -> io::IoResult<()> {
885-
pprust::print_mod(s, &krate.module, krate.attrs.as_slice())
883+
fn fake_print_crate<A: pprust::PpAnn>(s: &mut pprust::State<A>,
884+
krate: &ast::Crate) -> io::IoResult<()> {
885+
s.print_mod(&krate.module, krate.attrs.as_slice())
886886
}
887887

888888
// change every identifier to "zz"
@@ -914,9 +914,10 @@ mod test {
914914
let mut zz_fold = ToZzIdentFolder;
915915
let ast = string_to_crate(
916916
~"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}");
917+
let folded_crate = zz_fold.fold_crate(ast);
917918
assert_pred!(matches_codepattern,
918919
"matches_codepattern",
919-
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate),
920+
pprust::to_str(|s| fake_print_crate(s, &folded_crate)),
920921
~"#[a]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}");
921922
}
922923
@@ -926,9 +927,10 @@ mod test {
926927
let ast = string_to_crate(
927928
~"macro_rules! a {(b $c:expr $(d $e:token)f+ => \
928929
(g $(d $d $e)+))} ");
930+
let folded_crate = zz_fold.fold_crate(ast);
929931
assert_pred!(matches_codepattern,
930932
"matches_codepattern",
931-
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate),
933+
pprust::to_str(|s| fake_print_crate(s, &folded_crate)),
932934
~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))");
933935
}
934936
}

0 commit comments

Comments
 (0)