Skip to content

Commit 388ef34

Browse files
committed
Auto merge of rust-lang#78562 - JohnTitor:rollup-otg906u, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#77334 (Reorder benches const variable) - rust-lang#77888 (Simplify a nested bool match) - rust-lang#77921 (f64: Refactor collapsible_if) - rust-lang#78523 (Revert invalid `fn` return type parsing change) - rust-lang#78524 (Avoid BorrowMutError with RUSTC_LOG=debug) - rust-lang#78545 (Make anonymous binders start at 0) - rust-lang#78554 (Improve wording of `core::ptr::drop_in_place` docs) - rust-lang#78556 (Link to pass docs from NRVO module docs) Failed merges: - rust-lang#78424 (Fix some more clippy warnings) r? `@ghost`
2 parents 8df58ae + 2471a7c commit 388ef34

File tree

28 files changed

+84
-97
lines changed

28 files changed

+84
-97
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

+7-18
Original file line numberDiff line numberDiff line change
@@ -156,24 +156,13 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
156156
}
157157
}
158158
match tt {
159-
TokenTree::Token(token) => match token.kind {
160-
token::Comma => false,
161-
_ => true,
162-
},
163-
TokenTree::Delimited(_, DelimToken::Paren, _) => match prev {
164-
TokenTree::Token(token) => match token.kind {
165-
token::Ident(_, _) => false,
166-
_ => true,
167-
},
168-
_ => true,
169-
},
170-
TokenTree::Delimited(_, DelimToken::Bracket, _) => match prev {
171-
TokenTree::Token(token) => match token.kind {
172-
token::Pound => false,
173-
_ => true,
174-
},
175-
_ => true,
176-
},
159+
TokenTree::Token(token) => token.kind != token::Comma,
160+
TokenTree::Delimited(_, DelimToken::Paren, _) => {
161+
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }))
162+
}
163+
TokenTree::Delimited(_, DelimToken::Bracket, _) => {
164+
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }))
165+
}
177166
TokenTree::Delimited(..) => true,
178167
}
179168
}

compiler/rustc_data_structures/src/sync.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ impl<T: Clone> Clone for Lock<T> {
512512
}
513513
}
514514

515-
#[derive(Debug)]
515+
#[derive(Debug, Default)]
516516
pub struct RwLock<T>(InnerRwLock<T>);
517517

518518
impl<T> RwLock<T> {

compiler/rustc_metadata/src/rmeta/encoder.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -2042,6 +2042,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
20422042
encoder.emit_raw_bytes(&[0, 0, 0, 0]);
20432043

20442044
let source_map_files = tcx.sess.source_map().files();
2045+
let source_file_cache = (source_map_files[0].clone(), 0);
2046+
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
2047+
drop(source_map_files);
2048+
20452049
let hygiene_ctxt = HygieneEncodeContext::default();
20462050

20472051
let mut ecx = EncodeContext {
@@ -2052,13 +2056,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
20522056
lazy_state: LazyState::NoNode,
20532057
type_shorthands: Default::default(),
20542058
predicate_shorthands: Default::default(),
2055-
source_file_cache: (source_map_files[0].clone(), 0),
2059+
source_file_cache,
20562060
interpret_allocs: Default::default(),
2057-
required_source_files: Some(GrowableBitSet::with_capacity(source_map_files.len())),
2061+
required_source_files,
20582062
is_proc_macro: tcx.sess.crate_types().contains(&CrateType::ProcMacro),
20592063
hygiene_ctxt: &hygiene_ctxt,
20602064
};
2061-
drop(source_map_files);
20622065

20632066
// Encode the rustc version string in a predictable location.
20642067
rustc_version().encode(&mut ecx).unwrap();

compiler/rustc_middle/src/ty/fold.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ impl<'tcx> TyCtxt<'tcx> {
684684
}
685685

686686
/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
687-
/// assigned starting at 1 and increasing monotonically in the order traversed
687+
/// assigned starting at 0 and increasing monotonically in the order traversed
688688
/// by the fold operation.
689689
///
690690
/// The chief purpose of this function is to canonicalize regions so that two
@@ -698,8 +698,9 @@ impl<'tcx> TyCtxt<'tcx> {
698698
let mut counter = 0;
699699
Binder::bind(
700700
self.replace_late_bound_regions(sig, |_| {
701+
let r = self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)));
701702
counter += 1;
702-
self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)))
703+
r
703704
})
704705
.0,
705706
)

