1
Fork 0

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
This commit is contained in:
bors 2023-04-21 19:43:11 +00:00
commit fec9adcdbc
14 changed files with 153 additions and 40 deletions

View file

@ -876,16 +876,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
variant_did, variant_did,
ctor, ctor,
data.discr, data.discr,
self.root self.get_associated_item_or_field_def_ids(index)
.tables .map(|did| ty::FieldDef {
.children did,
.get(self, index) name: self.item_name(did.index),
.expect("fields are not encoded for a variant") vis: self.get_visibility(did.index),
.decode(self)
.map(|index| ty::FieldDef {
did: self.local_def_id(index),
name: self.item_name(index),
vis: self.get_visibility(index),
}) })
.collect(), .collect(),
adt_kind, adt_kind,
@ -910,7 +905,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
let variants = if let ty::AdtKind::Enum = adt_kind { let variants = if let ty::AdtKind::Enum = adt_kind {
self.root self.root
.tables .tables
.children .module_children_non_reexports
.get(self, item_id) .get(self, item_id)
.expect("variants are not encoded for an enum") .expect("variants are not encoded for an enum")
.decode(self) .decode(self)
@ -1022,12 +1017,10 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
} else { } else {
// Iterate over all children. // Iterate over all children.
for child_index in self.root.tables.children.get(self, id).unwrap().decode(self) { let non_reexports = self.root.tables.module_children_non_reexports.get(self, id);
// FIXME: Do not encode RPITITs as a part of this list. for child_index in non_reexports.unwrap().decode(self) {
if self.root.tables.opt_rpitit_info.get(self, child_index).is_none() {
yield self.get_mod_child(child_index, sess); yield self.get_mod_child(child_index, sess);
} }
}
let reexports = self.root.tables.module_children_reexports.get(self, id); let reexports = self.root.tables.module_children_reexports.get(self, id);
if !reexports.is_default() { if !reexports.is_default() {
@ -1058,17 +1051,16 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
.map_or(false, |ident| ident.name == kw::SelfLower) .map_or(false, |ident| ident.name == kw::SelfLower)
} }
fn get_associated_item_def_ids( fn get_associated_item_or_field_def_ids(
self, self,
id: DefIndex, id: DefIndex,
sess: &'a Session,
) -> impl Iterator<Item = DefId> + 'a { ) -> impl Iterator<Item = DefId> + 'a {
self.root self.root
.tables .tables
.children .associated_item_or_field_def_ids
.get(self, id) .get(self, id)
.expect("associated items not encoded for an item") .unwrap_or_else(|| self.missing("associated_item_or_field_def_ids", id))
.decode((self, sess)) .decode(self)
.map(move |child_index| self.local_def_id(child_index)) .map(move |child_index| self.local_def_id(child_index))
} }

View file

@ -276,7 +276,7 @@ provide! { tcx, def_id, other, cdata,
tcx.calculate_dtor(def_id, |_,_| Ok(())) tcx.calculate_dtor(def_id, |_,_| Ok(()))
} }
associated_item_def_ids => { associated_item_def_ids => {
tcx.arena.alloc_from_iter(cdata.get_associated_item_def_ids(def_id.index, tcx.sess)) tcx.arena.alloc_from_iter(cdata.get_associated_item_or_field_def_ids(def_id.index))
} }
associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) } associated_item => { cdata.get_associated_item(def_id.index, tcx.sess) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) } inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }

View file

