Skip to content

Commit

Permalink
Auto merge of #78562 - JohnTitor:rollup-otg906u, r=JohnTitor
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Oct 30, 2020
2 parents 8df58ae + 2471a7c commit 388ef34
Show file tree
Hide file tree
Showing 28 changed files with 84 additions and 97 deletions.
25 changes: 7 additions & 18 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,24 +156,13 @@ fn tt_prepend_space(tt: &TokenTree, prev: &TokenTree) -> bool {
}
}
match tt {
TokenTree::Token(token) => match token.kind {
token::Comma => false,
_ => true,
},
TokenTree::Delimited(_, DelimToken::Paren, _) => match prev {
TokenTree::Token(token) => match token.kind {
token::Ident(_, _) => false,
_ => true,
},
_ => true,
},
TokenTree::Delimited(_, DelimToken::Bracket, _) => match prev {
TokenTree::Token(token) => match token.kind {
token::Pound => false,
_ => true,
},
_ => true,
},
TokenTree::Token(token) => token.kind != token::Comma,
TokenTree::Delimited(_, DelimToken::Paren, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }))
}
TokenTree::Delimited(_, DelimToken::Bracket, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }))
}
TokenTree::Delimited(..) => true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ impl<T: Clone> Clone for Lock<T> {
}
}

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct RwLock<T>(InnerRwLock<T>);

impl<T> RwLock<T> {
Expand Down
9 changes: 6 additions & 3 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,10 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
encoder.emit_raw_bytes(&[0, 0, 0, 0]);

let source_map_files = tcx.sess.source_map().files();
let source_file_cache = (source_map_files[0].clone(), 0);
let required_source_files = Some(GrowableBitSet::with_capacity(source_map_files.len()));
drop(source_map_files);

let hygiene_ctxt = HygieneEncodeContext::default();

let mut ecx = EncodeContext {
Expand All @@ -2052,13 +2056,12 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
lazy_state: LazyState::NoNode,
type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
source_file_cache: (source_map_files[0].clone(), 0),
source_file_cache,
interpret_allocs: Default::default(),
required_source_files: Some(GrowableBitSet::with_capacity(source_map_files.len())),
required_source_files,
is_proc_macro: tcx.sess.crate_types().contains(&CrateType::ProcMacro),
hygiene_ctxt: &hygiene_ctxt,
};
drop(source_map_files);

// Encode the rustc version string in a predictable location.
rustc_version().encode(&mut ecx).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_middle/src/ty/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ impl<'tcx> TyCtxt<'tcx> {
}

/// Rewrite any late-bound regions so that they are anonymous. Region numbers are
/// assigned starting at 1 and increasing monotonically in the order traversed
/// assigned starting at 0 and increasing monotonically in the order traversed
/// by the fold operation.
///
/// The chief purpose of this function is to canonicalize regions so that two
Expand All @@ -698,8 +698,9 @@ impl<'tcx> TyCtxt<'tcx> {
let mut counter = 0;
Binder::bind(
self.replace_late_bound_regions(sig, |_| {
let r = self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)));
counter += 1;
self.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BrAnon(counter)))
r
})
.0,
)
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_mir/src/transform/nrvo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! See the docs for [`RenameReturnPlace`].
use rustc_hir::Mutability;
use rustc_index::bit_set::HybridBitSet;
use rustc_middle::mir::visit::{MutVisitor, NonUseContext, PlaceContext, Visitor};
Expand Down
17 changes: 4 additions & 13 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1666,19 +1666,10 @@ impl<'a> Parser<'a> {
req_name: ReqName,
ret_allow_plus: AllowPlus,
) -> PResult<'a, P<FnDecl>> {
let inputs = self.parse_fn_params(req_name)?;
let output = self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?;

if let ast::FnRetTy::Ty(ty) = &output {
if let TyKind::Path(_, Path { segments, .. }) = &ty.kind {
if let [.., last] = &segments[..] {
// Detect and recover `fn foo() -> Vec<i32>> {}`
self.check_trailing_angle_brackets(last, &[&token::OpenDelim(token::Brace)]);
}
}
}

Ok(P(FnDecl { inputs, output }))
Ok(P(FnDecl {
inputs: self.parse_fn_params(req_name)?,
output: self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes)?,
}))
}

/// Parses the parameter list of a function, including the `(` and `)` delimiters.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_span/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub use crate::*;

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

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

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

