Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 14 pull requests #87413

Merged
merged 32 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2dd69aa
Document iteration order of `retain` functions
janikrabe Jul 1, 2021
803f79d
Stabilize `into_parts()` and `into_error()`
inquisitivecrystal Jul 15, 2021
3c384ce
Fix panics on Windows when the build was cancelled
waterlens Jul 16, 2021
15a2e48
Package LLVM libs for the target rather than the build host
adamgemmell Jul 12, 2021
24254d6
Fix download-ci-llvm help comment
adamgemmell Jul 14, 2021
6cba798
better support for running libcore and liballoc tests with Miri
RalfJung Jul 18, 2021
7df0327
add testcase for 87076
hellow554 Jul 19, 2021
05217d5
move const-generic issues into seperate directory
hellow554 Jul 19, 2021
f63c805
add --codegen-backends=foo,bar ./configure flag
pietroalbini Jul 19, 2021
a02756c
Fix `--dry-run` when download-ci-llvm is set
jyn514 Jul 22, 2021
6194cc8
Don't default to `submodules = true` unless the rust repo has a .git …
jyn514 Jul 22, 2021
8837bf1
Remove Option from BufWriter
Alexendoo Jul 15, 2021
831ac19
Squash all commits.
chazkiker2 Jul 20, 2021
327eef9
Add test for fonts used for module items
GuillaumeGomez Jul 23, 2021
d714107
Add VecMap::get_value_matching and assert if > 1 element
spastorino Jun 17, 2021
c79df85
Add ConstraintLocator docs
spastorino Jul 22, 2021
97721a1
Add missing article
wooster0 Jul 23, 2021
a1518f0
update clippy ui test 'future_not_send.stderr' to match
chazkiker2 Jul 23, 2021
d453290
Rollup merge of #86410 - spastorino:get_value_matching, r=oli-obk
JohnTitor Jul 23, 2021
249a11f
Rollup merge of #86790 - janikrabe:retain-iter-order-doc, r=m-ou-se
JohnTitor Jul 23, 2021
2038fa5
Rollup merge of #87171 - Alexendoo:bufwriter-option, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
f335bca
Rollup merge of #87175 - inquisitivecrystal:inner-error, r=kennytm
JohnTitor Jul 23, 2021
ba869da
Rollup merge of #87185 - waterlens:issue-86499-fix, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
aca83f1
Rollup merge of #87191 - adamgemmell:dev/llvm-lib-package, r=Mark-Sim…
JohnTitor Jul 23, 2021
1a2b90b
Rollup merge of #87255 - RalfJung:miri-test-libcore, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
8b89c32
Rollup merge of #87266 - hellow554:issue87076, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
82a14e5
Rollup merge of #87283 - pietroalbini:configure-codegen-backends, r=M…
JohnTitor Jul 23, 2021
3fc79fd
Rollup merge of #87322 - chazkiker2:fix/suggestion-ref-sync-send, r=e…
JohnTitor Jul 23, 2021
1b9cd8b
Rollup merge of #87358 - jyn514:dry-run, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
f709999
Rollup merge of #87380 - jyn514:smarter-submodule-defaults, r=Mark-Si…
JohnTitor Jul 23, 2021
57ea2d8
Rollup merge of #87398 - GuillaumeGomez:test-font-module-items, r=not…
JohnTitor Jul 23, 2021
a651581
Rollup merge of #87412 - r00ster91:patch-13, r=Mark-Simulacrum
JohnTitor Jul 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions compiler/rustc_data_structures/src/vec_map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::borrow::Borrow;
use std::fmt::Debug;
use std::iter::FromIterator;
use std::slice::Iter;
use std::vec::IntoIter;
Expand All @@ -12,7 +13,8 @@ pub struct VecMap<K, V>(Vec<(K, V)>);

impl<K, V> VecMap<K, V>
where
K: PartialEq,
K: Debug + PartialEq,
V: Debug,
{
pub fn new() -> Self {
VecMap(Default::default())
Expand All @@ -37,14 +39,31 @@ where
self.0.iter().find(|(key, _)| k == key.borrow()).map(|elem| &elem.1)
}

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

/// Returns the value corresponding to the supplied predicate filter. It crashes if there's
/// more than one matching element.
///
/// The supplied predicate will be applied to each (key, value) pair and it will return a
/// reference to the value where the predicate returns `true`.
pub fn get_value_matching(&self, mut predicate: impl FnMut(&(K, V)) -> bool) -> Option<&V> {
let mut filter = self.0.iter().filter(|kv| predicate(kv));
let (_, value) = filter.next()?;
// This should return just one element, otherwise it's a bug
assert!(
filter.next().is_none(),
"Collection {:?} should have just one matching element",
self
);
Some(value)
}

/// Returns `true` if the map contains a value for the specified key.
///
/// The key may be any borrowed form of the map's key type,
Expand Down Expand Up @@ -131,7 +150,7 @@ impl<K, V> IntoIterator for VecMap<K, V> {
}
}

