]> git.lizzy.rs Git - rust.git/commitdiff
parse cfgspecs passed to rustdoc
authorAndrew Paseltiner <apaseltiner@gmail.com>
Tue, 10 Feb 2015 04:42:31 +0000 (23:42 -0500)
committerAndrew Paseltiner <apaseltiner@gmail.com>
Tue, 10 Feb 2015 15:31:14 +0000 (10:31 -0500)
fixes #22131

src/librustdoc/test.rs
src/test/run-make/issue-22131/Makefile [new file with mode: 0644]
src/test/run-make/issue-22131/foo.rs [new file with mode: 0644]

index e43c3a6da3ac70893479bb7bbcb86698eae4b32e..09df9fc8cbb66bc3b12d9abea82537e03c3457ba 100644 (file)
 use rustc::session::config::get_unstable_features_setting;
 use rustc::session::search_paths::{SearchPaths, PathKind};
 use rustc_driver::{driver, Compilation};
-use syntax::ast;
-use syntax::codemap::{CodeMap, dummy_spanned};
+use syntax::codemap::CodeMap;
 use syntax::diagnostic;
-use syntax::parse::token;
-use syntax::ptr::P;
 
 use core;
 use clean;
@@ -67,10 +64,7 @@ pub fn run(input: &str,
                                       span_diagnostic_handler);
 
     let mut cfg = config::build_configuration(&sess);
-    cfg.extend(cfgs.into_iter().map(|cfg_| {
-        let cfg_ = token::intern_and_get_ident(&cfg_);
-        P(dummy_spanned(ast::MetaWord(cfg_)))
-    }));
+    cfg.extend(config::parse_cfgspecs(cfgs).into_iter());
     let krate = driver::phase_1_parse_input(&sess, cfg, &input);
     let krate = driver::phase_2_configure_and_expand(&sess, krate,
                                                      "rustdoc-test", None)
diff --git a/src/test/run-make/issue-22131/Makefile b/src/test/run-make/issue-22131/Makefile
new file mode 100644 (file)
index 0000000..46d89f0
--- /dev/null
@@ -0,0 +1,6 @@
+-include ../tools.mk
+
+all: foo.rs
+       $(RUSTC) --cfg 'feature="bar"' --crate-type lib foo.rs
+       $(RUSTDOC) --test --cfg 'feature="bar"' -L $(TMPDIR) foo.rs |\
+       grep --quiet 'test foo_0 ... ok'
diff --git a/src/test/run-make/issue-22131/foo.rs b/src/test/run-make/issue-22131/foo.rs
new file mode 100644 (file)
index 0000000..0b1f129
--- /dev/null
@@ -0,0 +1,17 @@
+// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![crate_name="foo"]
+
+/// ```rust
+/// assert_eq!(foo::foo(), 1);
+/// ```
+#[cfg(feature = "bar")]
+pub fn foo() -> i32 { 1 }