Skip to content

Commit f09fb48

Browse files
committed
Auto merge of #81186 - GuillaumeGomez:rollup-y2d04g9, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #80382 (Improve search result tab handling) - #81112 (Remove unused alloc::std::ops re-export.) - #81115 (BTreeMap: prefer bulk_steal functions over specialized ones) - #81147 (Fix structured suggestion for explicit `drop` call) - #81161 (Remove inline script tags) - #81164 (Fix typo in simplify.rs) - #81166 (remove some outdated comments regarding debug assertions) - #81168 (Fixes #81109 - Typo in pointer::wrapping_sub) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 47121d6 + dcb7479 commit f09fb48

27 files changed

+166
-182
lines changed

compiler/rustc_mir_build/src/build/matches/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5555
// * the bindings from the previous iteration of the loop is prepended to the bindings from
5656
// the current iteration (in the implementation this is done by mem::swap and extend)
5757
// * after all iterations, these new bindings are then appended to the bindings that were
58-
// prexisting (i.e. `candidate.binding` when the function was called).
58+
// preexisting (i.e. `candidate.binding` when the function was called).
5959
//
6060
// example:
6161
// candidate.bindings = [1, 2, 3]

compiler/rustc_typeck/src/check/callee.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ pub fn check_legal_trait_for_method_call(
2525
tcx: TyCtxt<'_>,
2626
span: Span,
2727
receiver: Option<Span>,
28+
expr_span: Span,
2829
trait_id: DefId,
2930
) {
3031
if tcx.lang_items().drop_trait() == Some(trait_id) {
3132
let mut err = struct_span_err!(tcx.sess, span, E0040, "explicit use of destructor method");
3233
err.span_label(span, "explicit destructor calls not allowed");
3334

34-
let snippet = receiver
35+
let (sp, suggestion) = receiver
3536
.and_then(|s| tcx.sess.source_map().span_to_snippet(s).ok())
36-
.unwrap_or_default();
37-
38-
let suggestion =
39-
if snippet.is_empty() { "drop".to_string() } else { format!("drop({})", snippet) };
37+
.filter(|snippet| !snippet.is_empty())
38+
.map(|snippet| (expr_span, format!("drop({})", snippet)))
39+
.unwrap_or_else(|| (span, "drop".to_string()));
4040

4141
err.span_suggestion(
42-
span,
43-
&format!("consider using `drop` function: `{}`", suggestion),
44-
String::new(),
45-
Applicability::Unspecified,
42+
sp,
43+
"consider using `drop` function",
44+
suggestion,
45+
Applicability::MaybeIncorrect,
4646
);
4747

4848
err.emit();

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1163,7 +1163,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11631163
debug!("instantiate_value_path: def_id={:?} container={:?}", def_id, container);
11641164
match container {
11651165
ty::TraitContainer(trait_did) => {
1166-
callee::check_legal_trait_for_method_call(tcx, span, None, trait_did)
1166+
callee::check_legal_trait_for_method_call(tcx, span, None, span, trait_did)
11671167
}
11681168
ty::ImplContainer(impl_def_id) => {
11691169
if segments.len() == 1 {

compiler/rustc_typeck/src/check/method/confirm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
508508
self.tcx,
509509
self.span,
510510
Some(self.self_expr.span),
511+
self.call_expr.span,
511512
trait_def_id,
512513
),
513514
ty::ImplContainer(..) => {}

library/alloc/src/collections/btree/node.rs

+4-117
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,6 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Leaf> {
592592
self.val_area_mut(idx).write(val);
593593
}
594594
}
595-
596-
/// Adds a key-value pair to the beginning of the node.
597-
fn push_front(&mut self, key: K, val: V) {
598-
let new_len = self.len() + 1;
599-
assert!(new_len <= CAPACITY);
600-
unsafe {
601-
slice_insert(self.key_area_mut(..new_len), 0, key);
602-
slice_insert(self.val_area_mut(..new_len), 0, val);
603-
*self.len_mut() = new_len as u16;
604-
}
605-
}
606595
}
607596

608597
impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
@@ -638,88 +627,6 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
638627
Handle::new_edge(self.reborrow_mut(), idx + 1).correct_parent_link();
639628
}
640629
}
641-
642-
/// Adds a key-value pair, and an edge to go to the left of that pair,
643-
/// to the beginning of the node.
644-
fn push_front(&mut self, key: K, val: V, edge: Root<K, V>) {
645-
let new_len = self.len() + 1;
646-
assert!(edge.height == self.height - 1);
647-
assert!(new_len <= CAPACITY);
648-
649-
unsafe {
650-
slice_insert(self.key_area_mut(..new_len), 0, key);
651-
slice_insert(self.val_area_mut(..new_len), 0, val);
652-
slice_insert(self.edge_area_mut(..new_len + 1), 0, edge.node);
653-
*self.len_mut() = new_len as u16;
654-
}
655-
656-
self.correct_all_childrens_parent_links();
657-
}
658-
}
659-
660-
impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal> {
661-
/// Removes a key-value pair from the end of the node and returns the pair.
662-
/// Also removes the edge that was to the right of that pair and, if the node
663-
/// is internal, returns the orphaned subtree that this edge owned.
664-
///
665-
/// # Safety
666-
/// The node must not be empty.
667-
unsafe fn pop(&mut self) -> (K, V, Option<Root<K, V>>) {
668-
debug_assert!(self.len() > 0);
669-
670-
let idx = self.len() - 1;
671-
672-
unsafe {
673-
let key = self.key_area_mut(idx).assume_init_read();
674-
let val = self.val_area_mut(idx).assume_init_read();
675-
let edge = match self.reborrow_mut().force() {
676-
ForceResult::Leaf(_) => None,
677-
ForceResult::Internal(mut internal) => {
678-
let node = internal.edge_area_mut(idx + 1).assume_init_read();
679-
let mut edge = Root { node, height: internal.height - 1, _marker: PhantomData };
680-
// Currently, clearing the parent link is superfluous, because we will
681-
// insert the node elsewhere and set its parent link again.
682-
edge.clear_parent_link();
683-
Some(edge)
684-
}
685-
};
686-
687-
*self.len_mut() -= 1;
688-
(key, val, edge)
689-
}
690-
}
691-
692-
/// Removes a key-value pair from the beginning of the node and returns the pair.
693-
/// Also removes the edge that was to the left of that pair and, if the node is
694-
/// internal, returns the orphaned subtree that this edge owned.
695-
fn pop_front(&mut self) -> (K, V, Option<Root<K, V>>) {
696-
debug_assert!(self.len() > 0);
697-
698-
let old_len = self.len();
699-
700-
unsafe {
701-
let key = slice_remove(self.key_area_mut(..old_len), 0);
702-
let val = slice_remove(self.val_area_mut(..old_len), 0);
703-
let edge = match self.reborrow_mut().force() {
704-
ForceResult::Leaf(_) => None,
705-
ForceResult::Internal(mut internal) => {
706-
let node = slice_remove(internal.edge_area_mut(..old_len + 1), 0);
707-
let mut edge = Root { node, height: internal.height - 1, _marker: PhantomData };
708-
// Currently, clearing the parent link is superfluous, because we will
709-
// insert the node elsewhere and set its parent link again.
710-
edge.clear_parent_link();
711-
712-
internal.correct_childrens_parent_links(0..old_len);
713-
714-
Some(edge)
715-
}
716-
};
717-
718-
*self.len_mut() -= 1;
719-
720-
(key, val, edge)
721-
}
722-
}
723630
}
724631

