Skip to content

Commit

Permalink
Fix rustdoc and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Mar 17, 2014
1 parent e02aa72 commit e2ebc8f
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 103 deletions.
4 changes: 2 additions & 2 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ mod test {
};
let sessopts = build_session_options(matches);
let sess = build_session(sessopts, None);
let cfg = build_configuration(sess);
let cfg = build_configuration(&sess);
assert!((attr::contains_name(cfg.as_slice(), "test")));
}

Expand All @@ -1253,7 +1253,7 @@ mod test {
};
let sessopts = build_session_options(matches);
let sess = build_session(sessopts, None);
let cfg = build_configuration(sess);
let cfg = build_configuration(&sess);
let mut test_items = cfg.iter().filter(|m| m.name().equiv(&("test")));
assert!(test_items.next().is_some());
assert!(test_items.next().is_none());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ fn test_more() {
#[test]
fn test_simplification() {
let cx = mk_ctxt();
let item = quote_item!(cx,
let item = quote_item!(&cx,
fn new_int_alist<B>() -> alist<int, B> {
fn eq_int(a: int, b: int) -> bool { a == b }
return alist {eq_fn: eq_int, data: Vec::new()};
Expand Down
6 changes: 3 additions & 3 deletions src/librustdoc/clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ impl Clean<Type> for ast::Ty {
fn clean(&self) -> Type {
use syntax::ast::*;
debug!("cleaning type `{:?}`", self);
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
let codemap = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
debug!("span corresponds to `{}`", codemap.span_to_str(self.span));
match self.node {
TyNil => Unit,
Expand Down Expand Up @@ -866,7 +866,7 @@ pub struct Span {

impl Clean<Span> for syntax::codemap::Span {
fn clean(&self) -> Span {
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap;
let cm = local_data::get(super::ctxtkey, |x| *x.unwrap()).sess().codemap();
let filename = cm.span_to_filename(*self);
let lo = cm.lookup_char_pos(self.lo);
let hi = cm.lookup_char_pos(self.hi);
Expand Down Expand Up @@ -1180,7 +1180,7 @@ trait ToSource {
impl ToSource for syntax::codemap::Span {
fn to_src(&self) -> ~str {
debug!("converting span {:?} to snippet", self.clean());
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap.clone();
let cm = local_data::get(super::ctxtkey, |x| x.unwrap().clone()).sess().codemap().clone();
let sn = match cm.span_to_snippet(*self) {
Some(x) => x,
None => ~""
Expand Down
12 changes: 5 additions & 7 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc::middle::privacy;

use syntax::ast;
use syntax::parse::token;
use syntax::parse;
use syntax;

use std::cell::RefCell;
Expand Down Expand Up @@ -60,24 +59,23 @@ fn get_ast_and_resolve(cpath: &Path,
phase_2_configure_and_expand,
phase_3_run_analysis_passes};

let parsesess = parse::new_parse_sess();
let input = FileInput(cpath.clone());

let sessopts = @driver::session::Options {
let sessopts = driver::session::Options {
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs),
crate_types: vec!(driver::session::CrateTypeDylib),
.. (*rustc::driver::session::basic_options()).clone()
..rustc::driver::session::basic_options().clone()
};


let codemap = syntax::codemap::CodeMap::new();
let diagnostic_handler = syntax::diagnostic::default_handler();
let span_diagnostic_handler =
syntax::diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
syntax::diagnostic::mk_span_handler(diagnostic_handler, codemap);

let sess = driver::driver::build_session_(sessopts,
Some(cpath.clone()),
parsesess.cm,
span_diagnostic_handler);

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

let krate = phase_1_parse_input(&sess, cfg, &input);
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(sess),
let (krate, ast_map) = phase_2_configure_and_expand(&sess, &mut Loader::new(&sess),
krate, &from_str("rustdoc").unwrap());
let driver::driver::CrateAnalysis {
exported_items, public_items, ty_cx, ..
Expand Down
9 changes: 3 additions & 6 deletions src/librustdoc/html/highlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use std::io;

use syntax::parse;
use syntax::parse::lexer;
use syntax::diagnostic;
use syntax::codemap::{BytePos, Span};

use html::escape::Escape;
Expand All @@ -28,13 +27,11 @@ use t = syntax::parse::token;
/// Highlights some source code, returning the HTML output.
pub fn highlight(src: &str, class: Option<&str>) -> ~str {
let sess = parse::new_parse_sess();
let handler = diagnostic::default_handler();
let span_handler = diagnostic::mk_span_handler(handler, sess.cm);
let fm = parse::string_to_filemap(&sess, src.to_owned(), ~"<stdin>");
let mut out = io::MemWriter::new();
doit(&sess,
lexer::new_string_reader(span_handler, fm),
lexer::new_string_reader(&sess.span_diagnostic, fm),
class,
&mut out).unwrap();
str::from_utf8_lossy(out.unwrap()).into_owned()
Expand Down Expand Up @@ -68,7 +65,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>
// comment. This will classify some whitespace as a comment, but that
// doesn't matter too much for syntax highlighting purposes.
if test > last {
let snip = sess.cm.span_to_snippet(Span {
let snip = sess.span_diagnostic.cm.span_to_snippet(Span {
lo: last,
hi: test,
expn_info: None,
Expand Down Expand Up @@ -172,7 +169,7 @@ fn doit(sess: &parse::ParseSess, lexer: lexer::StringReader, class: Option<&str>

// as mentioned above, use the original source code instead of
// stringifying this token
let snip = sess.cm.span_to_snippet(next.sp).unwrap();
let snip = sess.span_diagnostic.cm.span_to_snippet(next.sp).unwrap();
if klass == "" {
try!(write!(out, "{}", Escape(snip)));
} else {
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ extern crate time;
#[phase(syntax, link)]
extern crate log;

use std::cell::RefCell;
use std::local_data;
use std::io;
use std::io::{File, MemWriter};
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

use std::{str, io};
use std::cell::RefCell;
use std::vec_ng::Vec;

use collections::HashSet;
Expand Down
23 changes: 9 additions & 14 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use rustc::driver::driver;
use rustc::driver::session;
use rustc::metadata::creader::Loader;
use syntax::diagnostic;
use syntax::parse;
use syntax::codemap::CodeMap;

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

let sessopts = @session::Options {
let sessopts = session::Options {
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs.clone()),
crate_types: vec!(session::CrateTypeDylib),
.. (*session::basic_options()).clone()
..session::basic_options().clone()
};


let cm = @CodeMap::new();
let codemap = CodeMap::new();
let diagnostic_handler = diagnostic::default_handler();
let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, cm);
let parsesess = parse::new_parse_sess_special_handler(span_diagnostic_handler,
cm);
diagnostic::mk_span_handler(diagnostic_handler, codemap);

let sess = driver::build_session_(sessopts,
Some(input_path),
parsesess.cm,
span_diagnostic_handler);

let cfg = driver::build_configuration(&sess);
let krate = driver::phase_1_parse_input(&sess, cfg, &input);
let (krate, _) = driver::phase_2_configure_and_expand(sess, &mut Loader::new(sess), krate,
let (krate, _) = driver::phase_2_configure_and_expand(&sess, &mut Loader::new(&sess), krate,
&from_str("rustdoc-test").unwrap());

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

let sessopts = @session::Options {
let sessopts = session::Options {
maybe_sysroot: Some(os::self_exe_path().unwrap().dir_path()),
addl_lib_search_paths: RefCell::new(libs),
crate_types: vec!(session::CrateTypeExecutable),
Expand All @@ -100,7 +95,7 @@ fn runtest(test: &str, cratename: &str, libs: HashSet<Path>, should_fail: bool,
prefer_dynamic: true,
.. session::basic_codegen_options()
},
.. (*session::basic_options()).clone()
..session::basic_options().clone()
};

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

// Compile the code
let codemap = CodeMap::new();
let diagnostic_handler = diagnostic::mk_handler(~emitter);
let span_diagnostic_handler =
diagnostic::mk_span_handler(diagnostic_handler, parsesess.cm);
diagnostic::mk_span_handler(diagnostic_handler, codemap);

let sess = driver::build_session_(sessopts,
None,
parsesess.cm,
span_diagnostic_handler);

let outdir = TempDir::new("rustdoctest").expect("rustdoc needs a tempdir");
Expand Down
14 changes: 7 additions & 7 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,15 +1044,15 @@ mod test {
let crate_ast = parse::parse_crate_from_source_str(
~"<test>",
src,
Vec::new(),sess);
Vec::new(), &sess);
// should fail:
let mut loader = ErrLoader;
let cfg = ::syntax::ext::expand::ExpansionConfig {
loader: &mut loader,
deriving_hash_type_parameter: false,
crate_id: from_str("test").unwrap(),
};
expand_crate(sess,cfg,crate_ast);
expand_crate(&sess,cfg,crate_ast);
}

// make sure that macros can leave scope for modules
Expand All @@ -1064,15 +1064,15 @@ mod test {
let crate_ast = parse::parse_crate_from_source_str(
~"<test>",
src,
Vec::new(),sess);
Vec::new(), &sess);
// should fail:
let mut loader = ErrLoader;
let cfg = ::syntax::ext::expand::ExpansionConfig {
loader: &mut loader,
deriving_hash_type_parameter: false,
crate_id: from_str("test").unwrap(),
};
expand_crate(sess,cfg,crate_ast);
expand_crate(&sess,cfg,crate_ast);
}

// macro_escape modules shouldn't cause macros to leave scope
Expand All @@ -1083,15 +1083,15 @@ mod test {
let crate_ast = parse::parse_crate_from_source_str(
~"<test>",
src,
Vec::new(), sess);
Vec::new(), &sess);
// should fail:
let mut loader = ErrLoader;
let cfg = ::syntax::ext::expand::ExpansionConfig {
loader: &mut loader,
deriving_hash_type_parameter: false,
crate_id: from_str("test").unwrap(),
};
expand_crate(sess, cfg, crate_ast);
expand_crate(&sess, cfg, crate_ast);
}

#[test] fn test_contains_flatten (){
Expand Down Expand Up @@ -1127,7 +1127,7 @@ mod test {

fn expand_crate_str(crate_str: ~str) -> ast::Crate {
let ps = parse::new_parse_sess();
let crate_ast = string_to_parser(&ps, source_str).parse_crate_mod();
let crate_ast = string_to_parser(&ps, crate_str).parse_crate_mod();
// the cfg argument actually does matter, here...
let mut loader = ErrLoader;
let cfg = ::syntax::ext::expand::ExpansionConfig {
Expand Down
12 changes: 7 additions & 5 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,9 @@ mod test {
use super::*;

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

// change every identifier to "zz"
Expand Down Expand Up @@ -914,9 +914,10 @@ mod test {
let mut zz_fold = ToZzIdentFolder;
let ast = string_to_crate(
~"#[a] mod b {fn c (d : e, f : g) {h!(i,j,k);l;m}}");
let folded_crate = zz_fold.fold_crate(ast);
assert_pred!(matches_codepattern,
"matches_codepattern",
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate),
pprust::to_str(|s| fake_print_crate(s, &folded_crate)),
~"#[a]mod zz{fn zz(zz:zz,zz:zz){zz!(zz,zz,zz);zz;zz}}");
}

Expand All @@ -926,9 +927,10 @@ mod test {
let ast = string_to_crate(
~"macro_rules! a {(b $c:expr $(d $e:token)f+ => \
(g $(d $d $e)+))} ");
let folded_crate = zz_fold.fold_crate(ast);
assert_pred!(matches_codepattern,
"matches_codepattern",
pprust::to_str(&mut zz_fold.fold_crate(ast),fake_print_crate),
pprust::to_str(|s| fake_print_crate(s, &folded_crate)),
~"zz!zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)))");
}
}
Loading

5 comments on commit e2ebc8f

@bors
Copy link
Contributor

@bors bors commented on e2ebc8f Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from cmr
at eddyb@e2ebc8f

@bors
Copy link
Contributor

@bors bors commented on e2ebc8f Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/at-exodus-chapter-11 = e2ebc8f into auto

@bors
Copy link
Contributor

@bors bors commented on e2ebc8f Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/at-exodus-chapter-11 = e2ebc8f merged ok, testing candidate = e4c91e6

@bors
Copy link
Contributor

@bors bors commented on e2ebc8f Mar 17, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e4c91e6

Please sign in to comment.