Skip to content

Commit 67b0300

Browse files
committed
Auto merge of #87413 - JohnTitor:rollup-dht22jk, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #86410 (VecMap::get_value_matching should return just one element) - #86790 (Document iteration order of `retain` functions) - #87171 (Remove Option from BufWriter) - #87175 (Stabilize `into_parts()` and `into_error()`) - #87185 (Fix panics on Windows when the build was cancelled) - #87191 (Package LLVM libs for the target rather than the build host) - #87255 (better support for running libcore tests with Miri) - #87266 (Add testcase for 87076) - #87283 (Add `--codegen-backends=foo,bar` configure flag) - #87322 (fix: clarify suggestion that `&T` must refer to `T: Sync` for `&T: Send`) - #87358 (Fix `--dry-run` when download-ci-llvm is set) - #87380 (Don't default to `submodules = true` unless the rust repo has a .git directory) - #87398 (Add test for fonts used for module items) - #87412 (Add missing article) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a1f419 + a651581 commit 67b0300

Some content is hidden

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

54 files changed

+213
-44
lines changed

compiler/rustc_data_structures/src/vec_map.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::borrow::Borrow;
2+
use std::fmt::Debug;
23
use std::iter::FromIterator;
34
use std::slice::Iter;
45
use std::vec::IntoIter;
@@ -12,7 +13,8 @@ pub struct VecMap<K, V>(Vec<(K, V)>);
1213