@ -1367,7 +1367,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if adt_def.is_enum() { if adt_def.is_enum() {
let module_children = tcx.module_children_non_reexports(local_def_id); let module_children = tcx.module_children_non_reexports(local_def_id);
record_array!(self.tables.children[def_id] <- record_array!(self.tables.module_children_non_reexports[def_id] <-
module_children.iter().map(|def_id| def_id.local_def_index)); module_children.iter().map(|def_id| def_id.local_def_index));
} else { } else {
// For non-enum, there is only one variant, and its def_id is the adt's. // 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> {
record!(self.tables.variant_data[variant.def_id] <- data); record!(self.tables.variant_data[variant.def_id] <- data);
self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const); self.tables.constness.set_some(variant.def_id.index, hir::Constness::Const);
record_array!(self.tables.children[variant.def_id] <- variant.fields.iter().map(|f| { record_array!(self.tables.associated_item_or_field_def_ids[variant.def_id] <- variant.fields.iter().map(|f| {
assert!(f.did.is_local()); assert!(f.did.is_local());
f.did.index f.did.index
})); }));
@ -1415,7 +1415,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id)); record!(self.tables.expn_that_defined[def_id] <- tcx.expn_that_defined(local_def_id));
} else { } else {
let non_reexports = tcx.module_children_non_reexports(local_def_id); let non_reexports = tcx.module_children_non_reexports(local_def_id);
record_array!(self.tables.children[def_id] <- record_array!(self.tables.module_children_non_reexports[def_id] <-
non_reexports.iter().map(|def_id| def_id.local_def_index)); non_reexports.iter().map(|def_id| def_id.local_def_index));
record_defaulted_array!(self.tables.module_children_reexports[def_id] <- record_defaulted_array!(self.tables.module_children_reexports[def_id] <-
@ -1617,7 +1617,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_item({:?})", def_id); debug!("EncodeContext::encode_info_for_item({:?})", def_id);
let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| { let record_associated_item_def_ids = |this: &mut Self, def_ids: &[DefId]| {
record_array!(this.tables.children[def_id] <- def_ids.iter().map(|&def_id| { record_array!(this.tables.associated_item_or_field_def_ids[def_id] <- def_ids.iter().map(|&def_id| {
assert!(def_id.is_local()); assert!(def_id.is_local());
def_id.index def_id.index
})) }))
@ -1678,6 +1678,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hir::ItemKind::Trait(..) => { hir::ItemKind::Trait(..) => {
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id)); record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
let module_children = tcx.module_children_non_reexports(item.owner_id.def_id);
record_array!(self.tables.module_children_non_reexports[def_id] <-
module_children.iter().map(|def_id| def_id.local_def_index));
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id); let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);
record_associated_item_def_ids(self, associated_item_def_ids); record_associated_item_def_ids(self, associated_item_def_ids);
for &item_def_id in associated_item_def_ids { for &item_def_id in associated_item_def_ids {

View file

@ -361,7 +361,8 @@ define_tables! {
- optional: - optional:
attributes: Table<DefIndex, LazyArray<ast::Attribute>>, attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
children: Table<DefIndex, LazyArray<DefIndex>>, module_children_non_reexports: Table<DefIndex, LazyArray<DefIndex>>,
associated_item_or_field_def_ids: Table<DefIndex, LazyArray<DefIndex>>,
opt_def_kind: Table<DefIndex, DefKind>, opt_def_kind: Table<DefIndex, DefKind>,
visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>, visibility: Table<DefIndex, LazyValue<ty::Visibility<DefIndex>>>,
def_span: Table<DefIndex, LazyValue<Span>>, def_span: Table<DefIndex, LazyValue<Span>>,

View file

@ -670,9 +670,10 @@ rustc_queries! {
desc { "computing the inferred outlives predicates for items in this crate" } desc { "computing the inferred outlives predicates for items in this crate" }
} }
/// Maps from an impl/trait `DefId` to a list of the `DefId`s of its items. /// Maps from an impl/trait or struct/variant `DefId`
/// to a list of the `DefId`s of its associated items or fields.
query associated_item_def_ids(key: DefId) -> &'tcx [DefId] { query associated_item_def_ids(key: DefId) -> &'tcx [DefId] {
desc { |tcx| "collecting associated items of `{}`", tcx.def_path_str(key) } desc { |tcx| "collecting associated items or fields of `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() } cache_on_disk_if { key.is_local() }
separate_provide_extern separate_provide_extern
} }

View file

@ -300,7 +300,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
interpret_alloc_index.reserve(new_n - n); interpret_alloc_index.reserve(new_n - n);
for idx in n..new_n { for idx in n..new_n {
let id = encoder.interpret_allocs[idx]; let id = encoder.interpret_allocs[idx];
let pos = encoder.position() as u32; let pos: u32 = encoder.position().try_into().unwrap();
interpret_alloc_index.push(pos); interpret_alloc_index.push(pos);
interpret::specialized_encode_alloc_id(&mut encoder, tcx, id); interpret::specialized_encode_alloc_id(&mut encoder, tcx, id);
} }

View file

@ -367,6 +367,7 @@ fn preprocess_link(link: &str) -> Box<str> {
let link = link.strip_suffix("{}").unwrap_or(link); let link = link.strip_suffix("{}").unwrap_or(link);
let link = link.strip_suffix("[]").unwrap_or(link); let link = link.strip_suffix("[]").unwrap_or(link);
let link = if link != "!" { link.strip_suffix('!').unwrap_or(link) } else { link }; let link = if link != "!" { link.strip_suffix('!').unwrap_or(link) } else { link };
let link = link.trim();
strip_generics_from_path(link).unwrap_or_else(|_| link.into()) strip_generics_from_path(link).unwrap_or_else(|_| link.into())
} }

View file

@ -197,7 +197,7 @@ impl<T, A: Allocator> Drop for Drain<'_, T, A> {
} }
} }
let iter = mem::replace(&mut self.iter, (&mut []).iter()); let iter = mem::take(&mut self.iter);
let drop_len = iter.len(); let drop_len = iter.len();
let mut vec = self.vec; let mut vec = self.vec;

