Skip to content

Commit

Permalink
Auto merge of rust-lang#78127 - JohnTitor:rollup-p1bxtqq, r=JohnTitor
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#77612 (BTreeMap: test invariants more thoroughly and more readably)
 - rust-lang#77761 (Assert that pthread mutex initialization succeeded)
 - rust-lang#77778 ([x.py setup] Allow setting up git hooks from other worktrees)
 - rust-lang#77838 (const keyword: brief paragraph on 'const fn')
 - rust-lang#77923 ([net] apply clippy lints)
 - rust-lang#77931 (Fix false positive for `unused_parens` lint)
 - rust-lang#77959 (Tweak ui-tests structure)
 - rust-lang#78105 (change name in .mailmap)
 - rust-lang#78111 (Trait predicate ambiguities are not always in `Self`)
 - rust-lang#78121 (Do not ICE on pattern that uses a binding multiple times in generator)

Failed merges:

r? `@ghost`
  • Loading branch information
bors committed Oct 20, 2020
2 parents a85e949 + 21df410 commit c9b5210
Show file tree
Hide file tree
Showing 142 changed files with 334 additions and 188 deletions.
2 changes: 1 addition & 1 deletion .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Ariel Ben-Yehuda <arielb1@mail.tau.ac.il> arielb1 <arielb1@mail.tau.ac.il>
Austin Seipp <mad.one@gmail.com> <as@hacks.yi.org>
Aydin Kim <ladinjin@hanmail.net> aydin.kim <aydin.kim@samsung.com>
Barosl Lee <vcs@barosl.com> Barosl LEE <github@barosl.com>
Bastian Kauschke <bastian_kauschke@hotmail.de>
Ben Alpert <ben@benalpert.com> <spicyjalapeno@gmail.com>
Ben Sago <ogham@users.noreply.github.com> Ben S <ogham@bsago.me>
Ben Sago <ogham@users.noreply.github.com> Ben S <ogham@users.noreply.github.com>
Expand Down Expand Up @@ -161,6 +160,7 @@ Kyle J Strand <batmanaod@gmail.com> <kyle.j.strand@gmail.com>
Kyle J Strand <batmanaod@gmail.com> <kyle.strand@pieinsurance.com>
Kyle J Strand <batmanaod@gmail.com> <kyle.strand@rms.com>
Laurențiu Nicola <lnicola@dend.ro>
lcnr <bastian_kauschke@hotmail.de>
Lee Jeffery <leejeffery@gmail.com> Lee Jeffery <lee@leejeffery.co.uk>
Lee Wondong <wdlee91@gmail.com>
Lennart Kudling <github@kudling.de>
Expand Down
17 changes: 2 additions & 15 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,6 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
if let (None, Some(ty)) =
(self.found_local_pattern, self.node_ty_contains_target(local.hir_id))
{
// FIXME: There's a trade-off here - we can either check that our target span
// is contained in `local.span` or not. If we choose to check containment
// we can avoid some spurious suggestions (see #72690), but we lose
// the ability to report on things like:
//
// ```
// let x = vec![];
// ```
//
// because the target span will be in the macro expansion of `vec![]`.
// At present we choose not to check containment.
self.found_local_pattern = Some(&*local.pat);
self.found_node_ty = Some(ty);
}
Expand All @@ -113,10 +102,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
if let (None, Some(ty)) =
(self.found_arg_pattern, self.node_ty_contains_target(param.hir_id))
{
if self.target_span.contains(param.pat.span) {
self.found_arg_pattern = Some(&*param.pat);
self.found_node_ty = Some(ty);
}
self.found_arg_pattern = Some(&*param.pat);
self.found_node_ty = Some(ty);
}
}
intravisit::walk_body(self, body);
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,13 +751,20 @@ impl UnusedDelimLint for UnusedParens {
if !Self::is_expr_delims_necessary(inner, followed_by_block)
&& value.attrs.is_empty()
&& !value.span.from_expansion()
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
|| match inner.kind {
ast::ExprKind::Binary(
rustc_span::source_map::Spanned { node, .. },
_,
_,
) if node.lazy() => false,
_ => true,
})
{
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
}
}
ast::ExprKind::Let(_, ref expr) => {
// FIXME(#60336): Properly handle `let true = (false && true)`
// actually needing the parenthesis.
self.check_unused_delims_expr(
cx,
expr,
Expand Down
30 changes: 15 additions & 15 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1462,9 +1462,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
let bound_predicate = predicate.bound_atom();
let mut err = match bound_predicate.skip_binder() {
ty::PredicateAtom::Trait(data, _) => {
let self_ty = data.trait_ref.self_ty();
let trait_ref = bound_predicate.rebind(data.trait_ref);
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind(), trait_ref);
debug!("trait_ref {:?}", trait_ref);

if predicate.references_error() {
return;
Expand All @@ -1479,6 +1478,17 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
// known, since we don't dispatch based on region
// relationships.

// Pick the first substitution that still contains inference variables as the one
// we're going to emit an error for. If there are none (see above), fall back to
// the substitution for `Self`.
let subst = {
let substs = data.trait_ref.substs;
substs
.iter()
.find(|s| s.has_infer_types_or_consts())
.unwrap_or_else(|| substs[0])
};

// This is kind of a hack: it frequently happens that some earlier
// error prevents types from being fully inferred, and then we get
// a bunch of uninteresting errors saying something like "<generic
Expand All @@ -1495,21 +1505,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
// check upstream for type errors and don't add the obligations to
// begin with in those cases.
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
self.emit_inference_failure_err(
body_id,
span,
self_ty.into(),
ErrorCode::E0282,
)
.emit();
self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0282).emit();
return;
}
let mut err = self.emit_inference_failure_err(
body_id,
span,
self_ty.into(),
ErrorCode::E0283,
);
let mut err =
self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0283);
err.note(&format!("cannot satisfy `{}`", predicate));
if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_typeck/src/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
let mut scope_var_ids =
self.guard_bindings.pop().expect("should have pushed at least one earlier");
for var_id in scope_var_ids.drain(..) {
assert!(
self.guard_bindings_set.remove(&var_id),
"variable should be placed in scope earlier"
);
self.guard_bindings_set.remove(&var_id);
}
}
self.visit_expr(body);
Expand Down
89 changes: 10 additions & 79 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::super::{navigate::Position, node, DeterministicRng};
use super::super::{node, DeterministicRng};
use super::Entry::{Occupied, Vacant};
use super::*;
use crate::boxed::Box;
Expand All @@ -7,7 +7,7 @@ use crate::rc::Rc;
use crate::string::{String, ToString};
use crate::vec::Vec;
use std::convert::TryFrom;
use std::iter::FromIterator;
use std::iter::{self, FromIterator};
use std::mem;
use std::ops::Bound::{self, Excluded, Included, Unbounded};
use std::ops::RangeBounds;
Expand Down Expand Up @@ -42,19 +42,6 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
}
}