compiler/rustc_mir/src/transform/nrvo.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! See the docs for [`RenameReturnPlace`].
2+
13
use rustc_hir::Mutability;
24
use rustc_index::bit_set::HybridBitSet;
35
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};

compiler/rustc_parse/src/parser/item.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -1666,19 +1666,10 @@ impl<'a> Parser<'a> {
16661666
req_name: ReqName,
16671667
ret_allow_plus: AllowPlus,
16681668
) -> PResult<'a, P<FnDecl>> {
1669-
let inputs = self.parse_fn_params(req_name)?;
1670-
let output = self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?;
1671-
1672-
if let ast::FnRetTy::Ty(ty) = &output {
1673-
if let TyKind::Path(_, Path { segments, .. }) = &ty.kind {
1674-
if let [.., last] = &segments[..] {
1675-
// Detect and recover `fn foo() -> Vec<i32>> {}`
1676-
self.check_trailing_angle_brackets(last, &[&token::OpenDelim(token::Brace)]);
1677-
}
1678-
}
1679-
}
1680-
1681-
Ok(P(FnDecl { inputs, output }))
1669+
Ok(P(FnDecl {
1670+
inputs: self.parse_fn_params(req_name)?,
1671+
output: self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?,
1672+
}))
16821673
}
16831674

16841675
/// Parses the parameter list of a function, including the `(` and `)` delimiters.

compiler/rustc_span/src/source_map.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub use crate::*;
1212

1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_data_structures::stable_hasher::StableHasher;
15-
use rustc_data_structures::sync::{AtomicU32, Lock, LockGuard, Lrc, MappedLockGuard};
15+
use rustc_data_structures::sync::{AtomicU32, Lrc, MappedReadGuard, ReadGuard, RwLock};
1616
use std::cmp;
1717
use std::convert::TryFrom;
1818
use std::hash::Hash;
@@ -168,7 +168,7 @@ pub struct SourceMap {
168168
/// The address space below this value is currently used by the files in the source map.
169169
used_address_space: AtomicU32,
170170

171-
files: Lock<SourceMapFiles>,
171+
files: RwLock<SourceMapFiles>,
172172
file_loader: Box<dyn FileLoader + Sync + Send>,
173173
// This is used to apply the file path remapping as specified via
174174
// `--remap-path-prefix` to all `SourceFile`s allocated within this `SourceMap`.
@@ -236,8 +236,8 @@ impl SourceMap {
236236

237237
// By returning a `MonotonicVec`, we ensure that consumers cannot invalidate
238238
// any existing indices pointing into `files`.
239-
pub fn files(&self) -> MappedLockGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
240-
LockGuard::map(self.files.borrow(), |files| &mut files.source_files)
239+
pub fn files(&self) -> MappedReadGuard<'_, monotonic::MonotonicVec<Lrc<SourceFile>>> {
240+
ReadGuard::map(self.files.borrow(), |files| &files.source_files)
241241
}
242242

243243
pub fn source_file_by_stable_id(

compiler/rustc_symbol_mangling/src/v0.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -200,15 +200,9 @@ impl SymbolMangler<'tcx> {
200200

201201
let lifetimes = regions
202202
.into_iter()
203-
.map(|br| {
204-
match br {
205-
ty::BrAnon(i) => {
206-
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
207-
assert_ne!(i, 0);
208-
i - 1
209-
}
210-
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
211-
}
203+
.map(|br| match br {
204+
ty::BrAnon(i) => i,
205+
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
212206
})
213207
.max()
214208
.map_or(0, |max| max + 1);
@@ -327,10 +321,6 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
327321
// Late-bound lifetimes use indices starting at 1,
328322
// see `BinderLevel` for more details.
329323
ty::ReLateBound(debruijn, ty::BrAnon(i)) => {
330-
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
331-
assert_ne!(i, 0);
332-
let i = i - 1;
333-
334324
let binder = &self.binders[self.binders.len() - 1 - debruijn.index()];
335325
let depth = binder.lifetime_depths.start + i;
336326

compiler/rustc_typeck/src/check/generator_interior.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,9 @@ pub fn resolve_interior<'a, 'tcx>(
186186
// which means that none of the regions inside relate to any other, even if
187187
// typeck had previously found constraints that would cause them to be related.
188188
let folded = fcx.tcx.fold_regions(&erased, &mut false, |_, current_depth| {
189+
let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)));
189190
counter += 1;
190-
fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)))
191+
r
191192
});
192193