pub fn source_file_by_stable_id(
Expand Down
16 changes: 3 additions & 13 deletions compiler/rustc_symbol_mangling/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,15 +200,9 @@ impl SymbolMangler<'tcx> {

let lifetimes = regions
.into_iter()
.map(|br| {
match br {
ty::BrAnon(i) => {
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
assert_ne!(i, 0);
i - 1
}
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
}
.map(|br| match br {
ty::BrAnon(i) => i,
_ => bug!("symbol_names: non-anonymized region `{:?}` in `{:?}`", br, value),
})
.max()
.map_or(0, |max| max + 1);
Expand Down Expand Up @@ -327,10 +321,6 @@ impl Printer<'tcx> for SymbolMangler<'tcx> {
// Late-bound lifetimes use indices starting at 1,
// see `BinderLevel` for more details.
ty::ReLateBound(debruijn, ty::BrAnon(i)) => {
// FIXME(eddyb) for some reason, `anonymize_late_bound_regions` starts at `1`.
assert_ne!(i, 0);
let i = i - 1;

let binder = &self.binders[self.binders.len() - 1 - debruijn.index()];
let depth = binder.lifetime_depths.start + i;

Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_typeck/src/check/generator_interior.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,9 @@ pub fn resolve_interior<'a, 'tcx>(
// which means that none of the regions inside relate to any other, even if
// typeck had previously found constraints that would cause them to be related.
let folded = fcx.tcx.fold_regions(&erased, &mut false, |_, current_depth| {
let r = fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)));
counter += 1;
fcx.tcx.mk_region(ty::ReLateBound(current_depth, ty::BrAnon(counter)))
r
});

cause.ty = folded;
Expand Down
4 changes: 2 additions & 2 deletions library/alloc/benches/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@ fn bench_in_place_collect_droppable(b: &mut Bencher) {
})
}

const LEN: usize = 16384;

#[bench]
fn bench_chain_collect(b: &mut Bencher) {
let data = black_box([0; LEN]);
Expand Down Expand Up @@ -613,8 +615,6 @@ pub fn map_fast(l: &[(u32, u32)]) -> Vec<u32> {
result
}

const LEN: usize = 16384;

#[bench]
fn bench_range_map_collect(b: &mut Bencher) {
b.iter(|| (0..LEN).map(|_| u32::default()).collect::<Vec<_>>());
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/ptr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ mod mut_ptr;
/// dropped normally.
///
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
/// dropping manually allocated memory (e.g., when writing Box/Rc/Vec),
/// as the compiler doesn't need to prove that it's sound to elide the
/// copy.
/// dropping manually allocated memory (e.g., in the implementations of
/// `Box`/`Rc`/`Vec`), as the compiler doesn't need to prove that it's
/// sound to elide the copy.
///
/// * It can be used to drop [pinned] data when `T` is not `repr(packed)`
/// (pinned data must not be moved before it is dropped).
Expand Down
2 changes: 1 addition & 1 deletion library/std/src/f32.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module provides constants which are specific to the implementation
//! of the `f32` floating point data type.
//!
//! *[See also the `f32` primitive type](../../std/primitive.f32.html).*
//! *[See also the `f32` primitive type](primitive@f32).*
//!
//! Mathematically significant numbers are provided in the `consts` sub-module.
//!
Expand Down
28 changes: 13 additions & 15 deletions library/std/src/f64.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module provides constants which are specific to the implementation
//! of the `f64` floating point data type.
//!
//! *[See also the `f64` primitive type](../../std/primitive.f64.html).*
//! *[See also the `f64` primitive type](primitive@f64).*
//!
//! Mathematically significant numbers are provided in the `consts` sub-module.
//!
Expand Down Expand Up @@ -920,22 +920,20 @@ impl f64 {
fn log_wrapper<F: Fn(f64) -> f64>(self, log_fn: F) -> f64 {
if !cfg!(any(target_os = "solaris", target_os = "illumos")) {
log_fn(self)
} else {
if self.is_finite() {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
Self::NEG_INFINITY // log(0) = -Inf
} else {
Self::NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else if self.is_finite() {
if self > 0.0 {
log_fn(self)
} else if self == 0.0 {
Self::NEG_INFINITY // log(0) = -Inf
} else {
Self::NAN // log(-Inf) = NaN
Self::NAN // log(-n) = NaN
}
} else if self.is_nan() {
self // log(NaN) = NaN
} else if self > 0.0 {
self // log(Inf) = Inf
} else {
Self::NAN // log(-Inf) = NaN
}
}
}
1 change: 1 addition & 0 deletions src/test/ui/auxiliary/rustc-rust-log-aux.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// rustc-env:RUSTC_LOG=debug
4 changes: 2 additions & 2 deletions src/test/ui/closure-expected-type/expect-fn-supply-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
|
= note: expected fn pointer `fn(&u32)`
found fn pointer `fn(&'x u32)`
note: the anonymous lifetime #2 defined on the body at 16:48...
note: the anonymous lifetime #1 defined on the body at 16:48...
--> $DIR/expect-fn-supply-fn.rs:16:48
|
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
Expand All @@ -30,7 +30,7 @@ note: the lifetime `'x` as defined on the function body at 13:36...
|
LL | fn expect_free_supply_free_from_fn<'x>(x: &'x u32) {
| ^^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 16:48
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 16:48
--> $DIR/expect-fn-supply-fn.rs:16:48
|
LL | with_closure_expecting_fn_with_free_region(|x: fn(&'x u32), y| {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | closure_expecting_bound(|x: &'x u32| {
|
= note: expected reference `&u32`
found reference `&'x u32`
note: the anonymous lifetime #2 defined on the body at 14:29...
note: the anonymous lifetime #1 defined on the body at 14:29...
--> $DIR/expect-region-supply-region-2.rs:14:29
|
LL | closure_expecting_bound(|x: &'x u32| {
Expand Down Expand Up @@ -37,7 +37,7 @@ note: the lifetime `'x` as defined on the function body at 9:30...
|
LL | fn expect_bound_supply_named<'x>() {
| ^^
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 14:29
note: ...does not necessarily outlive the anonymous lifetime #1 defined on the body at 14:29
--> $DIR/expect-region-supply-region-2.rs:14:29
|
LL | closure_expecting_bound(|x: &'x u32| {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-10291.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
LL | x
| ^
|
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 2:69...
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 2:69...
--> $DIR/issue-10291.rs:2:69
|
LL | drop::<Box<dyn for<'z> FnMut(&'z isize) -> &'z isize>>(Box::new(|z| {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-52533-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ LL | gimme(|x, y| y)
|
= note: expected reference `&Foo<'_, '_, u32>`
found reference `&Foo<'_, '_, u32>`
note: the anonymous lifetime #4 defined on the body at 9:11...
note: the anonymous lifetime #3 defined on the body at 9:11...
--> $DIR/issue-52533-1.rs:9:11
|
LL | gimme(|x, y| y)
| ^^^^^^^^
note: ...does not necessarily outlive the anonymous lifetime #3 defined on the body at 9:11
note: ...does not necessarily outlive the anonymous lifetime #2 defined on the body at 9:11
--> $DIR/issue-52533-1.rs:9:11
|
LL | gimme(|x, y| y)
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-52533.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ error[E0312]: lifetime of reference outlives lifetime of borrowed content...
LL | foo(|a, b| b)
| ^
|
note: ...the reference is valid for the anonymous lifetime #2 defined on the body at 5:9...
note: ...the reference is valid for the anonymous lifetime #1 defined on the body at 5:9...
--> $DIR/issue-52533.rs:5:9
|
LL | foo(|a, b| b)
| ^^^^^^^^
note: ...but the borrowed content is only valid for the anonymous lifetime #3 defined on the body at 5:9
note: ...but the borrowed content is only valid for the anonymous lifetime #2 defined on the body at 5:9
--> $DIR/issue-52533.rs:5:9
|
LL | foo(|a, b| b)
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/parser/fn-returns-fn-pointer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// check-pass
// Regression test for #78507.
fn foo() -> Option<fn() -> Option<bool>> {
Some(|| Some(true))
}
fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-24780.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Verify that '>' is not both expected and found at the same time, as it used
// to happen in #24780. For example, following should be an error:
// expected one of ..., `>`, ... found `>`. No longer exactly this, but keeping for posterity.
// expected one of ..., `>`, ... found `>`.

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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-24780.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: unmatched angle bracket
error: expected one of `!`, `+`, `::`, `;`, `where`, or `{`, found `>`
--> $DIR/issue-24780.rs:5:23
|
LL | fn foo() -> Vec<usize>> {
| ^^ help: remove extra angle bracket
| ^ expected one of `!`, `+`, `::`, `;`, `where`, or `{`

error: aborting due to previous error

Loading

0 comments on commit 388ef34

Please sign in to comment.