Skip to content

Commit fec9adc

Browse files
committedApr 21, 2023
Auto merge of #110648 - Dylan-DPC:rollup-em3ovcq, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #110333 (rustc_metadata: Split `children` into multiple tables) - #110501 (rustdoc: fix ICE from rustc_resolve and librustdoc parse divergence) - #110608 (Specialize some `io::Read` and `io::Write` methods for `VecDeque<u8>` and `&[u8]`) - #110632 (Panic instead of truncating if the incremental on-disk cache is too big) - #110633 (More `mem::take` in `library`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fa4cc63 + 482e407 commit fec9adc

File tree

14 files changed

+153
-40
lines changed

14 files changed

+153
-40
lines changed
 

‎compiler/rustc_metadata/src/rmeta/decoder.rs

+13-21
Original file line numberDiff line numberDiff line change
@@ -876,16 +876,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
876876
variant_did,
877877
ctor,
878878
data.discr,
879-
self.root
880-
.tables
881-
.children
882-
.get(self, index)
883-
.expect("fields are not encoded for a variant")
884-
.decode(self)
885-
.map(|index| ty::FieldDef {
886-
did: self.local_def_id(index),
887-
name: self.item_name(index),
888-
vis: self.get_visibility(index),
879+
self.get_associated_item_or_field_def_ids(index)
880+
.map(|did| ty::FieldDef {
881+
did,
882+
name: self.item_name(did.index),
883+
vis: self.get_visibility(did.index),
889884
})
890885
.collect(),
891886
adt_kind,
@@ -910,7 +905,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
910905
let variants = if let ty::AdtKind::Enum = adt_kind {
911906
self.root
912907
.tables
913-
.children
908+
.module_children_non_reexports
914909
.get(self, item_id)
915910
.expect("variants are not encoded for an enum")
916911
.decode(self)
@@ -1022,11 +1017,9 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10221017
}
10231018
} else {
10241019
// Iterate over all children.
1025-
for child_index in self.root.tables.children.get(self, id).unwrap().decode(self) {
1026-
// FIXME: Do not encode RPITITs as a part of this list.
1027-
if self.root.tables.opt_rpitit_info.get(self, child_index).is_none() {
1028-
yield self.get_mod_child(child_index, sess);
1029-
}
1020+
let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
1021+
for child_index in non_reexports.unwrap().decode(self) {
1022+
yield self.get_mod_child(child_index, sess);
10301023
}
10311024

10321025
let reexports = self.root.tables.module_children_reexports.get(self, id);
@@ -1058,17 +1051,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10581051
.map_or(false, |ident| ident.name == kw::SelfLower)
10591052
}
10601053

1061-
fn get_associated_item_def_ids(
1054+
fn get_associated_item_or_field_def_ids(
10621055
self,
10631056
id: DefIndex,
1064-
sess: &'a Session,
10651057
) -> impl Iterator<Item = DefId> + 'a {
10661058
self.root
10671059
.tables
1068-
.children
1060+
.associated_item_or_field_def_ids
10691061
.get(self, id)
1070-
.expect("associated items not encoded for an item")
1071-
.decode((self, sess))
1062+
.unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
1063+
.decode(self)
10721064
.map(move |child_index| self.local_def_id(child_index))
10731065
}
10741066

‎compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ provide! { tcx, def_id, other, cdata,
276276
tcx.calculate_dtor(def_id, |_,_| Ok(()))
277277
}
278278
associated_item_def_ids => {
279-
tcx.arena.alloc_from_iter(cdata.get_associated_item_def_ids(def_id.index, tcx.sess))
279+
tcx.arena.alloc_from_iter(cdata.get_associated_item_or_field_def_ids(def_id.index))
280280
}
281281
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
282282
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }

‎compiler/rustc_metadata/src/rmeta/encoder.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13671367

13681368
if adt_def.is_enum() {
13691369
let module_children = tcx.module_children_non_reexports(local_def_id);
1370-
record_array!(self.tables.children[def_id] <-
1370+
record_array!(self.tables.module_children_non_reexports[def_id] <-
13711371
module_children.iter().map(|def_id| def_id.local_def_index));
13721372
} else {
13731373
// For non-enum, there is only one variant, and its def_id is the adt's.
@@ -1385,7 +1385,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13851385
record!(self.tables.variant_data[variant.def_id] <- data);
13861386

13871387
self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const);
1388-
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| {
1388+
record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
13891389
assert!(f.did.is_local());
13901390
f.did.index
13911391
}));
@@ -1415,7 +1415,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14151415
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
14161416
} else {
14171417
let non_reexports = tcx.module_children_non_reexports(local_def_id);
1418-
record_array!(self.tables.children[def_id] <-
1418+
record_array!(self.tables.module_children_non_reexports[def_id] <-
14191419
non_reexports.iter().map(|def_id| def_id.local_def_index));
14201420

14211421
record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
@@ -1617,7 +1617,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16171617
debug!("EncodeContext::encode_info_for_item({:?})", def_id);
16181618

16191619
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
1620-
record_array!(this.tables.children[def_id] <- def_ids.iter().map(|&def_id| {
1620+
record_array!(this.tables.associated_item_or_field_def_ids[def_id] <- def_ids.iter().map(|&def_id| {
16211621
assert!(def_id.is_local());
16221622
def_id.index
16231623
}))
@@ -1678,6 +1678,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16781678
hir::ItemKind::Trait(..) => {
16791679
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
16801680

1681+
let module_children = tcx.module_children_non_reexports(item.owner_id.def_id);
1682+
record_array!(self.tables.module_children_non_reexports[def_id] <-
1683+
module_children.iter().map(|def_id| def_id.local_def_index));
1684+
16811685
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
16821686
record_associated_item_def_ids(self, associated_item_def_ids);
16831687
for &item_def_id in associated_item_def_ids {

‎compiler/rustc_metadata/src/rmeta/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,8 @@ define_tables! {
361361

362362
- optional:
363363
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
364-
children: Table<DefIndex, LazyArray<DefIndex>>,
364+
module_children_non_reexports: Table<DefIndex, LazyArray<DefIndex>>,
365+
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
365366
opt_def_kind: Table<DefIndex, DefKind>,
366367
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
367368
def_span: Table<DefIndex, LazyValue<Span>>,

‎compiler/rustc_middle/src/query/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,10 @@ rustc_queries! {
670670
desc { "computing the inferred outlives predicates for items in this crate" }
671671
}
672672

673-
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items.
673+
/// Maps from an impl/trait or struct/variant `DefId`
674+
/// to a list of the `DefId`s of its associated items or fields.
674675
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
675-
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) }
676+
desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
676677
cache_on_disk_if { key.is_local() }
677678
separate_provide_extern
678679
}

‎compiler/rustc_query_impl/src/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
300300
interpret_alloc_index.reserve(new_n - n);
301301
for idx in n..new_n {
302302
let id = encoder.interpret_allocs[idx];
303-
let pos = encoder.position() as u32;
303+
let pos: u32 = encoder.position().try_into().unwrap();
304304
interpret_alloc_index.push(pos);
305305
interpret::specialized_encode_alloc_id(&mut encoder, tcx, id);
306306
}

‎compiler/rustc_resolve/src/rustdoc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,7 @@ fn preprocess_link(link: &str) -> Box<str> {
367367
let link = link.strip_suffix("{}").unwrap_or(link);
368368
let link = link.strip_suffix("[]").unwrap_or(link);
369369
let link = if link != "!" { link.strip_suffix('!').unwrap_or(link) } else { link };
370+
let link = link.trim();
370371
strip_generics_from_path(link).unwrap_or_else(|_| link.into())
371372
}
372373

‎library/alloc/src/vec/drain.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
197197
}
198198
}
199199

200-
let iter = mem::replace(&mut self.iter, (&mut []).iter());
200+
let iter = mem::take(&mut self.iter);
201201
let drop_len = iter.len();
202202

203203
let mut vec = self.vec;

‎library/core/src/slice/iter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ where
685685
None
686686
} else {
687687
self.finished = true;
688-
Some(mem::replace(&mut self.v, &mut []))
688+
Some(mem::take(&mut self.v))
689689
}
690690
}
691691
}
@@ -749,7 +749,7 @@ where
749749
match idx_opt {
750750
None => self.finish(),
751751
Some(idx) => {
752-
let tmp = mem::replace(&mut self.v, &mut []);
752+
let tmp = mem::take(&mut self.v);
753753
let (head, tail) = tmp.split_at_mut(idx);
754754
self.v = head;
755755
Some(&mut tail[1..])
@@ -830,7 +830,7 @@ where
830830
if idx == self.v.len() {
831831
self.finished = true;
832832
}
833-
let tmp = mem::replace(&mut self.v, &mut []);
833+
let tmp = mem::take(&mut self.v);
834834
let (head, tail) = tmp.split_at_mut(idx);
835835
self.v = tail;
836836
Some(head)
@@ -876,7 +876,7 @@ where
876876
if idx == 0 {
877877
self.finished = true;
878878
}
879-
let tmp = mem::replace(&mut self.v, &mut []);
879+
let tmp = mem::take(&mut self.v);
880880
let (head, tail) = tmp.split_at_mut(idx);
881881
self.v = head;
882882
Some(tail)

‎library/std/src/io/impls.rs

+55-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::io::{
99
self, BorrowedCursor, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write,
1010
};
1111
use crate::mem;
12+
use crate::str;
1213

1314
// =============================================================================
1415
// Forwarding implementations
@@ -307,6 +308,17 @@ impl Read for &[u8] {
307308
*self = &self[len..];
308309
Ok(len)
309310
}
311+
312+
#[inline]
313+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
314+
let content = str::from_utf8(self).map_err(|_| {
315+
io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
316+
})?;
317+
buf.push_str(content);
318+
let len = self.len();
319+
*self = &self[len..];
320+
Ok(len)
321+
}
310322
}
311323

