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

Also resolve the type of constants, even if we already turned it into an error constant #125807

Merged
merged 2 commits into from
May 31, 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
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
self.handle_term(ct, ty::Const::outer_exclusive_binder, |tcx, guar| {
ty::Const::new_error(tcx, guar, ct.ty())
})
.super_fold_with(self)
}

fn fold_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/type-alias-impl-trait/const_generic_type.infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: `Bar` is forbidden as the type of a const generic parameter
--> $DIR/const_generic_type.rs:7:24
|
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`

error: aborting due to 1 previous error

19 changes: 19 additions & 0 deletions tests/ui/type-alias-impl-trait/const_generic_type.no_infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0283]: type annotations needed
--> $DIR/const_generic_type.rs:7:1
|
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot satisfy `_: std::fmt::Display`

error: `Bar` is forbidden as the type of a const generic parameter
--> $DIR/const_generic_type.rs:7:24
|
LL | async fn test<const N: crate::Bar>() {
| ^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0283`.
14 changes: 14 additions & 0 deletions tests/ui/type-alias-impl-trait/const_generic_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@edition: 2021
//@revisions: infer no_infer

#![feature(type_alias_impl_trait)]
type Bar = impl std::fmt::Display;

async fn test<const N: crate::Bar>() {
//[no_infer]~^ ERROR: type annotations needed
//~^^ ERROR: `Bar` is forbidden as the type of a const generic parameter
#[cfg(infer)]
let x: u32 = N;
}

fn main() {}
Loading