Skip to content

Commit e713b2a

Browse files
authored
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
2 parents c9e457d + 8369dbb commit e713b2a

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

compiler/rustc_lint/src/builtin.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
674674
return;
675675
}
676676
}
677-
let param_env = ty::ParamEnv::empty();
678-
if ty.is_copy_modulo_regions(cx.tcx, param_env) {
677+
if ty.is_copy_modulo_regions(cx.tcx, cx.param_env) {
679678
return;
680679
}
681-
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, param_env) {
680+
if type_implements_negative_copy_modulo_regions(cx.tcx, ty, cx.param_env) {
682681
return;
683682
}
684683
if def.is_variant_list_non_exhaustive()
@@ -694,7 +693,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
694693
.tcx
695694
.infer_ctxt()
696695
.build()
697-
.type_implements_trait(iter_trait, [ty], param_env)
696+
.type_implements_trait(iter_trait, [ty], cx.param_env)
698697
.must_apply_modulo_regions()
699698
{
700699
return;
@@ -711,7 +710,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
711710

712711
if type_allowed_to_implement_copy(
713712
cx.tcx,
714-
param_env,
713+
cx.param_env,
715714
ty,
716715
traits::ObligationCause::misc(item.span, item.owner_id.def_id),
717716
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ check-pass
2+
3+
#![feature(trivial_bounds)]
4+
#![allow(trivial_bounds)]
5+
6+
// Make sure that we still use the where-clauses from the struct when checking
7+
// if it may implement `Copy` unconditionally.
8+
// Fix for <https://github.com/rust-lang/rust/issues/125394>.
9+
10+
pub trait Foo {
11+
type Assoc;
12+
}
13+
14+
pub struct Bar;
15+
16+
// This needs to be public
17+
pub struct Baz2(<Bar as Foo>::Assoc)
18+
where
19+
Bar: Foo;
20+
21+
fn main() {}

0 commit comments

Comments
 (0)