struct SeriesChecker<T> {
previous: Option<T>,
}

impl<T: Copy + Debug + Ord> SeriesChecker<T> {
fn is_ascending(&mut self, next: T) {
if let Some(previous) = self.previous {
assert!(previous < next, "{:?} >= {:?}", previous, next);
}
self.previous = Some(next);
}
}

impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
/// Panics if the map (or the code navigating it) is corrupted.
fn check(&self)
Expand All @@ -63,44 +50,10 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
{
if let Some(root) = &self.root {
let root_node = root.node_as_ref();
let mut checker = SeriesChecker { previous: None };
let mut internal_length = 0;
let mut internal_kv_count = 0;
let mut leaf_length = 0;
root_node.visit_nodes_in_order(|pos| match pos {
Position::Leaf(node) => {
let is_root = root_node.height() == 0;
let min_len = if is_root { 0 } else { node::MIN_LEN };
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);

for idx in 0..node.len() {
let key = *unsafe { node.key_at(idx) };
checker.is_ascending(key);
}
leaf_length += node.len();
}
Position::Internal(node) => {
let is_root = root_node.height() == node.height();
let min_len = if is_root { 1 } else { node::MIN_LEN };
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);

for idx in 0..=node.len() {
let edge = unsafe { node::Handle::new_edge(node, idx) };
assert!(edge.descend().ascend().ok().unwrap() == edge);
}

internal_length += node.len();
}
Position::InternalKV(kv) => {
let key = *kv.into_kv().0;
checker.is_ascending(key);

internal_kv_count += 1;
}
});
assert_eq!(internal_length, internal_kv_count);
assert_eq!(root_node.calc_length(), internal_length + leaf_length);
assert_eq!(self.length, internal_length + leaf_length);
assert!(root_node.ascend().is_err());
root_node.assert_back_pointers();
root_node.assert_ascending();
assert_eq!(self.length, root_node.assert_and_add_lengths());
} else {
assert_eq!(self.length, 0);
}
Expand All @@ -116,28 +69,7 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
K: Debug,
{
if let Some(root) = self.root.as_ref() {
let mut result = String::new();
let root_node = root.node_as_ref();
root_node.visit_nodes_in_order(|pos| match pos {
Position::Leaf(leaf) => {
let depth = root_node.height();
let indent = " ".repeat(depth);
result += &format!("\n{}", indent);
for idx in 0..leaf.len() {
if idx > 0 {
result += ", ";
}
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
}
}
Position::Internal(_) => {}
Position::InternalKV(kv) => {
let depth = root_node.height() - kv.into_node().height();
let indent = " ".repeat(depth);
result += &format!("\n{}{:?}", indent, kv.into_kv().0);
}
});
result
root.node_as_ref().dump_keys()
} else {
String::from("not yet allocated")
}
Expand Down Expand Up @@ -170,7 +102,6 @@ fn test_levels() {
let last_key = *map.last_key_value().unwrap().0;
map.insert(last_key + 1, ());
}
println!("{}", map.dump_keys());
map.check();
// Structure:
// - 1 element in internal root node with 2 children
Expand Down Expand Up @@ -372,7 +303,7 @@ fn test_iter_rev() {
fn do_test_iter_mut_mutation<T>(size: usize)
where
T: Copy + Debug + Ord + TryFrom<usize>,
<T as std::convert::TryFrom<usize>>::Error: std::fmt::Debug,
<T as TryFrom<usize>>::Error: Debug,
{
let zero = T::try_from(0).unwrap();
let mut map: BTreeMap<T, T> = (0..size).map(|i| (T::try_from(i).unwrap(), zero)).collect();
Expand Down Expand Up @@ -857,7 +788,7 @@ mod test_drain_filter {
fn consuming_nothing() {
let pairs = (0..3).map(|i| (i, i));
let mut map: BTreeMap<_, _> = pairs.collect();
assert!(map.drain_filter(|_, _| false).eq(std::iter::empty()));
assert!(map.drain_filter(|_, _| false).eq(iter::empty()));
map.check();
}

Expand All @@ -878,7 +809,7 @@ mod test_drain_filter {
*v += 6;
false
})
.eq(std::iter::empty())
.eq(iter::empty())
);
assert!(map.keys().copied().eq(0..3));
assert!(map.values().copied().eq(6..9));
Expand Down
105 changes: 105 additions & 0 deletions library/alloc/src/collections/btree/node/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,111 @@
use super::super::navigate;
use super::*;
use crate::fmt::Debug;
use crate::string::String;
use core::cmp::Ordering::*;

impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
pub fn assert_back_pointers(self) {
match self.force() {
ForceResult::Leaf(_) => {}
ForceResult::Internal(node) => {
for idx in 0..=node.len() {
let edge = unsafe { Handle::new_edge(node, idx) };
let child = edge.descend();
assert!(child.ascend().ok() == Some(edge));
child.assert_back_pointers();
}
}
}
}

pub fn assert_ascending(self)
where
K: Copy + Debug + Ord,
{
struct SeriesChecker<T> {
previous: Option<T>,
}
impl<T: Copy + Debug + Ord> SeriesChecker<T> {
fn is_ascending(&mut self, next: T) {
if let Some(previous) = self.previous {
assert!(previous < next, "{:?} >= {:?}", previous, next);
}
self.previous = Some(next);
}
}

let mut checker = SeriesChecker { previous: None };
self.visit_nodes_in_order(|pos| match pos {
navigate::Position::Leaf(node) => {
for idx in 0..node.len() {
let key = *unsafe { node.key_at(idx) };
checker.is_ascending(key);
}
}
navigate::Position::InternalKV(kv) => {
let key = *kv.into_kv().0;
checker.is_ascending(key);
}
navigate::Position::Internal(_) => {}
});
}

pub fn assert_and_add_lengths(self) -> usize {
let mut internal_length = 0;
let mut internal_kv_count = 0;
let mut leaf_length = 0;
self.visit_nodes_in_order(|pos| match pos {
navigate::Position::Leaf(node) => {
let is_root = self.height() == 0;
let min_len = if is_root { 0 } else { MIN_LEN };
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
leaf_length += node.len();
}
navigate::Position::Internal(node) => {
let is_root = self.height() == node.height();
let min_len = if is_root { 1 } else { MIN_LEN };
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
internal_length += node.len();
}
navigate::Position::InternalKV(_) => {
internal_kv_count += 1;
}
});
assert_eq!(internal_length, internal_kv_count);
let total = internal_length + leaf_length;
assert_eq!(self.calc_length(), total);
total
}

pub fn dump_keys(self) -> String
where
K: Debug,
{
let mut result = String::new();
self.visit_nodes_in_order(|pos| match pos {
navigate::Position::Leaf(leaf) => {
let depth = self.height();
let indent = " ".repeat(depth);
result += &format!("\n{}", indent);
for idx in 0..leaf.len() {
if idx > 0 {
result += ", ";
}
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
}
}
navigate::Position::Internal(_) => {}
navigate::Position::InternalKV(kv) => {
let depth = self.height() - kv.into_node().height();
let indent = " ".repeat(depth);
result += &format!("\n{}{:?}", indent, kv.into_kv().0);
}
});
result
}
}

#[test]
fn test_splitpoint() {
for idx in 0..=CAPACITY {
Expand Down
Loading

0 comments on commit c9b5210

Please sign in to comment.