@@ -673,6 +673,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
673
673
if !self . report_similar_impl_candidates (
674
674
impl_candidates,
675
675
trait_ref,
676
+ obligation. cause . body_id ,
676
677
& mut err,
677
678
) {
678
679
// This is *almost* equivalent to
@@ -707,6 +708,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
707
708
self . report_similar_impl_candidates (
708
709
impl_candidates,
709
710
trait_ref,
711
+ obligation. cause . body_id ,
710
712
& mut err,
711
713
) ;
712
714
}
@@ -1353,6 +1355,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
1353
1355
& self ,
1354
1356
impl_candidates : Vec < ImplCandidate < ' tcx > > ,
1355
1357
trait_ref : ty:: PolyTraitRef < ' tcx > ,
1358
+ body_id : hir:: HirId ,
1356
1359
err : & mut Diagnostic ,
1357
1360
) -> bool ;
1358
1361
@@ -1735,6 +1738,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1735
1738
& self ,
1736
1739
impl_candidates : Vec < ImplCandidate < ' tcx > > ,
1737
1740
trait_ref : ty:: PolyTraitRef < ' tcx > ,
1741
+ body_id : hir:: HirId ,
1738
1742
err : & mut Diagnostic ,
1739
1743
) -> bool {
1740
1744
let report = |mut candidates : Vec < TraitRef < ' tcx > > , err : & mut Diagnostic | {
@@ -1816,11 +1820,9 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1816
1820
// FIXME(compiler-errors): This could be generalized, both to
1817
1821
// be more granular, and probably look past other `#[fundamental]`
1818
1822
// types, too.
1819
- match self . tcx . visibility ( def. did ( ) ) {
1820
- ty:: Visibility :: Public => true ,
1821
- ty:: Visibility :: Restricted ( def_id) => def_id. is_local ( ) ,
1822
- ty:: Visibility :: Invisible => false ,
1823
- }
1823
+ self . tcx
1824
+ . visibility ( def. did ( ) )
1825
+ . is_accessible_from ( body_id. owner . to_def_id ( ) , self . tcx )
1824
1826
} else {
1825
1827
true
1826
1828
}
0 commit comments