From 37a5b515e9c36ee3f57d9e0d7db7efce2fb02195 Mon Sep 17 00:00:00 2001 From: The8472 Date: Thu, 8 Apr 2021 09:57:12 +0200 Subject: [PATCH 01/17] implement TrustedRandomAccess for Take iterator adapter --- library/core/src/iter/adapters/take.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/library/core/src/iter/adapters/take.rs b/library/core/src/iter/adapters/take.rs index 9efc7a480aeb..54a47f1323eb 100644 --- a/library/core/src/iter/adapters/take.rs +++ b/library/core/src/iter/adapters/take.rs @@ -1,5 +1,8 @@ use crate::cmp; -use crate::iter::{adapters::SourceIter, FusedIterator, InPlaceIterable, TrustedLen}; +use crate::iter::{ + adapters::zip::try_get_unchecked, adapters::SourceIter, FusedIterator, InPlaceIterable, + TrustedLen, TrustedRandomAccess, +}; use crate::ops::{ControlFlow, Try}; /// An iterator that only iterates over the first `n` iterations of `iter`. @@ -111,6 +114,15 @@ where self.try_fold(init, ok(fold)).unwrap() } + + unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> ::Item + where + Self: TrustedRandomAccess, + { + // SAFETY: the caller must uphold the contract for + // `Iterator::__iterator_get_unchecked`. + unsafe { try_get_unchecked(&mut self.iter, idx) } + } } #[unstable(issue = "none", feature = "inplace_iteration")] @@ -207,3 +219,12 @@ impl FusedIterator for Take where I: FusedIterator {} #[unstable(feature = "trusted_len", issue = "37572")] unsafe impl TrustedLen for Take {} + +#[doc(hidden)] +#[unstable(feature = "trusted_random_access", issue = "none")] +unsafe impl TrustedRandomAccess for Take +where + I: TrustedRandomAccess, +{ + const MAY_HAVE_SIDE_EFFECT: bool = I::MAY_HAVE_SIDE_EFFECT; +} From 4873271955dde6d0d4a1e47851b3babf3577005d Mon Sep 17 00:00:00 2001 From: "Joshua M. Clulow" Date: Thu, 15 Apr 2021 20:52:30 -0700 Subject: [PATCH 02/17] bootstrap: use bash on illumos to run install scripts The default illumos shell ("sh" in the default PATH) is ksh93, rather than bash, and does not support constructs like "local" that came from bash. The bootstrap function for invoking "install.sh" scripts should use "bash" explicitly there to avoid issues. --- src/bootstrap/install.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/install.rs b/src/bootstrap/install.rs index 68e7dc800672..13ee909afd5e 100644 --- a/src/bootstrap/install.rs +++ b/src/bootstrap/install.rs @@ -17,6 +17,11 @@ use crate::Compiler; use crate::builder::{Builder, RunConfig, ShouldRun, Step}; use crate::config::{Config, TargetSelection}; +#[cfg(target_os = "illumos")] +const SHELL: &str = "bash"; +#[cfg(not(target_os = "illumos"))] +const SHELL: &str = "sh"; + fn install_sh( builder: &Builder<'_>, package: &str, @@ -37,7 +42,7 @@ fn install_sh( let empty_dir = builder.out.join("tmp/empty_dir"); t!(fs::create_dir_all(&empty_dir)); - let mut cmd = Command::new("sh"); + let mut cmd = Command::new(SHELL); cmd.current_dir(&empty_dir) .arg(sanitize_sh(&tarball.decompressed_output().join("install.sh"))) .arg(format!("--prefix={}", prepare_dir(prefix))) From 569096cbaffe39fbede339430c5ed8e80d991a80 Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Sat, 17 Apr 2021 23:43:20 -0700 Subject: [PATCH 03/17] rustdoc: use details tag for trait implementors This switches from JS-generated toggles to using the HTML
tag for expanding and collapsing entries in the "Implementors" section. --- src/librustdoc/html/render/mod.rs | 15 ++++++++--- src/librustdoc/html/static/main.js | 27 +++++-------------- src/librustdoc/html/static/rustdoc.css | 8 +++++- src/test/rustdoc/const-generics/add-impl.rs | 2 +- .../rustdoc/duplicate_impls/issue-33054.rs | 4 +-- src/test/rustdoc/issue-21474.rs | 2 +- src/test/rustdoc/issue-29503.rs | 2 +- src/test/rustdoc/issue-45584.rs | 4 +-- src/test/rustdoc/issue-50159.rs | 4 +-- src/test/rustdoc/issue-51236.rs | 2 +- src/test/rustdoc/issue-53812.rs | 10 +++---- src/test/rustdoc/issue-54705.rs | 4 +-- src/test/rustdoc/issue-55321.rs | 8 +++--- src/test/rustdoc/issue-56822.rs | 2 +- src/test/rustdoc/issue-60726.rs | 4 +-- src/test/rustdoc/synthetic_auto/basic.rs | 4 +-- src/test/rustdoc/synthetic_auto/complex.rs | 2 +- src/test/rustdoc/synthetic_auto/lifetimes.rs | 4 +-- src/test/rustdoc/synthetic_auto/manual.rs | 8 +++--- src/test/rustdoc/synthetic_auto/negative.rs | 4 +-- src/test/rustdoc/synthetic_auto/nested.rs | 4 +-- .../rustdoc/synthetic_auto/no-redundancy.rs | 2 +- src/test/rustdoc/synthetic_auto/project.rs | 4 +-- .../synthetic_auto/self-referential.rs | 2 +- .../rustdoc/synthetic_auto/static-region.rs | 2 +- 25 files changed, 68 insertions(+), 66 deletions(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d10b612a7379..a879a08ee472 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1313,6 +1313,7 @@ fn render_impl( let cache = cx.cache(); let traits = &cache.traits; let trait_ = i.trait_did_full(cache).map(|did| &traits[&did]); + let mut close_tags = String::new(); if render_mode == RenderMode::Normal { let id = cx.derive_id(match i.inner_impl().trait_ { @@ -1331,7 +1332,12 @@ fn render_impl( format!(" aliases=\"{}\"", aliases.join(",")) }; if let Some(use_absolute) = use_absolute { - write!(w, "

", id, aliases); + write!( + w, + "

", + id, aliases + ); + close_tags.insert_str(0, "

"); write!(w, "{}", i.inner_impl().print(use_absolute, cx)); if show_def_docs { for it in &i.inner_impl().items { @@ -1354,11 +1360,12 @@ fn render_impl( } else { write!( w, - "

{}", + "

{}", id, aliases, i.inner_impl().print(false, cx) ); + close_tags.insert_str(0, "

"); } write!(w, "", id); render_stability_since_raw( @@ -1370,6 +1377,7 @@ fn render_impl( ); write_srclink(cx, &i.impl_item, w); w.write_str("

"); + w.write_str(""); if trait_.is_some() { if let Some(portability) = portability(&i.impl_item, Some(parent)) { @@ -1580,6 +1588,7 @@ fn render_impl( } w.write_str("
"); + close_tags.insert_str(0, "
"); for trait_item in &i.inner_impl().items { doc_impl_item( w, @@ -1650,7 +1659,7 @@ fn render_impl( ); } } - w.write_str(""); + w.write_str(&close_tags); } fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer) { diff --git a/src/librustdoc/html/static/main.js b/src/librustdoc/html/static/main.js index f017fd846b1d..705ce89746a6 100644 --- a/src/librustdoc/html/static/main.js +++ b/src/librustdoc/html/static/main.js @@ -1196,31 +1196,18 @@ function hideThemeButtonState() { if (!next) { return; } - if (hasClass(e, "impl") && - (next.getElementsByClassName("method").length > 0 || - next.getElementsByClassName("associatedconstant").length > 0)) { - var newToggle = toggle.cloneNode(true); - insertAfter(newToggle, e.childNodes[e.childNodes.length - 1]); - // In case the option "auto-collapse implementors" is not set to false, we collapse - // all implementors. - if (hideImplementors === true && e.parentNode.id === "implementors-list") { - collapseDocs(newToggle, "hide"); - } - } }; onEachLazy(document.getElementsByClassName("method"), func); onEachLazy(document.getElementsByClassName("associatedconstant"), func); - onEachLazy(document.getElementsByClassName("impl"), funcImpl); var impl_call = function() {}; - // Large items are hidden by default in the HTML. If the setting overrides that, show 'em. - if (!hideLargeItemContents) { - onEachLazy(document.getElementsByTagName("details"), function (e) { - if (hasClass(e, "type-contents-toggle")) { - e.open = true; - } - }); - } + onEachLazy(document.getElementsByTagName("details"), function (e) { + var showLargeItem = !hideLargeItemContents && hasClass(e, "type-contents-toggle"); + var showImplementor = !hideImplementors && hasClass(e, "implementors-toggle"); + if (showLargeItem || showImplementor) { + e.open = true; + } + }); if (hideMethodDocs === true) { impl_call = function(e, newToggle) { if (e.id.match(/^impl(?:-\d+)?$/) === null) { diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 427564cd7794..d63679fa1570 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1561,6 +1561,10 @@ h4 > .notable-traits { left: -10px; } + .item-list > details.rustdoc-toggle > summary:not(.hideme)::before { + left: -10px; + } + #all-types { margin: 10px; } @@ -1775,6 +1779,7 @@ details.rustdoc-toggle > summary::before { font-weight: 300; font-size: 0.8em; letter-spacing: 1px; + cursor: pointer; } details.rustdoc-toggle > summary.hideme::before { @@ -1782,7 +1787,8 @@ details.rustdoc-toggle > summary.hideme::before { } details.rustdoc-toggle > summary:not(.hideme)::before { - float: left; + position: absolute; + left: -23px; } /* When a "hideme" summary is open and the "Expand description" or "Show diff --git a/src/test/rustdoc/const-generics/add-impl.rs b/src/test/rustdoc/const-generics/add-impl.rs index db4be82e6bfd..77432ba15395 100644 --- a/src/test/rustdoc/const-generics/add-impl.rs +++ b/src/test/rustdoc/const-generics/add-impl.rs @@ -8,7 +8,7 @@ pub struct Simd { inner: T, } -// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]/h3/code' 'impl Add> for Simd' +// @has foo/struct.Simd.html '//div[@id="trait-implementations-list"]//h3/code' 'impl Add> for Simd' impl Add for Simd { type Output = Self; diff --git a/src/test/rustdoc/duplicate_impls/issue-33054.rs b/src/test/rustdoc/duplicate_impls/issue-33054.rs index 112d632971a5..1e644bb97398 100644 --- a/src/test/rustdoc/duplicate_impls/issue-33054.rs +++ b/src/test/rustdoc/duplicate_impls/issue-33054.rs @@ -1,8 +1,8 @@ // @has issue_33054/impls/struct.Foo.html // @has - '//code' 'impl Foo' // @has - '//code' 'impl Bar for Foo' -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 -// @count - '//*[@id="main"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 +// @count - '//*[@id="main"]/details/summary/*[@class="impl"]' 1 // @has issue_33054/impls/bar/trait.Bar.html // @has - '//code' 'impl Bar for Foo' // @count - '//*[@class="struct"]' 1 diff --git a/src/test/rustdoc/issue-21474.rs b/src/test/rustdoc/issue-21474.rs index 896fc1a78f13..5de26abace6f 100644 --- a/src/test/rustdoc/issue-21474.rs +++ b/src/test/rustdoc/issue-21474.rs @@ -7,5 +7,5 @@ mod inner { pub trait Blah { } // @count issue_21474/struct.What.html \ -// '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 pub struct What; diff --git a/src/test/rustdoc/issue-29503.rs b/src/test/rustdoc/issue-29503.rs index 19bab394dcf2..2b25da77d7e7 100644 --- a/src/test/rustdoc/issue-29503.rs +++ b/src/test/rustdoc/issue-29503.rs @@ -5,7 +5,7 @@ pub trait MyTrait { fn my_string(&self) -> String; } -// @has - "//div[@id='implementors-list']/h3[@id='impl-MyTrait']//code" "impl MyTrait for T where T: Debug" +// @has - "//div[@id='implementors-list']//h3[@id='impl-MyTrait']//code" "impl MyTrait for T where T: Debug" impl MyTrait for T where T: fmt::Debug { fn my_string(&self) -> String { format!("{:?}", self) diff --git a/src/test/rustdoc/issue-45584.rs b/src/test/rustdoc/issue-45584.rs index 0225c0c5c2fa..8a5f0413826a 100644 --- a/src/test/rustdoc/issue-45584.rs +++ b/src/test/rustdoc/issue-45584.rs @@ -4,12 +4,12 @@ pub trait Bar {} // @has 'foo/struct.Foo1.html' pub struct Foo1; -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 // @has - '//*[@class="impl"]' "impl Bar for Foo1" impl Bar for Foo1 {} // @has 'foo/struct.Foo2.html' pub struct Foo2; -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 // @has - '//*[@class="impl"]' "impl Bar<&'static Foo2, Foo2> for u8" impl Bar<&'static Foo2, Foo2> for u8 {} diff --git a/src/test/rustdoc/issue-50159.rs b/src/test/rustdoc/issue-50159.rs index 74502be622a4..0820512e5214 100644 --- a/src/test/rustdoc/issue-50159.rs +++ b/src/test/rustdoc/issue-50159.rs @@ -13,8 +13,8 @@ impl Signal2 for B where B: Signal { // @has issue_50159/struct.Switch.html // @has - '//code' 'impl Send for Switch where ::Item: Send' // @has - '//code' 'impl Sync for Switch where ::Item: Sync' -// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 5 +// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5 pub struct Switch { pub inner: ::Item2, } diff --git a/src/test/rustdoc/issue-51236.rs b/src/test/rustdoc/issue-51236.rs index d9accf9c5998..d018c948162d 100644 --- a/src/test/rustdoc/issue-51236.rs +++ b/src/test/rustdoc/issue-51236.rs @@ -7,7 +7,7 @@ pub mod traits { } // @has issue_51236/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Owned where >::Reader: Send" pub struct Owned where T: for<'a> ::traits::Owned<'a> { marker: PhantomData<>::Reader>, diff --git a/src/test/rustdoc/issue-53812.rs b/src/test/rustdoc/issue-53812.rs index 3ebf154077f4..daebe059f8ef 100644 --- a/src/test/rustdoc/issue-53812.rs +++ b/src/test/rustdoc/issue-53812.rs @@ -12,9 +12,9 @@ macro_rules! array_impls { } } -// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]//h3[1]' 'MyStruct<[T; 0]>' -// @has - '//*[@id="implementors-list"]//h3[2]' 'MyStruct<[T; 1]>' -// @has - '//*[@id="implementors-list"]//h3[3]' 'MyStruct<[T; 2]>' -// @has - '//*[@id="implementors-list"]//h3[4]' 'MyStruct<[T; 3]>' -// @has - '//*[@id="implementors-list"]//h3[5]' 'MyStruct<[T; 10]>' +// @has issue_53812/trait.MyIterator.html '//*[@id="implementors-list"]/details[1]/summary/h3' 'MyStruct<[T; 0]>' +// @has - '//*[@id="implementors-list"]/details[2]/summary/h3' 'MyStruct<[T; 1]>' +// @has - '//*[@id="implementors-list"]/details[3]/summary/h3' 'MyStruct<[T; 2]>' +// @has - '//*[@id="implementors-list"]/details[4]/summary/h3' 'MyStruct<[T; 3]>' +// @has - '//*[@id="implementors-list"]/details[5]/summary/h3' 'MyStruct<[T; 10]>' array_impls! { 10 3 2 1 0 } diff --git a/src/test/rustdoc/issue-54705.rs b/src/test/rustdoc/issue-54705.rs index 263b1eb0bd65..47da94a4ccf4 100644 --- a/src/test/rustdoc/issue-54705.rs +++ b/src/test/rustdoc/issue-54705.rs @@ -3,10 +3,10 @@ pub trait ScopeHandle<'scope> {} // @has issue_54705/struct.ScopeFutureContents.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'scope, S> \ // Send for ScopeFutureContents<'scope, S> where S: Sync" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'scope, S> \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'scope, S> \ // Sync for ScopeFutureContents<'scope, S> where S: Sync" pub struct ScopeFutureContents<'scope, S> where S: ScopeHandle<'scope>, diff --git a/src/test/rustdoc/issue-55321.rs b/src/test/rustdoc/issue-55321.rs index d312a5114595..d1877f39ba76 100644 --- a/src/test/rustdoc/issue-55321.rs +++ b/src/test/rustdoc/issue-55321.rs @@ -1,16 +1,16 @@ #![feature(negative_impls)] // @has issue_55321/struct.A.html -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' "impl !Send for A" -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' "impl !Sync for A" +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' "impl !Send for A" +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' "impl !Sync for A" pub struct A(); impl !Send for A {} impl !Sync for A {} // @has issue_55321/struct.B.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // B" -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Sync for \ // B" pub struct B(A, Box); diff --git a/src/test/rustdoc/issue-56822.rs b/src/test/rustdoc/issue-56822.rs index 5b67817fa4ca..b932a3d34749 100644 --- a/src/test/rustdoc/issue-56822.rs +++ b/src/test/rustdoc/issue-56822.rs @@ -17,7 +17,7 @@ impl<'a, T> MyTrait for Inner<'a, T> { } // @has issue_56822/struct.Parser.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a> Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'a> Send for \ // Parser<'a>" pub struct Parser<'a> { field: > as MyTrait>::Output diff --git a/src/test/rustdoc/issue-60726.rs b/src/test/rustdoc/issue-60726.rs index 6acc86277385..79b8b70c5452 100644 --- a/src/test/rustdoc/issue-60726.rs +++ b/src/test/rustdoc/issue-60726.rs @@ -26,9 +26,9 @@ where {} // @has issue_60726/struct.IntoIter.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // IntoIter" -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Sync for \ // IntoIter" pub struct IntoIter{ hello:DynTrait>, diff --git a/src/test/rustdoc/synthetic_auto/basic.rs b/src/test/rustdoc/synthetic_auto/basic.rs index 38de5316b6cf..0dd3a3f7a86c 100644 --- a/src/test/rustdoc/synthetic_auto/basic.rs +++ b/src/test/rustdoc/synthetic_auto/basic.rs @@ -1,8 +1,8 @@ // @has basic/struct.Foo.html // @has - '//code' 'impl Send for Foo where T: Send' // @has - '//code' 'impl Sync for Foo where T: Sync' -// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 0 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 5 +// @count - '//*[@id="implementations-list"]//*[@class="impl"]' 0 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 5 pub struct Foo { field: T, } diff --git a/src/test/rustdoc/synthetic_auto/complex.rs b/src/test/rustdoc/synthetic_auto/complex.rs index 80a717718c22..d951a20e2dec 100644 --- a/src/test/rustdoc/synthetic_auto/complex.rs +++ b/src/test/rustdoc/synthetic_auto/complex.rs @@ -20,7 +20,7 @@ mod foo { } // @has complex/struct.NotOuter.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'a, T, K: \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'a, T, K: \ // ?Sized> Send for Outer<'a, T, K> where K: for<'b> Fn((&'b bool, &'a u8)) \ // -> &'b i8, T: MyTrait<'a>, >::MyItem: Copy, 'a: 'static" diff --git a/src/test/rustdoc/synthetic_auto/lifetimes.rs b/src/test/rustdoc/synthetic_auto/lifetimes.rs index 6d0a68f9b073..05c88f10822c 100644 --- a/src/test/rustdoc/synthetic_auto/lifetimes.rs +++ b/src/test/rustdoc/synthetic_auto/lifetimes.rs @@ -9,10 +9,10 @@ where {} // @has lifetimes/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Send \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Send \ // for Foo<'c, K> where K: for<'b> Fn(&'b bool) -> &'c u8, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Sync \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Sync \ // for Foo<'c, K> where K: Sync" pub struct Foo<'c, K: 'c> { inner_field: Inner<'c, K>, diff --git a/src/test/rustdoc/synthetic_auto/manual.rs b/src/test/rustdoc/synthetic_auto/manual.rs index d20b4744af15..88ddd57349a2 100644 --- a/src/test/rustdoc/synthetic_auto/manual.rs +++ b/src/test/rustdoc/synthetic_auto/manual.rs @@ -1,12 +1,12 @@ // @has manual/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' 'impl Sync for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' 'impl Sync for \ // Foo where T: Sync' // -// @has - '//*[@id="trait-implementations-list"]/*[@class="impl"]//code' \ +// @has - '//*[@id="trait-implementations-list"]//*[@class="impl"]//code' \ // 'impl Send for Foo' // -// @count - '//*[@id="trait-implementations-list"]/*[@class="impl"]' 1 -// @count - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]' 4 +// @count - '//*[@id="trait-implementations-list"]//*[@class="impl"]' 1 +// @count - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]' 4 pub struct Foo { field: T, } diff --git a/src/test/rustdoc/synthetic_auto/negative.rs b/src/test/rustdoc/synthetic_auto/negative.rs index 30713849da22..53801542c952 100644 --- a/src/test/rustdoc/synthetic_auto/negative.rs +++ b/src/test/rustdoc/synthetic_auto/negative.rs @@ -3,10 +3,10 @@ pub struct Inner { } // @has negative/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl !Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl !Send for \ // Outer" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl \ // !Sync for Outer" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/nested.rs b/src/test/rustdoc/synthetic_auto/nested.rs index e710ce1c2ed9..d4d93a87ffc9 100644 --- a/src/test/rustdoc/synthetic_auto/nested.rs +++ b/src/test/rustdoc/synthetic_auto/nested.rs @@ -9,10 +9,10 @@ where } // @has nested/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' 'impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' 'impl Send for \ // Foo where T: Copy' // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' \ // 'impl Sync for Foo where T: Sync' pub struct Foo { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/no-redundancy.rs b/src/test/rustdoc/synthetic_auto/no-redundancy.rs index cf173111ec1e..3a23dc2cf957 100644 --- a/src/test/rustdoc/synthetic_auto/no-redundancy.rs +++ b/src/test/rustdoc/synthetic_auto/no-redundancy.rs @@ -9,7 +9,7 @@ where } // @has no_redundancy/struct.Outer.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Outer where T: Copy + Send" pub struct Outer { inner_field: Inner, diff --git a/src/test/rustdoc/synthetic_auto/project.rs b/src/test/rustdoc/synthetic_auto/project.rs index 5346521f8d2e..060491e3cf10 100644 --- a/src/test/rustdoc/synthetic_auto/project.rs +++ b/src/test/rustdoc/synthetic_auto/project.rs @@ -23,10 +23,10 @@ where } // @has project/struct.Foo.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Send \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Send \ // for Foo<'c, K> where K: MyTrait, 'c: 'static" // -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl<'c, K> Sync \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl<'c, K> Sync \ // for Foo<'c, K> where K: MyTrait, ::MyItem: OtherTrait, 'c: 'static," pub struct Foo<'c, K: 'c> { inner_field: Inner<'c, K>, diff --git a/src/test/rustdoc/synthetic_auto/self-referential.rs b/src/test/rustdoc/synthetic_auto/self-referential.rs index 905aa20918be..ecdbdf41b202 100644 --- a/src/test/rustdoc/synthetic_auto/self-referential.rs +++ b/src/test/rustdoc/synthetic_auto/self-referential.rs @@ -23,7 +23,7 @@ impl Pattern for Wrapper { // @has self_referential/struct.WriteAndThen.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // WriteAndThen where ::Value: Send" pub struct WriteAndThen(pub P1::Value,pub > as Pattern>::Value) where P1: Pattern; diff --git a/src/test/rustdoc/synthetic_auto/static-region.rs b/src/test/rustdoc/synthetic_auto/static-region.rs index 59493744b623..a10e694c1b28 100644 --- a/src/test/rustdoc/synthetic_auto/static-region.rs +++ b/src/test/rustdoc/synthetic_auto/static-region.rs @@ -3,7 +3,7 @@ pub trait OwnedTrait<'a> { } // @has static_region/struct.Owned.html -// @has - '//*[@id="synthetic-implementations-list"]/*[@class="impl"]//code' "impl Send for \ +// @has - '//*[@id="synthetic-implementations-list"]//*[@class="impl"]//code' "impl Send for \ // Owned where >::Reader: Send" pub struct Owned where T: OwnedTrait<'static> { marker: >::Reader, From 1a46b26422e8fb2c89c23554f405d5dff2cb5917 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 09:22:30 -0400 Subject: [PATCH 04/17] Make a few functions private These were made public in 3105bcfdc11030abf9855af7a693cbf904460813. This is so long ago I doubt anyone remembers why they're public. No one uses them, including in-tree tools. --- compiler/rustc_session/src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index b6b349e4a803..47de57e3c700 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -795,7 +795,7 @@ pub const fn default_lib_output() -> CrateType { CrateType::Rlib } -pub fn default_configuration(sess: &Session) -> CrateConfig { +fn default_configuration(sess: &Session) -> CrateConfig { let end = &sess.target.endian; let arch = &sess.target.arch; let wordsz = sess.target.pointer_width.to_string(); @@ -890,7 +890,7 @@ pub fn build_configuration(sess: &Session, mut user_cfg: CrateConfig) -> CrateCo user_cfg } -pub fn build_target_config(opts: &Options, target_override: Option) -> Target { +pub(super) fn build_target_config(opts: &Options, target_override: Option) -> Target { let target_result = target_override.map_or_else(|| Target::search(&opts.target_triple), Ok); let target = target_result.unwrap_or_else(|e| { early_error( From 60ff298070842e8bb47078c7c3a0dbbdebc1d5a6 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 22 Apr 2021 14:16:33 -0700 Subject: [PATCH 05/17] Document From implementations for Waker and RawWaker --- library/alloc/src/task.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/library/alloc/src/task.rs b/library/alloc/src/task.rs index 58a9ae77244f..528ee4ff1542 100644 --- a/library/alloc/src/task.rs +++ b/library/alloc/src/task.rs @@ -87,6 +87,9 @@ pub trait Wake { #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for Waker { + /// Use a `Wake`-able type as a `Waker`. + /// + /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Arc) -> Waker { // SAFETY: This is safe because raw_waker safely constructs // a RawWaker from Arc. @@ -96,6 +99,9 @@ impl From> for Waker { #[stable(feature = "wake_trait", since = "1.51.0")] impl From> for RawWaker { + /// Use a `Wake`-able type as a `RawWaker`. + /// + /// No heap allocations or atomic operations are used for this conversion. fn from(waker: Arc) -> RawWaker { raw_waker(waker) } From f435f7185b634733834a61418dc4cba6a58aa1ec Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:27:37 -0400 Subject: [PATCH 06/17] Remove unnecessary `crate_name` parameter to `after_krate` It's always `tcx.crate_name(LOCAL_CRATE)`, it doesn't need to be passed in separately. --- src/librustdoc/formats/renderer.rs | 9 ++------- src/librustdoc/html/render/context.rs | 9 +++------ src/librustdoc/json/mod.rs | 8 ++------ 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index ae97cd64fb5f..94f860739dfe 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -43,11 +43,7 @@ crate trait FormatRenderer<'tcx>: Sized { /// Post processing hook for cleanup and dumping output to files. /// /// A handler is available if the renderer wants to report errors. - fn after_krate( - &mut self, - crate_name: Symbol, - diag: &rustc_errors::Handler, - ) -> Result<(), Error>; + fn after_krate(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>; fn cache(&self) -> &Cache; } @@ -73,7 +69,6 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( } // Render the crate documentation - let crate_name = krate.name; let mut work = vec![(format_renderer.make_child_renderer(), krate.module)]; let unknown = Symbol::intern(""); @@ -106,5 +101,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( } } prof.extra_verbose_generic_activity("renderer_after_krate", T::descr()) - .run(|| format_renderer.after_krate(crate_name, diag)) + .run(|| format_renderer.after_krate(diag)) } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 0aa7aa763c2a..9a4d02114cca 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt; use rustc_session::Session; use rustc_span::edition::Edition; use rustc_span::source_map::FileName; -use rustc_span::{symbol::sym, Symbol}; +use rustc_span::symbol::sym; use super::cache::{build_index, ExternalLocation}; use super::print_item::{full_path, item_path, print_item}; @@ -494,11 +494,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } } - fn after_krate( - &mut self, - crate_name: Symbol, - diag: &rustc_errors::Handler, - ) -> Result<(), Error> { + fn after_krate(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> { + let crate_name = self.tcx().crate_name(LOCAL_CRATE); let final_file = self.dst.join(&*crate_name.as_str()).join("all.html"); let settings_file = self.dst.join("settings.html"); diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index db3a0c5ceb16..da5a6d7af13e 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -14,7 +14,7 @@ use std::rc::Rc; use rustc_data_structures::fx::FxHashMap; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_span::{edition::Edition, Symbol}; +use rustc_span::edition::Edition; use rustdoc_json_types as types; @@ -204,11 +204,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(()) } - fn after_krate( - &mut self, - _crate_name: Symbol, - _diag: &rustc_errors::Handler, - ) -> Result<(), Error> { + fn after_krate(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> { debug!("Done with crate"); let mut index = (*self.index).clone().into_inner(); index.extend(self.get_trait_items()); From 68db5869e3b64ed13390454484bb977d2e202afa Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:32:24 -0400 Subject: [PATCH 07/17] Remove unnecessary `diag` parameter to `after_krate` --- src/librustdoc/formats/renderer.rs | 7 ++----- src/librustdoc/html/render/context.rs | 5 +++-- src/librustdoc/json/mod.rs | 2 +- src/librustdoc/lib.rs | 12 ++++-------- 4 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index 94f860739dfe..e6d97499b2c4 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -41,9 +41,7 @@ crate trait FormatRenderer<'tcx>: Sized { fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>; /// Post processing hook for cleanup and dumping output to files. - /// - /// A handler is available if the renderer wants to report errors. - fn after_krate(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error>; + fn after_krate(&mut self) -> Result<(), Error>; fn cache(&self) -> &Cache; } @@ -53,7 +51,6 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( krate: clean::Crate, options: RenderOptions, cache: Cache, - diag: &rustc_errors::Handler, edition: Edition, tcx: TyCtxt<'tcx>, ) -> Result<(), Error> { @@ -101,5 +98,5 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( } } prof.extra_verbose_generic_activity("renderer_after_krate", T::descr()) - .run(|| format_renderer.after_krate(diag)) + .run(|| format_renderer.after_krate()) } diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 9a4d02114cca..afdba5f0579f 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -494,7 +494,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } } - fn after_krate(&mut self, diag: &rustc_errors::Handler) -> Result<(), Error> { + fn after_krate(&mut self) -> Result<(), Error> { let crate_name = self.tcx().crate_name(LOCAL_CRATE); let final_file = self.dst.join(&*crate_name.as_str()).join("all.html"); let settings_file = self.dst.join("settings.html"); @@ -569,7 +569,8 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { // Flush pending errors. Rc::get_mut(&mut self.shared).unwrap().fs.close(); - let nb_errors = self.shared.errors.iter().map(|err| diag.struct_err(&err).emit()).count(); + let nb_errors = + self.shared.errors.iter().map(|err| self.tcx().sess.struct_err(&err).emit()).count(); if nb_errors > 0 { Err(Error::new(io::Error::new(io::ErrorKind::Other, "I/O error"), "")) } else { diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index da5a6d7af13e..58b43c83a9d5 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -204,7 +204,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(()) } - fn after_krate(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> { + fn after_krate(&mut self) -> Result<(), Error> { debug!("Done with crate"); let mut index = (*self.index).clone().into_inner(); index.extend(self.get_trait_items()); diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2a51d78f64a3..eefb8ced7af4 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -656,14 +656,14 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( krate: clean::Crate, renderopts: config::RenderOptions, cache: formats::cache::Cache, - diag: &rustc_errors::Handler, edition: rustc_span::edition::Edition, tcx: TyCtxt<'tcx>, ) -> MainResult { - match formats::run_format::(krate, renderopts, cache, &diag, edition, tcx) { + match formats::run_format::(krate, renderopts, cache, edition, tcx) { Ok(_) => Ok(()), Err(e) => { - let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error)); + let mut msg = + tcx.sess.struct_err(&format!("couldn't generate documentation: {}", e.error)); let file = e.file.display().to_string(); if file.is_empty() { msg.emit() @@ -692,7 +692,7 @@ fn main_options(options: config::Options) -> MainResult { // need to move these items separately because we lose them by the time the closure is called, // but we can't create the Handler ahead of time because it's not Send - let diag_opts = (options.error_format, options.edition, options.debugging_opts.clone()); + let edition = options.edition; let show_coverage = options.show_coverage; let run_check = options.run_check; @@ -758,15 +758,12 @@ fn main_options(options: config::Options) -> MainResult { } info!("going to format"); - let (error_format, edition, debugging_options) = diag_opts; - let diag = core::new_handler(error_format, None, &debugging_options); match output_format { config::OutputFormat::Html => sess.time("render_html", || { run_renderer::>( krate, render_opts, cache, - &diag, edition, tcx, ) @@ -776,7 +773,6 @@ fn main_options(options: config::Options) -> MainResult { krate, render_opts, cache, - &diag, edition, tcx, ) From 640cc741e0ecd54d0365772675727b98584d4465 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:35:20 -0400 Subject: [PATCH 08/17] Remove unnecessary `edition` parameter to renderer --- src/librustdoc/formats/renderer.rs | 6 ++---- src/librustdoc/html/render/context.rs | 3 +-- src/librustdoc/json/mod.rs | 2 -- src/librustdoc/lib.rs | 20 +++----------------- 4 files changed, 6 insertions(+), 25 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index e6d97499b2c4..6c5c53b7d1ac 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -1,5 +1,5 @@ use rustc_middle::ty::TyCtxt; -use rustc_span::{edition::Edition, Symbol}; +use rustc_span::Symbol; use crate::clean; use crate::config::RenderOptions; @@ -23,7 +23,6 @@ crate trait FormatRenderer<'tcx>: Sized { fn init( krate: clean::Crate, options: RenderOptions, - edition: Edition, cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error>; @@ -51,7 +50,6 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( krate: clean::Crate, options: RenderOptions, cache: Cache, - edition: Edition, tcx: TyCtxt<'tcx>, ) -> Result<(), Error> { let prof = &tcx.sess.prof; @@ -59,7 +57,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( let emit_crate = options.should_emit_crate(); let (mut format_renderer, krate) = prof .extra_verbose_generic_activity("create_renderer", T::descr()) - .run(|| T::init(krate, options, edition, cache, tcx))?; + .run(|| T::init(krate, options, cache, tcx))?; if !emit_crate { return Ok(()); diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index afdba5f0579f..9e05fa599a76 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -346,7 +346,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { fn init( mut krate: clean::Crate, options: RenderOptions, - edition: Edition, mut cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error> { @@ -435,7 +434,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { resource_suffix, static_root_path, fs: DocFS::new(sender), - edition, + edition: tcx.sess.edition(), codes: ErrorCodes::from(unstable_features.is_nightly_build()), playground, all: RefCell::new(AllTypes::new()), diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 58b43c83a9d5..0023f6c4c0ba 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -14,7 +14,6 @@ use std::rc::Rc; use rustc_data_structures::fx::FxHashMap; use rustc_middle::ty::TyCtxt; use rustc_session::Session; -use rustc_span::edition::Edition; use rustdoc_json_types as types; @@ -134,7 +133,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { fn init( krate: clean::Crate, options: RenderOptions, - _edition: Edition, cache: Cache, tcx: TyCtxt<'tcx>, ) -> Result<(Self, clean::Crate), Error> { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index eefb8ced7af4..26aaf0db6f62 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -656,10 +656,9 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( krate: clean::Crate, renderopts: config::RenderOptions, cache: formats::cache::Cache, - edition: rustc_span::edition::Edition, tcx: TyCtxt<'tcx>, ) -> MainResult { - match formats::run_format::(krate, renderopts, cache, edition, tcx) { + match formats::run_format::(krate, renderopts, cache, tcx) { Ok(_) => Ok(()), Err(e) => { let mut msg = @@ -692,7 +691,6 @@ fn main_options(options: config::Options) -> MainResult { // need to move these items separately because we lose them by the time the closure is called, // but we can't create the Handler ahead of time because it's not Send - let edition = options.edition; let show_coverage = options.show_coverage; let run_check = options.run_check; @@ -760,22 +758,10 @@ fn main_options(options: config::Options) -> MainResult { info!("going to format"); match output_format { config::OutputFormat::Html => sess.time("render_html", || { - run_renderer::>( - krate, - render_opts, - cache, - edition, - tcx, - ) + run_renderer::>(krate, render_opts, cache, tcx) }), config::OutputFormat::Json => sess.time("render_json", || { - run_renderer::>( - krate, - render_opts, - cache, - edition, - tcx, - ) + run_renderer::>(krate, render_opts, cache, tcx) }), } }) From 423963c07b2873c9f2b38ac88398187deb4b5437 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:38:20 -0400 Subject: [PATCH 09/17] Remove unnecessary `edition` field on SharedContext --- src/librustdoc/html/render/context.rs | 7 ++++--- src/librustdoc/html/render/mod.rs | 8 ++++---- src/librustdoc/html/render/write_shared.rs | 2 +- src/librustdoc/html/sources.rs | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 9e05fa599a76..75174e84a08d 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -111,8 +111,6 @@ crate struct SharedContext<'tcx> { crate static_root_path: Option, /// The fs handle we are working with. crate fs: DocFS, - /// The default edition used to parse doctests. - crate edition: Edition, pub(super) codes: ErrorCodes, pub(super) playground: Option, all: RefCell, @@ -141,6 +139,10 @@ impl SharedContext<'_> { crate fn maybe_collapsed_doc_value<'a>(&self, item: &'a clean::Item) -> Option { if self.collapsed { item.collapsed_doc_value() } else { item.doc_value() } } + + crate fn edition(&self) -> Edition { + self.tcx.sess.edition() + } } impl<'tcx> Context<'tcx> { @@ -434,7 +436,6 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { resource_suffix, static_root_path, fs: DocFS::new(sender), - edition: tcx.sess.edition(), codes: ErrorCodes::from(unstable_features.is_nightly_build()), playground, all: RefCell::new(AllTypes::new()), diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index d773f37ad90a..6cf4bedadcc9 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -530,7 +530,7 @@ fn render_markdown( &links, &mut ids, cx.shared.codes, - cx.shared.edition, + cx.shared.edition(), &cx.shared.playground ) .into_string() @@ -660,7 +660,7 @@ fn short_item_info( ¬e, &mut ids, error_codes, - cx.shared.edition, + cx.shared.edition(), &cx.shared.playground, ); message.push_str(&format!(": {}", html.into_string())); @@ -702,7 +702,7 @@ fn short_item_info( &unstable_reason.as_str(), &mut ids, error_codes, - cx.shared.edition, + cx.shared.edition(), &cx.shared.playground, ) .into_string() @@ -1358,7 +1358,7 @@ fn render_impl( &i.impl_item.links(cx), &mut ids, cx.shared.codes, - cx.shared.edition, + cx.shared.edition(), &cx.shared.playground ) .into_string() diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs index 78bcd40af753..8e10c696df05 100644 --- a/src/librustdoc/html/render/write_shared.rs +++ b/src/librustdoc/html/render/write_shared.rs @@ -425,7 +425,7 @@ pub(super) fn write_shared( md_opts.output = cx.dst.clone(); md_opts.external_html = (*cx.shared).layout.external_html.clone(); - crate::markdown::render(&index_page, md_opts, cx.shared.edition) + crate::markdown::render(&index_page, md_opts, cx.shared.edition()) .map_err(|e| Error::new(e, &index_page))?; } else { let dst = cx.dst.join("index.html"); diff --git a/src/librustdoc/html/sources.rs b/src/librustdoc/html/sources.rs index 001c8b090448..5a2a165191a6 100644 --- a/src/librustdoc/html/sources.rs +++ b/src/librustdoc/html/sources.rs @@ -129,7 +129,7 @@ impl SourceCollector<'_, 'tcx> { &self.scx.layout, &page, "", - |buf: &mut _| print_src(buf, contents, self.scx.edition), + |buf: &mut _| print_src(buf, contents, self.scx.edition()), &self.scx.style_files, ); self.scx.fs.write(&cur, v.as_bytes())?; From 7f6d540440fea578d760eb47158d1e0a9de5eb19 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:46:53 -0400 Subject: [PATCH 10/17] Remove unnecessary `item_name` parameter to `mod_item_out` --- src/librustdoc/formats/renderer.rs | 6 ++++-- src/librustdoc/html/render/context.rs | 2 +- src/librustdoc/json/mod.rs | 4 ---- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index 6c5c53b7d1ac..25a4129fdd1c 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -37,7 +37,9 @@ crate trait FormatRenderer<'tcx>: Sized { fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error>; /// Runs after recursively rendering all sub-items of a module. - fn mod_item_out(&mut self, item_name: &str) -> Result<(), Error>; + fn mod_item_out(&mut self) -> Result<(), Error> { + Ok(()) + } /// Post processing hook for cleanup and dumping output to files. fn after_krate(&mut self) -> Result<(), Error>; @@ -87,7 +89,7 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( work.push((cx.make_child_renderer(), it)); } - cx.mod_item_out(&name)?; + cx.mod_item_out()?; // FIXME: checking `item.name.is_some()` is very implicit and leads to lots of special // cases. Use an explicit match instead. } else if item.name.is_some() && !item.is_extern_crate() { diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index 75174e84a08d..d3ef97c0d59f 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -617,7 +617,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { Ok(()) } - fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> { + fn mod_item_out(&mut self) -> Result<(), Error> { info!("Recursed; leaving {}", self.dst.display()); // Go back to where we were at diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 0023f6c4c0ba..346d44511594 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -198,10 +198,6 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(()) } - fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> { - Ok(()) - } - fn after_krate(&mut self) -> Result<(), Error> { debug!("Done with crate"); let mut index = (*self.index).clone().into_inner(); From edb60a9243c204d9e281b34a7216fe0c94bb743c Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 22 Apr 2021 19:53:38 -0400 Subject: [PATCH 11/17] Remove unnecessary item_name parameter to `mod_item_in` --- src/librustdoc/formats/renderer.rs | 11 ++++------- src/librustdoc/html/render/context.rs | 7 ++++--- src/librustdoc/json/mod.rs | 2 +- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/formats/renderer.rs b/src/librustdoc/formats/renderer.rs index 25a4129fdd1c..b8ef3384c590 100644 --- a/src/librustdoc/formats/renderer.rs +++ b/src/librustdoc/formats/renderer.rs @@ -34,7 +34,7 @@ crate trait FormatRenderer<'tcx>: Sized { fn item(&mut self, item: clean::Item) -> Result<(), Error>; /// Renders a module (should not handle recursing into children). - fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error>; + fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error>; /// Runs after recursively rendering all sub-items of a module. fn mod_item_out(&mut self) -> Result<(), Error> { @@ -73,13 +73,10 @@ crate fn run_format<'tcx, T: FormatRenderer<'tcx>>( if item.is_mod() && T::RUN_ON_MODULE { // modules are special because they add a namespace. We also need to // recurse into the items of the module as well. - let name = item.name.as_ref().unwrap().to_string(); - if name.is_empty() { - panic!("Unexpected module with empty name"); - } - let _timer = prof.generic_activity_with_arg("render_mod_item", name.as_str()); + let _timer = + prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string()); - cx.mod_item_in(&item, &name)?; + cx.mod_item_in(&item)?; let module = match *item.kind { clean::StrippedItem(box clean::ModuleItem(m)) | clean::ModuleItem(m) => m, _ => unreachable!(), diff --git a/src/librustdoc/html/render/context.rs b/src/librustdoc/html/render/context.rs index d3ef97c0d59f..9cffcef9749f 100644 --- a/src/librustdoc/html/render/context.rs +++ b/src/librustdoc/html/render/context.rs @@ -578,7 +578,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { } } - fn mod_item_in(&mut self, item: &clean::Item, item_name: &str) -> Result<(), Error> { + fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> { // Stripped modules survive the rustdoc passes (i.e., `strip-private`) // if they contain impls for public types. These modules can also // contain items such as publicly re-exported structures. @@ -590,8 +590,9 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> { self.render_redirect_pages = item.is_stripped(); } let scx = &self.shared; - self.dst.push(item_name); - self.current.push(item_name.to_owned()); + let item_name = item.name.as_ref().unwrap().to_string(); + self.dst.push(&item_name); + self.current.push(item_name); info!("Recursing into {}", self.dst.display()); diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 346d44511594..b048e7f919fa 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -181,7 +181,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { Ok(()) } - fn mod_item_in(&mut self, item: &clean::Item, _module_name: &str) -> Result<(), Error> { + fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> { use clean::types::ItemKind::*; if let ModuleItem(m) = &*item.kind { for item in &m.items { From 8f41de595d2969e383cb681bd65b36c061fc346a Mon Sep 17 00:00:00 2001 From: marmeladema Date: Fri, 23 Apr 2021 17:01:27 +0100 Subject: [PATCH 12/17] Add test for issue #83017 --- .../ui/associated-type-bounds/issue-83017.rs | 39 +++++++++++++++++++ .../associated-type-bounds/issue-83017.stderr | 27 +++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/test/ui/associated-type-bounds/issue-83017.rs create mode 100644 src/test/ui/associated-type-bounds/issue-83017.stderr diff --git a/src/test/ui/associated-type-bounds/issue-83017.rs b/src/test/ui/associated-type-bounds/issue-83017.rs new file mode 100644 index 000000000000..8f0a9ea3566f --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-83017.rs @@ -0,0 +1,39 @@ +#![feature(associated_type_bounds)] + +trait TraitA<'a> { + type AsA; +} + +trait TraitB<'a, 'b> { + type AsB; +} + +trait TraitC<'a, 'b, 'c> {} + +struct X; + +impl<'a, 'b, 'c> TraitC<'a, 'b, 'c> for X {} + +struct Y; + +impl<'a, 'b> TraitB<'a, 'b> for Y { + type AsB = X; +} + +struct Z; + +impl<'a> TraitA<'a> for Z { + type AsA = Y; +} + +fn foo() +where + for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>, +{ +} + +fn main() { + foo::(); + //~^ ERROR: the trait bound `for<'a, 'b> >::AsA: TraitB<'a, 'b>` is not satisfied + //~| ERROR: the trait bound `for<'a, 'b, 'c> <>::AsA as TraitB<'a, 'b>>::AsB: TraitC<'a, 'b, 'c>` is not satisfied +} diff --git a/src/test/ui/associated-type-bounds/issue-83017.stderr b/src/test/ui/associated-type-bounds/issue-83017.stderr new file mode 100644 index 000000000000..4eb71fd0287e --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-83017.stderr @@ -0,0 +1,27 @@ +error[E0277]: the trait bound `for<'a, 'b> >::AsA: TraitB<'a, 'b>` is not satisfied + --> $DIR/issue-83017.rs:36:5 + | +LL | fn foo() + | --- required by a bound in this +LL | where +LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>, + | ------------------------------------------------------- required by this bound in `foo` +... +LL | foo::(); + | ^^^^^^^^ the trait `for<'a, 'b> TraitB<'a, 'b>` is not implemented for `>::AsA` + +error[E0277]: the trait bound `for<'a, 'b, 'c> <>::AsA as TraitB<'a, 'b>>::AsB: TraitC<'a, 'b, 'c>` is not satisfied + --> $DIR/issue-83017.rs:36:5 + | +LL | fn foo() + | --- required by a bound in this +LL | where +LL | for<'a> T: TraitA<'a, AsA: for<'b> TraitB<'a, 'b, AsB: for<'c> TraitC<'a, 'b, 'c>>>, + | -------------------------- required by this bound in `foo` +... +LL | foo::(); + | ^^^^^^^^ the trait `for<'a, 'b, 'c> TraitC<'a, 'b, 'c>` is not implemented for `<>::AsA as TraitB<'a, 'b>>::AsB` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From 3b96dfe1d4f48b1cd04ebffbf7b24d26650c9974 Mon Sep 17 00:00:00 2001 From: marmeladema Date: Fri, 23 Apr 2021 17:58:43 +0100 Subject: [PATCH 13/17] Add test for issue #81193 --- src/test/ui/associated-type-bounds/issue-81193.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/test/ui/associated-type-bounds/issue-81193.rs diff --git a/src/test/ui/associated-type-bounds/issue-81193.rs b/src/test/ui/associated-type-bounds/issue-81193.rs new file mode 100644 index 000000000000..d2aa54ab9512 --- /dev/null +++ b/src/test/ui/associated-type-bounds/issue-81193.rs @@ -0,0 +1,15 @@ +// check-pass + +#![feature(associated_type_bounds)] + +trait A<'a, 'b> {} + +trait B<'a, 'b, 'c> {} + +fn err<'u, 'a, F>() +where + for<'b> F: Iterator B<'a, 'b, 'c> + for<'c> A<'a, 'c>>, +{ +} + +fn main() {} From 21b3b27fe4695e13f089a75e67981478b3067a00 Mon Sep 17 00:00:00 2001 From: Adrien Morison Date: Fri, 23 Apr 2021 18:59:10 +0100 Subject: [PATCH 14/17] Mention FusedIterator case in Iterator::fuse doc Using `fuse` on an iterator that incorrectly implements `FusedIterator` does not fuse the iterator. This commit adds a note about this in the documentation of this method to increase awareness about this potential issue (esp. when relying on fuse in unsafe code). --- library/core/src/iter/traits/iterator.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index abd44b47f988..c0cab86cf622 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -1495,7 +1495,12 @@ pub trait Iterator { /// [`Some(T)`] again. `fuse()` adapts an iterator, ensuring that after a /// [`None`] is given, it will always return [`None`] forever. /// + /// Note that the [`Fuse`] wrapper is a no-op on iterators that implement + /// the [`FusedIterator`] trait. `fuse()` may therefore behave incorrectly + /// if the [`FusedIterator`] trait is improperly implemented. + /// /// [`Some(T)`]: Some + /// [`FusedIterator`]: crate::iter::FusedIterator /// /// # Examples /// From 7c50b82ffe7962495714e874ad66cc053bb2a369 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 23 Apr 2021 15:51:47 -0400 Subject: [PATCH 15/17] rustdoc: Remove unnecessary dummy span --- src/librustdoc/visit_ast.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index ca30d8f0d462..d852728b7496 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -71,9 +71,10 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } crate fn visit(mut self, krate: &'tcx hir::Crate<'_>) -> Module<'tcx> { + let span = krate.item.inner; let mut top_level_module = self.visit_mod_contents( - krate.item.inner, - &Spanned { span: rustc_span::DUMMY_SP, node: hir::VisibilityKind::Public }, + span, + &Spanned { span, node: hir::VisibilityKind::Public }, hir::CRATE_HIR_ID, &krate.item, self.cx.tcx.crate_name, @@ -130,7 +131,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { fn visit_mod_contents( &mut self, span: Span, - vis: &'tcx hir::Visibility<'_>, + vis: &hir::Visibility<'_>, id: hir::HirId, m: &'tcx hir::Mod<'tcx>, name: Symbol, From a657e17a7f4348bf95cbda8475cd2cc2507aea8e Mon Sep 17 00:00:00 2001 From: marmeladema Date: Fri, 23 Apr 2021 23:09:26 +0100 Subject: [PATCH 16/17] Add test for issue #33017 --- src/test/ui/specialization/issue-33017.rs | 45 +++++++++++++++++++ src/test/ui/specialization/issue-33017.stderr | 17 +++++++ 2 files changed, 62 insertions(+) create mode 100644 src/test/ui/specialization/issue-33017.rs create mode 100644 src/test/ui/specialization/issue-33017.stderr diff --git a/src/test/ui/specialization/issue-33017.rs b/src/test/ui/specialization/issue-33017.rs new file mode 100644 index 000000000000..4d19230df6ba --- /dev/null +++ b/src/test/ui/specialization/issue-33017.rs @@ -0,0 +1,45 @@ +// Test to ensure that trait bounds are propertly +// checked on specializable associated types + +#![allow(incomplete_features)] +#![feature(specialization)] + +trait UncheckedCopy: Sized { + type Output: From + Copy + Into; +} + +impl UncheckedCopy for T { + default type Output = Self; + //~^ ERROR: the trait bound `T: Copy` is not satisfied +} + +fn unchecked_copy(other: &T::Output) -> T { + (*other).into() +} + +fn bug(origin: String) { + // Turn the String into it's Output type... + // Which we can just do by `.into()`, the assoc type states `From`. + let origin_output = origin.into(); + + // Make a copy of String::Output, which is a String... + let mut copy: String = unchecked_copy::(&origin_output); + + // Turn the Output type into a String again, + // Which we can just do by `.into()`, the assoc type states `Into`. + let mut origin: String = origin_output.into(); + + // assert both Strings use the same buffer. + assert_eq!(copy.as_ptr(), origin.as_ptr()); + + // Any use of the copy we made becomes invalid, + drop(origin); + + // OH NO! UB UB UB UB! + copy.push_str(" world!"); + println!("{}", copy); +} + +fn main() { + bug(String::from("hello")); +} diff --git a/src/test/ui/specialization/issue-33017.stderr b/src/test/ui/specialization/issue-33017.stderr new file mode 100644 index 000000000000..bff4618d0be4 --- /dev/null +++ b/src/test/ui/specialization/issue-33017.stderr @@ -0,0 +1,17 @@ +error[E0277]: the trait bound `T: Copy` is not satisfied + --> $DIR/issue-33017.rs:12:5 + | +LL | type Output: From + Copy + Into; + | ---- required by this bound in `UncheckedCopy::Output` +... +LL | default type Output = Self; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `T` + | +help: consider restricting type parameter `T` + | +LL | impl UncheckedCopy for T { + | ^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0277`. From 9b430df4dc37c2d96110f808a9313f5127e27def Mon Sep 17 00:00:00 2001 From: marmeladema Date: Fri, 23 Apr 2021 23:12:21 +0100 Subject: [PATCH 17/17] Add test for issue #51892 --- src/test/ui/specialization/issue-51892.rs | 19 +++++++++++++++++++ src/test/ui/specialization/issue-51892.stderr | 10 ++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/test/ui/specialization/issue-51892.rs create mode 100644 src/test/ui/specialization/issue-51892.stderr diff --git a/src/test/ui/specialization/issue-51892.rs b/src/test/ui/specialization/issue-51892.rs new file mode 100644 index 000000000000..3cd0711ae42c --- /dev/null +++ b/src/test/ui/specialization/issue-51892.rs @@ -0,0 +1,19 @@ +#![allow(incomplete_features)] +#![feature(const_generics)] +#![feature(const_evaluatable_checked)] +#![feature(specialization)] + +pub trait Trait { + type Type; +} + +impl Trait for T { + default type Type = [u8; 1]; +} + +impl Trait for *const T { + type Type = [u8; std::mem::size_of::<::Type>()]; + //~^ ERROR: unconstrained generic constant +} + +fn main() {} diff --git a/src/test/ui/specialization/issue-51892.stderr b/src/test/ui/specialization/issue-51892.stderr new file mode 100644 index 000000000000..2d30164380a8 --- /dev/null +++ b/src/test/ui/specialization/issue-51892.stderr @@ -0,0 +1,10 @@ +error: unconstrained generic constant + --> $DIR/issue-51892.rs:15:5 + | +LL | type Type = [u8; std::mem::size_of::<::Type>()]; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: try adding a `where` bound using this expression: `where [(); std::mem::size_of::<::Type>()]:` + +error: aborting due to previous error +