Skip to content

Commit e8aef7c

Browse files
committed
Auto merge of #55502 - kennytm:rollup, r=kennytm
Rollup of 12 pull requests Successful merges: - #54885 (Don't lint 'unused_parens` on `if (break _) { .. }`) - #55205 (Improve a few cases of collecting to an FxHash(Map/Set)) - #55450 (msp430: remove the whole Atomic* API) - #55459 (Add UI test for #49296) - #55472 (Use opt.take() instead of mem::replace(opt, None)) - #55473 (Take advantage of impl Iterator in (transitive/elaborate)_bounds) - #55474 (Fix validation false positive) - #55476 (Change a flat_map with 0/1-element vecs to a filter_map) - #55487 (Adjust Ids of path segments in visibility modifiers) - #55493 (Doc fixes) - #55494 (borrowck=migrate must look at parents of closures) - #55496 (Update clippy) Failed merges: r? @ghost
2 parents b1ca390 + c16ff6e commit e8aef7c

38 files changed

+444
-139
lines changed

src/Cargo.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ dependencies = [
326326
"clippy-mini-macro-test 0.2.0",
327327
"clippy_dev 0.0.1",
328328
"clippy_lints 0.0.212",
329-
"compiletest_rs 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
329+
"compiletest_rs 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
330330
"derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
331331
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
332332
"regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -443,7 +443,7 @@ dependencies = [
443443

444444
[[package]]
445445
name = "compiletest_rs"
446-
version = "0.3.13"
446+
version = "0.3.16"
447447
source = "registry+https://github.com/rust-lang/crates.io-index"
448448
dependencies = [
449449
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -452,6 +452,7 @@ dependencies = [
452452
"libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)",
453453
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
454454
"miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
455+
"regex 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
455456
"serde 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
456457
"serde_derive 1.0.75 (registry+https://github.com/rust-lang/crates.io-index)",
457458
"serde_json 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1289,7 +1290,7 @@ dependencies = [
12891290
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
12901291
"cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
12911292
"colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
1292-
"compiletest_rs 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
1293+
"compiletest_rs 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
12931294
"env_logger 0.5.12 (registry+https://github.com/rust-lang/crates.io-index)",
12941295
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
12951296
"vergen 3.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3202,7 +3203,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
32023203
"checksum colored 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0aa3473e85a3161b59845d6096b289bb577874cafeaf75ea1b1beaa6572c7fc"
32033204
"checksum commoncrypto 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d056a8586ba25a1e4d61cb090900e495952c7886786fc55f909ab2f819b69007"
32043205
"checksum commoncrypto-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2"
3205-
"checksum compiletest_rs 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "d3064bc712922596dd5ab449fca9261d411893356581fe5297b96aa8f53bb1b8"
3206+
"checksum compiletest_rs 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)" = "75e809f56d6aa9575b67924b0af686c4f4c1380314f47947e235e9ff7fa94bed"
32063207
"checksum core-foundation 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc3532ec724375c7cb7ff0a097b714fde180bb1f6ed2ab27cfcd99ffca873cd2"
32073208
"checksum core-foundation-sys 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a3fb15cdbdd9cf8b82d97d0296bb5cd3631bba58d6e31650a002a8e7fb5721f9"
32083209
"checksum crossbeam 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "24ce9782d4d5c53674646a6a4c1863a21a8fc0cb649b3c94dfc16e45071dea19"

src/liballoc/collections/vec_deque.rs

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ use vec::Vec;
3636

3737
const INITIAL_CAPACITY: usize = 7; // 2^3 - 1
3838
const MINIMUM_CAPACITY: usize = 1; // 2 - 1
39+
#[cfg(target_pointer_width = "16")]
40+
const MAXIMUM_ZST_CAPACITY: usize = 1 << (16 - 1); // Largest possible power of two
3941
#[cfg(target_pointer_width = "32")]
4042
const MAXIMUM_ZST_CAPACITY: usize = 1 << (32 - 1); // Largest possible power of two
4143
#[cfg(target_pointer_width = "64")]

src/librustc/hir/lowering.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -3022,8 +3022,14 @@ impl<'a> LoweringContext<'a> {
30223022
hir::VisibilityKind::Inherited => hir::VisibilityKind::Inherited,
30233023
hir::VisibilityKind::Restricted { ref path, id: _, hir_id: _ } => {
30243024
let id = this.next_id();
3025+
let mut path = path.clone();
3026+
for seg in path.segments.iter_mut() {
3027+
if seg.id.is_some() {
3028+
seg.id = Some(this.next_id().node_id);
3029+
}
3030+
}
30253031
hir::VisibilityKind::Restricted {
3026-
path: path.clone(),
3032+
path,
30273033
id: id.node_id,
30283034
hir_id: id.hir_id,
30293035
}

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
217217
};
218218

219219
bug!("inconsistent DepNode for `{}`: \
220-
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}) {}",
220+
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
221221
node_str,
222222
self.definitions
223223
.def_path(self.current_dep_node_owner)

src/librustc/infer/lexical_region_resolve/graphviz.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,7 @@ impl<'a, 'gcx, 'tcx> dot::GraphWalk<'a> for ConstraintGraph<'a, 'gcx, 'tcx> {
230230
type Node = Node;
231231
type Edge = Edge<'tcx>;
232232
fn nodes(&self) -> dot::Nodes<'_, Node> {
233-
let mut set = FxHashSet::default();
234-
for node in self.node_ids.keys() {
235-
set.insert(*node);
236-
}
233+
let set = self.node_ids.keys().cloned().collect::<FxHashSet<_>>();
237234
debug!("constraint graph has {} nodes", set.len());
238235
set.into_iter().collect()
239236
}

src/librustc/middle/dependency_format.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,11 @@ pub enum Linkage {
9494

9595
pub fn calculate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
9696
let sess = &tcx.sess;
97-
let mut fmts = FxHashMap::default();
98-
for &ty in sess.crate_types.borrow().iter() {
97+
let fmts = sess.crate_types.borrow().iter().map(|&ty| {
9998
let linkage = calculate_type(tcx, ty);
10099
verify_ok(tcx, &linkage);
101-
fmts.insert(ty, linkage);
102-
}
100+
(ty, linkage)
101+
}).collect::<FxHashMap<_, _>>();
103102
sess.abort_if_errors();
104103
sess.dependency_formats.set(fmts);
105104
}

src/librustc/traits/util.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ pub fn elaborate_trait_ref<'cx, 'gcx, 'tcx>(
103103

104104
pub fn elaborate_trait_refs<'cx, 'gcx, 'tcx>(
105105
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
106-
trait_refs: &[ty::PolyTraitRef<'tcx>])
106+
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
107107
-> Elaborator<'cx, 'gcx, 'tcx>
108108
{
109-
let predicates = trait_refs.iter()
110-
.map(|trait_ref| trait_ref.to_predicate())
109+
let predicates = trait_refs.map(|trait_ref| trait_ref.to_predicate())
111110
.collect();
112111
elaborate_predicates(tcx, predicates)
113112
}
@@ -271,7 +270,7 @@ pub fn supertraits<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
271270
}
272271

273272
pub fn transitive_bounds<'cx, 'gcx, 'tcx>(tcx: TyCtxt<'cx, 'gcx, 'tcx>,
274-
bounds: &[ty::PolyTraitRef<'tcx>])
273+
bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>)
275274
-> Supertraits<'cx, 'gcx, 'tcx>
276275
{
277276
elaborate_trait_refs(tcx, bounds).filter_to_traits()

src/librustc/ty/query/on_disk_cache.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,13 @@ impl<'sess> OnDiskCache<'sess> {
174174
tcx.dep_graph.with_ignore(|| {
175175
// Allocate SourceFileIndices
176176
let (file_to_file_index, file_index_to_stable_id) = {
177-
let mut file_to_file_index = FxHashMap::default();
178-
let mut file_index_to_stable_id = FxHashMap::default();
177+
let files = tcx.sess.source_map().files();
178+
let mut file_to_file_index = FxHashMap::with_capacity_and_hasher(
179+
files.len(), Default::default());
180+
let mut file_index_to_stable_id = FxHashMap::with_capacity_and_hasher(
181+
files.len(), Default::default());
179182

180-
for (index, file) in tcx.sess.source_map().files().iter().enumerate() {
183+
for (index, file) in files.iter().enumerate() {
181184
let index = SourceFileIndex(index as u32);
182185
let file_ptr: *const SourceFile = &**file as *const _;
183186
file_to_file_index.insert(file_ptr, index);

src/librustc/ty/steal.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use rustc_data_structures::sync::{RwLock, ReadGuard, MappedReadGuard};
12-
use std::mem;
1312

1413
/// The `Steal` struct is intended to used as the value for a query.
1514
/// Specifically, we sometimes have queries (*cough* MIR *cough*)
@@ -51,7 +50,7 @@ impl<T> Steal<T> {
5150

5251
pub fn steal(&self) -> T {
5352
let value_ref = &mut *self.value.try_write().expect("stealing value which is locked");
54-
let value = mem::replace(value_ref, None);
53+
let value = value_ref.take();
5554
value.expect("attempt to read from stolen value")
5655
}
5756
}

src/librustc_data_structures/tiny_list.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
//! If you expect to store more than 1 element in the common case, steer clear
2323
//! and use a `Vec<T>`, `Box<[T]>`, or a `SmallVec<T>`.
2424
25-
use std::mem;
26-
2725
#[derive(Clone, Hash, Debug, PartialEq)]
2826
pub struct TinyList<T: PartialEq> {
2927
head: Option<Element<T>>
@@ -52,15 +50,15 @@ impl<T: PartialEq> TinyList<T> {
5250
pub fn insert(&mut self, data: T) {
5351
self.head = Some(Element {
5452
data,
55-
next: mem::replace(&mut self.head, None).map(Box::new),
53+
next: self.head.take().map(Box::new)
5654
});
5755
}
5856

5957
#[inline]
6058
pub fn remove(&mut self, data: &T) -> bool {
6159
self.head = match self.head {
6260
Some(ref mut head) if head.data == *data => {
63-
mem::replace(&mut head.next, None).map(|x| *x)
61+
head.next.take().map(|x| *x)
6462
}
6563
Some(ref mut head) => return head.remove_next(data),
6664
None => return false,
@@ -100,7 +98,7 @@ impl<T: PartialEq> Element<T> {
10098
if next.data != *data {
10199
return next.remove_next(data)
102100
} else {
103-
mem::replace(&mut next.next, None)
101+
next.next.take()
104102
}
105103
} else {
106104
return false

src/librustc_lint/unused.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,9 @@ impl UnusedParens {
278278
msg: &str,
279279
followed_by_block: bool) {
280280
if let ast::ExprKind::Paren(ref inner) = value.node {
281-
let necessary = followed_by_block && if let ast::ExprKind::Ret(_) = inner.node {
282-
true
283-
} else {
284-
parser::contains_exterior_struct_lit(&inner)
281+
let necessary = followed_by_block && match inner.node {
282+
ast::ExprKind::Ret(_) | ast::ExprKind::Break(..) => true,
283+
_ => parser::contains_exterior_struct_lit(&inner),
285284
};
286285
if !necessary {
287286
let expr_text = if let Ok(snippet) = cx.sess().source_map()

src/librustc_mir/borrow_check/mod.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,33 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
346346
mbcx.errors_buffer.sort_by_key(|diag| diag.span.primary_span());
347347

348348
if tcx.migrate_borrowck() {
349-
match tcx.borrowck(def_id).signalled_any_error {
349+
// When borrowck=migrate, check if AST-borrowck would
350+
// error on the given code.
351+
352+
// rust-lang/rust#55492: loop over parents to ensure that
353+
// errors that AST-borrowck only detects in some parent of
354+
// a closure still allows NLL to signal an error.
355+
let mut curr_def_id = def_id;
356+
let signalled_any_error = loop {
357+
match tcx.borrowck(curr_def_id).signalled_any_error {
358+
SignalledError::NoErrorsSeen => {
359+
// keep traversing (and borrow-checking) parents
360+
}
361+
SignalledError::SawSomeError => {
362+
// stop search here
363+
break SignalledError::SawSomeError;
364+
}
365+
}
366+
367+
if tcx.is_closure(curr_def_id) {
368+
curr_def_id = tcx.parent_def_id(curr_def_id)
369+
.expect("a closure must have a parent_def_id");
370+
} else {
371+
break SignalledError::NoErrorsSeen;
372+
}
373+
};
374+
375+
match signalled_any_error {
350376
SignalledError::NoErrorsSeen => {
351377
// if AST-borrowck signalled no errors, then
352378
// downgrade all the buffered MIR-borrowck errors

src/librustc_mir/const_eval.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,11 @@ pub fn const_eval_provider<'a, 'tcx>(
576576
key.param_env.reveal = Reveal::UserFacing;
577577
match tcx.const_eval(key) {
578578
// try again with reveal all as requested
579-
Err(ErrorHandled::TooGeneric) => {},
579+
Err(ErrorHandled::TooGeneric) => {
580+
// Promoteds should never be "too generic" when getting evaluated.
581+
// They either don't get evaluated, or we are in a monomorphic context
582+
assert!(key.value.promoted.is_none());
583+
},
580584
// dedupliate calls
581585
other => return other,
582586
}

src/librustc_mir/interpret/validity.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
303303
let (lo, hi) = layout.valid_range.clone().into_inner();
304304
let max_hi = u128::max_value() >> (128 - size.bits()); // as big as the size fits
305305
assert!(hi <= max_hi);
306-
if lo == 0 && hi == max_hi {
306+
// We could also write `(hi + 1) % (max_hi + 1) == lo` but `max_hi + 1` overflows for `u128`
307+
if (lo == 0 && hi == max_hi) || (hi + 1 == lo) {
307308
// Nothing to check
308309
return Ok(());
309310
}

src/librustc_target/spec/msp430_none_elf.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,14 @@ pub fn target() -> TargetResult {
3535
no_integrated_as: true,
3636

3737
// There are no atomic CAS instructions available in the MSP430
38-
// instruction set
39-
max_atomic_width: Some(16),
38+
// instruction set, and the LLVM backend doesn't currently support
39+
// compiler fences so the Atomic* API is missing on this target.
40+
// When the LLVM backend gains support for compile fences uncomment
41+
// the `singlethread: true` line and set `max_atomic_width` to
42+
// `Some(16)`.
43+
max_atomic_width: Some(0),
4044
atomic_cas: false,
45+
// singlethread: true,
4146

4247
// Because these devices have very little resources having an
4348
// unwinder is too onerous so we default to "abort" because the

src/librustc_traits/implied_outlives_bounds.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ fn implied_bounds_from_components(
159159
) -> Vec<OutlivesBound<'tcx>> {
160160
sup_components
161161
.into_iter()
162-
.flat_map(|component| {
162+
.filter_map(|component| {
163163
match component {
164164
Component::Region(r) =>
165-
vec![OutlivesBound::RegionSubRegion(sub_region, r)],
165+
Some(OutlivesBound::RegionSubRegion(sub_region, r)),
166166
Component::Param(p) =>
167-
vec![OutlivesBound::RegionSubParam(sub_region, p)],
167+
Some(OutlivesBound::RegionSubParam(sub_region, p)),
168168
Component::Projection(p) =>
169-
vec![OutlivesBound::RegionSubProjection(sub_region, p)],
169+
Some(OutlivesBound::RegionSubProjection(sub_region, p)),
170170
Component::EscapingProjection(_) =>
171171
// If the projection has escaping regions, don't
172172
// try to infer any implied bounds even for its
@@ -176,9 +176,9 @@ fn implied_bounds_from_components(
176176
// idea is that the WAY that the caller proves
177177
// that may change in the future and we want to
178178
// give ourselves room to get smarter here.
179-
vec![],
179+
None,
180180
Component::UnresolvedInferenceVariable(..) =>
181-
vec![],
181+
None,
182182
}
183183
})
184184
.collect()

src/librustc_typeck/astconv.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1112,12 +1112,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx>+'o {
11121112
{
11131113
let tcx = self.tcx();
11141114

1115-
let bounds: Vec<_> = self.get_type_parameter_bounds(span, ty_param_def_id)
1116-
.predicates.into_iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref()).collect();
1115+
let bounds = self.get_type_parameter_bounds(span, ty_param_def_id)
1116+
.predicates.into_iter().filter_map(|(p, _)| p.to_opt_poly_trait_ref());
11171117

11181118
// Check that there is exactly one way to find an associated type with the
11191119
// correct name.
1120-
let suitable_bounds = traits::transitive_bounds(tcx, &bounds)
1120+
let suitable_bounds = traits::transitive_bounds(tcx, bounds)
11211121
.filter(|b| self.trait_defines_associated_type_named(b.def_id(), assoc_name));
11221122

11231123
let param_node_id = tcx.hir.as_local_node_id(ty_param_def_id).unwrap();

0 commit comments

Comments
 (0)