about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-04-14 12:37:22 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-04-14 12:37:22 +0300
commitdbc7042bfe690d55cbcd40e75851efd8af9bb34e (patch)
tree379e31a9ba7eb4dcd7b53d7779d1e5c6f13ddf13 /src
parent3c3a1402949b42c4470af6e0aee2b8f15bf24129 (diff)
downloadrust-dbc7042bfe690d55cbcd40e75851efd8af9bb34e.tar.gz
rust-dbc7042bfe690d55cbcd40e75851efd8af9bb34e.zip
Address review comments
Diffstat (limited to 'src')
-rw-r--r--src/librustc_metadata/decoder.rs18
-rw-r--r--src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs3
2 files changed, 13 insertions, 8 deletions
diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs
index e2464c517ae..076e6590226 100644
--- a/src/librustc_metadata/decoder.rs
+++ b/src/librustc_metadata/decoder.rs
@@ -832,14 +832,16 @@ impl<'a, 'tcx> CrateMetadata {
                             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 });
                         }
diff --git a/src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs b/src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs
index 9057592259b..62f6e4463f9 100644
--- a/src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs
+++ b/src/test/ui/rfc-2008-non-exhaustive/variants_fictive_visibility.rs
@@ -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() {}