Skip to content

Rollup of 5 pull requests #131210

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ package.json
## Rustdoc GUI tests
tests/rustdoc-gui/src/**.lock

## direnv
.envrc
.direnv/

## nix
flake.nix
flake.lock
default.nix

# Before adding new lines, see the comment at the top.
5 changes: 5 additions & 0 deletions compiler/rustc_middle/src/ty/consts/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,11 @@ impl ScalarInt {
pub fn to_f128(self) -> Quad {
self.to_float()
}

#[inline]
pub fn bitwise_not(self) -> Self {
Self { data: self.size().truncate(!self.data), size: self.size }
}
}

macro_rules! from_x_for_scalar_int {
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_mir_transform/src/coverage/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fn coverage_attr_on(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
Some([item]) if item.has_name(sym::on) => return true,
Some(_) | None => {
// Other possibilities should have been rejected by `rustc_parse::validate_attr`.
tcx.dcx().span_bug(attr.span, "unexpected value of coverage attribute");
// Use `span_delayed_bug` to avoid an ICE in failing builds (#127880).
tcx.dcx().span_delayed_bug(attr.span, "unexpected value of coverage attribute");
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_mir_transform/src/jump_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ impl Condition {
}

fn inv(mut self) -> Self {
self.polarity = match self.polarity {
Polarity::Eq => Polarity::Ne,
Polarity::Ne => Polarity::Eq,
};
self.value = self.value.bitwise_not();

self
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_query_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// tidy-alphabetical-start
#![allow(internal_features)]
#![allow(rustc::potential_query_instability, unused_parens)]
#![allow(unused_parens)]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(min_specialization)]
Expand Down
5 changes: 4 additions & 1 deletion library/alloc/src/collections/binary_heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ impl<'a, T: Ord, A: Allocator> PeekMut<'a, T, A> {
// the caller could've mutated the element. It is removed from the
// heap on the next line and pop() is not sensitive to its value.
}
this.heap.pop().unwrap()

// SAFETY: Have a `PeekMut` element proves that the associated binary heap being non-empty,
// so the `pop` operation will not fail.
unsafe { this.heap.pop().unwrap_unchecked() }
}
}

Expand Down
13 changes: 13 additions & 0 deletions tests/codegen/binary-heap-peek-mut-pop-no-panic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ compile-flags: -O
//@ ignore-debug
#![crate_type = "lib"]

use std::collections::binary_heap::PeekMut;

// CHECK-LABEL: @peek_mut_pop
#[no_mangle]
pub fn peek_mut_pop(peek_mut: PeekMut<u32>) -> u32 {
// CHECK-NOT: panic
// CHECK-NOT: unwrap_failed
PeekMut::pop(peek_mut)
}
5 changes: 0 additions & 5 deletions tests/crashes/127880.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- // MIR for `not_int` before JumpThreading
+ // MIR for `not_int` after JumpThreading

fn not_int() -> i32 {
let mut _0: i32;
let _1: i32;
let mut _2: bool;
let mut _3: i32;
let mut _4: i32;
scope 1 {
debug a => _1;
}

bb0: {
StorageLive(_1);
_1 = const 1_i32;
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_4 = copy _1;
_3 = Not(move _4);
StorageDead(_4);
_2 = Eq(move _3, const 0_i32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ goto -> bb2;
}

bb1: {
StorageDead(_3);
_0 = const 1_i32;
goto -> bb3;
}

bb2: {
StorageDead(_3);
_0 = const 0_i32;
goto -> bb3;
}

bb3: {
StorageDead(_2);
StorageDead(_1);
return;
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
- // MIR for `not_int` before JumpThreading
+ // MIR for `not_int` after JumpThreading

fn not_int() -> i32 {
let mut _0: i32;
let _1: i32;
let mut _2: bool;
let mut _3: i32;
let mut _4: i32;
scope 1 {
debug a => _1;
}

bb0: {
StorageLive(_1);
_1 = const 1_i32;
StorageLive(_2);
StorageLive(_3);
StorageLive(_4);
_4 = copy _1;
_3 = Not(move _4);
StorageDead(_4);
_2 = Eq(move _3, const 0_i32);
- switchInt(move _2) -> [0: bb2, otherwise: bb1];
+ goto -> bb2;
}

bb1: {
StorageDead(_3);
_0 = const 1_i32;
goto -> bb3;
}

bb2: {
StorageDead(_3);
_0 = const 0_i32;
goto -> bb3;
}

bb3: {
StorageDead(_2);
StorageDead(_1);
return;
}
}

17 changes: 17 additions & 0 deletions tests/mir-opt/jump_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,21 @@ fn floats() -> u32 {
if x == 0.0 { 0 } else { 1 }
}

fn not_int() -> i32 {
// CHECK-LABEL: fn not_int(
// CHECK: goto -> bb2

// CHECK-LABEL: bb1: {
// _0 = const 1_i32;

// CHECK-LABEL: bb2: {
// _0 = const 0_i32;
// Test for issue #131195, where !a == b is assumed to be equivalent to a != b
// This is only the case for bools
let a = 1;
if !a == 0 { 1 } else { 0 }
}

fn main() {
// CHECK-LABEL: fn main(
too_complex(Ok(0));
Expand All @@ -546,6 +561,7 @@ fn main() {
aggregate(7);
assume(7, false);
floats();
not_int();
}

// EMIT_MIR jump_threading.too_complex.JumpThreading.diff
Expand All @@ -562,3 +578,4 @@ fn main() {
// EMIT_MIR jump_threading.assume.JumpThreading.diff
// EMIT_MIR jump_threading.aggregate_copy.JumpThreading.diff
// EMIT_MIR jump_threading.floats.JumpThreading.diff
// EMIT_MIR jump_threading.not_int.JumpThreading.diff
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
StorageLive(_4);
StorageLive(_3);
_3 = Gt(copy _2, const 65535_usize);
switchInt(move _3) -> [0: bb1, otherwise: bb5];
switchInt(move _3) -> [0: bb1, otherwise: bb6];
}

bb1: {
Expand All @@ -54,27 +54,30 @@ fn step_forward(_1: u16, _2: usize) -> u16 {
bb3: {
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
goto -> bb7;
goto -> bb5;
}

bb4: {
StorageDead(_5);
StorageDead(_6);
StorageDead(_7);
goto -> bb6;
goto -> bb5;
}

bb5: {
StorageDead(_3);
goto -> bb6;
StorageDead(_7);
goto -> bb7;
}

bb6: {
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u16>::MAX, const 1_u16) -> [success: bb7, unwind continue];
StorageDead(_3);
goto -> bb7;
}

bb7: {
assert(!const true, "attempt to compute `{} + {}`, which would overflow", const core::num::<impl u16>::MAX, const 1_u16) -> [success: bb8, unwind continue];
}

bb8: {
StorageLive(_8);
_8 = copy _2 as u16 (IntToInt);
_0 = Add(copy _1, copy _8);
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.feat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: malformed `coverage` attribute input
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|

error: aborting due to 1 previous error

26 changes: 26 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.nofeat.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: malformed `coverage` attribute input
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|

error[E0658]: the `#[coverage]` attribute is an experimental feature
--> $DIR/bad-attr-ice.rs:10:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
= note: see issue #84605 <https://github.com/rust-lang/rust/issues/84605> for more information
= help: add `#![feature(coverage_attribute)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
16 changes: 16 additions & 0 deletions tests/ui/coverage-attr/bad-attr-ice.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#![cfg_attr(feat, feature(coverage_attribute))]
//@ revisions: feat nofeat
//@ compile-flags: -Cinstrument-coverage
//@ needs-profiler-support

// Malformed `#[coverage(..)]` attributes should not cause an ICE when built
// with `-Cinstrument-coverage`.
// Regression test for <https://github.com/rust-lang/rust/issues/127880>.

#[coverage]
//~^ ERROR malformed `coverage` attribute input
//[nofeat]~| the `#[coverage]` attribute is an experimental feature
fn main() {}

// FIXME(#130766): When the `#[coverage(..)]` attribute is stabilized,
// get rid of the revisions and just make this a normal test.
Loading