Skip to content

Commit

Permalink
Auto merge of rust-lang#77013 - RalfJung:rollup-84ut0xq, r=RalfJung
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#76439 (Add error explanation for E0755)
 - rust-lang#76521 (Fix segfault if pthread_getattr_np fails)
 - rust-lang#76835 (make replace_prefix only take &str as arguments )
 - rust-lang#76967 (Revert adding Atomic::from_mut.)
 - rust-lang#76977 (Add a regression test for copy propagation miscompilation)
 - rust-lang#76981 (liballoc bench use imported path Bencher)
 - rust-lang#76983 (BTreeMap: extra testing & fixed comments)
 - rust-lang#76996 (Fix typo in rustc_lexer docs)
 - rust-lang#77009 (Dogfood total_cmp in the test crate)
 - rust-lang#77012 (update Miri for another bugfix)

Failed merges:

 - rust-lang#76489 (Add explanation for E0756)

r? `@ghost`
  • Loading branch information
bors committed Sep 21, 2020
2 parents e0bf356 + 6417eb0 commit 4eff9b0
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 148 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ E0751: include_str!("./error_codes/E0751.md"),
E0752: include_str!("./error_codes/E0752.md"),
E0753: include_str!("./error_codes/E0753.md"),
E0754: include_str!("./error_codes/E0754.md"),
E0755: include_str!("./error_codes/E0755.md"),
E0758: include_str!("./error_codes/E0758.md"),
E0759: include_str!("./error_codes/E0759.md"),
E0760: include_str!("./error_codes/E0760.md"),
Expand Down Expand Up @@ -632,7 +633,6 @@ E0774: include_str!("./error_codes/E0774.md"),
E0722, // Malformed `#[optimize]` attribute
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
E0755, // `#[ffi_pure]` is only allowed on foreign functions
E0756, // `#[ffi_const]` is only allowed on foreign functions
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0755.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The `ffi_pure` attribute was used on a non-foreign function.

Erroneous code example:

```compile_fail,E0755
#![feature(ffi_pure)]
#[ffi_pure] // error!
pub fn foo() {}
# fn main() {}
```

The `ffi_pure` attribute can only be used on foreign functions which do not have
side effects or infinite loops:

```
#![feature(ffi_pure)]
extern "C" {
#[ffi_pure] // ok!
pub fn strlen(s: *const i8) -> isize;
}
# fn main() {}
```

You can find more information about it in the [unstable Rust Book].

[unstable Rust Book]: https://doc.rust-lang.org/unstable-book/language-features/ffi-pure.html
2 changes: 1 addition & 1 deletion compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! The idea with `librustc_lexer` is to make a reusable library,
//! by separating out pure lexing and rustc-specific concerns, like spans,
//! error reporting an interning. So, rustc_lexer operates directly on `&str`,
//! error reporting, and interning. So, rustc_lexer operates directly on `&str`,
//! produces simple tokens which are a pair of type-tag and a bit of original text,
//! and does not report errors, instead storing them as flags on the token.
//!
Expand Down
25 changes: 9 additions & 16 deletions compiler/rustc_typeck/src/check/demand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,16 +362,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
false
}

