Skip to content

Commit c9b5210

Browse files
committed
Auto merge of rust-lang#78127 - JohnTitor:rollup-p1bxtqq, r=JohnTitor
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`
2 parents a85e949 + 21df410 commit c9b5210

File tree

142 files changed

+334
-188
lines changed

Some content is hidden

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

142 files changed

+334
-188
lines changed

.mailmap

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Ariel Ben-Yehuda <[email protected]> arielb1 <[email protected]>
2929
3030
Aydin Kim <[email protected]> aydin.kim <[email protected]>
3131
Barosl Lee <[email protected]> Barosl LEE <[email protected]>
32-
Bastian Kauschke <[email protected]>
3332
3433
3534
@@ -161,6 +160,7 @@ Kyle J Strand <[email protected]> <[email protected]>
161160
162161
163162
Laurențiu Nicola <[email protected]>
163+
164164
Lee Jeffery <[email protected]> Lee Jeffery <[email protected]>
165165
Lee Wondong <[email protected]>
166166
Lennart Kudling <[email protected]>

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,6 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
9191
if let (None, Some(ty)) =
9292
(self.found_local_pattern, self.node_ty_contains_target(local.hir_id))
9393
{
94-
// FIXME: There's a trade-off here - we can either check that our target span
95-
// is contained in `local.span` or not. If we choose to check containment
96-
// we can avoid some spurious suggestions (see #72690), but we lose
97-
// the ability to report on things like:
98-
//
99-
// ```
100-
// let x = vec![];
101-
// ```
102-
//
103-
// because the target span will be in the macro expansion of `vec![]`.
104-
// At present we choose not to check containment.
10594
self.found_local_pattern = Some(&*local.pat);
10695
self.found_node_ty = Some(ty);
10796
}
@@ -113,10 +102,8 @@ impl<'a, 'tcx> Visitor<'tcx> for FindHirNodeVisitor<'a, 'tcx> {
113102
if let (None, Some(ty)) =
114103
(self.found_arg_pattern, self.node_ty_contains_target(param.hir_id))
115104
{
116-
if self.target_span.contains(param.pat.span) {
117-
self.found_arg_pattern = Some(&*param.pat);
118-
self.found_node_ty = Some(ty);
119-
}
105+
self.found_arg_pattern = Some(&*param.pat);
106+
self.found_node_ty = Some(ty);
120107
}
121108
}
122109
intravisit::walk_body(self, body);

