Skip to content

Commit 1120301

Browse files
committed
uwu error message
1 parent e94b1b9 commit 1120301

20 files changed

+187
-27
lines changed

compiler/rustc_const_eval/src/interpret/util.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ where
1313
T: TypeVisitable<'tcx>,
1414
{
1515
debug!("ensure_monomorphic_enough: ty={:?}", ty);
16-
if !ty.needs_subst() {
16+
if !(ty.needs_subst() || ty.has_opaque_types()) {
1717
return Ok(());
1818
}
1919

@@ -31,7 +31,7 @@ where
3131
}
3232

3333
match *ty.kind() {
34-
ty::Param(_) => ControlFlow::Break(FoundParam),
34+
ty::Param(_) | ty::Opaque(..) => ControlFlow::Break(FoundParam),
3535
ty::Closure(def_id, substs)
3636
| ty::Generator(def_id, substs, ..)
3737
| ty::FnDef(def_id, substs) => {

compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
186186
let concrete = infcx.const_eval_resolve(param_env, uv.expand(), Some(span));
187187
match concrete {
188188
Err(ErrorHandled::TooGeneric) => {
189-
Err(NotConstEvaluatable::Error(infcx.tcx.sess.delay_span_bug(
189+
Err(NotConstEvaluatable::Error(infcx.tcx.sess.span_err(
190190
span,
191-
format!("Missing value for constant, but no error reported?"),
191+
format!("unable to use constant with a hidden value in the type system"),
192192
)))
193193
}
194194
Err(ErrorHandled::Linted) => {
@@ -237,11 +237,13 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
237237

238238
Err(ErrorHandled::TooGeneric) => Err(if uv.has_infer_types_or_consts() {
239239
NotConstEvaluatable::MentionsInfer
240-
} else if uv.has_param_types_or_consts() {
240+
} else if uv.has_param_types_or_consts() {
241241
NotConstEvaluatable::MentionsParam
242242
} else {
243-
let guar = infcx.tcx.sess.delay_span_bug(span, format!("Missing value for constant, but no error reported?"));
244-
NotConstEvaluatable::Error(guar)
243+
NotConstEvaluatable::Error(infcx.tcx.sess.span_err(
244+
span,
245+
format!("unable to use constant with a hidden value in the type system"),
246+
))
245247
}),
246248
Err(ErrorHandled::Linted) => {
247249
let reported =

src/test/ui/const-generics/generic_const_exprs/issue-76595.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ fn test<T, const P: usize>() where Bool<{core::mem::size_of::<T>() > 4}>: True {
1414
fn main() {
1515
test::<2>();
1616
//~^ ERROR this function takes 2 generic arguments
17+
//~| ERROR unable to use constant with a hidden value in the type system
1718
}

src/test/ui/const-generics/generic_const_exprs/issue-76595.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ help: add missing generic argument
1616
LL | test::<2, P>();
1717
| +++
1818

19-
error: aborting due to previous error
19+
error: unable to use constant with a hidden value in the type system
20+
--> $DIR/issue-76595.rs:15:5
21+
|
22+
LL | test::<2>();
23+
| ^^^^^^^^^
24+
25+
error: aborting due to 2 previous errors
2026

2127
For more information about this error, try `rustc --explain E0107`.

src/test/ui/const-generics/issues/issue-86530.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ where
1515
fn unit_literals() {
1616
z(" ");
1717
//~^ ERROR: the trait bound `&str: X` is not satisfied
18+
//~| ERROR: unable to use constant with a hidden value in the type system
1819
}
1920

2021
fn main() {}

src/test/ui/const-generics/issues/issue-86530.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error: unable to use constant with a hidden value in the type system
2+
--> $DIR/issue-86530.rs:16:5
3+
|
4+
LL | z(" ");
5+
| ^
6+
17
error[E0277]: the trait bound `&str: X` is not satisfied
28
--> $DIR/issue-86530.rs:16:7
39
|
@@ -15,6 +21,6 @@ LL | where
1521
LL | T: X,
1622
| ^ required by this bound in `z`
1723

18-
error: aborting due to previous error
24+
error: aborting due to 2 previous errors
1925

2026
For more information about this error, try `rustc --explain E0277`.

src/test/ui/const-generics/issues/issue-98629.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ trait Trait {
44
const N: usize;
55
}
66

7+
// FIXME: We should mention that `N` is missing
78
impl const Trait for i32 {}
8-
//~^ ERROR not all trait items implemented, missing: `N`
99

1010
fn f()
1111
where
1212
[(); <i32 as Trait>::N]:,
13+
//~^ ERROR unable to use constant with a hidden value in the type system
1314
{}
1415

1516
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
error[E0046]: not all trait items implemented, missing: `N`
2-
--> $DIR/issue-98629.rs:7:1
1+
error: unable to use constant with a hidden value in the type system
2+
--> $DIR/issue-98629.rs:11:5
33
|
4-
LL | const N: usize;
5-
| -------------- `N` from trait
6-
...
7-
LL | impl const Trait for i32 {}
8-
| ^^^^^^^^^^^^^^^^^^^^^^^^ missing `N` in implementation
4+
LL | [(); <i32 as Trait>::N]:,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
96

107
error: aborting due to previous error
118

12-
For more information about this error, try `rustc --explain E0046`.

src/test/ui/impl-trait/in-ctfe/array-len.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This previously compiled, but broke with #101478.
1+
// This previously compiled, but was intentionally changed in #101478.
22
//
33
// See that PR for more details.
44
trait MyTrait: Copy {
@@ -19,5 +19,7 @@ const fn output<T: MyTrait>(_: T) -> usize {
1919

2020
fn main() {
2121
let x = [0u8; output(yeet())];
22+
//~^ ERROR unable to use constant with a hidden value in the type system
2223
println!("{:?}", x);
24+
//~^ ERROR unable to use constant with a hidden value in the type system
2325
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: unable to use constant with a hidden value in the type system
2+
--> $DIR/array-len.rs:21:19
3+
|
4+
LL | let x = [0u8; output(yeet())];
5+
| ^^^^^^^^^^^^^^
6+
7+
error: unable to use constant with a hidden value in the type system
8+
--> $DIR/array-len.rs:23:22
9+
|
10+
LL | println!("{:?}", x);
11+
| ^
12+
|
13+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
14+
15+
error: aborting due to 2 previous errors
16+

src/test/ui/impl-trait/in-ctfe/enum-discr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This previously compiled, but broke with #101478.
1+
// This previously compiled, but was intentionally changed in #101478.
22
//
33
// See that PR for more details.
44
trait MyTrait: Copy {
@@ -20,6 +20,7 @@ const fn output<T: MyTrait>(_: T) -> usize {
2020
#[repr(usize)]
2121
enum Foo {
2222
Bar = output(yeet()),
23+
//~^ ERROR unable to use constant with a hidden value in the type system
2324
}
2425

2526
fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: unable to use constant with a hidden value in the type system
2+
--> $DIR/enum-discr.rs:22:11
3+
|
4+
LL | Bar = output(yeet()),
5+
| ^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

src/test/ui/impl-trait/in-ctfe/match-arm-exhaustive.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This previously compiled, but broke with #101478.
1+
// This previously compiled, but was intentionally changed in #101478.
22
//
33
// See that PR for more details.
44
trait MyTrait: Copy {
@@ -20,6 +20,8 @@ const CT: u8 = output(yeet());
2020
fn main() {
2121
match 0 {
2222
CT => (),
23+
//~^ ERROR constant pattern depends on a generic parameter
24+
//~| ERROR constant pattern depends on a generic parameter
2325
1.. => (),
2426
}
2527
}

src/test/ui/impl-trait/in-ctfe/match-arm-exhaustive.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: constant pattern depends on a generic parameter
2-
--> $DIR/match-arm-exhaustive.rs:19:9
2+
--> $DIR/match-arm-exhaustive.rs:22:9
33
|
44
LL | CT => (),
55
| ^^
66

77
error: constant pattern depends on a generic parameter
8-
--> $DIR/match-arm-exhaustive.rs:19:9
8+
--> $DIR/match-arm-exhaustive.rs:22:9
99
|
1010
LL | CT => (),
1111
| ^^

src/test/ui/issues/issue-77919.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fn main() {
22
[1; <Multiply<Five, Five>>::VAL];
3+
//~^ ERROR unable to use constant with a hidden value in the type system
34
}
45
trait TypeVal<T> {
56
const VAL: T;

src/test/ui/issues/issue-77919.stderr

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0412]: cannot find type `PhantomData` in this scope
2-
--> $DIR/issue-77919.rs:9:9
2+
--> $DIR/issue-77919.rs:10:9
33
|
44
LL | _n: PhantomData,
55
| ^^^^^^^^^^^ not found in this scope
@@ -10,23 +10,29 @@ LL | use std::marker::PhantomData;
1010
|
1111

1212
error[E0412]: cannot find type `VAL` in this scope
13-
--> $DIR/issue-77919.rs:11:63
13+
--> $DIR/issue-77919.rs:12:63
1414
|
1515
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
1616
| - ^^^ not found in this scope
1717
| |
1818
| help: you might be missing a type parameter: `, VAL`
1919

2020
error[E0046]: not all trait items implemented, missing: `VAL`
21-
--> $DIR/issue-77919.rs:11:1
21+
--> $DIR/issue-77919.rs:12:1
2222
|
2323
LL | const VAL: T;
2424
| ------------ `VAL` from trait
2525
...
2626
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
2727
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `VAL` in implementation
2828

29-
error: aborting due to 3 previous errors
29+
error: unable to use constant with a hidden value in the type system
30+
--> $DIR/issue-77919.rs:2:9
31+
|
32+
LL | [1; <Multiply<Five, Five>>::VAL];
33+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
34+
35+
error: aborting due to 4 previous errors
3036

3137
Some errors have detailed explanations: E0046, E0412.
3238
For more information about an error, try `rustc --explain E0046`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// ICE fixed by #101478.
2+
//
3+
// See that PR for more details.
4+
#![feature(specialization)]
5+
//~^ WARNING the feature `specialization` is incomplete and may not be safe to use
6+
7+
trait Foo {
8+
const ASSOC: usize;
9+
}
10+
11+
12+
impl Foo for u32 {
13+
default const ASSOC: usize = 0;
14+
}
15+
16+
fn foo() -> [u8; 0] {
17+
[0; <u32 as Foo>::ASSOC]
18+
//~^ ERROR unable to use constant with a hidden value in the type system
19+
//~| ERROR mismatched types
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/default-assoc-const.rs:4:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
= help: consider using `min_specialization` instead, which is more stable and complete
10+
11+
error[E0308]: mismatched types
12+
--> $DIR/default-assoc-const.rs:17:5
13+
|
14+
LL | fn foo() -> [u8; 0] {
15+
| ------- expected `[u8; 0]` because of return type
16+
LL | [0; <u32 as Foo>::ASSOC]
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `0`, found `<u32 as Foo>::ASSOC`
18+
|
19+
= note: expected array `[u8; 0]`
20+
found array `[u8; _]`
21+
22+
error: unable to use constant with a hidden value in the type system
23+
--> $DIR/default-assoc-const.rs:17:9
24+
|
25+
LL | [0; <u32 as Foo>::ASSOC]
26+
| ^^^^^^^^^^^^^^^^^^^
27+
28+
error: aborting due to 2 previous errors; 1 warning emitted
29+
30+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// ICE fixed by #101478.
2+
//
3+
// See that PR for more details.
4+
#![feature(specialization)]
5+
//~^ WARNING the feature `specialization` is incomplete and may not be safe to use
6+
7+
trait Foo {
8+
type Assoc: Trait;
9+
}
10+
11+
impl<T> Foo for Vec<T> {
12+
default type Assoc = u32;
13+
}
14+
15+
trait Trait {
16+
const ASSOC: usize;
17+
}
18+
19+
impl Trait for u32 {
20+
const ASSOC: usize = 0;
21+
}
22+
23+
fn foo() -> [u8; 0] {
24+
[0; <<Vec<u32> as Foo>::Assoc as Trait>::ASSOC]
25+
//~^ ERROR unable to use constant with a hidden value in the type system
26+
//~| ERROR mismatched types
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
warning: the feature `specialization` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/default-assoc-type.rs:4:12
3+
|
4+
LL | #![feature(specialization)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
= note: see issue #31844 <https://github.com/rust-lang/rust/issues/31844> for more information
9+
= help: consider using `min_specialization` instead, which is more stable and complete
10+
11+
error[E0308]: mismatched types
12+
--> $DIR/default-assoc-type.rs:24:5
13+
|
14+
LL | fn foo() -> [u8; 0] {
15+
| ------- expected `[u8; 0]` because of return type
16+
LL | [0; <<Vec<u32> as Foo>::Assoc as Trait>::ASSOC]
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `0`, found `<<Vec<u32> as Foo>::Assoc as Trait>::ASSOC`
18+
|
19+
= note: expected array `[u8; 0]`
20+
found array `[u8; _]`
21+
22+
error: unable to use constant with a hidden value in the type system
23+
--> $DIR/default-assoc-type.rs:24:9
24+
|
25+
LL | [0; <<Vec<u32> as Foo>::Assoc as Trait>::ASSOC]
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27+
28+
error: aborting due to 2 previous errors; 1 warning emitted
29+
30+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)