312324
#[stable(feature = "rust1", since = "1.0.0")]
@@ -336,7 +348,7 @@ impl Write for &mut [u8] {
336348
#[inline]
337349
fn write(&mut self, data: &[u8]) -> io::Result<usize> {
338350
let amt = cmp::min(data.len(), self.len());
339-
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt);
351+
let (a, b) = mem::take(self).split_at_mut(amt);
340352
a.copy_from_slice(&data[..amt]);
341353
*self = b;
342354
Ok(amt)
@@ -434,6 +446,33 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
434446
self.drain(..n);
435447
Ok(())
436448
}
449+
450+
#[inline]
451+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
452+
// The total len is known upfront so we can reserve it in a single call.
453+
let len = self.len();
454+
buf.reserve(len);
455+
456+
let (front, back) = self.as_slices();
457+
buf.extend_from_slice(front);
458+
buf.extend_from_slice(back);
459+
self.clear();
460+
Ok(len)
461+
}
462+
463+
#[inline]
464+
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
465+
// We have to use a single contiguous slice because the `VecDequeue` might be split in the
466+
// middle of an UTF-8 character.
467+
let len = self.len();
468+
let content = self.make_contiguous();
469+
let string = str::from_utf8(content).map_err(|_| {
470+
io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
471+
})?;
472+
buf.push_str(string);
473+
self.clear();
474+
Ok(len)
475+
}
437476
}
438477