fn replace_prefix<A, B, C>(&self, s: A, old: B, new: C) -> Option<String>
where
A: AsRef<str>,
B: AsRef<str>,
C: AsRef<str>,
{
let s = s.as_ref();
let old = old.as_ref();
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
if let Some(stripped) = s.strip_prefix(old) {
Some(new.as_ref().to_owned() + stripped)
Some(new.to_string() + stripped)
} else {
None
}
Expand Down Expand Up @@ -422,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(src, "b\"", "\"") {
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
return Some((
sp,
"consider removing the leading `b`",
Expand All @@ -436,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
if let hir::ExprKind::Lit(_) = expr.kind {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(src, "\"", "b\"") {
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
return Some((
sp,
"consider adding a leading `b`",
Expand Down Expand Up @@ -561,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// we may want to suggest removing a `&`.
if sm.is_imported(expr.span) {
if let Ok(src) = sm.span_to_snippet(sp) {
if let Some(src) = self.replace_prefix(src, "&", "") {
if let Some(src) = self.replace_prefix(&src, "&", "") {
return Some((
sp,
"consider removing the borrow",
Expand Down Expand Up @@ -598,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match mutbl_a {
hir::Mutability::Mut => {
if let Some(s) =
self.replace_prefix(src, "&mut ", new_prefix)
self.replace_prefix(&src, "&mut ", &new_prefix)
{
Some((s, Applicability::MachineApplicable))
} else {
Expand All @@ -607,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
hir::Mutability::Not => {
if let Some(s) =
self.replace_prefix(src, "&", new_prefix)
self.replace_prefix(&src, "&", &new_prefix)
{
Some((s, Applicability::Unspecified))
} else {
Expand All @@ -621,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
match mutbl_a {
hir::Mutability::Mut => {
if let Some(s) =
self.replace_prefix(src, "&mut ", new_prefix)
self.replace_prefix(&src, "&mut ", &new_prefix)
{
Some((s, Applicability::MachineApplicable))
} else {
Expand All @@ -630,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
hir::Mutability::Not => {
if let Some(s) =
self.replace_prefix(src, "&", new_prefix)
self.replace_prefix(&src, "&", &new_prefix)
{
Some((s, Applicability::MachineApplicable))
} else {
Expand Down
28 changes: 14 additions & 14 deletions library/alloc/benches/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ bench_in_place![
];

#[bench]
fn bench_in_place_recycle(b: &mut test::Bencher) {
fn bench_in_place_recycle(b: &mut Bencher) {
let mut data = vec![0; 1000];

b.iter(|| {
Expand All @@ -513,7 +513,7 @@ fn bench_in_place_recycle(b: &mut test::Bencher) {
}

#[bench]
fn bench_in_place_zip_recycle(b: &mut test::Bencher) {
fn bench_in_place_zip_recycle(b: &mut Bencher) {
let mut data = vec![0u8; 1000];
let mut rng = rand::thread_rng();
let mut subst = vec![0u8; 1000];
Expand All @@ -533,7 +533,7 @@ fn bench_in_place_zip_recycle(b: &mut test::Bencher) {
}

#[bench]
fn bench_in_place_zip_iter_mut(b: &mut test::Bencher) {
fn bench_in_place_zip_iter_mut(b: &mut Bencher) {
let mut data = vec![0u8; 256];
let mut rng = rand::thread_rng();
let mut subst = vec![0u8; 1000];
Expand All @@ -558,7 +558,7 @@ impl Drop for Droppable {
}

#[bench]
fn bench_in_place_collect_droppable(b: &mut test::Bencher) {
fn bench_in_place_collect_droppable(b: &mut Bencher) {
let v: Vec<Droppable> = std::iter::repeat_with(|| Droppable(0)).take(1000).collect();
b.iter(|| {
v.clone()
Expand All @@ -571,13 +571,13 @@ fn bench_in_place_collect_droppable(b: &mut test::Bencher) {
}

#[bench]
fn bench_chain_collect(b: &mut test::Bencher) {
fn bench_chain_collect(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| data.iter().cloned().chain([1].iter().cloned()).collect::<Vec<_>>());
}

#[bench]
fn bench_chain_chain_collect(b: &mut test::Bencher) {
fn bench_chain_chain_collect(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| {
data.iter()
Expand All @@ -589,7 +589,7 @@ fn bench_chain_chain_collect(b: &mut test::Bencher) {
}

#[bench]
fn bench_nest_chain_chain_collect(b: &mut test::Bencher) {
fn bench_nest_chain_chain_collect(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| {
data.iter().cloned().chain([1].iter().chain([2].iter()).cloned()).collect::<Vec<_>>()
Expand All @@ -616,12 +616,12 @@ pub fn map_fast(l: &[(u32, u32)]) -> Vec<u32> {
const LEN: usize = 16384;

#[bench]
fn bench_range_map_collect(b: &mut test::Bencher) {
fn bench_range_map_collect(b: &mut Bencher) {
b.iter(|| (0..LEN).map(|_| u32::default()).collect::<Vec<_>>());
}

#[bench]
fn bench_chain_extend_ref(b: &mut test::Bencher) {
fn bench_chain_extend_ref(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| {
let mut v = Vec::<u32>::with_capacity(data.len() + 1);
Expand All @@ -631,7 +631,7 @@ fn bench_chain_extend_ref(b: &mut test::Bencher) {
}

#[bench]
fn bench_chain_extend_value(b: &mut test::Bencher) {
fn bench_chain_extend_value(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| {
let mut v = Vec::<u32>::with_capacity(data.len() + 1);
Expand All @@ -641,7 +641,7 @@ fn bench_chain_extend_value(b: &mut test::Bencher) {
}

#[bench]
fn bench_rev_1(b: &mut test::Bencher) {
fn bench_rev_1(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| {
let mut v = Vec::<u32>::new();
Expand All @@ -651,13 +651,13 @@ fn bench_rev_1(b: &mut test::Bencher) {
}

#[bench]
fn bench_rev_2(b: &mut test::Bencher) {
fn bench_rev_2(b: &mut Bencher) {
let data = black_box([0; LEN]);
b.iter(|| example_plain_slow(&data));
}

#[bench]
fn bench_map_regular(b: &mut test::Bencher) {
fn bench_map_regular(b: &mut Bencher) {
let data = black_box([(0, 0); LEN]);
b.iter(|| {
let mut v = Vec::<u32>::new();
Expand All @@ -667,7 +667,7 @@ fn bench_map_regular(b: &mut test::Bencher) {
}

#[bench]
fn bench_map_fast(b: &mut test::Bencher) {
fn bench_map_fast(b: &mut Bencher) {
let data = black_box([(0, 0); LEN]);
b.iter(|| map_fast(&data));
}
19 changes: 19 additions & 0 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
let min_len = if is_root { 1 } else { node::MIN_LEN };
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);

for idx in 0..=node.len() {
let edge = unsafe { node::Handle::new_edge(node, idx) };
assert!(edge.descend().ascend().ok().unwrap() == edge);
}

internal_length += node.len();
}
Position::InternalKV(kv) => {
Expand Down Expand Up @@ -1846,3 +1851,17 @@ fn test_into_values() {
assert!(values.contains(&'b'));
assert!(values.contains(&'c'));
}

#[test]
fn test_insert_remove_intertwined() {
let loops = if cfg!(miri) { 100 } else { 1_000_000 };
let mut map = BTreeMap::new();
let mut i = 1;
for _ in 0..loops {
i = (i + 421) & 0xFF;
map.insert(i, i);
map.remove(&(0xFF - i));
}

map.check();
}
12 changes: 6 additions & 6 deletions library/alloc/src/collections/btree/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,8 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
}

impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
/// Adds a key/value pair and an edge to go to the right of that pair to
/// the end of the node.
/// Adds a key/value pair, and an edge to go to the right of that pair,
/// to the end of the node.
pub fn push(&mut self, key: K, val: V, edge: Root<K, V>) {
assert!(edge.height == self.height - 1);

Expand All @@ -630,8 +630,8 @@ impl<'a, K: 'a, V: 'a> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
}
}

/// Adds a key/value pair and an edge to go to the left of that pair to
/// the beginning of the node.
/// Adds a key/value pair, and an edge to go to the left of that pair,
/// to the beginning of the node.
pub fn push_front(&mut self, key: K, val: V, edge: Root<K, V>) {
assert!(edge.height == self.height - 1);
assert!(self.len() < CAPACITY);
Expand Down Expand Up @@ -1152,7 +1152,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
///
/// - The node is truncated to only contain the key/value pairs to the right of
/// this handle.
/// - The key and value pointed to by this handle and extracted.
/// - The key and value pointed to by this handle are extracted.
/// - All the key/value pairs to the right of this handle are put into a newly
/// allocated node.
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, K, V, Root<K, V>) {
Expand Down Expand Up @@ -1196,7 +1196,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
///
/// - The node is truncated to only contain the edges and key/value pairs to the
/// right of this handle.
/// - The key and value pointed to by this handle and extracted.
/// - The key and value pointed to by this handle are extracted.
/// - All the edges and key/value pairs to the right of this handle are put into
/// a newly allocated node.
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Internal>, K, V, Root<K, V>) {
Expand Down
Loading

0 comments on commit 4eff9b0

Please sign in to comment.