Skip to content

Commit 5d3a963

Browse files
authored
Rollup merge of #133954 - oli-obk:push-lxrmszqzszzu, r=jieyouxu
Hide errors whose suggestions would contain error constants or types best reviewed commit-by-commit. This is work towards cleaning up everything around `lit_to_const` and its mir equivalent. fixes #123809
2 parents 6457761 + 060cecb commit 5d3a963

File tree

6 files changed

+12
-82
lines changed

6 files changed

+12
-82
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
998998
self.lower_const_arg(ct, FeedConstTy::No).into()
999999
}
10001000
};
1001+
if term.references_error() {
1002+
continue;
1003+
}
10011004
// FIXME(#97583): This isn't syntactically well-formed!
10021005
where_bounds.push(format!(
10031006
" T: {trait}::{assoc_name} = {term}",

compiler/rustc_mir_build/src/thir/constant.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_ast as ast;
22
use rustc_hir::LangItem;
33
use rustc_middle::bug;
44
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
5-
use rustc_middle::ty::{self, ScalarInt, TyCtxt};
5+
use rustc_middle::ty::{self, ScalarInt, TyCtxt, TypeVisitableExt as _};
66
use tracing::trace;
77

88
use crate::build::parse_float_into_scalar;
@@ -13,6 +13,10 @@ pub(crate) fn lit_to_const<'tcx>(
1313
) -> Result<ty::Const<'tcx>, LitToConstError> {
1414
let LitToConstInput { lit, ty, neg } = lit_input;
1515

16+
if let Err(guar) = ty.error_reported() {
17+
return Ok(ty::Const::new_error(tcx, guar));
18+
}
19+
1620
let trunc = |n| {
1721
let width = match tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)) {
1822
Ok(layout) => layout.size,

tests/crashes/123809.rs

-4
This file was deleted.

tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,6 @@ LL | trait Parent2 { const C: &'static str; }
2626
LL |
2727
LL | fn take1(_: impl Trait1<C = "?">) {}
2828
| ^^^^^^^ ambiguous associated constant `C`
29-
|
30-
= help: consider introducing a new type parameter `T` and adding `where` constraints:
31-
where
32-
T: Trait1,
33-
T: Parent2::C = "?",
34-
T: Parent1::C = "?"
3529

3630
error: aborting due to 2 previous errors
3731

tests/ui/wf/ice-hir-wf-check-anon-const-issue-122989.rs

-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ trait Foo<const N: Bar<2>> {
33
//~^ WARN trait objects without an explicit `dyn` are deprecated
44
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
55
//~| ERROR cycle detected when computing type of `Foo::N`
6-
//~| ERROR the trait `Foo` cannot be made into an object
7-
//~| ERROR `(dyn Bar<2> + 'static)` is forbidden as the type of a const generic parameter
86
fn func() {}
97
}
108

119
trait Bar<const M: Foo<2>> {}
1210
//~^ WARN trait objects without an explicit `dyn` are deprecated
1311
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
14-
//~| ERROR the trait `Foo` cannot be made into an object
15-
//~| ERROR `(dyn Foo<2> + 'static)` is forbidden as the type of a const generic parameter
1612

1713
fn main() {}

tests/ui/wf/ice-hir-wf-check-anon-const-issue-122989.stderr

+4-67
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LL | trait Foo<const N: dyn Bar<2>> {
1313
| +++
1414

1515
warning: trait objects without an explicit `dyn` are deprecated
16-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:20
16+
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:9:20
1717
|
1818
LL | trait Bar<const M: Foo<2>> {}
1919
| ^^^^^^
@@ -32,7 +32,7 @@ LL | trait Foo<const N: Bar<2>> {
3232
| ^^^^^^^^^^^^^^^
3333
|
3434
note: ...which requires computing type of `Bar::M`...
35-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:11
35+
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:9:11
3636
|
3737
LL | trait Bar<const M: Foo<2>> {}
3838
| ^^^^^^^^^^^^^^^
@@ -44,69 +44,6 @@ LL | trait Foo<const N: Bar<2>> {
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
4545
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
4646

47-
error[E0038]: the trait `Foo` cannot be made into an object
48-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:2:24
49-
|
50-
LL | trait Foo<const N: Bar<2>> {
51-
| ^ `Foo` cannot be made into an object
52-
|
53-
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
54-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:8:8
55-
|
56-
LL | trait Foo<const N: Bar<2>> {
57-
| --- this trait cannot be made into an object...
58-
...
59-
LL | fn func() {}
60-
| ^^^^ ...because associated function `func` has no `self` parameter
61-
help: consider turning `func` into a method by giving it a `&self` argument
62-
|
63-
LL | fn func(&self) {}
64-
| +++++
65-
help: alternatively, consider constraining `func` so it does not apply to trait objects
66-
|
67-
LL | fn func() where Self: Sized {}
68-
| +++++++++++++++++
69-
70-
error: `(dyn Bar<2> + 'static)` is forbidden as the type of a const generic parameter
71-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:2:20
72-
|
73-
LL | trait Foo<const N: Bar<2>> {
74-
| ^^^^^^
75-
|
76-
= note: the only supported types are integers, `bool`, and `char`
77-
78-
error[E0038]: the trait `Foo` cannot be made into an object
79-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:11
80-
|
81-
LL | trait Bar<const M: Foo<2>> {}
82-
| ^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
83-
|
84-
note: for a trait to be "dyn-compatible" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
85-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:8:8
86-
|
87-
LL | trait Foo<const N: Bar<2>> {
88-
| --- this trait cannot be made into an object...
89-
...
90-
LL | fn func() {}
91-
| ^^^^ ...because associated function `func` has no `self` parameter
92-
help: consider turning `func` into a method by giving it a `&self` argument
93-
|
94-
LL | fn func(&self) {}
95-
| +++++
96-
help: alternatively, consider constraining `func` so it does not apply to trait objects
97-
|
98-
LL | fn func() where Self: Sized {}
99-
| +++++++++++++++++
100-
101-
error: `(dyn Foo<2> + 'static)` is forbidden as the type of a const generic parameter
102-
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:20
103-
|
104-
LL | trait Bar<const M: Foo<2>> {}
105-
| ^^^^^^
106-
|
107-
= note: the only supported types are integers, `bool`, and `char`
108-
109-
error: aborting due to 5 previous errors; 2 warnings emitted
47+
error: aborting due to 1 previous error; 2 warnings emitted
11048

111-
Some errors have detailed explanations: E0038, E0391.
112-
For more information about an error, try `rustc --explain E0038`.
49+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)