Skip to content

Commit

Permalink
Rollup merge of rust-lang#125416 - compiler-errors:param-env-missing-…
Browse files Browse the repository at this point in the history
…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 rust-lang#125394
  • Loading branch information
fmease committed May 22, 2024
2 parents 5112a5c + 8369dbb commit 0561804
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
9 changes: 4 additions & 5 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,11 +674,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
return;
}
}
let param_env = ty::ParamEnv::empty();
if ty.is_copy_modulo_regions(cx.tcx, param_env) {
if ty.is_copy_modulo_regions(cx.tcx, cx.param_env) {
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;
}
if def.is_variant_list_non_exhaustive()
Expand All @@ -694,7 +693,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
.tcx
.infer_ctxt()
.build()
.type_implements_trait(iter_trait, [ty], param_env)
.type_implements_trait(iter_trait, [ty], cx.param_env)
.must_apply_modulo_regions()
{
return;
Expand All @@ -711,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {

if type_allowed_to_implement_copy(
cx.tcx,
param_env,
cx.param_env,
ty,
traits::ObligationCause::misc(item.span, item.owner_id.def_id),
)
Expand Down
21 changes: 21 additions & 0 deletions tests/ui/lint/missing_copy_impl_trivial_bounds.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 0561804

Please sign in to comment.