Skip to content

Rollup of 4 pull requests #84241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3ae5fed
Fix a couple resolve bugs from binder refactor
jackh726 Apr 6, 2021
c96f86d
rustdoc: Stop hiding entire item declarations
Manishearth Mar 21, 2021
71c52ac
rustdoc: hide variants of enums > 5
Manishearth Mar 21, 2021
f146b97
rustdoc: hide fields of structs/unions > 5
Manishearth Mar 21, 2021
173cbec
rustdoc: smartly hide associated items of traits if there are too man…
Manishearth Mar 21, 2021
256e594
rustdoc: Add setting for hiding large items
Manishearth Mar 21, 2021
e2f59f4
Update src/librustdoc/html/render/print_item.rs
Manishearth Mar 22, 2021
846a4e9
Update src/librustdoc/html/render/print_item.rs
Manishearth Mar 22, 2021
def144c
Improve CSS for "hide contents, not items"
jsha Mar 27, 2021
8e9882d
Add css classes
Manishearth Mar 28, 2021
01afa07
should_hide_fields > 12
Manishearth Apr 12, 2021
b40bd5a
Add test for item hiding
Manishearth Apr 12, 2021
97cd30d
Wrap toggle_open()
Manishearth Apr 12, 2021
05d1e72
& -> &&
Manishearth Apr 12, 2021
942ed31
Move color to themes
Manishearth Apr 12, 2021
5c2820b
+ignore-tidy-filelength
Manishearth Apr 12, 2021
0174dd6
Compiler error messages: reduce assertiveness of message E0384
jayaddison Apr 12, 2021
55b2944
Update attribute tests
Manishearth Apr 13, 2021
ff47e97
Merge branch 'master' into compiler/E0384-reduce-assertiveness
jayaddison Apr 14, 2021
bccbf9d
VecDeque: binary_search_by(): return right away if hit found at back.…
vojtechkral Apr 12, 2021
e68680d
VecDeque: Add partition_point() #78021
vojtechkral Apr 4, 2021
44be1c2
VecDeque: Improve doc comments in binary search fns
vojtechkral Apr 15, 2021
a5c68d7
Rollup merge of #83337 - Manishearth:item-hide, r=GuillaumeGomez
Dylan-DPC Apr 16, 2021
8853aae
Rollup merge of #83944 - jackh726:binder-refactor-fix2, r=lcnr
Dylan-DPC Apr 16, 2021
a5ec5cf
Rollup merge of #84145 - vojtechkral:vecdeque-binary-search, r=m-ou-se
Dylan-DPC Apr 16, 2021
c7c59d7
Rollup merge of #84172 - jayaddison:compiler/E0384-reduce-assertivene…
Dylan-DPC Apr 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
if decl.can_be_made_mutable() {
err.span_suggestion(
decl.source_info.span,
"make this binding mutable",
"consider making this binding mutable",
format!("mut {}", name),
Applicability::MachineApplicable,
);
Expand Down
16 changes: 15 additions & 1 deletion compiler/rustc_resolve/src/late/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2719,6 +2719,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
Some(next) => next,
None => break None,
};
// See issue #83753. If someone writes an associated type on a non-trait, just treat it as
// there being no supertrait HRTBs.
match tcx.def_kind(def_id) {
DefKind::Trait | DefKind::TraitAlias | DefKind::Impl => {}
_ => break None,
}

