]> git.lizzy.rs Git - rust.git/commitdiff
Fix source-links for files with absolute-paths
authormitaa <mitaa.ceb@gmail.com>
Tue, 23 Feb 2016 06:52:43 +0000 (07:52 +0100)
committermitaa <mitaa.ceb@gmail.com>
Wed, 24 Feb 2016 18:43:02 +0000 (19:43 +0100)
`clean_srcpath` tries to make the source-path relative to `src_root`,
but this didn't work since `src_root` itself wasn't absolute.

src/librustdoc/clean/mod.rs
src/librustdoc/html/render.rs
src/test/rustdoc/issue-26995.rs [new file with mode: 0644]

index 7072f1b498bb91f6bee167e2bb17035f4a9c34d3..1ff88f1d12758ae8c76a32cf7f2e0091e53365bc 100644 (file)
@@ -48,6 +48,7 @@
 use std::path::PathBuf;
 use std::rc::Rc;
 use std::u32;
+use std::env::current_dir;
 
 use core::DocContext;
 use doctree;
@@ -201,7 +202,13 @@ fn clean(&self, cx: &DocContext) -> Crate {
         }
 
         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
         };
 
index 267220891b98bf44b470744b363bc90f03da8a16..a7c796dd2f5cdf279e8ae7e2195aeee2c8fefe42 100644 (file)
@@ -46,7 +46,7 @@
 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;
 
@@ -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,
         }
     }
 }
@@ -871,7 +872,7 @@ fn fold_item(&mut self, item: clean::Item) -> Option<clean::Item> {
             // 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, \
diff --git a/src/test/rustdoc/issue-26995.rs b/src/test/rustdoc/issue-26995.rs
new file mode 100644 (file)
index 0000000..bfb440a
--- /dev/null
@@ -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;