439478
/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed.
@@ -445,6 +484,21 @@ impl<A: Allocator> Write for VecDeque<u8, A> {
445484
Ok(buf.len())
446485
}
447486

487+
#[inline]
488+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
489+
let len = bufs.iter().map(|b| b.len()).sum();
490+
self.reserve(len);
491+
for buf in bufs {
492+
self.extend(&**buf);
493+
}
494+
Ok(len)
495+
}
496+
497+
#[inline]
498+
fn is_write_vectored(&self) -> bool {
499+
true
500+
}
501+
448502
#[inline]
449503
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
450504
self.extend(buf);

‎library/std/src/io/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ mod tests;
253253

254254
use crate::cmp;
255255
use crate::fmt;
256-
use crate::mem::replace;
256+
use crate::mem::take;
257257
use crate::ops::{Deref, DerefMut};
258258
use crate::slice;
259259
use crate::str;
@@ -1186,7 +1186,7 @@ impl<'a> IoSliceMut<'a> {
11861186
}
11871187
}
11881188

1189-
*bufs = &mut replace(bufs, &mut [])[remove..];
1189+
*bufs = &mut take(bufs)[remove..];
11901190
if bufs.is_empty() {
11911191
assert!(n == accumulated_len, "advancing io slices beyond their length");
11921192
} else {
@@ -1329,7 +1329,7 @@ impl<'a> IoSlice<'a> {
13291329
}
13301330
}
13311331