compiler/rustc_lint/src/unused.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -751,13 +751,20 @@ impl UnusedDelimLint for UnusedParens {
751751
if !Self::is_expr_delims_necessary(inner, followed_by_block)
752752
&& value.attrs.is_empty()
753753
&& !value.span.from_expansion()
754+
&& (ctx != UnusedDelimsCtx::LetScrutineeExpr
755+
|| match inner.kind {
756+
ast::ExprKind::Binary(
757+
rustc_span::source_map::Spanned { node, .. },
758+
_,
759+
_,
760+
) if node.lazy() => false,
761+
_ => true,
762+
})
754763
{
755764
self.emit_unused_delims_expr(cx, value, ctx, left_pos, right_pos)
756765
}
757766
}
758767
ast::ExprKind::Let(_, ref expr) => {
759-
// FIXME(#60336): Properly handle `let true = (false && true)`
760-
// actually needing the parenthesis.
761768
self.check_unused_delims_expr(
762769
cx,
763770
expr,

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

+15-15
Original file line numberDiff line numberDiff line change
@@ -1462,9 +1462,8 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14621462
let bound_predicate = predicate.bound_atom();
14631463
let mut err = match bound_predicate.skip_binder() {
14641464
ty::PredicateAtom::Trait(data, _) => {
1465-
let self_ty = data.trait_ref.self_ty();
14661465
let trait_ref = bound_predicate.rebind(data.trait_ref);
1467-
debug!("self_ty {:?} {:?} trait_ref {:?}", self_ty, self_ty.kind(), trait_ref);
1466+
debug!("trait_ref {:?}", trait_ref);
14681467

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

1481+
// Pick the first substitution that still contains inference variables as the one
1482+
// we're going to emit an error for. If there are none (see above), fall back to
1483+
// the substitution for `Self`.
1484+
let subst = {
1485+
let substs = data.trait_ref.substs;
1486+
substs
1487+
.iter()
1488+
.find(|s| s.has_infer_types_or_consts())
1489+
.unwrap_or_else(|| substs[0])
1490+
};
1491+
14821492
// This is kind of a hack: it frequently happens that some earlier
14831493
// error prevents types from being fully inferred, and then we get
14841494
// a bunch of uninteresting errors saying something like "<generic
@@ -1495,21 +1505,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'tcx> for InferCtxt<'a, 'tcx> {
14951505
// check upstream for type errors and don't add the obligations to
14961506
// begin with in those cases.
14971507
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
1498-
self.emit_inference_failure_err(
1499-
body_id,
1500-
span,
1501-
self_ty.into(),
1502-
ErrorCode::E0282,
1503-
)
1504-
.emit();
1508+
self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0282).emit();
15051509
return;
15061510
}
1507-
let mut err = self.emit_inference_failure_err(
1508-
body_id,
1509-
span,
1510-
self_ty.into(),
1511-
ErrorCode::E0283,
1512-
);
1511+
let mut err =
1512+
self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0283);
15131513
err.note(&format!("cannot satisfy `{}`", predicate));
15141514
if let ObligationCauseCode::ItemObligation(def_id) = obligation.cause.code {
15151515
self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id());

compiler/rustc_typeck/src/check/generator_interior.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> {
250250
let mut scope_var_ids =
251251
self.guard_bindings.pop().expect("should have pushed at least one earlier");
252252
for var_id in scope_var_ids.drain(..) {
253-
assert!(
254-
self.guard_bindings_set.remove(&var_id),
255-
"variable should be placed in scope earlier"
256-
);
253+
self.guard_bindings_set.remove(&var_id);
257254
}
258255
}
259256
self.visit_expr(body);

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

+10-79
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::super::{navigate::Position, node, DeterministicRng};
1+
use super::super::{node, DeterministicRng};
22
use super::Entry::{Occupied, Vacant};
33
use super::*;
44
use crate::boxed::Box;
@@ -7,7 +7,7 @@ use crate::rc::Rc;
77
use crate::string::{String, ToString};
88
use crate::vec::Vec;
99
use std::convert::TryFrom;
10-
use std::iter::FromIterator;
10+
use std::iter::{self, FromIterator};
1111
use std::mem;
1212
use std::ops::Bound::{self, Excluded, Included, Unbounded};
1313
use std::ops::RangeBounds;
@@ -42,19 +42,6 @@ fn test_all_refs<'a, T: 'a>(dummy: &mut T, iter: impl Iterator<Item = &'a mut T>
4242
}
4343
}
4444

