Skip to content

Commit 919c89b

Browse files
committed
Auto merge of rust-lang#124442 - matthiaskrgr:rollup-eims8ym, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#124370 (Fix substitution parts having a shifted underline in some cases) - rust-lang#124405 (miri core/alloc tests: do not test a 2nd target) - rust-lang#124425 (Do not ICE on invalid consts when walking mono-reachable blocks) - rust-lang#124435 (add more tests) - rust-lang#124437 (doc: Make the `mod.rs` in the comment point to the correct location) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 61a1dbd + 03a1bd8 commit 919c89b

18 files changed

+336
-13
lines changed

compiler/rustc_errors/src/emitter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2019,7 +2019,7 @@ impl HumanEmitter {
20192019
let offset: isize = offsets
20202020
.iter()
20212021
.filter_map(
2022-
|(start, v)| if span_start_pos <= *start { None } else { Some(v) },
2022+
|(start, v)| if span_start_pos < *start { None } else { Some(v) },
20232023
)
20242024
.sum();
20252025
let underline_start = (span_start_pos + start) as isize + offset;
@@ -2028,7 +2028,7 @@ impl HumanEmitter {
20282028
let padding: usize = max_line_num_len + 3;
20292029
for p in underline_start..underline_end {
20302030
if let DisplaySuggestion::Underline = show_code_change {
2031-
// If this is a replacement, underline with `^`, if this is an addition
2031+
// If this is a replacement, underline with `~`, if this is an addition
20322032
// underline with `+`.
20332033
buffer.putc(
20342034
row_num,

compiler/rustc_hir_typeck/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Type checking expressions.
22
//!
3-
//! See `mod.rs` for more context on type checking in general.
3+
//! See [`rustc_hir_analysis::check`] for more context on type checking in general.
44
55
use crate::cast;
66
use crate::coercion::CoerceMany;

compiler/rustc_middle/src/mir/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -701,10 +701,7 @@ impl<'tcx> Body<'tcx> {
701701
env,
702702
crate::ty::EarlyBinder::bind(constant.const_),
703703
);
704-
let Some(bits) = mono_literal.try_eval_bits(tcx, env) else {
705-
bug!("Couldn't evaluate constant {:?} in mono {:?}", constant, instance);
706-
};
707-
bits
704+
mono_literal.try_eval_bits(tcx, env)
708705
};
709706

710707
let TerminatorKind::SwitchInt { discr, targets } = &block.terminator().kind else {
@@ -714,7 +711,7 @@ impl<'tcx> Body<'tcx> {
714711
// If this is a SwitchInt(const _), then we can just evaluate the constant and return.
715712
let discr = match discr {
716713
Operand::Constant(constant) => {
717-
let bits = eval_mono_const(constant);
714+
let bits = eval_mono_const(constant)?;
718715
return Some((bits, targets));
719716
}
720717
Operand::Move(place) | Operand::Copy(place) => place,
@@ -748,7 +745,7 @@ impl<'tcx> Body<'tcx> {
748745
match rvalue {
749746
Rvalue::NullaryOp(NullOp::UbChecks, _) => Some((tcx.sess.ub_checks() as u128, targets)),
750747
Rvalue::Use(Operand::Constant(constant)) => {
751-
let bits = eval_mono_const(constant);
748+
let bits = eval_mono_const(constant)?;
752749
Some((bits, targets))
753750
}
754751
_ => None,

src/bootstrap/mk/Makefile.in

-3
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ check-aux:
5353
src/tools/cargotest \
5454
$(BOOTSTRAP_ARGS)
5555
# Run standard library tests in Miri.
56-
# We use a 64bit little-endian and a 32bit big-endian target for max coverage.
5756
$(Q)BOOTSTRAP_SKIP_TARGET_SANITY=1 \
5857
$(BOOTSTRAP) miri --stage 2 \
59-
--target x86_64-unknown-linux-gnu,mips-unknown-linux-gnu \
6058
library/core \
6159
library/alloc \
6260
--no-doc
6361
# Some doctests have intentional memory leaks.
64-
# Also, they work only on the host.
6562
$(Q)MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" \
6663
$(BOOTSTRAP) miri --stage 2 \
6764
library/core \

tests/crashes/109812.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//@ known-bug: #109812
2+
3+
#![warn(rust_2021_incompatible_closure_captures)]
4+
5+
enum Either {
6+
One(X),
7+
Two(X),
8+
}
9+
10+
struct X(Y);
11+
12+
struct Y;
13+
14+
fn move_into_fnmut() {
15+
let x = X(Y);
16+
17+
consume_fnmut(|| {
18+
let Either::Two(ref mut _t) = x;
19+
20+
let X(mut _t) = x;
21+
});
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ edition:2021
2+
// issues rust-lang/rust#111911
3+
// test for ICE opaque type with non-universal region substs
4+
5+
#![feature(adt_const_params)]
6+
#![allow(incomplete_features)]
7+
8+
pub async fn foo<const X: &'static str>() {}
9+
//~^ ERROR const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
10+
//~| ERROR const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
11+
fn bar<const N: &'static u8>() -> impl Sized {}
12+
13+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
2+
--> $DIR/opaque_type_with_non-universal_region_substs_ice-111911.rs:8:43
3+
|
4+
LL | pub async fn foo<const X: &'static str>() {}
5+
| ^^
6+
7+
error: const parameter `X` is part of concrete type but not used in parameter list for the `impl Trait` type alias
8+
--> $DIR/opaque_type_with_non-universal_region_substs_ice-111911.rs:8:43
9+
|
10+
LL | pub async fn foo<const X: &'static str>() {}
11+
| ^^
12+
|
13+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
14+
15+
error: aborting due to 2 previous errors
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// ICE Inconsistent rustc_transmute::is_transmutable(...) result, got Yes
2+
// issue: rust-lang/rust#110969
3+
#![feature(adt_const_params, generic_const_exprs, transmutability)]
4+
#![allow(incomplete_features, unstable_features)]
5+
6+
mod assert {
7+
use std::mem::BikeshedIntrinsicFrom;
8+
9+
pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
10+
where
11+
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
12+
//~^ ERROR trait takes at most 2 generic arguments but 3 generic arguments were supplied
13+
{
14+
}
15+
}
16+
17+
fn via_associated_const() {
18+
struct Context;
19+
#[repr(C)]
20+
struct Src;
21+
#[repr(C)]
22+
struct Dst;
23+
24+
trait Trait {
25+
const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
26+
//~^ ERROR mismatched types
27+
//~| ERROR `Src` cannot be safely transmuted into `Dst`
28+
//~| ERROR mismatched types
29+
}
30+
}
31+
32+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments were supplied
2+
--> $DIR/transmutable-ice-110969.rs:11:14
3+
|
4+
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
5+
| ^^^^^^^^^^^^^^^^^^^^^ ------ help: remove this generic argument
6+
| |
7+
| expected at most 2 generic arguments
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/transmutable-ice-110969.rs:25:74
11+
|
12+
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
13+
| ^^ expected `Assume`, found `()`
14+
15+
error[E0277]: `Src` cannot be safely transmuted into `Dst`
16+
--> $DIR/transmutable-ice-110969.rs:25:60
17+
|
18+
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
19+
| ^^^ `Dst` may carry safety invariants
20+
|
21+
note: required by a bound in `is_transmutable`
22+
--> $DIR/transmutable-ice-110969.rs:11:14
23+
|
24+
LL | pub fn is_transmutable<Src, Dst, Context, const ASSUME: std::mem::Assume>()
25+
| --------------- required by a bound in this function
26+
LL | where
27+
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
28+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `is_transmutable`
29+
30+
error[E0308]: mismatched types
31+
--> $DIR/transmutable-ice-110969.rs:25:29
32+
|
33+
LL | const FALSE: bool = assert::is_transmutable::<Src, Dst, Context, {}>();
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
35+
36+
error: aborting due to 4 previous errors
37+
38+
Some errors have detailed explanations: E0107, E0277, E0308.
39+
For more information about an error, try `rustc --explain E0107`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// issue: rust-lang/rust#113776
2+
// ice: expected type of closure body to be a closure or coroutine
3+
//@ edition: 2021
4+
#![allow(incomplete_features)]
5+
#![feature(generic_const_exprs)]
6+
7+
use core::ops::SubAssign;
8+
9+
fn f<T>(
10+
data: &[(); {
11+
let f: F = async { 1 };
12+
//~^ ERROR cannot find type `F` in this scope
13+
14+
1
15+
}],
16+
) -> impl Iterator<Item = SubAssign> {
17+
//~^ ERROR the type parameter `Rhs` must be explicitly specified
18+
//~| ERROR `()` is not an iterator
19+
//~| ERROR trait objects must include the `dyn` keyword
20+
//~| ERROR the type parameter `Rhs` must be explicitly specified [E0393]
21+
}
22+
23+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
error[E0412]: cannot find type `F` in this scope
2+
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:11:17
3+
|
4+
LL | let f: F = async { 1 };
5+
| ^
6+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
7+
|
8+
= note: similarly named trait `Fn` defined here
9+
|
10+
help: a trait with a similar name exists
11+
|
12+
LL | let f: Fn = async { 1 };
13+
| ~~
14+
help: you might be missing a type parameter
15+
|
16+
LL | fn f<T, F>(
17+
| +++
18+
19+
error[E0393]: the type parameter `Rhs` must be explicitly specified
20+
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
21+
|
22+
LL | ) -> impl Iterator<Item = SubAssign> {
23+
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
24+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
25+
|
26+
= note: type parameter `Rhs` must be specified for this
27+
|
28+
= note: because of the default `Self` reference, type parameters must be specified on object types
29+
30+
error[E0393]: the type parameter `Rhs` must be explicitly specified
31+
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
32+
|
33+
LL | ) -> impl Iterator<Item = SubAssign> {
34+
| ^^^^^^^^^ help: set the type parameter to the desired type: `SubAssign<Rhs>`
35+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
36+
|
37+
= note: type parameter `Rhs` must be specified for this
38+
|
39+
= note: because of the default `Self` reference, type parameters must be specified on object types
40+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
41+
42+
error[E0277]: `()` is not an iterator
43+
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:6
44+
|
45+
LL | ) -> impl Iterator<Item = SubAssign> {
46+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `()` is not an iterator
47+
|
48+
= help: the trait `Iterator` is not implemented for `()`
49+
50+
error[E0782]: trait objects must include the `dyn` keyword
51+
--> $DIR/expected-type-of-closure-body-to-be-a-closure-or-coroutine-ice-113776.rs:16:27
52+
|
53+
LL | ) -> impl Iterator<Item = SubAssign> {
54+
| ^^^^^^^^^
55+
|
56+
help: add `dyn` keyword before this trait
57+
|
58+
LL | ) -> impl Iterator<Item = dyn SubAssign> {
59+
| +++
60+
help: you might have meant to write a bound here
61+
|
62+
LL | ) -> impl Iterator<Item: SubAssign> {
63+
| ~
64+
65+
error: aborting due to 5 previous errors
66+
67+
Some errors have detailed explanations: E0277, E0393, E0412, E0782.
68+
For more information about an error, try `rustc --explain E0277`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// issue rust-lang/rust#111667
2+
// ICE failed to resolve instance for <[f32; 2] as CrossProduct ..
3+
//@ check-pass
4+
5+
#![feature(generic_const_exprs)]
6+
#![allow(incomplete_features)]
7+
8+
pub trait CrossProduct<'a, T, R> {
9+
fn cross(&'a self, t: &'a T) -> R;
10+
}
11+
12+
impl<'a, T, U, const N: usize> CrossProduct<'a, [U; N], [(&'a T, &'a U); N * N]> for [T; N] {
13+
fn cross(&'a self, us: &'a [U; N]) -> [(&'a T, &'a U); N * N] {
14+
std::array::from_fn(|i| (&self[i / N], &us[i % N]))
15+
}
16+
}
17+
18+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//@ build-fail
2+
3+
struct Bar<const BITS: usize>;
4+
5+
impl<const BITS: usize> Bar<BITS> {
6+
const ASSERT: bool = {
7+
let b = std::convert::identity(1);
8+
["oops"][b]; //~ ERROR evaluation of `Bar::<0>::ASSERT` failed
9+
true
10+
};
11+
12+
fn assert() {
13+
let val = Self::ASSERT;
14+
if val {
15+
std::convert::identity(val);
16+
}
17+
}
18+
}
19+
20+
21+
fn main() {
22+
Bar::<0>::assert();
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
error[E0080]: evaluation of `Bar::<0>::ASSERT` failed
2+
--> $DIR/mono-reachable-invalid-const.rs:8:9
3+
|
4+
LL | ["oops"][b];
5+
| ^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1
6+
7+
note: erroneous constant encountered
8+
--> $DIR/mono-reachable-invalid-const.rs:13:19
9+
|
10+
LL | let val = Self::ASSERT;
11+
| ^^^^^^^^^^^^
12+
13+
note: erroneous constant encountered
14+
--> $DIR/mono-reachable-invalid-const.rs:13:19
15+
|
16+
LL | let val = Self::ASSERT;
17+
| ^^^^^^^^^^^^
18+
|
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
21+
note: the above error was encountered while instantiating `fn Bar::<0>::assert`
22+
--> $DIR/mono-reachable-invalid-const.rs:22:5
23+
|
24+
LL | Bar::<0>::assert();
25+
| ^^^^^^^^^^^^^^^^^^
26+
27+
error: aborting due to 1 previous error
28+
29+
For more information about this error, try `rustc --explain E0080`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// issue: rust-lang/rust#112347
2+
// ICE future has no bound vars
3+
//@ edition:2021
4+
//@ check-pass
5+
6+
#![feature(type_alias_impl_trait)]
7+
8+
use std::future::Future;
9+
10+
type Fut<'a> = impl Future<Output = ()> + 'a;
11+
12+
fn foo<'a>(_: &()) -> Fut<'_> {
13+
async {}
14+
}
15+
16+
trait Test {
17+
fn hello();
18+
}
19+
20+
impl Test for ()
21+
where
22+
for<'a> Fut<'a>: Future<Output = ()>,
23+
{
24+
fn hello() {}
25+
}
26+
27+
fn main() {
28+
<()>::hello();
29+
}

0 commit comments

Comments
 (0)