1332-
*bufs = &mut replace(bufs, &mut [])[remove..];
1332+
*bufs = &mut take(bufs)[remove..];
13331333
if bufs.is_empty() {
13341334
assert!(n == accumulated_len, "advancing io slices beyond their length");
13351335
} else {

‎library/std/src/sys/unsupported/io.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ impl<'a> IoSliceMut<'a> {
3030

3131
#[inline]
3232
pub fn advance(&mut self, n: usize) {
33-
let slice = mem::replace(&mut self.0, &mut []);
33+
let slice = mem::take(&mut self.0);
3434
let (_, remaining) = slice.split_at_mut(n);
3535
self.0 = remaining;
3636
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// this test used to ICE
2+
#![deny(rustdoc::broken_intra_doc_links)]
3+
//! [Clone ()]. //~ ERROR unresolved
4+
//! [Clone !]. //~ ERROR incompatible
5+
//! [`Clone ()`]. //~ ERROR unresolved
6+
//! [`Clone !`]. //~ ERROR incompatible
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
error: unresolved link to `Clone`
2+
--> $DIR/issue-110495-suffix-with-space.rs:3:6
3+
|
4+
LL | //! [Clone ()].
5+
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-110495-suffix-with-space.rs:2:9
9+
|
10+
LL | #![deny(rustdoc::broken_intra_doc_links)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
help: to link to the trait, prefix with `trait@`
13+
|
14+
LL - //! [Clone ()].
15+
LL + //! [trait@Clone ].
16+
|
17+
18+
error: incompatible link kind for `Clone`
19+
--> $DIR/issue-110495-suffix-with-space.rs:4:6
20+
|
21+
LL | //! [Clone !].
22+
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
23+
|
24+
help: to link to the derive macro, prefix with `derive@`
25+
|
26+
LL - //! [Clone !].
27+
LL + //! [derive@Clone ].
28+
|
29+
30+
error: unresolved link to `Clone`
31+
--> $DIR/issue-110495-suffix-with-space.rs:5:7
32+
|
33+
LL | //! [`Clone ()`].
34+
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
35+
|
36+
help: to link to the trait, prefix with `trait@`
37+
|
38+
LL - //! [`Clone ()`].
39+
LL + //! [`trait@Clone (`].
40+
|
41+
42+
error: incompatible link kind for `Clone`
43+
--> $DIR/issue-110495-suffix-with-space.rs:6:7
44+
|
45+
LL | //! [`Clone !`].
46+
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
47+
|
48+
help: to link to the derive macro, prefix with `derive@`
49+
|
50+
LL | //! [`derive@Clone !`].
51+
| +++++++
52+
53+
error: aborting due to 4 previous errors
54+

0 commit comments

Comments
 (0)
Please sign in to comment.