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

Hide errors whose suggestions would contain error constants or types #133954

Merged
merged 2 commits into from
Dec 7, 2024
Merged
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
3 changes: 3 additions & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self.lower_const_arg(ct, FeedConstTy::No).into()
}
};
if term.references_error() {
continue;
}
// FIXME(#97583): This isn't syntactically well-formed!
where_bounds.push(format!(
" T: {trait}::{assoc_name} = {term}",
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_mir_build/src/thir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use rustc_ast as ast;
use rustc_hir::LangItem;
use rustc_middle::bug;
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
use rustc_middle::ty::{self, ScalarInt, TyCtxt};
use rustc_middle::ty::{self, ScalarInt, TyCtxt, TypeVisitableExt as _};
use tracing::trace;

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

if let Err(guar) = ty.error_reported() {
return Ok(ty::Const::new_error(tcx, guar));
}

let trunc = |n| {
let width = match tcx.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(ty)) {
Ok(layout) => layout.size,
Expand Down
4 changes: 0 additions & 4 deletions tests/crashes/123809.rs

This file was deleted.

6 changes: 0 additions & 6 deletions tests/ui/associated-consts/assoc-const-eq-ambiguity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@ LL | trait Parent2 { const C: &'static str; }
LL |
LL | fn take1(_: impl Trait1<C = "?">) {}
| ^^^^^^^ ambiguous associated constant `C`
|
= help: consider introducing a new type parameter `T` and adding `where` constraints:
where
T: Trait1,
T: Parent2::C = "?",
T: Parent1::C = "?"

error: aborting due to 2 previous errors

Expand Down
4 changes: 0 additions & 4 deletions tests/ui/wf/ice-hir-wf-check-anon-const-issue-122989.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ trait Foo<const N: Bar<2>> {
//~^ WARN trait objects without an explicit `dyn` are deprecated
//~| WARN this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
//~| ERROR cycle detected when computing type of `Foo::N`
//~| ERROR the trait `Foo` cannot be made into an object
//~| ERROR `(dyn Bar<2> + 'static)` is forbidden as the type of a const generic parameter
fn func() {}
}

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

fn main() {}
71 changes: 4 additions & 67 deletions tests/ui/wf/ice-hir-wf-check-anon-const-issue-122989.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LL | trait Foo<const N: dyn Bar<2>> {
| +++

warning: trait objects without an explicit `dyn` are deprecated
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:20
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:9:20
|
LL | trait Bar<const M: Foo<2>> {}
| ^^^^^^
Expand All @@ -32,7 +32,7 @@ LL | trait Foo<const N: Bar<2>> {
| ^^^^^^^^^^^^^^^
|
note: ...which requires computing type of `Bar::M`...
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:11
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:9:11
|
LL | trait Bar<const M: Foo<2>> {}
| ^^^^^^^^^^^^^^^
Expand All @@ -44,69 +44,6 @@ LL | trait Foo<const N: Bar<2>> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= 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

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:2:24
|
LL | trait Foo<const N: Bar<2>> {
| ^ `Foo` cannot be made into an object
|
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>
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:8:8
|
LL | trait Foo<const N: Bar<2>> {
| --- this trait cannot be made into an object...
...
LL | fn func() {}
| ^^^^ ...because associated function `func` has no `self` parameter
help: consider turning `func` into a method by giving it a `&self` argument
|
LL | fn func(&self) {}
| +++++
help: alternatively, consider constraining `func` so it does not apply to trait objects
|
LL | fn func() where Self: Sized {}
| +++++++++++++++++

error: `(dyn Bar<2> + 'static)` is forbidden as the type of a const generic parameter
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:2:20
|
LL | trait Foo<const N: Bar<2>> {
| ^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`

error[E0038]: the trait `Foo` cannot be made into an object
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:11
|
LL | trait Bar<const M: Foo<2>> {}
| ^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
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>
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:8:8
|
LL | trait Foo<const N: Bar<2>> {
| --- this trait cannot be made into an object...
...
LL | fn func() {}
| ^^^^ ...because associated function `func` has no `self` parameter
help: consider turning `func` into a method by giving it a `&self` argument
|
LL | fn func(&self) {}
| +++++
help: alternatively, consider constraining `func` so it does not apply to trait objects
|
LL | fn func() where Self: Sized {}
| +++++++++++++++++

error: `(dyn Foo<2> + 'static)` is forbidden as the type of a const generic parameter
--> $DIR/ice-hir-wf-check-anon-const-issue-122989.rs:11:20
|
LL | trait Bar<const M: Foo<2>> {}
| ^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`

error: aborting due to 5 previous errors; 2 warnings emitted
error: aborting due to 1 previous error; 2 warnings emitted

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