Skip to content

Commit 4eff9b0

Browse files
committed
Auto merge of #77013 - RalfJung:rollup-84ut0xq, r=RalfJung
Rollup of 10 pull requests Successful merges: - #76439 (Add error explanation for E0755) - #76521 (Fix segfault if pthread_getattr_np fails) - #76835 (make replace_prefix only take &str as arguments ) - #76967 (Revert adding Atomic::from_mut.) - #76977 (Add a regression test for copy propagation miscompilation) - #76981 (liballoc bench use imported path Bencher) - #76983 (BTreeMap: extra testing & fixed comments) - #76996 (Fix typo in rustc_lexer docs) - #77009 (Dogfood total_cmp in the test crate) - #77012 (update Miri for another bugfix) Failed merges: - #76489 (Add explanation for E0756) r? `@ghost`
2 parents e0bf356 + 6417eb0 commit 4eff9b0

File tree

14 files changed

+120
-148
lines changed

14 files changed

+120
-148
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ E0751: include_str!("./error_codes/E0751.md"),
440440
E0752: include_str!("./error_codes/E0752.md"),
441441
E0753: include_str!("./error_codes/E0753.md"),
442442
E0754: include_str!("./error_codes/E0754.md"),
443+
E0755: include_str!("./error_codes/E0755.md"),
443444
E0758: include_str!("./error_codes/E0758.md"),
444445
E0759: include_str!("./error_codes/E0759.md"),
445446
E0760: include_str!("./error_codes/E0760.md"),
@@ -632,7 +633,6 @@ E0774: include_str!("./error_codes/E0774.md"),
632633
E0722, // Malformed `#[optimize]` attribute
633634
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
634635
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
635-
E0755, // `#[ffi_pure]` is only allowed on foreign functions
636636
E0756, // `#[ffi_const]` is only allowed on foreign functions
637637
E0757, // `#[ffi_const]` functions cannot be `#[ffi_pure]`
638638
E0772, // `'static' obligation coming from `impl dyn Trait {}` or `impl Foo for dyn Bar {}`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
The `ffi_pure` attribute was used on a non-foreign function.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0755
6+
#![feature(ffi_pure)]
7+
8+
#[ffi_pure] // error!
9+
pub fn foo() {}
10+
# fn main() {}
11+
```
12+
13+
The `ffi_pure` attribute can only be used on foreign functions which do not have
14+
side effects or infinite loops:
15+
16+
```
17+
#![feature(ffi_pure)]
18+
19+
extern "C" {
20+
#[ffi_pure] // ok!
21+
pub fn strlen(s: *const i8) -> isize;
22+
}
23+
# fn main() {}
24+
```
25+
26+
You can find more information about it in the [unstable Rust Book].
27+
28+
[unstable Rust Book]: https://doc.rust-lang.org/unstable-book/language-features/ffi-pure.html

compiler/rustc_lexer/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! The idea with `librustc_lexer` is to make a reusable library,
44
//! by separating out pure lexing and rustc-specific concerns, like spans,
5-
//! error reporting an interning. So, rustc_lexer operates directly on `&str`,
5+
//! error reporting, and interning. So, rustc_lexer operates directly on `&str`,
66
//! produces simple tokens which are a pair of type-tag and a bit of original text,
77
//! and does not report errors, instead storing them as flags on the token.
88
//!

compiler/rustc_typeck/src/check/demand.rs

+9-16
Original file line numberDiff line numberDiff line change
@@ -362,16 +362,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
362362
false
363363
}
364364

365-
fn replace_prefix<A, B, C>(&self, s: A, old: B, new: C) -> Option<String>
366-
where
367-
A: AsRef<str>,
368-
B: AsRef<str>,
369-
C: AsRef<str>,
370-
{
371-
let s = s.as_ref();
372-
let old = old.as_ref();
365+
fn replace_prefix(&self, s: &str, old: &str, new: &str) -> Option<String> {
373366
if let Some(stripped) = s.strip_prefix(old) {
374-
Some(new.as_ref().to_owned() + stripped)
367+
Some(new.to_string() + stripped)
375368
} else {
376369
None
377370
}
@@ -422,7 +415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
422415
(&ty::Str, &ty::Array(arr, _) | &ty::Slice(arr)) if arr == self.tcx.types.u8 => {
423416
if let hir::ExprKind::Lit(_) = expr.kind {
424417
if let Ok(src) = sm.span_to_snippet(sp) {
425-
if let Some(src) = self.replace_prefix(src, "b\"", "\"") {
418+
if let Some(src) = self.replace_prefix(&src, "b\"", "\"") {
426419
return Some((
427420
sp,
428421
"consider removing the leading `b`",
@@ -436,7 +429,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
436429
(&ty::Array(arr, _) | &ty::Slice(arr), &ty::Str) if arr == self.tcx.types.u8 => {
437430
if let hir::ExprKind::Lit(_) = expr.kind {
438431
if let Ok(src) = sm.span_to_snippet(sp) {
439-
if let Some(src) = self.replace_prefix(src, "\"", "b\"") {
432+
if let Some(src) = self.replace_prefix(&src, "\"", "b\"") {
440433
return Some((
441434
sp,
442435
"consider adding a leading `b`",
@@ -561,7 +554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
561554
// we may want to suggest removing a `&`.
562555
if sm.is_imported(expr.span) {
563556
if let Ok(src) = sm.span_to_snippet(sp) {
564-
if let Some(src) = self.replace_prefix(src, "&", "") {
557+
if let Some(src) = self.replace_prefix(&src, "&", "") {
565558
return Some((
566559
sp,
567560
"consider removing the borrow",
@@ -598,7 +591,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
598591
match mutbl_a {
599592
hir::Mutability::Mut => {
600593
if let Some(s) =
601-
self.replace_prefix(src, "&mut ", new_prefix)
594+
self.replace_prefix(&src, "&mut ", &new_prefix)
602595
{
603596
Some((s, Applicability::MachineApplicable))
604597
} else {
@@ -607,7 +600,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
607600
}
608601
hir::Mutability::Not => {
609602
if let Some(s) =
610-
self.replace_prefix(src, "&", new_prefix)
603+
self.replace_prefix(&src, "&", &new_prefix)
611604
{
612605
Some((s, Applicability::Unspecified))
613606
} else {
@@ -621,7 +614,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
621614
match mutbl_a {
622615
hir::Mutability::Mut => {
623616
if let Some(s) =
624-
self.replace_prefix(src, "&mut ", new_prefix)
617+
self.replace_prefix(&src, "&mut ", &new_prefix)
625618
{
626619
Some((s, Applicability::MachineApplicable))
627620
} else {
@@ -630,7 +623,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
630623
}
631624
hir::Mutability::Not => {
632625
if let Some(s) =
633-
self.replace_prefix(src, "&", new_prefix)
626+
self.replace_prefix(&src, "&", &new_prefix)
634627
{
635628
Some((s, Applicability::MachineApplicable))
636629
} else {

library/alloc/benches/vec.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ bench_in_place![
496496
];
497497

498498
#[bench]
499-
fn bench_in_place_recycle(b: &mut test::Bencher) {
499+
fn bench_in_place_recycle(b: &mut Bencher) {
500500
let mut data = vec![0; 1000];
501501

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

515515
#[bench]
516-
fn bench_in_place_zip_recycle(b: &mut test::Bencher) {
516+
fn bench_in_place_zip_recycle(b: &mut Bencher) {
517517
let mut data = vec![0u8; 1000];
518518
let mut rng = rand::thread_rng();
519519
let mut subst = vec![0u8; 1000];
@@ -533,7 +533,7 @@ fn bench_in_place_zip_recycle(b: &mut test::Bencher) {
533533
}
534534

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

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

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

579579
#[bench]
580-
fn bench_chain_chain_collect(b: &mut test::Bencher) {
580+
fn bench_chain_chain_collect(b: &mut Bencher) {
581581
let data = black_box([0; LEN]);
582582
b.iter(|| {
583583
data.iter()
@@ -589,7 +589,7 @@ fn bench_chain_chain_collect(b: &mut test::Bencher) {
589589
}
590590

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

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

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

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

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

653653
#[bench]
654-
fn bench_rev_2(b: &mut test::Bencher) {
654+
fn bench_rev_2(b: &mut Bencher) {
655655
let data = black_box([0; LEN]);
656656
b.iter(|| example_plain_slow(&data));
657657
}
658658

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

669669
#[bench]
670-
fn bench_map_fast(b: &mut test::Bencher) {
670+
fn bench_map_fast(b: &mut Bencher) {
671671
let data = black_box([(0, 0); LEN]);
672672
b.iter(|| map_fast(&data));
673673
}

library/alloc/src/collections/btree/map/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ impl<'a, K: 'a, V: 'a> BTreeMap<K, V> {
8888
let min_len = if is_root { 1 } else { node::MIN_LEN };
8989
assert!(node.len() >= min_len, "{} < {}", node.len(), min_len);
9090

91+
for idx in 0..=node.len() {
92+
let edge = unsafe { node::Handle::new_edge(node, idx) };
93+
assert!(edge.descend().ascend().ok().unwrap() == edge);
94+
}
95+
9196
internal_length += node.len();
9297
}
9398
Position::InternalKV(kv) => {
@@ -1846,3 +1851,17 @@ fn test_into_values() {
18461851
assert!(values.contains(&'b'));
18471852
assert!(values.contains(&'c'));
18481853
}
1854+
1855+
#[test]
1856+
fn test_insert_remove_intertwined() {
1857+
let loops = if cfg!(miri) { 100 } else { 1_000_000 };
1858+
let mut map = BTreeMap::new();
1859+
let mut i = 1;
1860+
for _ in 0..loops {
1861+
i = (i + 421) & 0xFF;
1862+
map.insert(i, i);
1863+
map.remove(&(0xFF - i));
1864+
}
1865+
1866+
map.check();
1867+
}

library/alloc/src/collections/btree/node.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ impl<'a, K, V> NodeRef<marker::Mut<'a>, K, V, marker::Internal> {
613613
}
614614

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

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

633-
/// Adds a key/value pair and an edge to go to the left of that pair to
634-
/// the beginning of the node.
633+
/// Adds a key/value pair, and an edge to go to the left of that pair,
634+
/// to the beginning of the node.
635635
pub fn push_front(&mut self, key: K, val: V, edge: Root<K, V>) {
636636
assert!(edge.height == self.height - 1);
637637
assert!(self.len() < CAPACITY);
@@ -1152,7 +1152,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, mark
11521152
///
11531153
/// - The node is truncated to only contain the key/value pairs to the right of
11541154
/// this handle.
1155-
/// - The key and value pointed to by this handle and extracted.
1155+
/// - The key and value pointed to by this handle are extracted.
11561156
/// - All the key/value pairs to the right of this handle are put into a newly
11571157
/// allocated node.
11581158
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, K, V, Root<K, V>) {
@@ -1196,7 +1196,7 @@ impl<'a, K: 'a, V: 'a> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>,
11961196
///
11971197
/// - The node is truncated to only contain the edges and key/value pairs to the
11981198
/// right of this handle.
1199-
/// - The key and value pointed to by this handle and extracted.
1199+
/// - The key and value pointed to by this handle are extracted.
12001200
/// - All the edges and key/value pairs to the right of this handle are put into
12011201
/// a newly allocated node.
12021202
pub fn split(mut self) -> (NodeRef<marker::Mut<'a>, K, V, marker::Internal>, K, V, Root<K, V>) {

0 commit comments

Comments
 (0)