Rollup merge of #125416 - compiler-errors:param-env-missing-copy, r=lcnr

Use correct param-env in `MissingCopyImplementations`

We shouldn't assume the param-env is empty for this lint, since although we check the struct has no parameters, there still may be trivial where-clauses.

fixes #125394
This commit is contained in:
Matthias Krüger 2024-05-23 14:09:25 +02:00 committed by GitHub
commit e713b2a00c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 5 deletions

View File

@ -674,11 +674,10 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
return; return;
} }
} }
let param_env = ty::ParamEnv::empty(); if ty.is_copy_modulo_regions(cx.tcx, cx.param_env) {
if ty.is_copy_modulo_regions(cx.tcx, param_env) {
return; return;
} }
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) { if type_implements_negative_copy_modulo_regions(cx.tcx, ty, cx.param_env) {
return; return;
} }
if def.is_variant_list_non_exhaustive() if def.is_variant_list_non_exhaustive()
@ -694,7 +693,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
.tcx .tcx
.infer_ctxt() .infer_ctxt()
.build() .build()
.type_implements_trait(iter_trait, [ty], param_env) .type_implements_trait(iter_trait, [ty], cx.param_env)
.must_apply_modulo_regions() .must_apply_modulo_regions()
{ {
return; return;
@ -711,7 +710,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, item: &hir::Item<'_>) {
if type_allowed_to_implement_copy( if type_allowed_to_implement_copy(
cx.tcx, cx.tcx,
param_env, cx.param_env,
ty, ty,
traits::ObligationCause::misc(item.span, item.owner_id.def_id), traits::ObligationCause::misc(item.span, item.owner_id.def_id),
) )

View File

@ -0,0 +1,21 @@
//@ check-pass
#![feature(trivial_bounds)]
#![allow(trivial_bounds)]
// Make sure that we still use the where-clauses from the struct when checking
// if it may implement `Copy` unconditionally.
// Fix for <https://github.com/rust-lang/rust/issues/125394>.
pub trait Foo {
type Assoc;
}
pub struct Bar;
// This needs to be public
pub struct Baz2(<Bar as Foo>::Assoc)
where
Bar: Foo;
fn main() {}