Skip to content

Commit 50fb77f

Browse files
committed
rustdoc: Stop requiring a crate ID attribute
This is mostly just an artificial requirement as it can use similar logic to the compiler to infer the crate id.
1 parent 5d145c1 commit 50fb77f

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/librustdoc/clean.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use syntax::codemap::Pos;
2020
use syntax::parse::token::InternedString;
2121
use syntax::parse::token;
2222

23+
use rustc::back::link;
24+
use rustc::driver::driver;
2325
use rustc::metadata::cstore;
2426
use rustc::metadata::csearch;
2527
use rustc::metadata::decoder;
@@ -75,19 +77,23 @@ pub struct Crate {
7577

7678
impl<'a> Clean<Crate> for visit_ast::RustdocVisitor<'a> {
7779
fn clean(&self) -> Crate {
78-
use syntax::attr::find_crateid;
7980
let cx = local_data::get(super::ctxtkey, |x| *x.unwrap());
8081

8182
let mut externs = Vec::new();
8283
cx.sess().cstore.iter_crate_data(|n, meta| {
8384
externs.push((n, meta.clean()));
8485
});
8586

87+
let input = driver::FileInput(cx.src.clone());
88+
let t_outputs = driver::build_output_filenames(&input,
89+
&None,
90+
&None,
91+
self.attrs.as_slice(),
92+
cx.sess());
93+
let id = link::find_crate_id(self.attrs.as_slice(),
94+
t_outputs.out_filestem);
8695
Crate {
87-
name: match find_crateid(self.attrs.as_slice()) {
88-
Some(n) => n.name,
89-
None => fail!("rustdoc requires a `crate_id` crate attribute"),
90-
},
96+
name: id.name,
9197
module: Some(self.module.clean()),
9298
externs: externs,
9399
}

src/librustdoc/core.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub enum MaybeTyped {
3434

3535
pub struct DocContext {
3636
pub krate: ast::Crate,
37-
pub maybe_typed: MaybeTyped
37+
pub maybe_typed: MaybeTyped,
38+
pub src: Path,
3839
}
3940

4041
impl DocContext {
@@ -96,7 +97,8 @@ fn get_ast_and_resolve(cpath: &Path, libs: HashSet<Path>, cfgs: Vec<~str>)
9697
debug!("crate: {:?}", krate);
9798
(DocContext {
9899
krate: krate,
99-
maybe_typed: Typed(ty_cx)
100+
maybe_typed: Typed(ty_cx),
101+
src: cpath.clone(),
100102
}, CrateAnalysis {
101103
exported_items: exported_items,
102104
public_items: public_items,

src/librustdoc/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn run(input: &str, cfgs: Vec<~str>,
5555
diagnostic::mk_span_handler(diagnostic_handler, codemap);
5656

5757
let sess = driver::build_session_(sessopts,
58-
Some(input_path),
58+
Some(input_path.clone()),
5959
span_diagnostic_handler);
6060

6161
let mut cfg = driver::build_configuration(&sess);
@@ -70,6 +70,7 @@ pub fn run(input: &str, cfgs: Vec<~str>,
7070
let ctx = @core::DocContext {
7171
krate: krate,
7272
maybe_typed: core::NotTyped(sess),
73+
src: input_path,
7374
};
7475
local_data::set(super::ctxtkey, ctx);
7576

0 commit comments

Comments
 (0)