193194
cause.ty = folded;

library/alloc/benches/vec.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,8 @@ fn bench_in_place_collect_droppable(b: &mut Bencher) {
570570
})
571571
}
572572

573+
const LEN: usize = 16384;
574+
573575
#[bench]
574576
fn bench_chain_collect(b: &mut Bencher) {
575577
let data = black_box([0; LEN]);
@@ -613,8 +615,6 @@ pub fn map_fast(l: &[(u32, u32)]) -> Vec<u32> {
613615
result
614616
}
615617

616-
const LEN: usize = 16384;
617-
618618
#[bench]
619619
fn bench_range_map_collect(b: &mut Bencher) {
620620
b.iter(|| (0..LEN).map(|_| u32::default()).collect::<Vec<_>>());

library/core/src/ptr/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ mod mut_ptr;
9999
/// dropped normally.
100100
///
101101
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
102-
/// dropping manually allocated memory (e.g., when writing Box/Rc/Vec),
103-
/// as the compiler doesn't need to prove that it's sound to elide the
104-
/// copy.
102+
/// dropping manually allocated memory (e.g., in the implementations of
103+
/// `Box`/`Rc`/`Vec`), as the compiler doesn't need to prove that it's
104+
/// sound to elide the copy.
105105
///
106106
/// * It can be used to drop [pinned] data when `T` is not `repr(packed)`
107107
/// (pinned data must not be moved before it is dropped).

library/std/src/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module provides constants which are specific to the implementation
22
//! of the `f32` floating point data type.
33
//!
4-
//! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
4+
//! *[See also the `f32` primitive type](primitive@f32).*
55
//!
66
//! Mathematically significant numbers are provided in the `consts` sub-module.
77
//!

library/std/src/f64.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This module provides constants which are specific to the implementation
22
//! of the `f64` floating point data type.
33
//!
4-
//! *[See also the `f64` primitive type](../../std/primitive.f64.html).*
4+
//! *[See also the `f64` primitive type](primitive@f64).*
55
//!
66
//! Mathematically significant numbers are provided in the `consts` sub-module.
77
//!
@@ -920,22 +920,20 @@ impl f64 {
920920
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
921921
if !cfg!(any(target_os = "solaris", target_os = "illumos")) {
922922
log_fn(self)
923-
} else {
924-
if self.is_finite() {
925-
if self > 0.0 {
926-
log_fn(self)
927-
} else if self == 0.0 {
928-
Self::NEG_INFINITY // log(0) = -Inf
929-
} else {
930-
Self::NAN // log(-n) = NaN
931-
}
932-
} else if self.is_nan() {
933-
self // log(NaN) = NaN
934-
} else if self > 0.0 {
935-
self // log(Inf) = Inf
923+
} else if self.is_finite() {
924+
if self > 0.0 {
925+
log_fn(self)
926+
} else if self == 0.0 {
927+
Self::NEG_INFINITY // log(0) = -Inf
936928
} else {
937-
Self::NAN // log(-Inf) = NaN
929+
Self::NAN // log(-n) = NaN
938930
}
931+
} else if self.is_nan() {
932+
self // log(NaN) = NaN
933+
} else if self > 0.0 {
934+
self // log(Inf) = Inf
935+
} else {
936+
Self::NAN // log(-Inf) = NaN
939937
}
940938
}
941939
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// rustc-env:RUSTC_LOG=debug

src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
66
|
77
= note: expected fn pointer `fn(&u32)`
88
found fn pointer `fn(&'x u32)`
9-
note: the anonymous lifetime #2 defined on the body at 16:48...
9+
note: the anonymous lifetime #1 defined on the body at 16:48...
1010
--> $DIR/expect-fn-supply-fn.rs:16:48
1111
|
1212
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
@@ -30,7 +30,7 @@ note: the lifetime `'x` as defined on the function body at 13:36...
3030
|
3131
LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
3232
| ^^
33-
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 16:48
33+
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 16:48
3434
--> $DIR/expect-fn-supply-fn.rs:16:48
3535
|
3636
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});

src/test/ui/closures/closure-expected-type/expect-region-supply-region-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
66
|
77
= note: expected reference `&u32`
88
found reference `&'x u32`
9-
note: the anonymous lifetime #2 defined on the body at 14:29...
9+
note: the anonymous lifetime #1 defined on the body at 14:29...
1010
--> $DIR/expect-region-supply-region-2.rs:14:29
1111
|
1212
LL | closure_expecting_bound(|x: &'x u32| {
@@ -37,7 +37,7 @@ note: the lifetime `'x` as defined on the function body at 9:30...
3737
|
3838
LL | fn expect_bound_supply_named<'x>() {
3939
| ^^
40-
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 14:29
40+
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 14:29
4141
--> $DIR/expect-region-supply-region-2.rs:14:29
4242
|
4343
LL | closure_expecting_bound(|x: &'x u32| {

src/test/ui/issues/issue-10291.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | x
55
| ^
66
|
7-
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 2:69...
7+
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 2:69...
88
--> $DIR/issue-10291.rs:2:69
99
|
1010
LL | drop::<Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {

src/test/ui/issues/issue-52533-1.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ LL | gimme(|x, y| y)
66
|
77
= note: expected reference `&Foo<'_, '_, u32>`
88
found reference `&Foo<'_, '_, u32>`
9-
note: the anonymous lifetime #4 defined on the body at 9:11...
9+
note: the anonymous lifetime #3 defined on the body at 9:11...
1010
--> $DIR/issue-52533-1.rs:9:11
1111
|
1212
LL | gimme(|x, y| y)
1313
| ^^^^^^^^
14-
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the body at 9:11
14+
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 9:11
1515
--> $DIR/issue-52533-1.rs:9:11
1616
|
1717
LL | gimme(|x, y| y)

src/test/ui/issues/issue-52533.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
44
LL | foo(|a, b| b)
55
| ^
66
|
7-
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 5:9...
7+
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 5:9...
88
--> $DIR/issue-52533.rs:5:9
99
|
1010
LL | foo(|a, b| b)
1111
| ^^^^^^^^
12-
note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined on the body at 5:9
12+
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the body at 5:9
1313
--> $DIR/issue-52533.rs:5:9
1414
|
1515
LL | foo(|a, b| b)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// check-pass
2+
// Regression test for #78507.
3+
fn foo() -> Option<fn() -> Option<bool>> {
4+
Some(|| Some(true))
5+
}
6+
fn main() {}

src/test/ui/parser/issue-24780.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Verify that '>' is not both expected and found at the same time, as it used
22
// to happen in #24780. For example, following should be an error:
3-
// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
3+
// expected one of ..., `>`, ... found `>`.
44

5-
fn foo() -> Vec<usize>> { //~ ERROR unmatched angle bracket
5+
fn foo() -> Vec<usize>> { //~ ERROR expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
66
Vec::new()
77
}
88

src/test/ui/parser/issue-24780.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
error: unmatched angle bracket
1+
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
22
--> $DIR/issue-24780.rs:5:23
33
|
44
LL | fn foo() -> Vec<usize>> {
5-
| ^^ help: remove extra angle bracket
5+
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)