Skip to content
Open
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
5 changes: 4 additions & 1 deletion compiler/rustc_ty_utils/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {

#[instrument(level = "trace", skip(self))]
fn collect_taits_declared_in_body(&mut self) {
let body = self.tcx.hir_body_owned_by(self.item).value;
let Some(body) = self.tcx.hir_maybe_body_owned_by(self.item) else {
return;
};
let body = body.value;
struct TaitInBodyFinder<'a, 'tcx> {
collector: &'a mut OpaqueTypeCollector<'tcx>,
}
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/impl-trait/ice-148622-opaque-as-const-generics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#![feature(type_alias_impl_trait)]

pub type Opaque = impl std::future::Future;
//~^ ERROR: unconstrained opaque type

trait Foo<const N: Opaque> {
//~^ ERROR: `Opaque` is forbidden as the type of a const generic parameter
fn bar(&self) -> [u8; N];
//~^ ERROR: the constant `N` is not of type `usize`
}

fn main() {}
31 changes: 31 additions & 0 deletions tests/ui/impl-trait/ice-148622-opaque-as-const-generics.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
error: `Opaque` is forbidden as the type of a const generic parameter
--> $DIR/ice-148622-opaque-as-const-generics.rs:6:20
|
LL | trait Foo<const N: Opaque> {
| ^^^^^^
|
= note: the only supported types are integers, `bool`, and `char`

error: the constant `N` is not of type `usize`
--> $DIR/ice-148622-opaque-as-const-generics.rs:8:22
|
LL | fn bar(&self) -> [u8; N];
| ^^^^^^^ expected `usize`, found future
|
note: this item must have a `#[define_opaque(Opaque)]` attribute to be able to define hidden types
--> $DIR/ice-148622-opaque-as-const-generics.rs:8:8
|
LL | fn bar(&self) -> [u8; N];
| ^^^
= note: the length of array `[u8; N]` must be type `usize`

error: unconstrained opaque type
--> $DIR/ice-148622-opaque-as-const-generics.rs:3:19
|
LL | pub type Opaque = impl std::future::Future;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `Opaque` must be used in combination with a concrete type within the same crate

error: aborting due to 3 previous errors

Loading