Skip to content

Commit

Permalink
Rollup merge of rust-lang#31835 - mitaa:rdoc-global-src, r=alexcrichton
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Feb 25, 2016
2 parents 39f41c6 + cf76fcf commit 6078a86
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ use std::collections::HashMap;
use std::path::PathBuf;
use std::rc::Rc;
use std::u32;
use std::env::current_dir;

use core::DocContext;
use doctree;
Expand Down Expand Up @@ -201,7 +202,13 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
}

let src = match cx.input {
Input::File(ref path) => path.clone(),
Input::File(ref path) => {
if path.is_absolute() {
path.clone()
} else {
current_dir().unwrap().join(path)
}
},
Input::Str(_) => PathBuf::new() // FIXME: this is wrong
};

Expand Down
19 changes: 11 additions & 8 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use std::io::prelude::*;
use std::io::{self, BufWriter, BufReader};
use std::iter::repeat;
use std::mem;
use std::path::{PathBuf, Path};
use std::path::{PathBuf, Path, Component};
use std::str;
use std::sync::Arc;

Expand Down Expand Up @@ -810,16 +810,17 @@ fn clean_srcpath<F>(src_root: &Path, p: &Path, keep_filename: bool, mut f: F) wh
// make it relative, if possible
let p = p.strip_prefix(src_root).unwrap_or(p);

let mut iter = p.iter().map(|x| x.to_str().unwrap()).peekable();
let mut iter = p.components().peekable();

while let Some(c) = iter.next() {
if !keep_filename && iter.peek().is_none() {
break;
}

if ".." == c {
f("up");
} else {
f(c)
match c {
Component::ParentDir => f("up"),
Component::Normal(c) => f(c.to_str().unwrap()),
_ => continue,
}
}
}
Expand Down Expand Up @@ -871,7 +872,7 @@ impl<'a> DocFolder for SourceCollector<'a> {
// entire crate. The other option is maintaining this mapping on a
// per-file basis, but that's probably not worth it...
self.cx
.include_sources = match self.emit_source(&item.source .filename) {
.include_sources = match self.emit_source(&item.source.filename) {
Ok(()) => true,
Err(e) => {
println!("warning: source code was requested to be rendered, \
Expand Down Expand Up @@ -1489,9 +1490,11 @@ impl<'a> Item<'a> {
true, |component| {
path.push(component.to_string());
});

// If the span points into an external macro the
// source-file will be bogus, i.e `<foo macros>`
if Path::new(&self.item.source.filename).is_file() {
let filename = &self.item.source.filename;
if !(filename.starts_with("<") && filename.ends_with("macros>")) {
Some(format!("{root}src/{krate}/{path}.html#{href}",
root = self.cx.root_path,
krate = self.cx.layout.krate,
Expand Down
17 changes: 17 additions & 0 deletions src/test/rustdoc/issue-26995.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2016 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.

// ignore-windows
// compile-flags: --no-defaults

// @has src/issue_26995/dev/null.html
// @has issue_26995/null/index.html '//a/@href' '../../src/issue_26995/dev/null.html'
#[path="/dev/null"]
pub mod null;

0 comments on commit 6078a86

Please sign in to comment.