|
2 | 2 |
|
3 | 3 | use crate::traits::{self, ObligationCause}; |
4 | 4 |
|
| 5 | +use rustc_data_structures::fx::FxIndexSet; |
5 | 6 | use rustc_hir as hir; |
6 | 7 | use rustc_infer::infer::outlives::env::OutlivesEnvironment; |
7 | 8 | use rustc_infer::infer::TyCtxtInferExt; |
8 | 9 | use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable}; |
9 | 10 |
|
10 | 11 | use crate::traits::error_reporting::TypeErrCtxtExt; |
11 | 12 |
|
| 13 | +use super::outlives_bounds::InferCtxtExt; |
| 14 | + |
12 | 15 | #[derive(Clone)] |
13 | 16 | pub enum CopyImplementationError<'tcx> { |
14 | 17 | InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>)>), |
@@ -45,6 +48,7 @@ pub fn type_allowed_to_implement_copy<'tcx>( |
45 | 48 | }; |
46 | 49 |
|
47 | 50 | let copy_def_id = tcx.require_lang_item(hir::LangItem::Copy, Some(parent_cause.span)); |
| 51 | + |
48 | 52 | let mut infringing = Vec::new(); |
49 | 53 | for variant in adt.variants() { |
50 | 54 | for field in &variant.fields { |
@@ -85,7 +89,16 @@ pub fn type_allowed_to_implement_copy<'tcx>( |
85 | 89 | infringing.push((field, ty)); |
86 | 90 | } |
87 | 91 |
|
88 | | - let outlives_env = OutlivesEnvironment::new(param_env); |
| 92 | + // Check regions assuming the self type of the impl is WF |
| 93 | + let outlives_env = OutlivesEnvironment::with_bounds( |
| 94 | + param_env, |
| 95 | + Some(&infcx), |
| 96 | + infcx.implied_bounds_tys( |
| 97 | + param_env, |
| 98 | + parent_cause.body_id, |
| 99 | + FxIndexSet::from_iter([self_type]), |
| 100 | + ), |
| 101 | + ); |
89 | 102 | infcx.process_registered_region_obligations( |
90 | 103 | outlives_env.region_bound_pairs(), |
91 | 104 | param_env, |
|
0 commit comments