if trait_defines_associated_type_named(def_id) {
break Some(bound_vars.into_iter().collect());
}
Expand Down Expand Up @@ -2764,7 +2771,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
| Scope::TraitRefBoundary { ref s, .. } => {
scope = *s;
}
Scope::Root => bug!("In fn_like_elision without appropriate scope above"),
Scope::Root => {
// See issue #83907. Just bail out from looking inside.
self.tcx.sess.delay_span_bug(
rustc_span::DUMMY_SP,
"In fn_like_elision without appropriate scope above",
);
return;
}
}
};
// While not strictly necessary, we gather anon lifetimes *before* actually
Expand Down
72 changes: 69 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,12 @@ impl<T> VecDeque<T> {
/// [`Result::Err`] is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
///
/// [`binary_search_by`]: VecDeque::binary_search_by
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
/// [`partition_point`]: VecDeque::partition_point
///
/// # Examples
///
/// Looks up a series of four elements. The first is found, with a
Expand Down Expand Up @@ -2457,6 +2463,12 @@ impl<T> VecDeque<T> {
/// [`Result::Err`] is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
///
/// [`binary_search`]: VecDeque::binary_search
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
/// [`partition_point`]: VecDeque::partition_point
///
/// # Examples
///
/// Looks up a series of four elements. The first is found, with a
Expand All @@ -2481,8 +2493,11 @@ impl<T> VecDeque<T> {
F: FnMut(&'a T) -> Ordering,
{
let (front, back) = self.as_slices();
let cmp_back = back.first().map(|elem| f(elem));

if let Some(Ordering::Less | Ordering::Equal) = back.first().map(|elem| f(elem)) {
if let Some(Ordering::Equal) = cmp_back {
Ok(front.len())
} else if let Some(Ordering::Less) = cmp_back {
back.binary_search_by(f).map(|idx| idx + front.len()).map_err(|idx| idx + front.len())
} else {
front.binary_search_by(f)
Expand All @@ -2492,15 +2507,21 @@ impl<T> VecDeque<T> {
/// Binary searches this sorted `VecDeque` with a key extraction function.
///
/// Assumes that the `VecDeque` is sorted by the key, for instance with
/// [`make_contiguous().sort_by_key()`](#method.make_contiguous) using the same
/// key extraction function.
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
///
/// If the value is found then [`Result::Ok`] is returned, containing the
/// index of the matching element. If there are multiple matches, then any
/// one of the matches could be returned. If the value is not found then
/// [`Result::Err`] is returned, containing the index where a matching
/// element could be inserted while maintaining sorted order.
///
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
///
/// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous
/// [`binary_search`]: VecDeque::binary_search
/// [`binary_search_by`]: VecDeque::binary_search_by
/// [`partition_point`]: VecDeque::partition_point
///
/// # Examples
///
/// Looks up a series of four elements in a slice of pairs sorted by
Expand Down Expand Up @@ -2531,6 +2552,51 @@ impl<T> VecDeque<T> {
{
self.binary_search_by(|k| f(k).cmp(b))
}

/// Returns the index of the partition point according to the given predicate
/// (the index of the first element of the second partition).
///
/// The deque is assumed to be partitioned according to the given predicate.
/// This means that all elements for which the predicate returns true are at the start of the deque
/// and all elements for which the predicate returns false are at the end.
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
/// (all odd numbers are at the start, all even at the end).
///
/// If this deque is not partitioned, the returned result is unspecified and meaningless,
/// as this method performs a kind of binary search.
///
/// See also [`binary_search`], [`binary_search_by`], and [`binary_search_by_key`].
///
/// [`binary_search`]: VecDeque::binary_search
/// [`binary_search_by`]: VecDeque::binary_search_by
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
///
/// # Examples
///
/// ```
/// #![feature(vecdeque_binary_search)]
/// use std::collections::VecDeque;
///
/// let deque: VecDeque<_> = vec![1, 2, 3, 3, 5, 6, 7].into();
/// let i = deque.partition_point(|&x| x < 5);
///
/// assert_eq!(i, 4);
/// assert!(deque.iter().take(i).all(|&x| x < 5));
/// assert!(deque.iter().skip(i).all(|&x| !(x < 5)));
/// ```
#[unstable(feature = "vecdeque_binary_search", issue = "78021")]
pub fn partition_point<P>(&self, mut pred: P) -> usize
where
P: FnMut(&T) -> bool,
{
let (front, back) = self.as_slices();

if let Some(true) = back.first().map(|v| pred(v)) {
back.partition_point(pred) + front.len()
} else {
front.partition_point(pred)
}
}
}

impl<T: Clone> VecDeque<T> {
Expand Down
18 changes: 18 additions & 0 deletions library/alloc/tests/vec_deque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,24 @@ fn test_binary_search_by_key() {
assert_eq!(deque.binary_search_by_key(&4, |&(v,)| v), Err(3));
}

#[test]
fn test_partition_point() {
// Contiguous (front only) search:
let deque: VecDeque<_> = vec![1, 2, 3, 5, 6].into();
assert!(deque.as_slices().1.is_empty());
assert_eq!(deque.partition_point(|&v| v <= 3), 3);

// Split search (both front & back non-empty):
let mut deque: VecDeque<_> = vec![5, 6].into();
deque.push_front(3);
deque.push_front(2);
deque.push_front(1);
deque.push_back(10);
assert!(!deque.as_slices().0.is_empty());
assert!(!deque.as_slices().1.is_empty());
assert_eq!(deque.partition_point(|&v| v <= 5), 4);
}

#[test]
fn test_zero_sized_push() {
const N: usize = 8;
Expand Down
64 changes: 26 additions & 38 deletions src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ use std::path::PathBuf;
use std::str;
use std::string::ToString;

use itertools::Itertools;
use rustc_ast_pretty::pprust;
use rustc_attr::{Deprecation, StabilityLevel};
use rustc_data_structures::fx::FxHashSet;
Expand Down Expand Up @@ -486,18 +485,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
],
)
.into(),
(
"Auto-hide item declarations",
vec![
("auto-hide-struct", "Auto-hide structs declaration", true),
("auto-hide-enum", "Auto-hide enums declaration", false),
("auto-hide-union", "Auto-hide unions declaration", true),
("auto-hide-trait", "Auto-hide traits declaration", true),
("auto-hide-macro", "Auto-hide macros declaration", false),
],
)
.into(),
("auto-hide-attributes", "Auto-hide item attributes.", true).into(),
("auto-hide-large-items", "Auto-hide item contents for large items.", true).into(),
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true)
.into(),
Expand Down Expand Up @@ -947,19 +935,21 @@ fn render_assoc_item(
+ name.as_str().len()
+ generics_len;

let (indent, end_newline) = if parent == ItemType::Trait {
let (indent, indent_str, end_newline) = if parent == ItemType::Trait {
header_len += 4;
(4, false)
let indent_str = " ";
render_attributes_in_pre(w, meth, indent_str);
(4, indent_str, false)
} else {
(0, true)
render_attributes_in_code(w, meth);
(0, "", true)
};
render_attributes(w, meth, false);
w.reserve(header_len + "<a href=\"\" class=\"fnname\">{".len() + "</a>".len());
write!(
w,
"{}{}{}{}{}{}{}fn <a href=\"{href}\" class=\"fnname\">{name}</a>\
{generics}{decl}{notable_traits}{where_clause}",
if parent == ItemType::Trait { " " } else { "" },
indent_str,
vis,
constness,
asyncness,
Expand Down Expand Up @@ -1015,35 +1005,33 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
sym::non_exhaustive,
];

// The `top` parameter is used when generating the item declaration to ensure it doesn't have a
// left padding. For example:
//
// #[foo] <----- "top" attribute
// struct Foo {
// #[bar] <---- not "top" attribute
// bar: usize,
// }
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
let attrs = it
.attrs
fn attributes(it: &clean::Item) -> Vec<String> {
it.attrs
.other_attrs
.iter()
.filter_map(|attr| {
if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
Some(pprust::attribute_to_string(&attr))
Some(pprust::attribute_to_string(&attr).replace("\n", "").replace(" ", " "))
} else {
None
}
})
.join("\n");
.collect()
}

if !attrs.is_empty() {
write!(
w,
"<span class=\"docblock attributes{}\">{}</span>",
if top { " top-attr" } else { "" },
&attrs
);
// When an attribute is rendered inside a `<pre>` tag, it is formatted using
// a whitespace prefix and newline.
fn render_attributes_in_pre(w: &mut Buffer, it: &clean::Item, prefix: &str) {
for a in attributes(it) {
write!(w, "{}{}\n", prefix, a);
}
}

// When an attribute is rendered inside a <code> tag, it is formatted using
// a div to produce a newline after it.
fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
for a in attributes(it) {
write!(w, "<div class=\"code-attribute\">{}</div>", a);
}
}

Expand Down
Loading