diff --git a/compiler/rustc_hir_analysis/src/variance/mod.rs b/compiler/rustc_hir_analysis/src/variance/mod.rs index a7760326bb4c3..0800d99e9452e 100644 --- a/compiler/rustc_hir_analysis/src/variance/mod.rs +++ b/compiler/rustc_hir_analysis/src/variance/mod.rs @@ -198,6 +198,10 @@ fn variance_of_opaque( ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref: ty::TraitRef { def_id: _, args, .. }, polarity: _, + }) + | ty::ClauseKind::HostEffect(ty::HostEffectPredicate { + trait_ref: ty::TraitRef { def_id: _, args, .. }, + constness: _, }) => { for arg in &args[1..] { arg.visit_with(&mut collector); diff --git a/tests/ui/traits/const-traits/variance.rs b/tests/ui/traits/const-traits/variance.rs new file mode 100644 index 0000000000000..90b5c50161d51 --- /dev/null +++ b/tests/ui/traits/const-traits/variance.rs @@ -0,0 +1,13 @@ +#![feature(rustc_attrs, const_trait_impl)] +#![allow(internal_features)] +#![rustc_variance_of_opaques] + +#[const_trait] +trait Foo {} + +impl const Foo for () {} + +fn foo<'a: 'a>() -> impl const Foo {} +//~^ ERROR ['a: *] + +fn main() {} diff --git a/tests/ui/traits/const-traits/variance.stderr b/tests/ui/traits/const-traits/variance.stderr new file mode 100644 index 0000000000000..f55069311848a --- /dev/null +++ b/tests/ui/traits/const-traits/variance.stderr @@ -0,0 +1,8 @@ +error: ['a: *] + --> $DIR/variance.rs:10:21 + | +LL | fn foo<'a: 'a>() -> impl const Foo {} + | ^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error +