From ea5843cc7781dd572679c69fd008bfe71279b03d Mon Sep 17 00:00:00 2001 From: Andy Russell Date: Fri, 16 Nov 2018 14:30:52 -0500 Subject: [PATCH 01/45] fix intra-link resolution spans in block comments This commit improves the calculation of code spans for intra-doc resolution failures. All sugared doc comments should now have the correct spans, including those where the comment is longer than the docs. It also fixes an issue where the spans were calculated incorrectly for certain unsugared doc comments. The diagnostic will now always use the span of the attributes, as originally intended. Fixes #55964. --- src/librustdoc/clean/mod.rs | 2 - .../passes/collect_intra_doc_links.rs | 81 ++++++++++++------ src/test/rustdoc-ui/intra-links-warning.rs | 23 +++++ .../rustdoc-ui/intra-links-warning.stderr | 84 +++++++++++++------ 4 files changed, 140 insertions(+), 50 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0518d73e1e30f..50b17f59b47d9 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -708,8 +708,6 @@ impl> NestedAttributesExt for I { /// kept separate because of issue #42760. #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Debug, Hash)] pub enum DocFragment { - // FIXME #44229 (misdreavus): sugared and raw doc comments can be brought back together once - // hoedown is completely removed from rustdoc. /// A doc fragment created from a `///` or `//!` doc comment. SugaredDoc(usize, syntax_pos::Span, String), /// A doc fragment created from a "raw" `#[doc=""]` attribute. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index f5056cead567e..31047ab353a47 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -497,6 +497,19 @@ fn span_of_attrs(attrs: &Attributes) -> syntax_pos::Span { start.to(end) } +/// Reports a resolution failure diagnostic. +/// +/// Ideally we can report the diagnostic with the actual span in the source where the link failure +/// occurred. However, there's a mismatch between the span in the source code and the span in the +/// markdown, so we have to do a bit of work to figure out the correspondence. +/// +/// It's not too hard to find the span for sugared doc comments (`///` and `/**`), because the +/// source will match the markdown exactly, excluding the comment markers. However, it's much more +/// difficult to calculate the spans for unsugared docs, because we have to deal with escaping and +/// other source features. So, we attempt to find the exact source span of the resolution failure +/// in sugared docs, but use the span of the documentation attributes themselves for unsugared +/// docs. Because this span might be overly large, we display the markdown line containing the +/// failure as a note. fn resolution_failure( cx: &DocContext, attrs: &Attributes, @@ -507,34 +520,50 @@ fn resolution_failure( let sp = span_of_attrs(attrs); let msg = format!("`[{}]` cannot be resolved, ignoring it...", path_str); - let code_dox = sp.to_src(cx); - - let doc_comment_padding = 3; let mut diag = if let Some(link_range) = link_range { - // blah blah blah\nblah\nblah [blah] blah blah\nblah blah - // ^ ~~~~~~ - // | link_range - // last_new_line_offset - let mut diag; - if dox.lines().count() == code_dox.lines().count() { - let line_offset = dox[..link_range.start].lines().count(); - // The span starts in the `///`, so we don't have to account for the leading whitespace - let code_dox_len = if line_offset <= 1 { - doc_comment_padding - } else { - // The first `///` - doc_comment_padding + - // Each subsequent leading whitespace and `///` - code_dox.lines().skip(1).take(line_offset - 1).fold(0, |sum, line| { - sum + doc_comment_padding + line.len() - line.trim_start().len() - }) - }; - // Extract the specific span + if attrs.doc_strings.iter().all(|frag| match frag { + DocFragment::SugaredDoc(..) => true, + _ => false, + }) { + let source_dox = sp.to_src(cx); + let mut source_lines = source_dox.lines().peekable(); + let mut md_lines = dox.lines().peekable(); + + // The number of bytes from the start of the source span to the resolution failure that + // are *not* part of the markdown, like comment markers. + let mut source_offset = 0; + + // Eat any source lines before the markdown starts (e.g., `/**` on its own line). + while let Some(source_line) = source_lines.peek() { + if source_line.contains(md_lines.peek().unwrap()) { + break; + } + + // Include the newline. + source_offset += source_line.len() + 1; + source_lines.next().unwrap(); + } + + // The number of lines up to and including the resolution failure. + let num_lines = dox[..link_range.start].lines().count(); + + // Consume inner comment markers (e.g., `///` or ` *`). + for (source_line, md_line) in source_lines.zip(md_lines).take(num_lines) { + source_offset += if md_line.is_empty() { + // If there is no markdown on this line, then the whole line is a comment + // marker. We don't have to count the newline here because it's in the markdown + // too. + source_line.len() + } else { + source_line.find(md_line).unwrap() + }; + } + let sp = sp.from_inner_byte_pos( - link_range.start + code_dox_len, - link_range.end + code_dox_len, + link_range.start + source_offset, + link_range.end + source_offset, ); diag = cx.tcx.struct_span_lint_node(lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, @@ -548,6 +577,10 @@ fn resolution_failure( sp, &msg); + // blah blah blah\nblah\nblah [blah] blah blah\nblah blah + // ^ ~~~~ + // | link_range + // last_new_line_offset let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); diff --git a/src/test/rustdoc-ui/intra-links-warning.rs b/src/test/rustdoc-ui/intra-links-warning.rs index d6bc275b57a6a..3051bec88d24d 100644 --- a/src/test/rustdoc-ui/intra-links-warning.rs +++ b/src/test/rustdoc-ui/intra-links-warning.rs @@ -55,3 +55,26 @@ macro_rules! f { } } f!("Foo\nbar [BarF] bar\nbaz"); + +/** # for example, + * + * time to introduce a link [error]*/ +pub struct A; + +/** + * # for example, + * + * time to introduce a link [error] + */ +pub struct B; + +#[doc = "single line [error]"] +pub struct C; + +#[doc = "single line with \"escaping\" [error]"] +pub struct D; + +/// Item docs. +#[doc="Hello there!"] +/// [error] +pub struct E; diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index c05f99fadc9e4..543919938cea7 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -55,6 +55,60 @@ LL | /// [Qux:Y] | = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` +warning: `[error]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:61:30 + | +LL | * time to introduce a link [error]*/ + | ^^^^^ cannot be resolved, ignoring + | + = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` + +warning: `[error]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:67:30 + | +LL | * time to introduce a link [error] + | ^^^^^ cannot be resolved, ignoring + | + = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` + +warning: `[error]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:71:1 + | +LL | #[doc = "single line [error]"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the link appears in this line: + + single line [error] + ^^^^^ + = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` + +warning: `[error]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:74:1 + | +LL | #[doc = "single line with /"escaping/" [error]"] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: the link appears in this line: + + single line with "escaping" [error] + ^^^^^ + = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` + +warning: `[error]` cannot be resolved, ignoring it... + --> $DIR/intra-links-warning.rs:77:1 + | +LL | / /// Item docs. +LL | | #[doc="Hello there!"] +LL | | /// [error] + | |___________^ + | + = note: the link appears in this line: + + [error] + ^^^^^ + = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` + warning: `[BarA]` cannot be resolved, ignoring it... --> $DIR/intra-links-warning.rs:24:10 | @@ -64,37 +118,19 @@ LL | /// bar [BarA] bar = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` warning: `[BarB]` cannot be resolved, ignoring it... - --> $DIR/intra-links-warning.rs:28:1 + --> $DIR/intra-links-warning.rs:30:9 | -LL | / /** -LL | | * Foo -LL | | * bar [BarB] bar -LL | | * baz -LL | | */ - | |___^ +LL | * bar [BarB] bar + | ^^^^ cannot be resolved, ignoring | - = note: the link appears in this line: - - bar [BarB] bar - ^^^^ = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` warning: `[BarC]` cannot be resolved, ignoring it... - --> $DIR/intra-links-warning.rs:35:1 + --> $DIR/intra-links-warning.rs:37:6 | -LL | / /** Foo -LL | | -LL | | bar [BarC] bar -LL | | baz -... | -LL | | -LL | | */ - | |__^ +LL | bar [BarC] bar + | ^^^^ cannot be resolved, ignoring | - = note: the link appears in this line: - - bar [BarC] bar - ^^^^ = help: to escape `[` and `]` characters, just add '/' before them like `/[` or `/]` warning: `[BarD]` cannot be resolved, ignoring it... From 700c83bc05ebeddbe3d3a10c2e309826d563b12b Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Sun, 24 Jun 2018 09:38:56 +0200 Subject: [PATCH 02/45] Document `From` implementations --- src/libstd/path.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index a153456370c6f..ab37bb7520972 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1397,6 +1397,8 @@ impl<'a> From<&'a Path> for Box { #[stable(feature = "path_buf_from_box", since = "1.18.0")] impl From> for PathBuf { + /// Converts a `Box` into a `PathBuf`. + /// This conversion does not allocate memory fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } @@ -1404,6 +1406,8 @@ impl From> for PathBuf { #[stable(feature = "box_from_path_buf", since = "1.20.0")] impl From for Box { + /// Converts a `PathBuf` into a `Box`. + /// This conversion does not allocate memory fn from(p: PathBuf) -> Box { p.into_boxed_path() } @@ -1426,6 +1430,9 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { + /// Converts a `OsString` into a `PathBuf`. + /// This conversion copies the data. + /// This conversion does allocate memory. fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1433,6 +1440,9 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { + /// Converts a `PathBuf` into a `OsString`. + /// This conversion copies the data. + /// This conversion does allocate memory. fn from(path_buf : PathBuf) -> OsString { path_buf.inner } @@ -1440,6 +1450,8 @@ impl From for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { + /// Converts a `String` into a `PathBuf`. + /// This conversion does not allocate memory fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) } @@ -1536,6 +1548,10 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { + /// Converts a `PathBuf` into a `Arc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1545,6 +1561,10 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { + /// Converts a `PathBuf` into a `Arc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1554,6 +1574,10 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { + /// Converts a `PathBuf` into a `Rc`. + /// This conversion happens in place. + /// This conversion does not allocate memory. + /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From 072bca3ff5a3907a71c22fba041825cfa3eb321e Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Mon, 25 Jun 2018 14:24:39 +0200 Subject: [PATCH 03/45] Remove 'unsafe' comments --- src/libstd/path.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index ab37bb7520972..9145eeb6063f6 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1551,7 +1551,6 @@ impl From for Arc { /// Converts a `PathBuf` into a `Arc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1564,7 +1563,6 @@ impl<'a> From<&'a Path> for Arc { /// Converts a `PathBuf` into a `Arc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1577,7 +1575,6 @@ impl From for Rc { /// Converts a `PathBuf` into a `Rc`. /// This conversion happens in place. /// This conversion does not allocate memory. - /// This function is unsafe. Data can't be moved from this reference. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From 88a708dd6a5bb14f3a19ae98238ddf2d03cb93d3 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Mon, 25 Jun 2018 21:29:22 +0200 Subject: [PATCH 04/45] Update comments --- src/libstd/path.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9145eeb6063f6..e631bb90f5741 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1431,8 +1431,7 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { /// Converts a `OsString` into a `PathBuf`. - /// This conversion copies the data. - /// This conversion does allocate memory. + /// This conversion does not allocate memory fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1441,8 +1440,7 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { /// Converts a `PathBuf` into a `OsString`. - /// This conversion copies the data. - /// This conversion does allocate memory. + /// This conversion does not allocate memory fn from(path_buf : PathBuf) -> OsString { path_buf.inner } From 5c747eb32654401b9b6fe053c3f51399a6454f8c Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Thu, 26 Jul 2018 10:59:46 +0200 Subject: [PATCH 05/45] Update style of comments --- src/libstd/path.rs | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index e631bb90f5741..9f6fcad242292 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1397,7 +1397,8 @@ impl<'a> From<&'a Path> for Box { #[stable(feature = "path_buf_from_box", since = "1.18.0")] impl From> for PathBuf { - /// Converts a `Box` into a `PathBuf`. + /// Converts a `Box` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() @@ -1406,7 +1407,8 @@ impl From> for PathBuf { #[stable(feature = "box_from_path_buf", since = "1.20.0")] impl From for Box { - /// Converts a `PathBuf` into a `Box`. + /// Converts a `PathBuf` into a `Box` + /// /// This conversion does not allocate memory fn from(p: PathBuf) -> Box { p.into_boxed_path() @@ -1430,7 +1432,8 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { - /// Converts a `OsString` into a `PathBuf`. + /// Converts a `OsString` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(s: OsString) -> PathBuf { PathBuf { inner: s } @@ -1439,7 +1442,8 @@ impl From for PathBuf { #[stable(feature = "from_path_buf_for_os_string", since = "1.14.0")] impl From for OsString { - /// Converts a `PathBuf` into a `OsString`. + /// Converts a `PathBuf` into a `OsString` + /// /// This conversion does not allocate memory fn from(path_buf : PathBuf) -> OsString { path_buf.inner @@ -1448,7 +1452,8 @@ impl From for OsString { #[stable(feature = "rust1", since = "1.0.0")] impl From for PathBuf { - /// Converts a `String` into a `PathBuf`. + /// Converts a `String` into a `PathBuf` + /// /// This conversion does not allocate memory fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) @@ -1546,9 +1551,11 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { - /// Converts a `PathBuf` into a `Arc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Arc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1558,9 +1565,12 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { - /// Converts a `PathBuf` into a `Arc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Arc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory + /// #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1570,9 +1580,11 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts a `PathBuf` into a `Rc`. - /// This conversion happens in place. - /// This conversion does not allocate memory. + /// Converts a `PathBuf` into a `Rc` + /// + /// This conversion happens in place + /// + /// This conversion does not allocate memory #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); From e8dafbaf10bf9e54854382f0aa830d219aec85bb Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 21 Nov 2018 13:06:22 +0100 Subject: [PATCH 06/45] Adjust doc comments --- src/libstd/path.rs | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 9f6fcad242292..2d0a2501f7e99 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1399,7 +1399,7 @@ impl<'a> From<&'a Path> for Box { impl From> for PathBuf { /// Converts a `Box` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(boxed: Box) -> PathBuf { boxed.into_path_buf() } @@ -1409,7 +1409,8 @@ impl From> for PathBuf { impl From for Box { /// Converts a `PathBuf` into a `Box` /// - /// This conversion does not allocate memory + /// This conversion currently should not allocate memory, + // but this behavior is not guaranteed on all platforms or in all future versions. fn from(p: PathBuf) -> Box { p.into_boxed_path() } @@ -1434,7 +1435,7 @@ impl<'a, T: ?Sized + AsRef> From<&'a T> for PathBuf { impl From for PathBuf { /// Converts a `OsString` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(s: OsString) -> PathBuf { PathBuf { inner: s } } @@ -1444,7 +1445,7 @@ impl From for PathBuf { impl From for OsString { /// Converts a `PathBuf` into a `OsString` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(path_buf : PathBuf) -> OsString { path_buf.inner } @@ -1454,7 +1455,7 @@ impl From for OsString { impl From for PathBuf { /// Converts a `String` into a `PathBuf` /// - /// This conversion does not allocate memory + /// This conversion does not allocate or copy memory. fn from(s: String) -> PathBuf { PathBuf::from(OsString::from(s)) } @@ -1551,11 +1552,7 @@ impl<'a> From> for PathBuf { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Arc { - /// Converts a `PathBuf` into a `Arc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: PathBuf) -> Arc { let arc: Arc = Arc::from(s.into_os_string()); @@ -1565,12 +1562,7 @@ impl From for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Arc { - /// Converts a `PathBuf` into a `Arc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory - /// + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Arc { let arc: Arc = Arc::from(s.as_os_str()); @@ -1580,11 +1572,7 @@ impl<'a> From<&'a Path> for Arc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl From for Rc { - /// Converts a `PathBuf` into a `Rc` - /// - /// This conversion happens in place - /// - /// This conversion does not allocate memory + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: PathBuf) -> Rc { let rc: Rc = Rc::from(s.into_os_string()); @@ -1594,6 +1582,7 @@ impl From for Rc { #[stable(feature = "shared_from_slice2", since = "1.24.0")] impl<'a> From<&'a Path> for Rc { + /// Converts a Path into a Rc by copying the Path data into a new Rc buffer. #[inline] fn from(s: &Path) -> Rc { let rc: Rc = Rc::from(s.as_os_str()); From 7933628de58851281544fe2a7b4e0d0673652e47 Mon Sep 17 00:00:00 2001 From: Bastian Gruber Date: Wed, 21 Nov 2018 13:57:56 +0100 Subject: [PATCH 07/45] Remove trailing whitespace --- src/libstd/path.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 2d0a2501f7e99..dcd02ac59b6c8 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -1409,7 +1409,7 @@ impl From> for PathBuf { impl From for Box { /// Converts a `PathBuf` into a `Box` /// - /// This conversion currently should not allocate memory, + /// This conversion currently should not allocate memory, // but this behavior is not guaranteed on all platforms or in all future versions. fn from(p: PathBuf) -> Box { p.into_boxed_path() From c209ed84359804d200454f117946d41e5ac84159 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 1 Nov 2018 02:20:49 +0100 Subject: [PATCH 08/45] Improve no result found sentence in doc search --- src/librustdoc/html/static/main.js | 11 ++++++++++- src/librustdoc/html/static/rustdoc.css | 13 ++++++++++--- src/librustdoc/html/static/themes/dark.css | 2 +- src/librustdoc/html/static/themes/light.css | 2 +- 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index 3174c1be3adc8..27b1dfc9ce39a 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1340,7 +1340,16 @@ output = '
No results :(
' + 'Try on DuckDuckGo?
'; + '">DuckDuckGo?

' + + 'Or try looking in one of these:'; } return [output, length]; } diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 8bcb828a5ade1..aa43a0bb58ad9 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -658,9 +658,9 @@ a { padding-right: 10px; } .content .search-results td:first-child a:after { - clear: both; - content: ""; - display: block; + clear: both; + content: ""; + display: block; } .content .search-results td:first-child a span { float: left; @@ -1116,6 +1116,13 @@ pre.rust { margin-top: 20px; } +.search-failed > ul { + text-align: left; + max-width: 570px; + margin-left: auto; + margin-right: auto; +} + #titles { height: 35px; } diff --git a/src/librustdoc/html/static/themes/dark.css b/src/librustdoc/html/static/themes/dark.css index 4a8950b236c62..9c90c94858116 100644 --- a/src/librustdoc/html/static/themes/dark.css +++ b/src/librustdoc/html/static/themes/dark.css @@ -285,7 +285,7 @@ pre.ignore:hover, .information:hover + pre.ignore { color: rgba(255,142,0,1); } -.search-failed > a { +.search-failed a { color: #0089ff; } diff --git a/src/librustdoc/html/static/themes/light.css b/src/librustdoc/html/static/themes/light.css index b3b0b6b2ea9e8..e839fc3f2783f 100644 --- a/src/librustdoc/html/static/themes/light.css +++ b/src/librustdoc/html/static/themes/light.css @@ -279,7 +279,7 @@ pre.ignore:hover, .information:hover + pre.ignore { color: rgba(255,142,0,1); } -.search-failed > a { +.search-failed a { color: #0089ff; } From 47b5e23e6b72183b993584dc41c51652eb6adb3a Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Mon, 26 Nov 2018 18:36:03 +0000 Subject: [PATCH 09/45] Introduce ptr::hash for references --- src/libcore/ptr.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index e9cf11424cae1..6b4ee66bb02cf 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2509,6 +2509,29 @@ pub fn eq(a: *const T, b: *const T) -> bool { a == b } +/// Hash the raw pointer address behind a reference, rather than the value +/// it points to. +/// +/// # Examples +/// +/// ``` +/// use std::collections::hash_map::DefaultHasher; +/// use std::hash::Hasher; +/// use std::ptr; +/// +/// let five = 5; +/// let five_ref = &five; +/// +/// let mut hasher = DefaultHasher::new(); +/// ptr::hash(five_ref, hasher); +/// println!("Hash is {:x}!", hasher.finish()); +/// ``` +#[stable(feature = "rust1", since = "1.0.0")] // TODO: replace with ??? +pub fn hash(a: &T, into: &mut S) { + use hash::Hash; + NonNull::from(a).hash(into) +} + // Impls for function pointers macro_rules! fnptr_impls_safety_abi { ($FnTy: ty, $($Arg: ident),*) => { From 86d20f9342c8b6cfd24d199eacb26ed11a95da12 Mon Sep 17 00:00:00 2001 From: Dale Wijnand <344610+dwijnand@users.noreply.github.com> Date: Mon, 26 Nov 2018 19:23:20 +0000 Subject: [PATCH 10/45] FIXME is the new TODO --- src/libcore/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 6b4ee66bb02cf..7a57c365b2301 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2526,7 +2526,7 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// ptr::hash(five_ref, hasher); /// println!("Hash is {:x}!", hasher.finish()); /// ``` -#[stable(feature = "rust1", since = "1.0.0")] // TODO: replace with ??? +#[stable(feature = "rust1", since = "1.0.0")] // FIXME: replace with ??? pub fn hash(a: &T, into: &mut S) { use hash::Hash; NonNull::from(a).hash(into) From 5558c07c6e24b6677e3a60a1314d705c8c23ab47 Mon Sep 17 00:00:00 2001 From: Dale Wijnand <344610+dwijnand@users.noreply.github.com> Date: Mon, 26 Nov 2018 21:31:12 +0000 Subject: [PATCH 11/45] Fix ptr::hex doc example --- src/libcore/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 7a57c365b2301..c0e8e58114414 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2523,7 +2523,7 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// let five_ref = &five; /// /// let mut hasher = DefaultHasher::new(); -/// ptr::hash(five_ref, hasher); +/// ptr::hash(five_ref, &mut hasher); /// println!("Hash is {:x}!", hasher.finish()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] // FIXME: replace with ??? From 7b429b0440eb7e8888ea600ca2103cb13999b3a2 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 16:25:38 +0000 Subject: [PATCH 12/45] Fix stability attribute for ptr::hash --- src/libcore/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index c0e8e58114414..13aae988d6c10 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2526,7 +2526,7 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// ptr::hash(five_ref, &mut hasher); /// println!("Hash is {:x}!", hasher.finish()); /// ``` -#[stable(feature = "rust1", since = "1.0.0")] // FIXME: replace with ??? +#[unstable(feature = "ptr_hash", reason = "newly added", issue = "56285")] pub fn hash(a: &T, into: &mut S) { use hash::Hash; NonNull::from(a).hash(into) From 81251491ddecb5c55b6d22b04abf33ef65d3a74b Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 16:33:01 +0000 Subject: [PATCH 13/45] Pick a better variable name for ptr::hash --- src/libcore/ptr.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 13aae988d6c10..ff679d92e6096 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2527,9 +2527,9 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// println!("Hash is {:x}!", hasher.finish()); /// ``` #[unstable(feature = "ptr_hash", reason = "newly added", issue = "56285")] -pub fn hash(a: &T, into: &mut S) { +pub fn hash(hashee: &T, into: &mut S) { use hash::Hash; - NonNull::from(a).hash(into) + NonNull::from(hashee).hash(into) } // Impls for function pointers From afb4fbd951bc9780b5a7812f9a72aa9e2f085814 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 16:46:24 +0000 Subject: [PATCH 14/45] Add an assert_eq in ptr::hash's doc example --- src/libcore/ptr.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index ff679d92e6096..7b93795728b92 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2524,7 +2524,13 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// /// let mut hasher = DefaultHasher::new(); /// ptr::hash(five_ref, &mut hasher); -/// println!("Hash is {:x}!", hasher.finish()); +/// let actual = hasher.finish(); +/// +/// let mut hasher = DefaultHasher::new(); +/// (five_ref as *const T).hash(&mut hasher); +/// let expected = hasher.finish(); +/// +/// assert_eq!(actual, expected); /// ``` #[unstable(feature = "ptr_hash", reason = "newly added", issue = "56285")] pub fn hash(hashee: &T, into: &mut S) { From 4a7ffe2646b5d152297ab8008cc64693b4fd3d0a Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 16:46:59 +0000 Subject: [PATCH 15/45] Fix issue number --- src/libcore/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 7b93795728b92..7c8b195db8f1c 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2532,7 +2532,7 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// /// assert_eq!(actual, expected); /// ``` -#[unstable(feature = "ptr_hash", reason = "newly added", issue = "56285")] +#[unstable(feature = "ptr_hash", reason = "newly added", issue = "56286")] pub fn hash(hashee: &T, into: &mut S) { use hash::Hash; NonNull::from(hashee).hash(into) From 9755410f73584909ffa2f3241a946d47139d1902 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 20:09:18 +0000 Subject: [PATCH 16/45] Try to fix ptr::hash's doc example --- src/libcore/ptr.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 7c8b195db8f1c..3024031b3bb29 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2516,18 +2516,19 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// /// ``` /// use std::collections::hash_map::DefaultHasher; -/// use std::hash::Hasher; +/// use std::hash::{Hash, Hasher}; /// use std::ptr; /// /// let five = 5; /// let five_ref = &five; /// /// let mut hasher = DefaultHasher::new(); +/// #[feature(ptr_hash)] /// ptr::hash(five_ref, &mut hasher); /// let actual = hasher.finish(); /// /// let mut hasher = DefaultHasher::new(); -/// (five_ref as *const T).hash(&mut hasher); +/// (five_ref as *const i32).hash(&mut hasher); /// let expected = hasher.finish(); /// /// assert_eq!(actual, expected); From 097b5db5f67c28719d0065c6a74a2e56ae52d2d3 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Tue, 27 Nov 2018 21:18:20 +0000 Subject: [PATCH 17/45] Move feature enable in ptr::hash doc example --- src/libcore/ptr.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 3024031b3bb29..0213b310efaa3 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2515,6 +2515,7 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// # Examples /// /// ``` +/// #![feature(ptr_hash)] /// use std::collections::hash_map::DefaultHasher; /// use std::hash::{Hash, Hasher}; /// use std::ptr; @@ -2523,7 +2524,6 @@ pub fn eq(a: *const T, b: *const T) -> bool { /// let five_ref = &five; /// /// let mut hasher = DefaultHasher::new(); -/// #[feature(ptr_hash)] /// ptr::hash(five_ref, &mut hasher); /// let actual = hasher.finish(); /// From dd717deccb3a4698beac8edb0a75e2efb6f08ebb Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 1 Oct 2018 00:47:54 +0200 Subject: [PATCH 18/45] Add crate filtering --- src/librustdoc/html/layout.rs | 15 ++-- src/librustdoc/html/render.rs | 2 +- src/librustdoc/html/static/main.js | 99 +++++++++++++++++---- src/librustdoc/html/static/rustdoc.css | 24 ++++- src/librustdoc/html/static/themes/dark.css | 8 +- src/librustdoc/html/static/themes/light.css | 9 +- 6 files changed, 131 insertions(+), 26 deletions(-) diff --git a/src/librustdoc/html/layout.rs b/src/librustdoc/html/layout.rs index 6868c7707adc8..d585b737517b3 100644 --- a/src/librustdoc/html/layout.rs +++ b/src/librustdoc/html/layout.rs @@ -81,11 +81,16 @@ pub fn render(