Skip to content

Commit 467dff7

Browse files
committed
Fix build and add comment about lifetimes
1 parent baa017e commit 467dff7

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

‎compiler/rustc_builtin_macros/src/deriving/reborrow.rs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use rustc_ast::{
2-
self as ast, AngleBracketedArg, AttrArgs, DUMMY_NODE_ID, GenericArg, GenericBound,
3-
GenericParam, GenericParamKind, Generics, ItemKind, WherePredicate, WherePredicateKind,
4-
WhereRegionPredicate, token,
2+
self as ast, AngleBracketedArg, AttrArgs, DUMMY_NODE_ID, GenericArg, Generics, ItemKind, token,
53
};
64
use rustc_data_structures::fx::FxHashSet;
75
use rustc_errors::E0802;
86
use rustc_expand::base::ExtCtxt;
97
use rustc_macros::Diagnostic;
10-
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
11-
use thin_vec::{ThinVec, thin_vec};
8+
use rustc_span::{Ident, Span, Symbol, sym};
9+
use thin_vec::ThinVec;
1210

1311
use crate::deriving::generic::*;
1412
use crate::deriving::new_path;

‎compiler/rustc_hir_analysis/src/coherence/builtin/coerce_shared.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>(
749749
return false;
750750
}
751751

752+
// impl<'a: 'b, 'b> CoerceShared<Target<'b>> for Source<'a> {}
753+
//
754+
// We expect all fields of `Source<'a>` to be one of:
755+
// 1. `CoreceShared<TargetField<'b>>`: this is handled separately
756+
// 2. assignable to target field: this is checked with a covariant .relate() call.
757+
// 3. `&'a mut T` assigned to `&'b T`: this is checked below with .sub_regions() and .sup().
752758
match relation {
753759
FieldRelation::Equal => {
754760
if infcx
@@ -767,8 +773,11 @@ fn field_tys_satisfy_relation_after_normalization_and_resolution<'tcx>(
767773
else {
768774
return false;
769775
};
776+
// Here we're effectively checking assignability of `&'source_region mut T` to
777+
// `&'target_region T`, so we require `'source_region: 'target_region` using
778+
// `.sub_regions()` and the `T`'s to be unifiable with `.sup()`.
770779
infcx.sub_regions(
771-
SubregionOrigin::RelateObjectBound(span),
780+
SubregionOrigin::Reborrow(span),
772781
target_region,
773782
source_region,
774783
ty::VisibleForLeakCheck::Yes,

0 commit comments

Comments
 (0)