725632
impl<BorrowType, K, V> NodeRef<BorrowType, K, V, marker::LeafOrInternal> {
@@ -1399,18 +1306,8 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
13991306
mut self,
14001307
track_right_edge_idx: usize,
14011308
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::Edge> {
1402-
unsafe {
1403-
let (k, v, edge) = self.left_child.pop();
1404-
1405-
let (k, v) = self.parent.replace_kv(k, v);
1406-
1407-
match self.right_child.reborrow_mut().force() {
1408-
ForceResult::Leaf(mut leaf) => leaf.push_front(k, v),
1409-
ForceResult::Internal(mut internal) => internal.push_front(k, v, edge.unwrap()),
1410-
}
1411-
1412-
Handle::new_edge(self.right_child, 1 + track_right_edge_idx)
1413-
}
1309+
self.bulk_steal_left(1);
1310+
unsafe { Handle::new_edge(self.right_child, 1 + track_right_edge_idx) }
14141311
}
14151312

14161313
/// Removes a key-value pair from the right child and places it in the key-value storage
@@ -1421,18 +1318,8 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> {
14211318
mut self,
14221319
track_left_edge_idx: usize,
14231320
) -> Handle<NodeRef<marker::Mut<'a>, K, V, marker::LeafOrInternal>, marker::Edge> {
1424-
unsafe {
1425-
let (k, v, edge) = self.right_child.pop_front();
1426-
1427-
let (k, v) = self.parent.replace_kv(k, v);
1428-
1429-
match self.left_child.reborrow_mut().force() {
1430-
ForceResult::Leaf(mut leaf) => leaf.push(k, v),
1431-
ForceResult::Internal(mut internal) => internal.push(k, v, edge.unwrap()),
1432-
}
1433-
1434-
Handle::new_edge(self.left_child, track_left_edge_idx)
1435-
}
1321+
self.bulk_steal_right(1);
1322+
unsafe { Handle::new_edge(self.left_child, track_left_edge_idx) }
14361323
}
14371324

