Skip to content

Commit 6078a86

Browse files
committed
Rollup merge of #31835 - mitaa:rdoc-global-src, r=alexcrichton
fixes #26995 r? @alexcrichton
2 parents 39f41c6 + cf76fcf commit 6078a86

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

src/librustdoc/clean/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ use std::collections::HashMap;
4848
use std::path::PathBuf;
4949
use std::rc::Rc;
5050
use std::u32;
51+
use std::env::current_dir;
5152

5253
use core::DocContext;
5354
use doctree;
@@ -201,7 +202,13 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
201202
}
202203

203204
let src = match cx.input {
204-
Input::File(ref path) => path.clone(),
205+
Input::File(ref path) => {
206+
if path.is_absolute() {
207+
path.clone()
208+
} else {
209+
current_dir().unwrap().join(path)
210+
}
211+
},
205212
Input::Str(_) => PathBuf::new() // FIXME: this is wrong
206213
};
207214

src/librustdoc/html/render.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use std::io::prelude::*;
4646
use std::io::{self, BufWriter, BufReader};
4747
use std::iter::repeat;
4848
use std::mem;
49-
use std::path::{PathBuf, Path};
49+
use std::path::{PathBuf, Path, Component};
5050
use std::str;
5151
use std::sync::Arc;
5252

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

813-
let mut iter = p.iter().map(|x| x.to_str().unwrap()).peekable();
813+
let mut iter = p.components().peekable();
814+
814815
while let Some(c) = iter.next() {
815816
if !keep_filename && iter.peek().is_none() {
816817
break;
817818
}
818819

819-
if ".." == c {
820-
f("up");
821-
} else {
822-
f(c)
820+
match c {
821+
Component::ParentDir => f("up"),
822+
Component::Normal(c) => f(c.to_str().unwrap()),
823+
_ => continue,
823824
}
824825
}
825826
}
@@ -871,7 +872,7 @@ impl<'a> DocFolder for SourceCollector<'a> {
871872
// entire crate. The other option is maintaining this mapping on a
872873
// per-file basis, but that's probably not worth it...
873874
self.cx
874-
.include_sources = match self.emit_source(&item.source .filename) {
875+
.include_sources = match self.emit_source(&item.source.filename) {
875876
Ok(()) => true,
876877
Err(e) => {
877878
println!("warning: source code was requested to be rendered, \
@@ -1489,9 +1490,11 @@ impl<'a> Item<'a> {
14891490
true, |component| {
14901491
path.push(component.to_string());
14911492
});
1493+
14921494
// If the span points into an external macro the
14931495
// source-file will be bogus, i.e `<foo macros>`
1494-
if Path::new(&self.item.source.filename).is_file() {
1496+
let filename = &self.item.source.filename;
1497+
if !(filename.starts_with("<") && filename.ends_with("macros>")) {
14951498
Some(format!("{root}src/{krate}/{path}.html#{href}",
14961499
root = self.cx.root_path,
14971500
krate = self.cx.layout.krate,

src/test/rustdoc/issue-26995.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-windows
12+
// compile-flags: --no-defaults
13+
14+
// @has src/issue_26995/dev/null.html
15+
// @has issue_26995/null/index.html '//a/@href' '../../src/issue_26995/dev/null.html'
16+
#[path="/dev/null"]
17+
pub mod null;

0 commit comments

Comments
 (0)