impl<K: PartialEq, V> Extend<(K, V)> for VecMap<K, V> {
impl<K: PartialEq + Debug, V: Debug> Extend<(K, V)> for VecMap<K, V> {
fn extend<I: IntoIterator<Item = (K, V)>>(&mut self, iter: I) {
for (k, v) in iter {
self.insert(k, v);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1857,12 +1857,37 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}
}
GeneratorInteriorOrUpvar::Upvar(upvar_span) => {
// `Some(ref_ty)` if `target_ty` is `&T` and `T` fails to impl `Sync`
let refers_to_non_sync = match target_ty.kind() {
ty::Ref(_, ref_ty, _) => match self.evaluate_obligation(&obligation) {
Ok(eval) if !eval.may_apply() => Some(ref_ty),
_ => None,
},
_ => None,
};

let (span_label, span_note) = match refers_to_non_sync {
// if `target_ty` is `&T` and `T` fails to impl `Sync`,
// include suggestions to make `T: Sync` so that `&T: Send`
Some(ref_ty) => (
format!(
"has type `{}` which {}, because `{}` is not `Sync`",
target_ty, trait_explanation, ref_ty
),
format!(
"captured value {} because `&` references cannot be sent unless their referent is `Sync`",
trait_explanation
),
),
None => (
format!("has type `{}` which {}", target_ty, trait_explanation),
format!("captured value {}", trait_explanation),
),
};

let mut span = MultiSpan::from_span(upvar_span);
span.push_span_label(
upvar_span,
format!("has type `{}` which {}", target_ty, trait_explanation),
);
err.span_note(span, &format!("captured value {}", trait_explanation));
span.push_span_label(upvar_span, span_label);
err.span_note(span, &span_note);
}
}

Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_typeck/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
let concrete_ty = tcx
.mir_borrowck(owner.expect_local())
.concrete_opaque_types
.get_by(|(key, _)| key.def_id == def_id.to_def_id())
.get_value_matching(|(key, _)| key.def_id == def_id.to_def_id())
.map(|concrete_ty| *concrete_ty)
.unwrap_or_else(|| {
tcx.sess.delay_span_bug(
Expand Down Expand Up @@ -512,8 +512,15 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {

struct ConstraintLocator<'tcx> {
tcx: TyCtxt<'tcx>,

/// def_id of the opaque type whose defining uses are being checked
def_id: DefId,
// (first found type span, actual type)

/// as we walk the defining uses, we are checking that all of them
/// define the same hidden type. This variable is set to `Some`
/// with the first type that we find, and then later types are
/// checked against it (we also carry the span of that first
/// type).
found: Option<(Span, Ty<'tcx>)>,
}

Expand All @@ -531,7 +538,7 @@ fn find_opaque_ty_constraints(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Ty<'_> {
.tcx
.typeck(def_id)
.concrete_opaque_types
.get_by(|(key, _)| key.def_id == self.def_id)
.any_value_matching(|(key, _)| key.def_id == self.def_id)
.is_none()
{
debug!("no constraints in typeck results");
Expand Down
2 changes: 1 addition & 1 deletion config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ changelog-seen = 2
# This is false by default so that distributions don't unexpectedly download
# LLVM from the internet.
#
# All tier 1 targets are currently supported; set this to `"if-supported"` if
# All tier 1 targets are currently supported; set this to `"if-available"` if
# you are not sure whether you're on a tier 1 target.
#
# We also currently only support this when building LLVM for the build triple.
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/btree/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,7 @@ impl<K, V> BTreeMap<K, V> {
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
/// The elements are visited in ascending key order.
///
/// # Examples
///
Expand Down
1 change: 1 addition & 0 deletions library/alloc/src/collections/btree/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ impl<T> BTreeSet<T> {
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
/// The elements are visited in ascending order.
///
/// # Examples
///
Expand Down
4 changes: 4 additions & 0 deletions library/alloc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
//! [`Rc`]: rc
//! [`RefCell`]: core::cell

// To run liballoc tests without x.py without ending up with two copies of liballoc, Miri needs to be
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
// rustc itself never sets the feature, so this line has no affect there.
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
#![allow(unused_attributes)]
#![stable(feature = "alloc", since = "1.36.0")]
#![doc(
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
//
// This cfg won't affect doc tests.
#![cfg(not(test))]
// To run libcore tests without x.py without ending up with two copies of libcore, Miri needs to be
// able to "empty" this crate. See <https://github.com/rust-lang/miri-test-libstd/issues/4>.
// rustc itself never sets the feature, so this line has no affect there.
#![cfg(any(not(feature = "miri-test-libstd"), test, doctest))]
#![stable(feature = "core", since = "1.6.0")]
#![doc(
html_playground_url = "https://play.rust-lang.org/",
Expand Down
1 change: 1 addition & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ where
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)` returns `false`.
/// The elements are visited in unsorted (and unspecified) order.
///
/// # Examples
///
Expand Down
1 change: 1 addition & 0 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -912,6 +912,7 @@ where
/// Retains only the elements specified by the predicate.
///
/// In other words, remove all elements `e` such that `f(&e)` returns `false`.
/// The elements are visited in unsorted (and unspecified) order.
///
/// # Examples
///
Expand Down
24 changes: 14 additions & 10 deletions library/std/src/io/buffered/bufwriter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ use crate::ptr;
/// [`flush`]: BufWriter::flush
#[stable(feature = "rust1", since = "1.0.0")]
pub struct BufWriter<W: Write> {
inner: Option<W>,
inner: W,
// The buffer. Avoid using this like a normal `Vec` in common code paths.
// That is, don't use `buf.push`, `buf.extend_from_slice`, or any other
// methods that require bounds checking or the like. This makes an enormous
Expand Down Expand Up @@ -112,7 +112,7 @@ impl<W: Write> BufWriter<W> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W> {
BufWriter { inner: Some(inner), buf: Vec::with_capacity(capacity), panicked: false }
BufWriter { inner, buf: Vec::with_capacity(capacity), panicked: false }
}

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

let mut guard = BufGuard::new(&mut self.buf);
let inner = self.inner.as_mut().unwrap();
while !guard.done() {
self.panicked = true;
let r = inner.write(guard.remaining());
let r = self.inner.write(guard.remaining());
self.panicked = false;

match r {
Expand Down Expand Up @@ -212,7 +211,7 @@ impl<W: Write> BufWriter<W> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn get_ref(&self) -> &W {
self.inner.as_ref().unwrap()
&self.inner
}

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

/// Returns a reference to the internally buffered data.
Expand Down Expand Up @@ -308,7 +307,7 @@ impl<W: Write> BufWriter<W> {
pub fn into_inner(mut self) -> Result<W, IntoInnerError<BufWriter<W>>> {
match self.flush_buf() {
Err(e) => Err(IntoInnerError::new(self, e)),
Ok(()) => Ok(self.inner.take().unwrap()),
Ok(()) => Ok(self.into_raw_parts().0),
}
}

Expand Down Expand Up @@ -339,7 +338,12 @@ impl<W: Write> BufWriter<W> {
pub fn into_raw_parts(mut self) -> (W, Result<Vec<u8>, WriterPanicked>) {
let buf = mem::take(&mut self.buf);
let buf = if !self.panicked { Ok(buf) } else { Err(WriterPanicked { buf }) };
(self.inner.take().unwrap(), buf)

// SAFETY: forget(self) prevents double dropping inner
let inner = unsafe { ptr::read(&mut self.inner) };
mem::forget(self);

(inner, buf)
}

// Ensure this function does not get inlined into `write`, so that it
Expand Down Expand Up @@ -643,7 +647,7 @@ where
{
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_struct("BufWriter")
.field("writer", &self.inner.as_ref().unwrap())
.field("writer", &self.inner)
.field("buffer", &format_args!("{}/{}", self.buf.len(), self.buf.capacity()))
.finish()
}
Expand All @@ -663,7 +667,7 @@ impl<W: Write + Seek> Seek for BufWriter<W> {
#[stable(feature = "rust1", since = "1.0.0")]
impl<W: Write> Drop for BufWriter<W> {
fn drop(&mut self) {
if self.inner.is_some() && !self.panicked {
if !self.panicked {
// dtors should not panic, so we ignore a failed flush
let _r = self.flush_buf();
}
Expand Down
6 changes: 2 additions & 4 deletions library/std/src/io/buffered/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ impl<W> IntoInnerError<W> {
///
/// # Example
/// ```
/// #![feature(io_into_inner_error_parts)]
/// use std::io::{BufWriter, ErrorKind, Write};
///
/// let mut not_enough_space = [0u8; 10];
Expand All @@ -143,7 +142,7 @@ impl<W> IntoInnerError<W> {
/// let err = into_inner_err.into_error();
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
/// ```
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
#[stable(feature = "io_into_inner_error_parts", since = "1.55.0")]
pub fn into_error(self) -> Error {
self.1
}
Expand All @@ -156,7 +155,6 @@ impl<W> IntoInnerError<W> {
///
/// # Example
/// ```
/// #![feature(io_into_inner_error_parts)]
/// use std::io::{BufWriter, ErrorKind, Write};
///
/// let mut not_enough_space = [0u8; 10];
Expand All @@ -167,7 +165,7 @@ impl<W> IntoInnerError<W> {
/// assert_eq!(err.kind(), ErrorKind::WriteZero);
/// assert_eq!(recovered_writer.buffer(), b"t be actually written");
/// ```
#[unstable(feature = "io_into_inner_error_parts", issue = "79704")]
#[stable(feature = "io_into_inner_error_parts", since = "1.55.0")]
pub fn into_parts(self) -> (Error, W) {
(self.1, self.0)
}
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//!
//! This module contains some of the real meat in the rustbuild build system
//! which is where Cargo is used to compile the standard library, libtest, and
//! compiler. This module is also responsible for assembling the sysroot as it
//! the compiler. This module is also responsible for assembling the sysroot as it
//! goes along from the output of the previous stage.

use std::borrow::Cow;
Expand Down
Loading