Skip to content

Commit 2faef12

Browse files
committed
Auto merge of #84241 - Dylan-DPC:rollup-jk9nt6k, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #83337 (rustdoc: Hide item contents, not items) - #83944 (Fix a couple resolve bugs from binder refactor) - #84145 (Address comments for vecdeque_binary_search #78021) - #84172 (Compiler error messages: reduce assertiveness of message E0384) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3833636 + c7c59d7 commit 2faef12

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+526
-194
lines changed

compiler/rustc_mir/src/borrow_check/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1681,7 +1681,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16811681
if decl.can_be_made_mutable() {
16821682
err.span_suggestion(
16831683
decl.source_info.span,
1684-
"make this binding mutable",
1684+
"consider making this binding mutable",
16851685
format!("mut {}", name),
16861686
Applicability::MachineApplicable,
16871687
);

compiler/rustc_resolve/src/late/lifetimes.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -2719,6 +2719,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27192719
Some(next) => next,
27202720
None => break None,
27212721
};
2722+
// See issue #83753. If someone writes an associated type on a non-trait, just treat it as
2723+
// there being no supertrait HRTBs.
2724+
match tcx.def_kind(def_id) {
2725+
DefKind::Trait | DefKind::TraitAlias | DefKind::Impl => {}
2726+
_ => break None,
2727+
}
2728+
27222729
if trait_defines_associated_type_named(def_id) {
27232730
break Some(bound_vars.into_iter().collect());
27242731
}
@@ -2764,7 +2771,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
27642771
| Scope::TraitRefBoundary { ref s, .. } => {
27652772
scope = *s;
27662773
}
2767-
Scope::Root => bug!("In fn_like_elision without appropriate scope above"),
2774+
Scope::Root => {
2775+
// See issue #83907. Just bail out from looking inside.
2776+
self.tcx.sess.delay_span_bug(
2777+
rustc_span::DUMMY_SP,
2778+
"In fn_like_elision without appropriate scope above",
2779+
);
2780+
return;
2781+
}
27682782
}
27692783
};
27702784
// While not strictly necessary, we gather anon lifetimes *before* actually

library/alloc/src/collections/vec_deque/mod.rs

+69-3
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,12 @@ impl<T> VecDeque<T> {
24032403
/// [`Result::Err`] is returned, containing the index where a matching
24042404
/// element could be inserted while maintaining sorted order.
24052405
///
2406+
/// See also [`binary_search_by`], [`binary_search_by_key`], and [`partition_point`].
2407+
///
2408+
/// [`binary_search_by`]: VecDeque::binary_search_by
2409+
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
2410+
/// [`partition_point`]: VecDeque::partition_point
2411+
///
24062412
/// # Examples
24072413
///
24082414
/// Looks up a series of four elements. The first is found, with a
@@ -2457,6 +2463,12 @@ impl<T> VecDeque<T> {
24572463
/// [`Result::Err`] is returned, containing the index where a matching
24582464
/// element could be inserted while maintaining sorted order.
24592465
///
2466+
/// See also [`binary_search`], [`binary_search_by_key`], and [`partition_point`].
2467+
///
2468+
/// [`binary_search`]: VecDeque::binary_search
2469+
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
2470+
/// [`partition_point`]: VecDeque::partition_point
2471+
///
24602472
/// # Examples
24612473
///
24622474
/// Looks up a series of four elements. The first is found, with a
@@ -2481,8 +2493,11 @@ impl<T> VecDeque<T> {
24812493
F: FnMut(&'a T) -> Ordering,
24822494
{
24832495
let (front, back) = self.as_slices();
2496+
let cmp_back = back.first().map(|elem| f(elem));
24842497

2485-
if let Some(Ordering::Less | Ordering::Equal) = back.first().map(|elem| f(elem)) {
2498+
if let Some(Ordering::Equal) = cmp_back {
2499+
Ok(front.len())
2500+
} else if let Some(Ordering::Less) = cmp_back {
24862501
back.binary_search_by(f).map(|idx| idx + front.len()).map_err(|idx| idx + front.len())
24872502
} else {
24882503
front.binary_search_by(f)
@@ -2492,15 +2507,21 @@ impl<T> VecDeque<T> {
24922507
/// Binary searches this sorted `VecDeque` with a key extraction function.
24932508
///
24942509
/// Assumes that the `VecDeque` is sorted by the key, for instance with
2495-
/// [`make_contiguous().sort_by_key()`](#method.make_contiguous) using the same
2496-
/// key extraction function.
2510+
/// [`make_contiguous().sort_by_key()`] using the same key extraction function.
24972511
///
24982512
/// If the value is found then [`Result::Ok`] is returned, containing the
24992513
/// index of the matching element. If there are multiple matches, then any
25002514
/// one of the matches could be returned. If the value is not found then
25012515
/// [`Result::Err`] is returned, containing the index where a matching
25022516
/// element could be inserted while maintaining sorted order.
25032517
///
2518+
/// See also [`binary_search`], [`binary_search_by`], and [`partition_point`].
2519+
///
2520+
/// [`make_contiguous().sort_by_key()`]: VecDeque::make_contiguous
2521+
/// [`binary_search`]: VecDeque::binary_search
2522+
/// [`binary_search_by`]: VecDeque::binary_search_by
2523+
/// [`partition_point`]: VecDeque::partition_point
2524+
///
25042525
/// # Examples
25052526
///
25062527
/// Looks up a series of four elements in a slice of pairs sorted by
@@ -2531,6 +2552,51 @@ impl<T> VecDeque<T> {
25312552
{
25322553
self.binary_search_by(|k| f(k).cmp(b))
25332554
}
2555+
2556+
/// Returns the index of the partition point according to the given predicate
2557+
/// (the index of the first element of the second partition).
2558+
///
2559+
/// The deque is assumed to be partitioned according to the given predicate.
2560+
/// This means that all elements for which the predicate returns true are at the start of the deque
2561+
/// and all elements for which the predicate returns false are at the end.
2562+
/// For example, [7, 15, 3, 5, 4, 12, 6] is a partitioned under the predicate x % 2 != 0
2563+
/// (all odd numbers are at the start, all even at the end).
2564+
///
2565+
/// If this deque is not partitioned, the returned result is unspecified and meaningless,
2566+
/// as this method performs a kind of binary search.
2567+
///
2568+
/// See also [`binary_search`], [`binary_search_by`], and [`binary_search_by_key`].
2569+
///
2570+
/// [`binary_search`]: VecDeque::binary_search
2571+
/// [`binary_search_by`]: VecDeque::binary_search_by
2572+
/// [`binary_search_by_key`]: VecDeque::binary_search_by_key
2573+
///
2574+
/// # Examples
2575+
///
2576+
/// ```
2577+
/// #![feature(vecdeque_binary_search)]
2578+
/// use std::collections::VecDeque;
2579+
///
2580+
/// let deque: VecDeque<_> = vec![1, 2, 3, 3, 5, 6, 7].into();
2581+
/// let i = deque.partition_point(|&x| x < 5);
2582+
///
2583+
/// assert_eq!(i, 4);
2584+
/// assert!(deque.iter().take(i).all(|&x| x < 5));
2585+
/// assert!(deque.iter().skip(i).all(|&x| !(x < 5)));
2586+
/// ```
2587+
#[unstable(feature = "vecdeque_binary_search", issue = "78021")]
2588+
pub fn partition_point<P>(&self, mut pred: P) -> usize
2589+
where
2590+
P: FnMut(&T) -> bool,
2591+
{
2592+
let (front, back) = self.as_slices();
2593+
2594+
if let Some(true) = back.first().map(|v| pred(v)) {
2595+
back.partition_point(pred) + front.len()
2596+
} else {
2597+
front.partition_point(pred)
2598+
}
2599+
}
25342600
}
25352601

25362602
impl<T: Clone> VecDeque<T> {

library/alloc/tests/vec_deque.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,24 @@ fn test_binary_search_by_key() {
16991699
assert_eq!(deque.binary_search_by_key(&4, |&(v,)| v), Err(3));
17001700
}
17011701

1702+
#[test]
1703+
fn test_partition_point() {
1704+
// Contiguous (front only) search:
1705+
let deque: VecDeque<_> = vec![1, 2, 3, 5, 6].into();
1706+
assert!(deque.as_slices().1.is_empty());
1707+
assert_eq!(deque.partition_point(|&v| v <= 3), 3);
1708+
1709+
// Split search (both front & back non-empty):
1710+
let mut deque: VecDeque<_> = vec![5, 6].into();
1711+
deque.push_front(3);
1712+
deque.push_front(2);
1713+
deque.push_front(1);
1714+
deque.push_back(10);
1715+
assert!(!deque.as_slices().0.is_empty());
1716+
assert!(!deque.as_slices().1.is_empty());
1717+
assert_eq!(deque.partition_point(|&v| v <= 5), 4);
1718+
}
1719+
17021720
#[test]
17031721
fn test_zero_sized_push() {
17041722
const N: usize = 8;

src/librustdoc/html/render/mod.rs

+26-38
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ use std::path::PathBuf;
4343
use std::str;
4444
use std::string::ToString;
4545

46-
use itertools::Itertools;
4746
use rustc_ast_pretty::pprust;
4847
use rustc_attr::{Deprecation, StabilityLevel};
4948
use rustc_data_structures::fx::FxHashSet;
@@ -486,18 +485,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result<Strin
486485
],
487486
)
488487
.into(),
489-
(
490-
"Auto-hide item declarations",
491-
vec![
492-
("auto-hide-struct", "Auto-hide structs declaration", true),
493-
("auto-hide-enum", "Auto-hide enums declaration", false),
494-
("auto-hide-union", "Auto-hide unions declaration", true),
495-
("auto-hide-trait", "Auto-hide traits declaration", true),
496-
("auto-hide-macro", "Auto-hide macros declaration", false),
497-
],
498-
)
499-
.into(),
500-
("auto-hide-attributes", "Auto-hide item attributes.", true).into(),
488+
("auto-hide-large-items", "Auto-hide item contents for large items.", true).into(),
501489
("auto-hide-method-docs", "Auto-hide item methods' documentation", false).into(),
502490
("auto-hide-trait-implementations", "Auto-hide trait implementation documentation", true)
503491
.into(),
@@ -947,19 +935,21 @@ fn render_assoc_item(
947935
+ name.as_str().len()
948936
+ generics_len;
949937

950-
let (indent, end_newline) = if parent == ItemType::Trait {
938+
let (indent, indent_str, end_newline) = if parent == ItemType::Trait {
951939
header_len += 4;
952-
(4, false)
940+
let indent_str = " ";
941+
render_attributes_in_pre(w, meth, indent_str);
942+
(4, indent_str, false)
953943
} else {
954-
(0, true)
944+
render_attributes_in_code(w, meth);
945+
(0, "", true)
955946
};
956-
render_attributes(w, meth, false);
957947
w.reserve(header_len + "<a href=\"\" class=\"fnname\">{".len() + "</a>".len());
958948
write!(
959949
w,
960950
"{}{}{}{}{}{}{}fn <a href=\"{href}\" class=\"fnname\">{name}</a>\
961951
{generics}{decl}{notable_traits}{where_clause}",
962-
if parent == ItemType::Trait { " " } else { "" },
952+
indent_str,
963953
vis,
964954
constness,
965955
asyncness,
@@ -1015,35 +1005,33 @@ const ALLOWED_ATTRIBUTES: &[Symbol] = &[
10151005
sym::non_exhaustive,
10161006
];
10171007

1018-
// The `top` parameter is used when generating the item declaration to ensure it doesn't have a
1019-
// left padding. For example:
1020-
//
1021-
// #[foo] <----- "top" attribute
1022-
// struct Foo {
1023-
// #[bar] <---- not "top" attribute
1024-
// bar: usize,
1025-
// }
1026-
fn render_attributes(w: &mut Buffer, it: &clean::Item, top: bool) {
1027-
let attrs = it
1028-
.attrs
1008+
fn attributes(it: &clean::Item) -> Vec<String> {
1009+
it.attrs
10291010
.other_attrs
10301011
.iter()
10311012
.filter_map(|attr| {
10321013
if ALLOWED_ATTRIBUTES.contains(&attr.name_or_empty()) {
1033-
Some(pprust::attribute_to_string(&attr))
1014+
Some(pprust::attribute_to_string(&attr).replace("\n", "").replace(" ", " "))
10341015
} else {
10351016
None
10361017
}
10371018
})
1038-
.join("\n");
1019+
.collect()
1020+
}
10391021

1040-
if !attrs.is_empty() {
1041-
write!(
1042-
w,
1043-
"<span class=\"docblock attributes{}\">{}</span>",
1044-
if top { " top-attr" } else { "" },
1045-
&attrs
1046-
);
1022+
// When an attribute is rendered inside a `<pre>` tag, it is formatted using
1023+
// a whitespace prefix and newline.
1024+
fn render_attributes_in_pre(w: &mut Buffer, it: &clean::Item, prefix: &str) {
1025+
for a in attributes(it) {
1026+
write!(w, "{}{}\n", prefix, a);
1027+
}
1028+
}
1029+
1030+
// When an attribute is rendered inside a <code> tag, it is formatted using
1031+
// a div to produce a newline after it.
1032+
fn render_attributes_in_code(w: &mut Buffer, it: &clean::Item) {
1033+
for a in attributes(it) {
1034+
write!(w, "<div class=\"code-attribute\">{}</div>", a);
10471035
}
10481036
}
10491037

0 commit comments

Comments
 (0)