14381325
/// This does stealing similar to `steal_left` but steals multiple elements at once.

library/alloc/src/collections/btree/remove.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -121,25 +121,25 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
121121
self,
122122
) -> Option<NodeRef<marker::Mut<'a>, K, V, marker::Internal>> {
123123
match self.forget_type().choose_parent_kv() {
124-
Ok(Left(left_parent_kv)) => {
124+
Ok(Left(mut left_parent_kv)) => {
125125
debug_assert_eq!(left_parent_kv.right_child_len(), MIN_LEN - 1);
126126
if left_parent_kv.can_merge() {
127127
let parent = left_parent_kv.merge_tracking_parent();
128128
Some(parent)
129129
} else {
130130
debug_assert!(left_parent_kv.left_child_len() > MIN_LEN);
131-
left_parent_kv.steal_left(0);
131+
left_parent_kv.bulk_steal_left(1);
132132
None
133133
}
134134
}
135-
Ok(Right(right_parent_kv)) => {
135+
Ok(Right(mut right_parent_kv)) => {
136136
debug_assert_eq!(right_parent_kv.left_child_len(), MIN_LEN - 1);
137137
if right_parent_kv.can_merge() {
138138
let parent = right_parent_kv.merge_tracking_parent();
139139
Some(parent)
140140
} else {
141141
debug_assert!(right_parent_kv.right_child_len() > MIN_LEN);
142-
right_parent_kv.steal_right(0);
142+
right_parent_kv.bulk_steal_right(1);
143143
None
144144
}
145145
}

library/alloc/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,6 @@ pub mod task;
185185
mod tests;
186186
pub mod vec;
187187

188-
#[cfg(not(test))]
189-
mod std {
190-
pub use core::ops; // RangeFull
191-
}
192-
193188
#[doc(hidden)]
194189
#[unstable(feature = "liballoc_internals", issue = "none", reason = "implementation detail")]
195190
pub mod __export {

library/core/src/ptr/const_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ impl<T: ?Sized> *const T {
633633
}
634634

635635
/// Calculates the offset from a pointer using wrapping arithmetic.
636-
/// (convenience for `.wrapping_offset((count as isize).wrapping_sub())`)
636+
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
637637
///
638638
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
639639
/// offset of `3 * size_of::<T>()` bytes.

library/core/src/ptr/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,6 @@ pub unsafe fn replace<T>(dst: *mut T, mut src: T) -> T {
687687
#[stable(feature = "rust1", since = "1.0.0")]
688688
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
689689
pub const unsafe fn read<T>(src: *const T) -> T {
690-
// `copy_nonoverlapping` takes care of debug_assert.
691690
let mut tmp = MaybeUninit::<T>::uninit();
692691
// SAFETY: the caller must guarantee that `src` is valid for reads.
693692
// `src` cannot overlap `tmp` because `tmp` was just allocated on
@@ -787,7 +786,6 @@ pub const unsafe fn read<T>(src: *const T) -> T {
787786
#[stable(feature = "ptr_unaligned", since = "1.17.0")]
788787
#[rustc_const_unstable(feature = "const_ptr_read", issue = "80377")]
789788
pub const unsafe fn read_unaligned<T>(src: *const T) -> T {
790-
// `copy_nonoverlapping` takes care of debug_assert.
791789
let mut tmp = MaybeUninit::<T>::uninit();
792790
// SAFETY: the caller must guarantee that `src` is valid for reads.
793791
// `src` cannot overlap `tmp` because `tmp` was just allocated on
@@ -988,7 +986,6 @@ pub unsafe fn write_unaligned<T>(dst: *mut T, src: T) {
988986
// `dst` cannot overlap `src` because the caller has mutable access
989987
// to `dst` while `src` is owned by this function.
990988
unsafe {
991-
// `copy_nonoverlapping` takes care of debug_assert.
992989
copy_nonoverlapping(&src as *const T as *const u8, dst as *mut u8, mem::size_of::<T>());
993990
}
994991
mem::forget(src);

library/core/src/ptr/mut_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ impl<T: ?Sized> *mut T {
740740
}
741741

742742
/// Calculates the offset from a pointer using wrapping arithmetic.
743-
/// (convenience for `.wrapping_offset((count as isize).wrapping_sub())`)
743+
/// (convenience for `.wrapping_offset((count as isize).wrapping_neg())`)
744744
///
745745
/// `count` is in units of T; e.g., a `count` of 3 represents a pointer
746746
/// offset of `3 * size_of::<T>()` bytes.

src/librustdoc/html/layout.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,7 @@ crate fn render<T: Print, S: Print>(
111111
<section id=\"search\" class=\"content hidden\"></section>\
112112
<section class=\"footer\"></section>\
113113
{after_content}\
114-
<script>\
115-
window.rootPath = \"{root_path}\";\
116-
window.currentCrate = \"{krate}\";\
117-
</script>\
114+
<div id=\"rustdoc-vars\" data-root-path=\"{root_path}\" data-current-crate=\"{krate}\"></div>
118115
<script src=\"{static_root_path}main{suffix}.js\"></script>\
119116
{static_extra_scripts}\
120117
{extra_scripts}\

src/librustdoc/html/markdown.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,8 @@ fn init_id_map() -> FxHashMap<String, usize> {
13131313
map.insert("toggle-all-docs".to_owned(), 1);
13141314
map.insert("all-types".to_owned(), 1);
13151315
map.insert("default-settings".to_owned(), 1);
1316+
map.insert("rustdoc-vars".to_owned(), 1);
1317+
map.insert("sidebar-vars".to_owned(), 1);
13161318
// This is the list of IDs used by rustdoc sections.
13171319
map.insert("fields".to_owned(), 1);
13181320
map.insert("variants".to_owned(), 1);

src/librustdoc/html/render/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -4216,11 +4216,8 @@ fn print_sidebar(cx: &Context<'_>, it: &clean::Item, buffer: &mut Buffer, cache:
42164216
let relpath = if it.is_mod() { "../" } else { "" };
42174217
write!(
42184218
buffer,
4219-
"<script>window.sidebarCurrent = {{\
4220-
name: \"{name}\", \
4221-
ty: \"{ty}\", \
4222-
relpath: \"{path}\"\
4223-
}};</script>",
4219+
"<div id=\"sidebar-vars\" data-name=\"{name}\" data-ty=\"{ty}\" data-relpath=\"{path}\">\
4220+
</div>",
42244221
name = it.name.unwrap_or(kw::Empty),
42254222
ty = it.type_(),
42264223
path = relpath

0 commit comments

Comments
 (0)