Merge branch 'master' into escape-reason-docs
This commit is contained in:
commit
e766c465d2
601 changed files with 19295 additions and 10334 deletions
|
|
@ -1737,7 +1737,6 @@ impl Clean<Type> for hir::Ty {
|
|||
segments.pop();
|
||||
let trait_path = hir::Path {
|
||||
span: p.span,
|
||||
global: p.global,
|
||||
def: Def::Trait(cx.tcx.associated_item(p.def.def_id()).container.id()),
|
||||
segments: segments.into(),
|
||||
};
|
||||
|
|
@ -1756,7 +1755,6 @@ impl Clean<Type> for hir::Ty {
|
|||
}
|
||||
let trait_path = hir::Path {
|
||||
span: self.span,
|
||||
global: false,
|
||||
def: def,
|
||||
segments: vec![].into(),
|
||||
};
|
||||
|
|
@ -2213,9 +2211,9 @@ impl Path {
|
|||
impl Clean<Path> for hir::Path {
|
||||
fn clean(&self, cx: &DocContext) -> Path {
|
||||
Path {
|
||||
global: self.global,
|
||||
global: self.is_global(),
|
||||
def: self.def,
|
||||
segments: self.segments.clean(cx),
|
||||
segments: if self.is_global() { &self.segments[1..] } else { &self.segments }.clean(cx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2270,24 +2268,19 @@ impl Clean<PathSegment> for hir::PathSegment {
|
|||
}
|
||||
|
||||
fn qpath_to_string(p: &hir::QPath) -> String {
|
||||
let (segments, global) = match *p {
|
||||
hir::QPath::Resolved(_, ref path) => {
|
||||
(&path.segments, path.global)
|
||||
}
|
||||
hir::QPath::TypeRelative(_, ref segment) => {
|
||||
return segment.name.to_string()
|
||||
}
|
||||
let segments = match *p {
|
||||
hir::QPath::Resolved(_, ref path) => &path.segments,
|
||||
hir::QPath::TypeRelative(_, ref segment) => return segment.name.to_string(),
|
||||
};
|
||||
|
||||
let mut s = String::new();
|
||||
let mut first = true;
|
||||
for i in segments.iter().map(|x| x.name.as_str()) {
|
||||
if !first || global {
|
||||
for (i, seg) in segments.iter().enumerate() {
|
||||
if i > 0 {
|
||||
s.push_str("::");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
s.push_str(&i);
|
||||
if seg.name != keywords::CrateRoot.name() {
|
||||
s.push_str(&*seg.name.as_str());
|
||||
}
|
||||
}
|
||||
s
|
||||
}
|
||||
|
|
@ -2801,7 +2794,7 @@ impl Clean<Item> for doctree::Macro {
|
|||
visibility: Some(Public),
|
||||
stability: self.stab.clean(cx),
|
||||
deprecation: self.depr.clean(cx),
|
||||
def_id: cx.tcx.map.local_def_id(self.id),
|
||||
def_id: self.def_id,
|
||||
inner: MacroItem(Macro {
|
||||
source: format!("macro_rules! {} {{\n{}}}",
|
||||
name,
|
||||
|
|
|
|||
|
|
@ -233,9 +233,11 @@ pub struct DefaultImpl {
|
|||
pub whence: Span,
|
||||
}
|
||||
|
||||
// For Macro we store the DefId instead of the NodeId, since we also create
|
||||
// these imported macro_rules (which only have a DUMMY_NODE_ID).
|
||||
pub struct Macro {
|
||||
pub name: Name,
|
||||
pub id: ast::NodeId,
|
||||
pub def_id: hir::def_id::DefId,
|
||||
pub attrs: hir::HirVec<ast::Attribute>,
|
||||
pub whence: Span,
|
||||
pub matchers: hir::HirVec<Span>,
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ impl<'a> fmt::Display for WhereClause<'a> {
|
|||
if !f.alternate() {
|
||||
clause.push_str("</span>");
|
||||
let plain = format!("{:#}", self);
|
||||
if plain.len() > 80 {
|
||||
if plain.len() + pad > 80 {
|
||||
//break it onto its own line regardless, but make sure method impls and trait
|
||||
//blocks keep their fixed padding (2 and 9, respectively)
|
||||
let padding = if pad > 10 {
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ r##"<!DOCTYPE html>
|
|||
|
||||
<title>{title}</title>
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="{root_path}normalize.css">
|
||||
<link rel="stylesheet" type="text/css" href="{root_path}rustdoc.css">
|
||||
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
|
||||
{css_extension}
|
||||
|
|
|
|||
|
|
@ -591,7 +591,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
|||
ty: item.type_(),
|
||||
name: item.name.clone().unwrap(),
|
||||
path: fqp[..fqp.len() - 1].join("::"),
|
||||
desc: Escape(&shorter(item.doc_value())).to_string(),
|
||||
desc: plain_summary_line(item.doc_value()),
|
||||
parent: Some(did),
|
||||
parent_idx: None,
|
||||
search_type: get_index_search_type(&item),
|
||||
|
|
@ -629,7 +629,7 @@ fn build_index(krate: &clean::Crate, cache: &mut Cache) -> String {
|
|||
}
|
||||
|
||||
let crate_doc = krate.module.as_ref().map(|module| {
|
||||
Escape(&shorter(module.doc_value())).to_string()
|
||||
plain_summary_line(module.doc_value())
|
||||
}).unwrap_or(String::new());
|
||||
|
||||
let mut crate_data = BTreeMap::new();
|
||||
|
|
@ -1064,7 +1064,7 @@ impl DocFolder for Cache {
|
|||
ty: item.type_(),
|
||||
name: s.to_string(),
|
||||
path: path.join("::").to_string(),
|
||||
desc: Escape(&shorter(item.doc_value())).to_string(),
|
||||
desc: plain_summary_line(item.doc_value()),
|
||||
parent: parent,
|
||||
parent_idx: None,
|
||||
search_type: get_index_search_type(&item),
|
||||
|
|
@ -1468,6 +1468,13 @@ impl<'a> Item<'a> {
|
|||
return None;
|
||||
}
|
||||
} else {
|
||||
// Macros from other libraries get special filenames which we can
|
||||
// safely ignore.
|
||||
if self.item.source.filename.starts_with("<") &&
|
||||
self.item.source.filename.ends_with("macros>") {
|
||||
return None;
|
||||
}
|
||||
|
||||
let (krate, src_root) = match cache.extern_locations.get(&self.item.def_id.krate) {
|
||||
Some(&(ref name, ref src, Local)) => (name, src),
|
||||
Some(&(ref name, ref src, Remote(ref s))) => {
|
||||
|
|
@ -1655,8 +1662,13 @@ fn document_full(w: &mut fmt::Formatter, item: &clean::Item) -> fmt::Result {
|
|||
}
|
||||
|
||||
fn document_stability(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item) -> fmt::Result {
|
||||
for stability in short_stability(item, cx, true) {
|
||||
write!(w, "<div class='stability'>{}</div>", stability)?;
|
||||
let stabilities = short_stability(item, cx, true);
|
||||
if !stabilities.is_empty() {
|
||||
write!(w, "<div class='stability'>")?;
|
||||
for stability in stabilities {
|
||||
write!(w, "{}", stability)?;
|
||||
}
|
||||
write!(w, "</div>")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -1855,7 +1867,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
|
|||
String::new()
|
||||
};
|
||||
let text = format!("Deprecated{}{}", since, MarkdownHtml(&deprecated_reason));
|
||||
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
|
||||
stability.push(format!("<div class='stab deprecated'>{}</div>", text))
|
||||
};
|
||||
|
||||
if stab.level == stability::Unstable {
|
||||
|
|
@ -1880,7 +1892,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
|
|||
String::new()
|
||||
};
|
||||
let text = format!("Unstable{}{}", unstable_extra, MarkdownHtml(&unstable_reason));
|
||||
stability.push(format!("<em class='stab unstable'>{}</em>", text))
|
||||
stability.push(format!("<div class='stab unstable'>{}</div>", text))
|
||||
};
|
||||
} else if let Some(depr) = item.deprecation.as_ref() {
|
||||
let note = if show_reason && !depr.note.is_empty() {
|
||||
|
|
@ -1895,7 +1907,7 @@ fn short_stability(item: &clean::Item, cx: &Context, show_reason: bool) -> Vec<S
|
|||
};
|
||||
|
||||
let text = format!("Deprecated{}{}", since, MarkdownHtml(¬e));
|
||||
stability.push(format!("<em class='stab deprecated'>{}</em>", text))
|
||||
stability.push(format!("<div class='stab deprecated'>{}</div>", text))
|
||||
}
|
||||
|
||||
stability
|
||||
|
|
|
|||
|
|
@ -609,7 +609,7 @@
|
|||
displayPath + '<span class="' + type + '">' +
|
||||
name + '</span></a></td><td>' +
|
||||
'<a href="' + href + '">' +
|
||||
'<span class="desc">' + item.desc +
|
||||
'<span class="desc">' + escape(item.desc) +
|
||||
' </span></a></td></tr>';
|
||||
});
|
||||
} else {
|
||||
|
|
@ -807,14 +807,6 @@
|
|||
search();
|
||||
}
|
||||
|
||||
function plainSummaryLine(markdown) {
|
||||
markdown.replace(/\n/g, ' ')
|
||||
.replace(/'/g, "\'")
|
||||
.replace(/^#+? (.+?)/, "$1")
|
||||
.replace(/\[(.*?)\]\(.*?\)/g, "$1")
|
||||
.replace(/\[(.*?)\]\[.*?\]/g, "$1");
|
||||
}
|
||||
|
||||
index = buildIndex(rawSearchIndex);
|
||||
startSearch();
|
||||
|
||||
|
|
@ -836,13 +828,10 @@
|
|||
if (crates[i] === window.currentCrate) {
|
||||
klass += ' current';
|
||||
}
|
||||
if (rawSearchIndex[crates[i]].items[0]) {
|
||||
var desc = rawSearchIndex[crates[i]].items[0][3];
|
||||
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'title': plainSummaryLine(desc),
|
||||
'class': klass}).text(crates[i]);
|
||||
ul.append($('<li>').append(link));
|
||||
}
|
||||
var link = $('<a>', {'href': '../' + crates[i] + '/index.html',
|
||||
'title': rawSearchIndex[crates[i]].doc,
|
||||
'class': klass}).text(crates[i]);
|
||||
ul.append($('<li>').append(link));
|
||||
}
|
||||
sidebar.append(div);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
@import "normalize.css";
|
||||
|
||||
/**
|
||||
* Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
||||
* file at the top-level directory of this distribution and at
|
||||
|
|
@ -52,13 +50,15 @@
|
|||
font-family: 'Source Code Pro';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Source Code Pro'), url("SourceCodePro-Regular.woff") format('woff');
|
||||
/* Avoid using locally installed font because bad versions are in circulation:
|
||||
* see https://github.com/rust-lang/rust/issues/24355 */
|
||||
src: url("SourceCodePro-Regular.woff") format('woff');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Source Code Pro';
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
src: local('Source Code Pro Semibold'), url("SourceCodePro-Semibold.woff") format('woff');
|
||||
src: url("SourceCodePro-Semibold.woff") format('woff');
|
||||
}
|
||||
|
||||
* {
|
||||
|
|
@ -523,20 +523,20 @@ body.blur > :not(#help) {
|
|||
padding: 20px;
|
||||
}
|
||||
|
||||
em.stab {
|
||||
display: inline-block;
|
||||
.stab {
|
||||
display: table;
|
||||
border-width: 1px;
|
||||
border-style: solid;
|
||||
padding: 3px;
|
||||
margin-bottom: 5px;
|
||||
font-size: 90%;
|
||||
font-style: normal;
|
||||
}
|
||||
em.stab p {
|
||||
.stab p {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.module-item .stab {
|
||||
display: inline;
|
||||
border-width: 0;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
|
|
|
|||
|
|
@ -30,10 +30,6 @@ h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.t
|
|||
background-color: white;
|
||||
}
|
||||
|
||||
div.stability > em > code {
|
||||
background-color: initial;
|
||||
}
|
||||
|
||||
.docblock code, .docblock-short code {
|
||||
background-color: #F5F5F5;
|
||||
}
|
||||
|
|
@ -129,5 +125,5 @@ a.test-arrow {
|
|||
background-color: white;
|
||||
}
|
||||
|
||||
em.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
||||
em.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
|
||||
.stab.unstable { background: #FFF5D6; border-color: #FFC600; }
|
||||
.stab.deprecated { background: #F3DFFF; border-color: #7F0087; }
|
||||
|
|
|
|||
|
|
@ -54,6 +54,9 @@ extern crate serialize as rustc_serialize; // used by deriving
|
|||
use std::collections::{BTreeMap, BTreeSet};
|
||||
use std::default::Default;
|
||||
use std::env;
|
||||
use std::fmt::Display;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::sync::mpsc::channel;
|
||||
|
|
@ -183,7 +186,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
let matches = match getopts::getopts(&args[1..], &all_groups) {
|
||||
Ok(m) => m,
|
||||
Err(err) => {
|
||||
println!("{}", err);
|
||||
print_error(err);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
|
@ -211,11 +214,11 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
}
|
||||
|
||||
if matches.free.is_empty() {
|
||||
println!("expected an input file to act on");
|
||||
print_error("missing file operand");
|
||||
return 1;
|
||||
}
|
||||
if matches.free.len() > 1 {
|
||||
println!("only one input file may be specified");
|
||||
print_error("too many file operands");
|
||||
return 1;
|
||||
}
|
||||
let input = &matches.free[0];
|
||||
|
|
@ -227,7 +230,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
let externs = match parse_externs(&matches) {
|
||||
Ok(ex) => ex,
|
||||
Err(err) => {
|
||||
println!("{}", err);
|
||||
print_error(err);
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
|
@ -247,7 +250,10 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
|
||||
if let Some(ref p) = css_file_extension {
|
||||
if !p.is_file() {
|
||||
println!("{}", "--extend-css option must take a css file as input");
|
||||
writeln!(
|
||||
&mut io::stderr(),
|
||||
"rustdoc: option --extend-css argument must be a file."
|
||||
).unwrap();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -257,7 +263,7 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
&matches.opt_strs("html-before-content"),
|
||||
&matches.opt_strs("html-after-content")) {
|
||||
Some(eh) => eh,
|
||||
None => return 3
|
||||
None => return 3,
|
||||
};
|
||||
let crate_name = matches.opt_str("crate-name");
|
||||
let playground_url = matches.opt_str("playground-url");
|
||||
|
|
@ -291,17 +297,26 @@ pub fn main_args(args: &[String]) -> isize {
|
|||
0
|
||||
}
|
||||
Some(s) => {
|
||||
println!("unknown output format: {}", s);
|
||||
print_error(format!("unknown output format: {}", s));
|
||||
1
|
||||
}
|
||||
}
|
||||
});
|
||||
res.unwrap_or_else(|s| {
|
||||
println!("input error: {}", s);
|
||||
print_error(format!("input error: {}", s));
|
||||
1
|
||||
})
|
||||
}
|
||||
|
||||
/// Prints an uniformised error message on the standard error output
|
||||
fn print_error<T>(error_message: T) where T: Display {
|
||||
writeln!(
|
||||
&mut io::stderr(),
|
||||
"rustdoc: {}\nTry 'rustdoc --help' for more information.",
|
||||
error_message
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
/// Looks inside the command line arguments to extract the relevant input format
|
||||
/// and files and then generates the necessary rustdoc output for formatting.
|
||||
fn acquire_input<R, F>(input: &str,
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
|||
let mut out = match File::create(&output) {
|
||||
Err(e) => {
|
||||
let _ = writeln!(&mut io::stderr(),
|
||||
"error opening `{}` for writing: {}",
|
||||
"rustdoc: {}: {}",
|
||||
output.display(), e);
|
||||
return 4;
|
||||
}
|
||||
|
|
@ -80,8 +80,10 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
|||
|
||||
let (metadata, text) = extract_leading_metadata(&input_str);
|
||||
if metadata.is_empty() {
|
||||
let _ = writeln!(&mut io::stderr(),
|
||||
"invalid markdown file: expecting initial line with `% ...TITLE...`");
|
||||
let _ = writeln!(
|
||||
&mut io::stderr(),
|
||||
"rustdoc: invalid markdown file: expecting initial line with `% ...TITLE...`"
|
||||
);
|
||||
return 5;
|
||||
}
|
||||
let title = metadata[0];
|
||||
|
|
@ -132,7 +134,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
|
|||
match err {
|
||||
Err(e) => {
|
||||
let _ = writeln!(&mut io::stderr(),
|
||||
"error writing to `{}`: {}",
|
||||
"rustdoc: cannot write to `{}`: {}",
|
||||
output.display(), e);
|
||||
6
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
None);
|
||||
// attach the crate's exported macros to the top-level module:
|
||||
let macro_exports: Vec<_> =
|
||||
krate.exported_macros.iter().map(|def| self.visit_macro(def)).collect();
|
||||
krate.exported_macros.iter().map(|def| self.visit_local_macro(def)).collect();
|
||||
self.module.macros.extend(macro_exports);
|
||||
self.module.is_crate = true;
|
||||
}
|
||||
|
|
@ -201,6 +201,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
if def_id.krate == LOCAL_CRATE {
|
||||
continue // These are `krate.exported_macros`, handled in `self.visit()`.
|
||||
}
|
||||
let imported_from = self.cx.sess().cstore.original_crate_name(def_id.krate);
|
||||
let def = match self.cx.sess().cstore.load_macro(def_id, self.cx.sess()) {
|
||||
LoadedMacro::MacroRules(macro_rules) => macro_rules,
|
||||
// FIXME(jseyfried): document proc macro reexports
|
||||
|
|
@ -210,14 +211,14 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
// FIXME(jseyfried) merge with `self.visit_macro()`
|
||||
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
|
||||
om.macros.push(Macro {
|
||||
id: def.id,
|
||||
def_id: def_id,
|
||||
attrs: def.attrs.clone().into(),
|
||||
name: def.ident.name,
|
||||
whence: def.span,
|
||||
matchers: matchers,
|
||||
stab: self.stability(def.id),
|
||||
depr: self.deprecation(def.id),
|
||||
imported_from: def.imported_from.map(|ident| ident.name),
|
||||
imported_from: Some(imported_from),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -513,19 +514,19 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// convert each exported_macro into a doc item
|
||||
fn visit_macro(&self, def: &hir::MacroDef) -> Macro {
|
||||
fn visit_local_macro(&self, def: &hir::MacroDef) -> Macro {
|
||||
// Extract the spans of all matchers. They represent the "interface" of the macro.
|
||||
let matchers = def.body.chunks(4).map(|arm| arm[0].get_span()).collect();
|
||||
|
||||
Macro {
|
||||
id: def.id,
|
||||
def_id: self.cx.tcx.map.local_def_id(def.id),
|
||||
attrs: def.attrs.clone(),
|
||||
name: def.name,
|
||||
whence: def.span,
|
||||
matchers: matchers,
|
||||
stab: self.stability(def.id),
|
||||
depr: self.deprecation(def.id),
|
||||
imported_from: def.imported_from,
|
||||
imported_from: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue