copy self type is implied wf
This commit is contained in:
parent
8cf7f40a89
commit
333c6bf523
@ -2,6 +2,7 @@
|
||||
|
||||
use crate::traits::{self, ObligationCause};
|
||||
|
||||
use rustc_data_structures::fx::FxIndexSet;
|
||||
use rustc_hir as hir;
|
||||
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
@ -9,6 +10,8 @@
|
||||
|
||||
use crate::traits::error_reporting::TypeErrCtxtExt;
|
||||
|
||||
use super::outlives_bounds::InferCtxtExt;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum CopyImplementationError<'tcx> {
|
||||
InfrigingFields(Vec<(&'tcx ty::FieldDef, Ty<'tcx>)>),
|
||||
@ -45,6 +48,7 @@ pub fn type_allowed_to_implement_copy<'tcx>(
|
||||
};
|
||||
|
||||
let copy_def_id = tcx.require_lang_item(hir::LangItem::Copy, Some(parent_cause.span));
|
||||
|
||||
let mut infringing = Vec::new();
|
||||
for variant in adt.variants() {
|
||||
for field in &variant.fields {
|
||||
@ -85,7 +89,16 @@ pub fn type_allowed_to_implement_copy<'tcx>(
|
||||
infringing.push((field, ty));
|
||||
}
|
||||
|
||||
let outlives_env = OutlivesEnvironment::new(param_env);
|
||||
// Check regions assuming the self type of the impl is WF
|
||||
let outlives_env = OutlivesEnvironment::with_bounds(
|
||||
param_env,
|
||||
Some(&infcx),
|
||||
infcx.implied_bounds_tys(
|
||||
param_env,
|
||||
parent_cause.body_id,
|
||||
FxIndexSet::from_iter([self_type]),
|
||||
),
|
||||
);
|
||||
infcx.process_registered_region_obligations(
|
||||
outlives_env.region_bound_pairs(),
|
||||
param_env,
|
||||
|
14
src/test/ui/traits/copy-requires-self-wf.rs
Normal file
14
src/test/ui/traits/copy-requires-self-wf.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// check-pass
|
||||
|
||||
#[derive(Clone)]
|
||||
struct A<'a, T>(&'a T);
|
||||
|
||||
impl<'a, T: Copy + 'a> Copy for A<'a, T> {}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct B<'a, T>(A<'a, T>);
|
||||
|
||||
// `T: '_` should be implied by `WF(B<'_, T>)`.
|
||||
impl<T: Copy> Copy for B<'_, T> {}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in New Issue
Block a user