Skip to content
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

Rollup of 5 pull requests #124442

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
b52e4bd
Fix substitution parts having a shifted underline in some cases
ShE3py Apr 25, 2024
babead5
miri core/alloc tests: do not test a 2nd target
RalfJung Apr 26, 2024
82cc02a
Do not ICE on invalid consts when walking mono-reachable blocks
saethlin Apr 27, 2024
24829ee
add test for ICE: tcx.resolutions(()) is not supported for local crat…
matthiaskrgr Apr 27, 2024
52ab0b6
add test for https://github.com/rust-lang/rust/issues/109812
matthiaskrgr Apr 27, 2024
1adf750
add test for Inconsistent rustc_transmute::is_transmutable(...) resul…
matthiaskrgr Apr 27, 2024
3d1a1db
add test for ICE failed to resolve instance for <[f32; 2] as CrossPro…
matthiaskrgr Apr 27, 2024
6a5f02b
add test for const generic ty's with lifetimes cause opaque types to ICE
matthiaskrgr Apr 27, 2024
a54988a
add test for ice future has no bound vars.
matthiaskrgr Apr 27, 2024
f7b9861
add test for ice expected-type-of-closure-body-to-be-a-closure-or-cor…
matthiaskrgr Apr 27, 2024
4faaa53
doc: Replace mod.rs with the appropriate link
linyihai Apr 27, 2024
09a2a71
Rollup merge of #124370 - ShE3py:substitution-part-offset, r=fee1-dead
matthiaskrgr Apr 27, 2024
a6b35f5
Rollup merge of #124405 - RalfJung:miri-core-alloc-tests, r=clubby789
matthiaskrgr Apr 27, 2024
af621a4
Rollup merge of #124425 - saethlin:ceci-nest-pas-une-ice, r=compiler-…
matthiaskrgr Apr 27, 2024
625f5d4
Rollup merge of #124435 - matthiaskrgr:tests, r=jieyouxu
matthiaskrgr Apr 27, 2024
03a1bd8
Rollup merge of #124437 - linyihai:doc-link-typeck, r=compiler-errors
matthiaskrgr Apr 27, 2024
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
4 changes: 2 additions & 2 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2019,7 +2019,7 @@ impl HumanEmitter {
let offset: isize = offsets
.iter()
.filter_map(
|(start, v)| if span_start_pos <= *start { None } else { Some(v) },
|(start, v)| if span_start_pos < *start { None } else { Some(v) },
)
.sum();
let underline_start = (span_start_pos + start) as isize + offset;
Expand All @@ -2028,7 +2028,7 @@ impl HumanEmitter {
let padding: usize = max_line_num_len + 3;
for p in underline_start..underline_end {
if let DisplaySuggestion::Underline = show_code_change {
// If this is a replacement, underline with `^`, if this is an addition
// If this is a replacement, underline with `~`, if this is an addition
// underline with `+`.
buffer.putc(
row_num,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Type checking expressions.
//!
//! See `mod.rs` for more context on type checking in general.
//! See [`rustc_hir_analysis::check`] for more context on type checking in general.

use crate::cast;
use crate::coercion::CoerceMany;
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,7 @@ impl<'tcx> Body<'tcx> {
env,
crate::ty::EarlyBinder::bind(constant.const_),
);
let Some(bits) = mono_literal.try_eval_bits(tcx, env) else {
bug!("Couldn't evaluate constant {:?} in mono {:?}", constant, instance);
};
bits
mono_literal.try_eval_bits(tcx, env)
};

let TerminatorKind::SwitchInt { discr, targets } = &block.terminator().kind else {
Expand All @@ -714,7 +711,7 @@ impl<'tcx> Body<'tcx> {
// If this is a SwitchInt(const _), then we can just evaluate the constant and return.
let discr = match discr {
Operand::Constant(constant) => {
let bits = eval_mono_const(constant);
let bits = eval_mono_const(constant)?;
return Some((bits, targets));
}
Operand::Move(place) | Operand::Copy(place) => place,
Expand Down Expand Up @@ -748,7 +745,7 @@ impl<'tcx> Body<'tcx> {
match rvalue {
Rvalue::NullaryOp(NullOp::UbChecks, _) => Some((tcx.sess.ub_checks() as u128, targets)),
Rvalue::Use(Operand::Constant(constant)) => {
let bits = eval_mono_const(constant);
let bits = eval_mono_const(constant)?;
Some((bits, targets))
}
_ => None,
Expand Down
3 changes: 0 additions & 3 deletions src/bootstrap/mk/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,12 @@ check-aux:
src/tools/cargotest \
$(BOOTSTRAP_ARGS)
# Run standard library tests in Miri.
# We use a 64bit little-endian and a 32bit big-endian target for max coverage.
$(Q)BOOTSTRAP_SKIP_TARGET_SANITY=1 \
$(BOOTSTRAP) miri --stage 2 \
--target x86_64-unknown-linux-gnu,mips-unknown-linux-gnu \
library/core \
library/alloc \
--no-doc
# Some doctests have intentional memory leaks.
# Also, they work only on the host.
$(Q)MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" \
$(BOOTSTRAP) miri --stage 2 \
library/core \
Expand Down
22 changes: 22 additions & 0 deletions tests/crashes/109812.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//@ known-bug: #109812

#![warn(rust_2021_incompatible_closure_captures)]

enum Either {
One(X),
Two(X),
}

struct X(Y);

struct Y;

fn move_into_fnmut() {
let x = X(Y);

consume_fnmut(|| {
let Either::Two(ref mut _t) = x;

let X(mut _t) = x;
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@ edition:2021
// issues rust-lang/rust#111911
// test for ICE opaque type with non-universal region substs

#![feature(adt_const_params)]
#![allow(incomplete_features)]

pub async fn foo<const X: &'static str>() {}
//~^ ERROR const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
//~| ERROR const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
fn bar<const N: &'static u8>() -> impl Sized {}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
error: const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/opaque_type_with_non-universal_region_substs_ice-111911.rs:8:43
|
LL | pub async fn foo<const X: &'static str>() {}
| ^^

error: const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
--> $DIR/opaque_type_with_non-universal_region_substs_ice-111911.rs:8:43
|
LL | pub async fn foo<const X: &'static str>() {}
| ^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// ICE Inconsistent rustc_transmute::is_transmutable(...) result, got Yes
// issue: rust-lang/rust#110969
#![feature(adt_const_params, generic_const_exprs, transmutability)]
#![allow(incomplete_features, unstable_features)]

mod assert {
use std::mem::BikeshedIntrinsicFrom;

pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
where
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
//~^ ERROR trait takes at most 2 generic arguments but 3 generic arguments were supplied
{
}
}

fn via_associated_const() {
struct Context;
#[repr(C)]
struct Src;
#[repr(C)]
struct Dst;

trait Trait {
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
//~^ ERROR mismatched types
//~| ERROR `Src` cannot be safely transmuted into `Dst`
//~| ERROR mismatched types
}
}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments were supplied
--> $DIR/transmutable-ice-110969.rs:11:14
|
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
| ^^^^^^^^^^^^^^^^^^^^^ ------ help: remove this generic argument
| |
| expected at most 2 generic arguments

error[E0308]: mismatched types
--> $DIR/transmutable-ice-110969.rs:25:74
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^ expected `Assume`, found `()`

error[E0277]: `Src` cannot be safely transmuted into `Dst`
--> $DIR/transmutable-ice-110969.rs:25:60
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^^ `Dst` may carry safety invariants
|
note: required by a bound in `is_transmutable`
--> $DIR/transmutable-ice-110969.rs:11:14
|
LL | pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
| --------------- required by a bound in this function
LL | where
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable`

error[E0308]: mismatched types
--> $DIR/transmutable-ice-110969.rs:25:29
|
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`

error: aborting due to 4 previous errors

Some errors have detailed explanations: E0107, E0277, E0308.
For more information about an error, try `rustc --explain E0107`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// issue: rust-lang/rust#113776
// ice: expected type of closure body to be a closure or coroutine
//@ edition: 2021
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]

use core::ops::SubAssign;

fn f<T>(
data: &[(); {
let f: F = async { 1 };
//~^ ERROR cannot find type `F` in this scope

1
}],
) -> impl Iterator<Item = SubAssign> {
//~^ ERROR the type parameter `Rhs` must be explicitly specified
//~| ERROR `()` is not an iterator
//~| ERROR trait objects must include the `dyn` keyword
//~| ERROR the type parameter `Rhs` must be explicitly specified [E0393]
}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
error[E0412]: cannot find type `F` in this scope
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:11:17
|
LL | let f: F = async { 1 };
| ^
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
|
= note: similarly named trait `Fn` defined here
|
help: a trait with a similar name exists
|
LL | let f: Fn = async { 1 };
| ~~
help: you might be missing a type parameter
|
LL | fn f<T, F>(
| +++

error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
= note: type parameter `Rhs` must be specified for this
|
= note: because of the default `Self` reference, type parameters must be specified on object types

error[E0393]: the type parameter `Rhs` must be explicitly specified
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
|
= note: type parameter `Rhs` must be specified for this
|
= note: because of the default `Self` reference, type parameters must be specified on object types
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0277]: `()` is not an iterator
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
|
= help: the trait `Iterator` is not implemented for `()`

error[E0782]: trait objects must include the `dyn` keyword
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
|
LL | ) -> impl Iterator<Item = SubAssign> {
| ^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
LL | ) -> impl Iterator<Item = dyn SubAssign> {
| +++
help: you might have meant to write a bound here
|
LL | ) -> impl Iterator<Item: SubAssign> {
| ~

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0277, E0393, E0412, E0782.
For more information about an error, try `rustc --explain E0277`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// issue rust-lang/rust#111667
// ICE failed to resolve instance for <[f32; 2] as CrossProduct ..
//@ check-pass

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

pub trait CrossProduct<'a, T, R> {
fn cross(&'a self, t: &'a T) -> R;
}

impl<'a, T, U, const N: usize> CrossProduct<'a, [U; N], [(&'a T, &'a U); N * N]> for [T; N] {
fn cross(&'a self, us: &'a [U; N]) -> [(&'a T, &'a U); N * N] {
std::array::from_fn(|i| (&self[i / N], &us[i % N]))
}
}

pub fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/consts/mono-reachable-invalid-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//@ build-fail

struct Bar<const BITS: usize>;

impl<const BITS: usize> Bar<BITS> {
const ASSERT: bool = {
let b = std::convert::identity(1);
["oops"][b]; //~ ERROR evaluation of `Bar::<0>::ASSERT` failed
true
};

fn assert() {
let val = Self::ASSERT;
if val {
std::convert::identity(val);
}
}
}


fn main() {
Bar::<0>::assert();
}
29 changes: 29 additions & 0 deletions tests/ui/consts/mono-reachable-invalid-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
error[E0080]: evaluation of `Bar::<0>::ASSERT` failed
--> $DIR/mono-reachable-invalid-const.rs:8:9
|
LL | ["oops"][b];
| ^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1

note: erroneous constant encountered
--> $DIR/mono-reachable-invalid-const.rs:13:19
|
LL | let val = Self::ASSERT;
| ^^^^^^^^^^^^

note: erroneous constant encountered
--> $DIR/mono-reachable-invalid-const.rs:13:19
|
LL | let val = Self::ASSERT;
| ^^^^^^^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

note: the above error was encountered while instantiating `fn Bar::<0>::assert`
--> $DIR/mono-reachable-invalid-const.rs:22:5
|
LL | Bar::<0>::assert();
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
29 changes: 29 additions & 0 deletions tests/ui/impl-trait/future-no-bound-vars-ice-112347.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// issue: rust-lang/rust#112347
// ICE future has no bound vars
//@ edition:2021
//@ check-pass

#![feature(type_alias_impl_trait)]

use std::future::Future;

type Fut<'a> = impl Future<Output = ()> + 'a;

fn foo<'a>(_: &()) -> Fut<'_> {
async {}
}

trait Test {
fn hello();
}

impl Test for ()
where
for<'a> Fut<'a>: Future<Output = ()>,
{
fn hello() {}
}

fn main() {
<()>::hello();
}
Loading
Loading