View file

@ -685,7 +685,7 @@ where
None None
} else { } else {
self.finished = true; self.finished = true;
Some(mem::replace(&mut self.v, &mut [])) Some(mem::take(&mut self.v))
} }
} }
} }
@ -749,7 +749,7 @@ where
match idx_opt { match idx_opt {
None => self.finish(), None => self.finish(),
Some(idx) => { Some(idx) => {
let tmp = mem::replace(&mut self.v, &mut []); let tmp = mem::take(&mut self.v);
let (head, tail) = tmp.split_at_mut(idx); let (head, tail) = tmp.split_at_mut(idx);
self.v = head; self.v = head;
Some(&mut tail[1..]) Some(&mut tail[1..])
@ -830,7 +830,7 @@ where
if idx == self.v.len() { if idx == self.v.len() {
self.finished = true; self.finished = true;
} }
let tmp = mem::replace(&mut self.v, &mut []); let tmp = mem::take(&mut self.v);
let (head, tail) = tmp.split_at_mut(idx); let (head, tail) = tmp.split_at_mut(idx);
self.v = tail; self.v = tail;
Some(head) Some(head)
@ -876,7 +876,7 @@ where
if idx == 0 { if idx == 0 {
self.finished = true; self.finished = true;
} }
let tmp = mem::replace(&mut self.v, &mut []); let tmp = mem::take(&mut self.v);
let (head, tail) = tmp.split_at_mut(idx); let (head, tail) = tmp.split_at_mut(idx);
self.v = head; self.v = head;
Some(tail) Some(tail)

View file

@ -9,6 +9,7 @@ use crate::io::{
self, BorrowedCursor, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write, self, BorrowedCursor, BufRead, ErrorKind, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write,
}; };
use crate::mem; use crate::mem;
use crate::str;
// ============================================================================= // =============================================================================
// Forwarding implementations // Forwarding implementations
@ -307,6 +308,17 @@ impl Read for &[u8] {
*self = &self[len..]; *self = &self[len..];
Ok(len) Ok(len)
} }
#[inline]
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
let content = str::from_utf8(self).map_err(|_| {
io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
})?;
buf.push_str(content);
let len = self.len();
*self = &self[len..];
Ok(len)
}
} }
#[stable(feature = "rust1", since = "1.0.0")] #[stable(feature = "rust1", since = "1.0.0")]
@ -336,7 +348,7 @@ impl Write for &mut [u8] {
#[inline] #[inline]
fn write(&mut self, data: &[u8]) -> io::Result<usize> { fn write(&mut self, data: &[u8]) -> io::Result<usize> {
let amt = cmp::min(data.len(), self.len()); let amt = cmp::min(data.len(), self.len());
let (a, b) = mem::replace(self, &mut []).split_at_mut(amt); let (a, b) = mem::take(self).split_at_mut(amt);
a.copy_from_slice(&data[..amt]); a.copy_from_slice(&data[..amt]);
*self = b; *self = b;
Ok(amt) Ok(amt)
@ -434,6 +446,33 @@ impl<A: Allocator> Read for VecDeque<u8, A> {
self.drain(..n); self.drain(..n);
Ok(()) Ok(())
} }
#[inline]
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> io::Result<usize> {
// The total len is known upfront so we can reserve it in a single call.
let len = self.len();
buf.reserve(len);
let (front, back) = self.as_slices();
buf.extend_from_slice(front);
buf.extend_from_slice(back);
self.clear();
Ok(len)
}
#[inline]
fn read_to_string(&mut self, buf: &mut String) -> io::Result<usize> {
// We have to use a single contiguous slice because the `VecDequeue` might be split in the
// middle of an UTF-8 character.
let len = self.len();
let content = self.make_contiguous();
let string = str::from_utf8(content).map_err(|_| {
io::const_io_error!(ErrorKind::InvalidData, "stream did not contain valid UTF-8")
})?;
buf.push_str(string);
self.clear();
Ok(len)
}
} }
/// Write is implemented for `VecDeque<u8>` by appending to the `VecDeque`, growing it as needed. /// 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> {
Ok(buf.len()) Ok(buf.len())
} }
#[inline]
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
let len = bufs.iter().map(|b| b.len()).sum();
self.reserve(len);
for buf in bufs {
self.extend(&**buf);
}
Ok(len)
}
#[inline]
fn is_write_vectored(&self) -> bool {
true
}
#[inline] #[inline]
fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { fn write_all(&mut self, buf: &[u8]) -> io::Result<()> {
self.extend(buf); self.extend(buf);

View file

@ -253,7 +253,7 @@ mod tests;
use crate::cmp; use crate::cmp;
use crate::fmt; use crate::fmt;
use crate::mem::replace; use crate::mem::take;
use crate::ops::{Deref, DerefMut}; use crate::ops::{Deref, DerefMut};
use crate::slice; use crate::slice;
use crate::str; use crate::str;
@ -1186,7 +1186,7 @@ impl<'a> IoSliceMut<'a> {
} }
} }
*bufs = &mut replace(bufs, &mut [])[remove..]; *bufs = &mut take(bufs)[remove..];
if bufs.is_empty() { if bufs.is_empty() {
assert!(n == accumulated_len, "advancing io slices beyond their length"); assert!(n == accumulated_len, "advancing io slices beyond their length");
} else { } else {
@ -1329,7 +1329,7 @@ impl<'a> IoSlice<'a> {
} }
} }
*bufs = &mut replace(bufs, &mut [])[remove..]; *bufs = &mut take(bufs)[remove..];
if bufs.is_empty() { if bufs.is_empty() {
assert!(n == accumulated_len, "advancing io slices beyond their length"); assert!(n == accumulated_len, "advancing io slices beyond their length");
} else { } else {

View file

@ -30,7 +30,7 @@ impl<'a> IoSliceMut<'a> {
#[inline] #[inline]
pub fn advance(&mut self, n: usize) { pub fn advance(&mut self, n: usize) {
let slice = mem::replace(&mut self.0, &mut []); let slice = mem::take(&mut self.0);
let (_, remaining) = slice.split_at_mut(n); let (_, remaining) = slice.split_at_mut(n);
self.0 = remaining; self.0 = remaining;
} }

View file

@ -0,0 +1,6 @@
// this test used to ICE
#![deny(rustdoc::broken_intra_doc_links)]
//! [Clone ()]. //~ ERROR unresolved
//! [Clone !]. //~ ERROR incompatible
//! [`Clone ()`]. //~ ERROR unresolved
//! [`Clone !`]. //~ ERROR incompatible

View file

@ -0,0 +1,54 @@
error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:3:6
|
LL | //! [Clone ()].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
|
note: the lint level is defined here
--> $DIR/issue-110495-suffix-with-space.rs:2:9
|
LL | #![deny(rustdoc::broken_intra_doc_links)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: to link to the trait, prefix with `trait@`
|
LL - //! [Clone ()].
LL + //! [trait@Clone ].
|
error: incompatible link kind for `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:4:6
|
LL | //! [Clone !].
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
|
help: to link to the derive macro, prefix with `derive@`
|
LL - //! [Clone !].
LL + //! [derive@Clone ].
|
error: unresolved link to `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:5:7
|
LL | //! [`Clone ()`].
| ^^^^^^^^ this link resolves to the trait `Clone`, which is not in the value namespace
|
help: to link to the trait, prefix with `trait@`
|
LL - //! [`Clone ()`].
LL + //! [`trait@Clone (`].
|
error: incompatible link kind for `Clone`
--> $DIR/issue-110495-suffix-with-space.rs:6:7
|
LL | //! [`Clone !`].
| ^^^^^^^ this link resolved to a derive macro, which is not a macro
|
help: to link to the derive macro, prefix with `derive@`
|
LL | //! [`derive@Clone !`].
| +++++++
error: aborting due to 4 previous errors