about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-07-19 01:16:25 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-19 01:16:25 +0400
commitda2752e00f0139fb13282b2bd97aa0f8c665aee9 (patch)
tree1f43ad0c535a11270645ede3480ecbc224aab587 /compiler
parent7163e7ff6542b200971a783dc2a720a0ff676e70 (diff)
downloadrust-da2752e00f0139fb13282b2bd97aa0f8c665aee9.tar.gz
rust-da2752e00f0139fb13282b2bd97aa0f8c665aee9.zip
check accessibility before suggesting wrapping expressions
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_typeck/src/check/demand.rs18
1 files changed, 10 insertions, 8 deletions
diff --git a/compiler/rustc_typeck/src/check/demand.rs b/compiler/rustc_typeck/src/check/demand.rs
index 31da5cfe7fa..30d7cc2e5fc 100644
--- a/compiler/rustc_typeck/src/check/demand.rs
+++ b/compiler/rustc_typeck/src/check/demand.rs
@@ -19,7 +19,6 @@ use rustc_span::{BytePos, Span};
 use super::method::probe;
 
 use std::iter;
-use std::ops::Bound;
 
 impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
     pub fn emit_coerce_suggestions(
@@ -349,13 +348,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 }
             }
 
-            // Avoid suggesting wrapping in `NonZeroU64` and alike
-            if self.tcx.layout_scalar_valid_range(expected_adt.did())
-                != (Bound::Unbounded, Bound::Unbounded)
-            {
-                return;
-            }
-
             let compatible_variants: Vec<String> = expected_adt
                 .variants()
                 .iter()
@@ -364,6 +356,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                 })
                 .filter_map(|variant| {
                     let sole_field = &variant.fields[0];
+
+                    if !sole_field.did.is_local()
+                        && !sole_field.vis.is_accessible_from(
+                            self.tcx.parent_module(expr.hir_id).to_def_id(),
+                            self.tcx,
+                        )
+                    {
+                        return None;
+                    }
+
                     let sole_field_ty = sole_field.ty(self.tcx, substs);
                     if self.can_coerce(expr_ty, sole_field_ty) {
                         let variant_path =