ty::Visibility::Restricted(self.current_module.normal_ancestor_id)
}
ast::VisibilityKind::Restricted { ref path, id, .. } => {
- // Visibilities are resolved as global by default, add starting root segment.
+ // For visibilities we are not ready to provide correct implementation of "uniform
+ // paths" right now, so on 2018 edition we only allow module-relative paths for now.
+ let first_ident = path.segments[0].ident;
+ if self.session.rust_2018() && !first_ident.is_path_segment_keyword() {
+ let msg = "relative paths are not supported in visibilities on 2018 edition";
+ self.session.struct_span_err(first_ident.span, msg)
+ .span_suggestion(path.span, "try", format!("crate::{}", path))
+ .emit();
+ return ty::Visibility::Public;
+ }
+ // On 2015 visibilities are resolved as crate-relative by default,
+ // add starting root segment if necessary.
let segments = path.make_root().iter().chain(path.segments.iter())
.map(|seg| Segment { ident: seg.ident, id: Some(seg.id) })
.collect::<Vec<_>>();
--- /dev/null
+// edition:2018
+
+mod m {
+ pub(in crate) struct S1; // OK
+ pub(in super) struct S2; // OK
+ pub(in self) struct S3; // OK
+ pub(in ::core) struct S4;
+ //~^ ERROR visibilities can only be restricted to ancestor modules
+ pub(in a::b) struct S5;
+ //~^ ERROR relative paths are not supported in visibilities on 2018 edition
+}
+
+fn main() {}
--- /dev/null
+error: visibilities can only be restricted to ancestor modules
+ --> $DIR/relative-2018.rs:7:12
+ |
+LL | pub(in ::core) struct S4;
+ | ^^^^^^
+
+error: relative paths are not supported in visibilities on 2018 edition
+ --> $DIR/relative-2018.rs:9:12
+ |
+LL | pub(in a::b) struct S5;
+ | ^---
+ | |
+ | help: try: `crate::a::b`
+
+error: aborting due to 2 previous errors
+