1314
impl<K, V> VecMap<K, V>
1415
where
15-
K: PartialEq,
16+
K: Debug + PartialEq,
17+
V: Debug,
1618
{
1719
pub fn new() -> Self {
1820
VecMap(Default::default())
@@ -37,14 +39,31 @@ where
3739
self.0.iter().find(|(key, _)| k == key.borrow()).map(|elem| &elem.1)
3840
}
3941

40-
/// Returns the value corresponding to the supplied predicate filter.
42+
/// Returns the any value corresponding to the supplied predicate filter.
4143
///
4244
/// The supplied predicate will be applied to each (key, value) pair and it will return a
4345
/// reference to the values where the predicate returns `true`.
44-
pub fn get_by(&self, mut predicate: impl FnMut(&(K, V)) -> bool) -> Option<&V> {
46+
pub fn any_value_matching(&self, mut predicate: impl FnMut(&(K, V)) -> bool) -> Option<&V> {
4547
self.0.iter().find(|kv| predicate(kv)).map(|elem| &elem.1)
4648
}
4749

50+
/// Returns the value corresponding to the supplied predicate filter. It crashes if there's
51+
/// more than one matching element.
52+
///
53+
/// The supplied predicate will be applied to each (key, value) pair and it will return a
54+
/// reference to the value where the predicate returns `true`.
55+
pub fn get_value_matching(&self, mut predicate: impl FnMut(&(K, V)) -> bool) -> Option<&V> {
56+
let mut filter = self.0.iter().filter(|kv| predicate(kv));
57+
let (_, value) = filter.next()?;
58+
// This should return just one element, otherwise it's a bug
59+
assert!(
60+
filter.next().is_none(),
61+
"Collection {:?} should have just one matching element",
62+
self
63+
);
64+
Some(value)
65+
}
66+
4867
/// Returns `true` if the map contains a value for the specified key.
4968
///
5069
/// The key may be any borrowed form of the map's key type,
@@ -131,7 +150,7 @@ impl<K, V> IntoIterator for VecMap<K, V> {
131150
}
132151
}
133152

134-
impl<K: PartialEq, V> Extend<(K, V)> for VecMap<K, V> {
153+
impl<K: PartialEq + Debug, V: Debug> Extend<(K, V)> for VecMap<K, V> {
135154
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
136155
for (k, v) in iter {
137156
self.insert(k, v);

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+30-5
Original file line numberDiff line numberDiff line change
@@ -1857,12 +1857,37 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
18571857
}
18581858
}
18591859
GeneratorInteriorOrUpvar::Upvar(upvar_span) => {
1860+
// `Some(ref_ty)` if `target_ty` is `&T` and `T` fails to impl `Sync`
1861+
let refers_to_non_sync = match target_ty.kind() {
1862+
ty::Ref(_, ref_ty, _) => match self.evaluate_obligation(&obligation) {
1863+
Ok(eval) if !eval.may_apply() => Some(ref_ty),
1864+
_ => None,
1865+
},
1866+
_ => None,
1867+
};
1868+
1869+
let (span_label, span_note) = match refers_to_non_sync {
1870+
// if `target_ty` is `&T` and `T` fails to impl `Sync`,
1871+
// include suggestions to make `T: Sync` so that `&T: Send`
1872+
Some(ref_ty) => (
1873+
format!(
1874+
"has type `{}` which {}, because `{}` is not `Sync`",
1875+
target_ty, trait_explanation, ref_ty
1876+
),
1877+
format!(
1878+
"captured value {} because `&` references cannot be sent unless their referent is `Sync`",
1879+
trait_explanation
1880+
),
1881+
),
1882+
None => (
1883+
format!("has type `{}` which {}", target_ty, trait_explanation),
1884+
format!("captured value {}", trait_explanation),
1885+
),
1886+
};
1887+
18601888
let mut span = MultiSpan::from_span(upvar_span);
1861-
span.push_span_label(
1862-
upvar_span,
1863-
format!("has type `{}` which {}", target_ty, trait_explanation),
1864-
);
1865-
err.span_note(span, &format!("captured value {}", trait_explanation));
1889+
span.push_span_label(upvar_span, span_label);
1890+
err.span_note(span, &span_note);
18661891
}
18671892
}
18681893

compiler/rustc_typeck/src/collect/type_of.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
364364
let concrete_ty = tcx
365365
.mir_borrowck(owner.expect_local())
366366
.concrete_opaque_types
367-
.get_by(|(key, _)| key.def_id == def_id.to_def_id())
367+
.get_value_matching(|(key, _)| key.def_id == def_id.to_def_id())
368368
.map(|concrete_ty| *concrete_ty)
369369
.unwrap_or_else(|| {
370370
tcx.sess.delay_span_bug(
@@ -512,8 +512,15 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
512512

513513
struct ConstraintLocator<'tcx> {
514514
tcx: TyCtxt<'tcx>,
515+
516+
/// def_id of the opaque type whose defining uses are being checked
515517
def_id: DefId,
516-
// (first found type span, actual type)
518+
519+
/// as we walk the defining uses, we are checking that all of them
520+
/// define the same hidden type. This variable is set to `Some`
521+
/// with the first type that we find, and then later types are
522+
/// checked against it (we also carry the span of that first
523+
/// type).
517524
found: Option<(Span, Ty<'tcx>)>,
518525
}
519526

@@ -531,7 +538,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
531538
.tcx
532539
.typeck(def_id)
533540
.concrete_opaque_types
534-
.get_by(|(key, _)| key.def_id == self.def_id)
541+
.any_value_matching(|(key, _)| key.def_id == self.def_id)
535542
.is_none()
536543
{
537544
debug!("no constraints in typeck results");

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ changelog-seen = 2
3838
# This is false by default so that distributions don't unexpectedly download
3939
# LLVM from the internet.
4040
#
41-
# All tier 1 targets are currently supported; set this to `"if-supported"` if
41+
# All tier 1 targets are currently supported; set this to `"if-available"` if
4242
# you are not sure whether you're on a tier 1 target.
4343
#
4444
# We also currently only support this when building LLVM for the build triple.

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

+1
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,7 @@ impl<K, V> BTreeMap<K, V> {
935935
/// Retains only the elements specified by the predicate.
936936
///
937937
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
938+
/// The elements are visited in ascending key order.
938939
///
939940
/// # Examples
940941
///

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

+1
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,7 @@ impl<T> BTreeSet<T> {
846846
/// Retains only the elements specified by the predicate.
847847
///
848848
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
849+
/// The elements are visited in ascending order.
849850
///
850851
/// # Examples
851852
///

library/alloc/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
//! [`Rc`]: rc
5757
//! [`RefCell`]: core::cell
5858
59+
// To run liballoc tests without x.py without ending up with two copies of liballoc, Miri needs to be
60+
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
61+
// rustc itself never sets the feature, so this line has no affect there.
62+
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
5963
#![allow(unused_attributes)]
6064
#![stable(feature = "alloc", since = "1.36.0")]
6165
#![doc(

library/core/src/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
//
5050
// This cfg won't affect doc tests.
5151
#![cfg(not(test))]
52+
// To run libcore tests without x.py without ending up with two copies of libcore, Miri needs to be
53+
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
54+
// rustc itself never sets the feature, so this line has no affect there.
55+
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
5256
#![stable(feature = "core", since = "1.6.0")]
5357
#![doc(
5458
html_playground_url = "https://play.rust-lang.org/",

library/std/src/collections/hash/map.rs

+1
Original file line numberDiff line numberDiff line change
@@ -934,6 +934,7 @@ where
934934
/// Retains only the elements specified by the predicate.
935935
///
936936
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
937+
/// The elements are visited in unsorted (and unspecified) order.
937938
///
938939
/// # Examples
939940
///

library/std/src/collections/hash/set.rs

+1
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ where
912912
/// Retains only the elements specified by the predicate.
913913
///
914914
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
915+
/// The elements are visited in unsorted (and unspecified) order.
915916
///
916917
/// # Examples
917918
///

library/std/src/io/buffered/bufwriter.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::ptr;
6868
/// [`flush`]: BufWriter::flush
6969
#[stable(feature = "rust1", since = "1.0.0")]
7070
pub struct BufWriter<W: Write> {
71-
inner: Option<W>,
71+
inner: W,
7272
// The buffer. Avoid using this like a normal `Vec` in common code paths.
7373
// That is, don't use `buf.push`, `buf.extend_from_slice`, or any other
7474
// methods that require bounds checking or the like. This makes an enormous
@@ -112,7 +112,7 @@ impl<W: Write> BufWriter<W> {
112112
/// ```
113113
#[stable(feature = "rust1", since = "1.0.0")]
114114
pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W> {
115-
BufWriter { inner: Some(inner), buf: Vec::with_capacity(capacity), panicked: false }
115+
BufWriter { inner, buf: Vec::with_capacity(capacity), panicked: false }
116116
}
117117

118118
/// Send data in our local buffer into the inner writer, looping as
@@ -161,10 +161,9 @@ impl<W: Write> BufWriter<W> {
161161
}
162162

163163
let mut guard = BufGuard::new(&mut self.buf);
164-
let inner = self.inner.as_mut().unwrap();
165164
while !guard.done() {
166165
self.panicked = true;
167-
let r = inner.write(guard.remaining());
166+
let r = self.inner.write(guard.remaining());
168167
self.panicked = false;
169168

170169
match r {
@@ -212,7 +211,7 @@ impl<W: Write> BufWriter<W> {
212211
/// ```
213212
#[stable(feature = "rust1", since = "1.0.0")]
214213
pub fn get_ref(&self) -> &W {
215-
self.inner.as_ref().unwrap()
214+
&self.inner
216215
}
217216

218217
/// Gets a mutable reference to the underlying writer.
@@ -232,7 +231,7 @@ impl<W: Write> BufWriter<W> {
232231
/// ```
233232
#[stable(feature = "rust1", since = "1.0.0")]
234233
pub fn get_mut(&mut self) -> &mut W {
235-
self.inner.as_mut().unwrap()
234+
&mut self.inner
236235
}
237236

238237
/// Returns a reference to the internally buffered data.
@@ -308,7 +307,7 @@ impl<W: Write> BufWriter<W> {
308307
pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> {
309308
match self.flush_buf() {
310309
Err(e) => Err(IntoInnerError::new(self, e)),
311-
Ok(()) => Ok(self.inner.take().unwrap()),
310+
Ok(()) => Ok(self.into_raw_parts().0),
312311
}
313312
}
314313

@@ -339,7 +338,12 @@ impl<W: Write> BufWriter<W> {
339338
pub fn into_raw_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
340339
let buf = mem::take(&mut self.buf);
341340
let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };
342-
(self.inner.take().unwrap(), buf)
341+
342+
// SAFETY: forget(self) prevents double dropping inner
343+
let inner = unsafe { ptr::read(&mut self.inner) };
344+
mem::forget(self);
345+
346+
(inner, buf)
343347
}
344348

345349
// Ensure this function does not get inlined into `write`, so that it
@@ -643,7 +647,7 @@ where
643647
{
644648
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
645649
fmt.debug_struct("BufWriter")
646-
.field("writer", &self.inner.as_ref().unwrap())
650+
.field("writer", &self.inner)
647651
.field("buffer", &format_args!("{}/{}", self.buf.len(), self.buf.capacity()))
648652
.finish()
649653
}
@@ -663,7 +667,7 @@ impl<W: Write + Seek> Seek for BufWriter<W> {
663667
#[stable(feature = "rust1", since = "1.0.0")]
664668
impl<W: Write> Drop for BufWriter<W> {
665669
fn drop(&mut self) {
666-
if self.inner.is_some() && !self.panicked {
670+
if !self.panicked {
667671
// dtors should not panic, so we ignore a failed flush
668672
let _r = self.flush_buf();
669673
}

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ impl<W> IntoInnerError<W> {
133133
///
134134
/// # Example
135135
/// ```
136-
/// #![feature(io_into_inner_error_parts)]
137136
/// use std::io::{BufWriter, ErrorKind, Write};
138137
///
139138
/// let mut not_enough_space = [0u8; 10];
@@ -143,7 +142,7 @@ impl<W> IntoInnerError<W> {
143142
/// let err = into_inner_err.into_error();
144143
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
145144
/// ```
146-
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
145+
#[stable(feature = "io_into_inner_error_parts", since = "1.55.0")]
147146
pub fn into_error(self) -> Error {
148147
self.1
149148
}
@@ -156,7 +155,6 @@ impl<W> IntoInnerError<W> {
156155
///
157156
/// # Example
158157
/// ```
159-
/// #![feature(io_into_inner_error_parts)]
160158
/// use std::io::{BufWriter, ErrorKind, Write};
161159
///
162160
/// let mut not_enough_space = [0u8; 10];
@@ -167,7 +165,7 @@ impl<W> IntoInnerError<W> {
167165
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
168166
/// assert_eq!(recovered_writer.buffer(), b"t be actually written");
169167
/// ```
170-
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
168+
#[stable(feature = "io_into_inner_error_parts", since = "1.55.0")]
171169
pub fn into_parts(self) -> (Error, W) {
172170
(self.1, self.0)
173171
}

src/bootstrap/compile.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//!
44
//! This module contains some of the real meat in the rustbuild build system
55
//! which is where Cargo is used to compile the standard library, libtest, and
6-
//! compiler. This module is also responsible for assembling the sysroot as it
6+
//! the compiler. This module is also responsible for assembling the sysroot as it
77
//! goes along from the output of the previous stage.
88
99
use std::borrow::Cow;

0 commit comments

Comments
 (0)