diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-05-23 14:09:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-23 14:09:25 +0200 |
| commit | e713b2a00c8e0cbb555bc8e042df9ec1e9934d18 (patch) | |
| tree | 6cfa26aabafe39f6077336a7b3a9d22c9438c25a | |
| parent | c9e457dbd68b781ad05958bcd803a7cfbb0b765d (diff) | |
| parent | 8369dbba4360f783b84cfb13304329ae1cbd092f (diff) | |
| download | rust-e713b2a00c8e0cbb555bc8e042df9ec1e9934d18.tar.gz rust-e713b2a00c8e0cbb555bc8e042df9ec1e9934d18.zip | |
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
| -rw-r--r-- | compiler/rustc_lint/src/builtin.rs | 9 | ||||
| -rw-r--r-- | tests/ui/lint/missing_copy_impl_trivial_bounds.rs | 21 |
2 files changed, 25 insertions, 5 deletions
diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 0f059bceae7..a3a8e5199ff 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -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() @@ -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; @@ -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), ) diff --git a/tests/ui/lint/missing_copy_impl_trivial_bounds.rs b/tests/ui/lint/missing_copy_impl_trivial_bounds.rs new file mode 100644 index 00000000000..9b743417bd5 --- /dev/null +++ b/tests/ui/lint/missing_copy_impl_trivial_bounds.rs @@ -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() {} |
