From 27ca2507defe13c5c989a9aa64d138645a7db65e Mon Sep 17 00:00:00 2001 From: mitaa Date: Wed, 24 Feb 2016 19:40:16 +0100 Subject: [PATCH 1/2] Allow creation of src-links for device files --- src/librustdoc/html/render.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 692d230446cda..267220891b98b 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1489,9 +1489,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 `` - 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, From cf76fcf30d1efefd01bba0ed9b81cd867262346f Mon Sep 17 00:00:00 2001 From: mitaa Date: Tue, 23 Feb 2016 07:52:43 +0100 Subject: [PATCH 2/2] Fix source-links for files with absolute-paths `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 | 9 ++++++++- src/librustdoc/html/render.rs | 15 ++++++++------- src/test/rustdoc/issue-26995.rs | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 src/test/rustdoc/issue-26995.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7072f1b498bb9..1ff88f1d12758 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -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; @@ -201,7 +202,13 @@ impl<'a, 'tcx> Clean 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 }; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 267220891b98b..a7c796dd2f5cd 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -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; @@ -810,16 +810,17 @@ fn clean_srcpath(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 @@ 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, \ diff --git a/src/test/rustdoc/issue-26995.rs b/src/test/rustdoc/issue-26995.rs new file mode 100644 index 0000000000000..bfb440a18392e --- /dev/null +++ b/src/test/rustdoc/issue-26995.rs @@ -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 or the MIT license +// , 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;