Skip to content

Commit 388ef34

Browse files
committed
Auto merge of #78562 - JohnTitor:rollup-otg906u, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #77334 (Reorder benches const variable) - #77888 (Simplify a nested bool match) - #77921 (f64: Refactor collapsible_if) - #78523 (Revert invalid `fn` return type parsing change) - #78524 (Avoid BorrowMutError with RUSTC_LOG=debug) - #78545 (Make anonymous binders start at 0) - #78554 (Improve wording of `core::ptr::drop_in_place` docs) - #78556 (Link to pass docs from NRVO module docs) Failed merges: - #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

Lines changed: 7 additions & 18 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 3 additions & 2 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 13 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 13 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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<_>>());

0 commit comments

Comments
 (0)