Skip to content

Commit

Permalink
Auto merge of #92090 - matthiaskrgr:rollup-pbyqddi, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - #91834 (Update browser-ui-test version and improve rustdoc-gui tests readability)
 - #91894 (Remove `in_band_lifetimes` from `rustc_incremental`)
 - #91932 (Add user seed to `-Z randomize-layout`)
 - #91956 (fix(rustc_lint): better detect when parens are necessary)
 - #92020 (Remove P: Unpin bound on impl Stream for Pin)
 - #92063 (docs: fix typo)
 - #92082 (rustdoc: Write doc-comments directly instead of using FromIterator)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 19, 2021
2 parents daf2204 + d486e68 commit df2f45c
Show file tree
Hide file tree
Showing 27 changed files with 374 additions and 99 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_incremental/src/assert_dep_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct IfThisChanged<'tcx> {
then_this_would_need: Targets,
}

impl IfThisChanged<'tcx> {
impl<'tcx> IfThisChanged<'tcx> {
fn argument(&self, attr: &ast::Attribute) -> Option<Symbol> {
let mut value = None;
for list_item in attr.meta_item_list().unwrap_or_default() {
Expand Down Expand Up @@ -172,7 +172,7 @@ impl IfThisChanged<'tcx> {
}
}

impl Visitor<'tcx> for IfThisChanged<'tcx> {
impl<'tcx> Visitor<'tcx> for IfThisChanged<'tcx> {
type Map = Map<'tcx>;

fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/assert_module_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct AssertModuleSource<'tcx> {
available_cgus: BTreeSet<String>,
}

impl AssertModuleSource<'tcx> {
impl<'tcx> AssertModuleSource<'tcx> {
fn check_attr(&self, attr: &ast::Attribute) {
let (expected_reuse, comp_kind) = if attr.has_name(sym::rustc_partition_reused) {
(CguReuse::PreLto, ComparisonKind::AtLeast)
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_incremental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#![deny(missing_docs)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(in_band_lifetimes)]
#![feature(let_else)]
#![feature(nll)]
#![recursion_limit = "256"]
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_incremental/src/persist/dirty_clean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub struct DirtyCleanVisitor<'tcx> {
checked_attrs: FxHashSet<ast::AttrId>,
}

impl DirtyCleanVisitor<'tcx> {
impl<'tcx> DirtyCleanVisitor<'tcx> {
/// Possibly "deserialize" the attribute into a clean/dirty assertion
fn assertion_maybe(&mut self, item_id: LocalDefId, attr: &Attribute) -> Option<Assertion> {
if !attr.has_name(sym::rustc_clean) {
Expand Down Expand Up @@ -352,7 +352,7 @@ impl DirtyCleanVisitor<'tcx> {
}
}

impl ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
impl<'tcx> ItemLikeVisitor<'tcx> for DirtyCleanVisitor<'tcx> {
fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
self.check_item(item.def_id, item.span);
}
Expand Down Expand Up @@ -415,7 +415,7 @@ pub struct FindAllAttrs<'tcx> {
found_attrs: Vec<&'tcx Attribute>,
}

impl FindAllAttrs<'tcx> {
impl<'tcx> FindAllAttrs<'tcx> {
fn is_active_attr(&mut self, attr: &Attribute) -> bool {
if attr.has_name(sym::rustc_clean) && check_config(self.tcx, attr) {
return true;
Expand All @@ -434,7 +434,7 @@ impl FindAllAttrs<'tcx> {
}
}

impl intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> {
impl<'tcx> intravisit::Visitor<'tcx> for FindAllAttrs<'tcx> {
type Map = Map<'tcx>;

fn nested_visit_map(&mut self) -> intravisit::NestedVisitorMap<Self::Map> {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,11 @@ trait UnusedDelimLint {

lhs_needs_parens
|| (followed_by_block
&& match inner.kind {
&& match &inner.kind {
ExprKind::Ret(_) | ExprKind::Break(..) | ExprKind::Yield(..) => true,
ExprKind::Range(_lhs, Some(rhs), _limits) => {
matches!(rhs.kind, ExprKind::Block(..))
}
_ => parser::contains_exterior_struct_lit(&inner),
})
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,6 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {

let mut inverse_memory_index: Vec<u32> = (0..fields.len() as u32).collect();

// `ReprOptions.layout_seed` is a deterministic seed that we can use to
// randomize field ordering with
let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);

let optimize = !repr.inhibit_struct_field_reordering_opt();
if optimize {
let end =
Expand All @@ -364,6 +360,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
// the field ordering to try and catch some code making assumptions about layouts
// we don't guarantee
if repr.can_randomize_type_layout() {
// `ReprOptions.layout_seed` is a deterministic seed that we can use to
// randomize field ordering with
let mut rng = Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);

// Shuffle the ordering of the fields
optimizing.shuffle(&mut rng);

Expand Down
15 changes: 11 additions & 4 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,9 @@ bitflags! {
// the seed stored in `ReprOptions.layout_seed`
const RANDOMIZE_LAYOUT = 1 << 5;
// Any of these flags being set prevent field reordering optimisation.
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits |
ReprFlags::IS_SIMD.bits |
ReprFlags::IS_LINEAR.bits;
const IS_UNOPTIMISABLE = ReprFlags::IS_C.bits
| ReprFlags::IS_SIMD.bits
| ReprFlags::IS_LINEAR.bits;
}
}

Expand Down Expand Up @@ -1640,7 +1640,14 @@ impl ReprOptions {

// Generate a deterministically-derived seed from the item's path hash
// to allow for cross-crate compilation to actually work
let field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash();
let mut field_shuffle_seed = tcx.def_path_hash(did).0.to_smaller_hash();

// If the user defined a custom seed for layout randomization, xor the item's
// path hash with the user defined seed, this will allowing determinism while
// still allowing users to further randomize layout generation for e.g. fuzzing
if let Some(user_seed) = tcx.sess.opts.debugging_opts.layout_seed {
field_shuffle_seed ^= user_seed;
}

for attr in tcx.get_attrs(did).iter() {
for r in attr::find_repr_attrs(&tcx.sess, attr) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,8 @@ options! {
"print some statistics about the query system (default: no)"),
randomize_layout: bool = (false, parse_bool, [TRACKED],
"randomize the layout of types (default: no)"),
layout_seed: Option<u64> = (None, parse_opt_number, [TRACKED],
"seed layout randomization"),
relax_elf_relocations: Option<bool> = (None, parse_opt_bool, [TRACKED],
"whether ELF relocations can be relaxed"),
relro_level: Option<RelroLevel> = (None, parse_relro_level, [TRACKED],
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ where
/// clone_on_write.values.to_mut().push(3);
/// println!("clone_on_write = {:?}", clone_on_write.values);
///
/// // The data was mutated. Let check it out.
/// // The data was mutated. Let's check it out.
/// match clone_on_write {
/// Items { values: Cow::Owned(_) } => println!("clone_on_write contains owned data"),
/// _ => panic!("expect owned data"),
Expand Down
4 changes: 2 additions & 2 deletions library/core/src/stream/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ impl<S: ?Sized + Stream + Unpin> Stream for &mut S {
#[unstable(feature = "async_stream", issue = "79024")]
impl<P> Stream for Pin<P>
where
P: DerefMut + Unpin,
P: DerefMut,
P::Target: Stream,
{
type Item = <P::Target as Stream>::Item;

fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.get_mut().as_mut().poll_next(cx)
<P::Target as Stream>::poll_next(self.as_deref_mut(), cx)
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
2 changes: 1 addition & 1 deletion src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ENV PATH="/node-v14.4.0-linux-x64/bin:${PATH}"
# https://github.com/puppeteer/puppeteer/issues/375
#
# We also specify the version in case we need to update it to go around cache limitations.
RUN npm install -g browser-ui-test@0.5.0 --unsafe-perm=true
RUN npm install -g browser-ui-test@0.5.1 --unsafe-perm=true

ENV RUST_CONFIGURE_ARGS \
--build=x86_64-unknown-linux-gnu \
Expand Down
23 changes: 12 additions & 11 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::cell::RefCell;
use std::default::Default;
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::lazy::SyncOnceCell as OnceCell;
use std::path::PathBuf;
use std::rc::Rc;
Expand Down Expand Up @@ -958,16 +957,14 @@ fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
}
}

impl<'a> FromIterator<&'a DocFragment> for String {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = &'a DocFragment>,
{
iter.into_iter().fold(String::new(), |mut acc, frag| {
add_doc_fragment(&mut acc, frag);
acc
})
/// Collapse a collection of [`DocFragment`]s into one string,
/// handling indentation and newlines as needed.
crate fn collapse_doc_fragments(doc_strings: &[DocFragment]) -> String {
let mut acc = String::new();
for frag in doc_strings {
add_doc_fragment(&mut acc, frag);
}
acc
}

/// A link that has not yet been rendered.
Expand Down Expand Up @@ -1113,7 +1110,11 @@ impl Attributes {
/// Finds all `doc` attributes as NameValues and returns their corresponding values, joined
/// with newlines.
crate fn collapsed_doc_value(&self) -> Option<String> {
if self.doc_strings.is_empty() { None } else { Some(self.doc_strings.iter().collect()) }
if self.doc_strings.is_empty() {
None
} else {
Some(collapse_doc_fragments(&self.doc_strings))
}
}

crate fn get_doc_aliases(&self) -> Box<[Symbol]> {
Expand Down
5 changes: 4 additions & 1 deletion src/librustdoc/passes/unindent_comments/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use super::*;

use crate::clean::collapse_doc_fragments;

use rustc_span::create_default_session_globals_then;
use rustc_span::source_map::DUMMY_SP;
use rustc_span::symbol::Symbol;
Expand All @@ -19,7 +22,7 @@ fn run_test(input: &str, expected: &str) {
create_default_session_globals_then(|| {
let mut s = create_doc_fragment(input);
unindent_fragments(&mut s);
assert_eq!(&s.iter().collect::<String>(), expected);
assert_eq!(collapse_doc_fragments(&s), expected);
});
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/rustdoc-gui/anchors.goml
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ assert-css: ("#impl a.anchor", {"color": "rgb(0, 0, 0)"})
move-cursor-to: ".top-doc .docblock .section-header:first-child"
assert-css: (
".top-doc .docblock .section-header:first-child > a::before",
{"left": "-10px", "padding-right": "10px"}
{"left": "-10px", "padding-right": "10px"},
)
// We also check that the heading itself has a different indent.
assert-css: (".top-doc .docblock .section-header:first-child", {"margin-left": "15px"})

move-cursor-to: ".top-doc .docblock .section-header:not(:first-child)"
assert-css: (
".top-doc .docblock .section-header:not(:first-child) > a::before",
{"left": "-25px", "padding-right": "10px"}
{"left": "-25px", "padding-right": "10px"},
)
assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-left": "0px"})

Expand All @@ -51,14 +51,14 @@ assert-css: (".top-doc .docblock .section-header:not(:first-child)", {"margin-le
move-cursor-to: "#title-for-struct-impl-doc"
assert-css: (
"#title-for-struct-impl-doc > a::before",
{"left": "-25px", "padding-right": "10px"}
{"left": "-25px", "padding-right": "10px"},
)
assert-css: ("#title-for-struct-impl-doc", {"margin-left": "0px"})
// Now a method docs.
move-cursor-to: "#title-for-struct-impl-item-doc"
assert-css: (
"#title-for-struct-impl-item-doc > a::before",
{"left": "-25px", "padding-right": "10px"}
{"left": "-25px", "padding-right": "10px"},
)
assert-css: ("#title-for-struct-impl-item-doc", {"margin-left": "0px"})

Expand All @@ -69,6 +69,6 @@ goto: file://|DOC_PATH|/test_docs/enum.WhoLetTheDogOut.html
move-cursor-to: ".top-doc .docblock .section-header"
assert-css: (
".top-doc .docblock .section-header > a::before",
{"left": "-25px", "padding-right": "10px"}
{"left": "-25px", "padding-right": "10px"},
)
assert-css: (".top-doc .docblock .section-header", {"margin-left": "0px"})
2 changes: 1 addition & 1 deletion src/test/rustdoc-gui/docblock-code-block-line-number.goml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ wait-for: "pre.line-number"
assert-css: ("pre.line-number", {
"margin": "0px",
"padding": "13px 8px",
"text-align": "right"
"text-align": "right",
})
// The first code block has two lines so let's check its `<pre>` elements lists both of them.
assert-text: ("pre.line-number", "1\n2")
6 changes: 5 additions & 1 deletion src/test/rustdoc-gui/docblock-table-overflow.goml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ assert-property: (".top-doc .docblock table", {"scrollWidth": "1573"})
// Checking it works on other doc blocks as well...

// Logically, the ".docblock" and the "<p>" should have the same scroll width.
compare-elements-property: ("#implementations + details .docblock", "#implementations + details .docblock > p", ["scrollWidth"])
compare-elements-property: (
"#implementations + details .docblock",
"#implementations + details .docblock > p",
["scrollWidth"],
)
assert-property: ("#implementations + details .docblock", {"scrollWidth": "816"})
// However, since there is overflow in the <table>, its scroll width is bigger.
assert-property: ("#implementations + details .docblock table", {"scrollWidth": "1573"})
15 changes: 12 additions & 3 deletions src/test/rustdoc-gui/font-weight.goml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
goto: file://|DOC_PATH|/lib2/struct.Foo.html
// This test checks that the font weight is correctly applied.
assert-css: ("//*[@class='docblock item-decl']//a[text()='Alias']", {"font-weight": "400"})
assert-css: ("//*[@class='structfield small-section-header']//a[text()='Alias']", {"font-weight": "400"})
assert-css: (
"//*[@class='structfield small-section-header']//a[text()='Alias']",
{"font-weight": "400"},
)
assert-css: ("#method\.a_method > .code-header", {"font-weight": "600"})
assert-css: ("#associatedtype\.X > .code-header", {"font-weight": "600"})
assert-css: ("#associatedconstant\.Y > .code-header", {"font-weight": "600"})
Expand All @@ -25,8 +28,14 @@ goto: file://|DOC_PATH|/lib2/trait.Trait.html
//
// This uses '/parent::*' as a proxy for the style of the text node.
// We can't just select the '<a>' because intermediate tags could be added.
assert-count: ("//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", 1)
assert-css: ("//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*", {"font-weight": "400"})
assert-count: (
"//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
1,
)
assert-css: (
"//*[@class='docblock item-decl']/pre[@class='rust trait']/code/a[@class='constant']//text()/parent::*",
{"font-weight": "400"},
)

assert-count: (".methods .type", 1)
assert-css: (".methods .type", {"font-weight": "600"})
Expand Down
Loading

0 comments on commit df2f45c

Please sign in to comment.