45-
struct SeriesChecker<T> {
46-
previous: Option<T>,
47-
}
48-
49-
impl<T: Copy + Debug + Ord> SeriesChecker<T> {
50-
fn is_ascending(&mut self, next: T) {
51-
if let Some(previous) = self.previous {
52-
assert!(previous < next, "{:?} >= {:?}", previous, next);
53-
}
54-
self.previous = Some(next);
55-
}
56-
}
57-
5845
impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
5946
/// Panics if the map (or the code navigating it) is corrupted.
6047
fn check(&self)
@@ -63,44 +50,10 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
6350
{
6451
if let Some(root) = &self.root {
6552
let root_node = root.node_as_ref();
66-
let mut checker = SeriesChecker { previous: None };
67-
let mut internal_length = 0;
68-
let mut internal_kv_count = 0;
69-
let mut leaf_length = 0;
70-
root_node.visit_nodes_in_order(|pos| match pos {
71-
Position::Leaf(node) => {
72-
let is_root = root_node.height() == 0;
73-
let min_len = if is_root { 0 } else { node::MIN_LEN };
74-
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
75-
76-
for idx in 0..node.len() {
77-
let key = *unsafe { node.key_at(idx) };
78-
checker.is_ascending(key);
79-
}
80-
leaf_length += node.len();
81-
}
82-
Position::Internal(node) => {
83-
let is_root = root_node.height() == node.height();
84-
let min_len = if is_root { 1 } else { node::MIN_LEN };
85-
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
86-
87-
for idx in 0..=node.len() {
88-
let edge = unsafe { node::Handle::new_edge(node, idx) };
89-
assert!(edge.descend().ascend().ok().unwrap() == edge);
90-
}
91-
92-
internal_length += node.len();
93-
}
94-
Position::InternalKV(kv) => {
95-
let key = *kv.into_kv().0;
96-
checker.is_ascending(key);
97-
98-
internal_kv_count += 1;
99-
}
100-
});
101-
assert_eq!(internal_length, internal_kv_count);
102-
assert_eq!(root_node.calc_length(), internal_length + leaf_length);
103-
assert_eq!(self.length, internal_length + leaf_length);
53+
assert!(root_node.ascend().is_err());
54+
root_node.assert_back_pointers();
55+
root_node.assert_ascending();
56+
assert_eq!(self.length, root_node.assert_and_add_lengths());
10457
} else {
10558
assert_eq!(self.length, 0);
10659
}
@@ -116,28 +69,7 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
11669
K: Debug,
11770
{
11871
if let Some(root) = self.root.as_ref() {
119-
let mut result = String::new();
120-
let root_node = root.node_as_ref();
121-
root_node.visit_nodes_in_order(|pos| match pos {
122-
Position::Leaf(leaf) => {
123-
let depth = root_node.height();
124-
let indent = " ".repeat(depth);
125-
result += &format!("\n{}", indent);
126-
for idx in 0..leaf.len() {
127-
if idx > 0 {
128-
result += ", ";
129-
}
130-
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
131-
}
132-
}
133-
Position::Internal(_) => {}
134-
Position::InternalKV(kv) => {
135-
let depth = root_node.height() - kv.into_node().height();
136-
let indent = " ".repeat(depth);
137-
result += &format!("\n{}{:?}", indent, kv.into_kv().0);
138-
}
139-
});
140-
result
72+
root.node_as_ref().dump_keys()
14173
} else {
14274
String::from("not yet allocated")
14375
}
@@ -170,7 +102,6 @@ fn test_levels() {
170102
let last_key = *map.last_key_value().unwrap().0;
171103
map.insert(last_key + 1, ());
172104
}
173-
println!("{}", map.dump_keys());
174105
map.check();
175106
// Structure:
176107
// - 1 element in internal root node with 2 children
@@ -372,7 +303,7 @@ fn test_iter_rev() {
372303
fn do_test_iter_mut_mutation<T>(size: usize)
373304
where
374305
T: Copy + Debug + Ord + TryFrom<usize>,
375-
<T as std::convert::TryFrom<usize>>::Error: std::fmt::Debug,
306+
<T as TryFrom<usize>>::Error: Debug,
376307
{
377308
let zero = T::try_from(0).unwrap();
378309
let mut map: BTreeMap<T, T> = (0..size).map(|i| (T::try_from(i).unwrap(), zero)).collect();
@@ -857,7 +788,7 @@ mod test_drain_filter {
857788
fn consuming_nothing() {
858789
let pairs = (0..3).map(|i| (i, i));
859790
let mut map: BTreeMap<_, _> = pairs.collect();
860-
assert!(map.drain_filter(|_, _| false).eq(std::iter::empty()));
791+
assert!(map.drain_filter(|_, _| false).eq(iter::empty()));
861792
map.check();
862793
}
863794

@@ -878,7 +809,7 @@ mod test_drain_filter {
878809
*v += 6;
879810
false
880811
})
881-
.eq(std::iter::empty())
812+
.eq(iter::empty())
882813
);
883814
assert!(map.keys().copied().eq(0..3));
884815
assert!(map.values().copied().eq(6..9));

library/alloc/src/collections/btree/node/tests.rs

+105
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,111 @@
1+
use super::super::navigate;
12
use super::*;
3+
use crate::fmt::Debug;
4+
use crate::string::String;
25
use core::cmp::Ordering::*;
36

7+
impl<'a, K: 'a, V: 'a> NodeRef<marker::Immut<'a>, K, V, marker::LeafOrInternal> {
8+
pub fn assert_back_pointers(self) {
9+
match self.force() {
10+
ForceResult::Leaf(_) => {}
11+
ForceResult::Internal(node) => {
12+
for idx in 0..=node.len() {
13+
let edge = unsafe { Handle::new_edge(node, idx) };
14+
let child = edge.descend();
15+
assert!(child.ascend().ok() == Some(edge));
16+
child.assert_back_pointers();
17+
}
18+
}
19+
}
20+
}
21+
22+
pub fn assert_ascending(self)
23+
where
24+
K: Copy + Debug + Ord,
25+
{
26+
struct SeriesChecker<T> {
27+
previous: Option<T>,
28+
}
29+
impl<T: Copy + Debug + Ord> SeriesChecker<T> {
30+
fn is_ascending(&mut self, next: T) {
31+
if let Some(previous) = self.previous {
32+
assert!(previous < next, "{:?} >= {:?}", previous, next);
33+
}
34+
self.previous = Some(next);
35+
}
36+
}
37+
38+
let mut checker = SeriesChecker { previous: None };
39+
self.visit_nodes_in_order(|pos| match pos {
40+
navigate::Position::Leaf(node) => {
41+
for idx in 0..node.len() {
42+
let key = *unsafe { node.key_at(idx) };
43+
checker.is_ascending(key);
44+
}
45+
}
46+
navigate::Position::InternalKV(kv) => {
47+
let key = *kv.into_kv().0;
48+
checker.is_ascending(key);
49+
}
50+
navigate::Position::Internal(_) => {}
51+
});
52+
}
53+
54+
pub fn assert_and_add_lengths(self) -> usize {
55+
let mut internal_length = 0;
56+
let mut internal_kv_count = 0;
57+
let mut leaf_length = 0;
58+
self.visit_nodes_in_order(|pos| match pos {
59+
navigate::Position::Leaf(node) => {
60+
let is_root = self.height() == 0;
61+
let min_len = if is_root { 0 } else { MIN_LEN };
62+
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
63+
leaf_length += node.len();
64+
}
65+
navigate::Position::Internal(node) => {
66+
let is_root = self.height() == node.height();
67+
let min_len = if is_root { 1 } else { MIN_LEN };
68+
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
69+
internal_length += node.len();
70+
}
71+
navigate::Position::InternalKV(_) => {
72+
internal_kv_count += 1;
73+
}
74+
});
75+
assert_eq!(internal_length, internal_kv_count);
76+
let total = internal_length + leaf_length;
77+
assert_eq!(self.calc_length(), total);
78+
total
79+
}
80+
81+
pub fn dump_keys(self) -> String
82+
where
83+
K: Debug,
84+
{
85+
let mut result = String::new();
86+
self.visit_nodes_in_order(|pos| match pos {
87+
navigate::Position::Leaf(leaf) => {
88+
let depth = self.height();
89+
let indent = " ".repeat(depth);
90+
result += &format!("\n{}", indent);
91+
for idx in 0..leaf.len() {
92+
if idx > 0 {
93+
result += ", ";
94+
}
95+
result += &format!("{:?}", unsafe { leaf.key_at(idx) });
96+
}
97+
}
98+
navigate::Position::Internal(_) => {}
99+
navigate::Position::InternalKV(kv) => {
100+
let depth = self.height() - kv.into_node().height();
101+
let indent = " ".repeat(depth);
102+
result += &format!("\n{}{:?}", indent, kv.into_kv().0);
103+
}
104+
});
105+
result
106+
}
107+
}
108+
4109
#[test]
5110
fn test_splitpoint() {
6111
for idx in 0..=CAPACITY {

0 commit comments

Comments
 (0)