]> git.lizzy.rs Git - rust.git/commitdiff
Address review comments
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 14 Apr 2019 09:37:22 +0000 (12:37 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sun, 14 Apr 2019 09:37:22 +0000 (12:37 +0300)
src/librustc_metadata/decoder.rs
src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs

index e2464c517ae728419527d412fb3e115e47f23355..076e6590226e5330165d77776b39a77cd09bce06 100644 (file)
@@ -832,14 +832,16 @@ pub fn each_child_of_item<F>(&self, id: DefIndex, mut callback: F, sess: &Sessio
                             let ctor_kind = self.get_ctor_kind(child_index);
                             let ctor_def = Def::Ctor(ctor_def_id, CtorOf::Variant, ctor_kind);
                             let mut vis = self.get_visibility(ctor_def_id.index);
-                            // If the variant is marked as non_exhaustive then lower the visibility
-                            // to within the crate.
-                            let has_non_exhaustive = || { attr::contains_name(
-                                &self.get_item_attrs(def_id.index, sess), "non_exhaustive"
-                            )};
-                            if vis == ty::Visibility::Public && has_non_exhaustive() {
-                                let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
-                                vis = ty::Visibility::Restricted(crate_def_id);
+                            if ctor_def_id == def_id && vis == ty::Visibility::Public {
+                                // For non-exhaustive variants lower the constructor visibility to
+                                // within the crate. We only need this for fictive constructors,
+                                // for other constructors correct visibilities
+                                // were already encoded in metadata.
+                                let attrs = self.get_item_attrs(def_id.index, sess);
+                                if attr::contains_name(&attrs, "non_exhaustive") {
+                                    let crate_def_id = DefId { index: CRATE_DEF_INDEX, ..def_id };
+                                    vis = ty::Visibility::Restricted(crate_def_id);
+                                }
                             }
                             callback(def::Export { def: ctor_def, ident, vis, span });
                         }
index 9057592259ba6bc06e6b5501d224080193209b38..62f6e4463f936f214ea2f32c9f3edb4898d9b51a 100644 (file)
@@ -4,6 +4,9 @@
 extern crate variants;
 
 const S: u8 = 0;
+
+// OK, `Struct` in value namespace is crate-private, so it's filtered away
+// and there's no conflict with the previously defined `const S`.
 use variants::NonExhaustiveVariants::Struct as S;
 
 fn main() {}