]> git.lizzy.rs Git - rust.git/commitdiff
Make #[doc(include)] paths behave like other paths
authorJonas Schievink <jonasschievink@gmail.com>
Sat, 18 May 2019 13:56:53 +0000 (15:56 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Tue, 23 Jul 2019 15:17:31 +0000 (17:17 +0200)
This makes them relative to the containing file instead of the crate
root

src/libstd/os/raw/mod.rs
src/libsyntax/ext/expand.rs

index c0b0b6d40d891a742ff08dfa8841843ec96ce4da..fd50657800d50809b1bc1bbd13d2d58f2343e76b 100644 (file)
@@ -8,7 +8,8 @@
 
 #![stable(feature = "raw_os", since = "1.1.0")]
 
-#[doc(include = "os/raw/char.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/char.md"))]
+#[cfg_attr(not(stage0), doc(include = "char.md"))]
 #[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
                                        target_arch = "arm",
                                        target_arch = "powerpc",
@@ -31,7 +32,8 @@
                                          target_arch = "powerpc")),
           all(target_os = "fuchsia", target_arch = "aarch64")))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
-#[doc(include = "os/raw/char.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/char.md"))]
+#[cfg_attr(not(stage0), doc(include = "char.md"))]
 #[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
                                            target_arch = "arm",
                                            target_arch = "powerpc",
                                              target_arch = "powerpc")),
               all(target_os = "fuchsia", target_arch = "aarch64"))))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
-#[doc(include = "os/raw/schar.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/schar.md"))]
+#[cfg_attr(not(stage0), doc(include = "schar.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
-#[doc(include = "os/raw/uchar.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/uchar.md"))]
+#[cfg_attr(not(stage0), doc(include = "uchar.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
-#[doc(include = "os/raw/short.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/short.md"))]
+#[cfg_attr(not(stage0), doc(include = "short.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
-#[doc(include = "os/raw/ushort.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/ushort.md"))]
+#[cfg_attr(not(stage0), doc(include = "ushort.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
-#[doc(include = "os/raw/int.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/int.md"))]
+#[cfg_attr(not(stage0), doc(include = "int.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
-#[doc(include = "os/raw/uint.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/uint.md"))]
+#[cfg_attr(not(stage0), doc(include = "uint.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
-#[doc(include = "os/raw/long.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/long.md"))]
+#[cfg_attr(not(stage0), doc(include = "long.md"))]
 #[cfg(any(target_pointer_width = "32", windows))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
-#[doc(include = "os/raw/ulong.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/ulong.md"))]
+#[cfg_attr(not(stage0), doc(include = "ulong.md"))]
 #[cfg(any(target_pointer_width = "32", windows))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
-#[doc(include = "os/raw/long.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/long.md"))]
+#[cfg_attr(not(stage0), doc(include = "long.md"))]
 #[cfg(all(target_pointer_width = "64", not(windows)))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
-#[doc(include = "os/raw/ulong.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/ulong.md"))]
+#[cfg_attr(not(stage0), doc(include = "ulong.md"))]
 #[cfg(all(target_pointer_width = "64", not(windows)))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
-#[doc(include = "os/raw/longlong.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/longlong.md"))]
+#[cfg_attr(not(stage0), doc(include = "longlong.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
-#[doc(include = "os/raw/ulonglong.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/ulonglong.md"))]
+#[cfg_attr(not(stage0), doc(include = "ulonglong.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
-#[doc(include = "os/raw/float.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/float.md"))]
+#[cfg_attr(not(stage0), doc(include = "float.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
-#[doc(include = "os/raw/double.md")]
+#[cfg_attr(stage0, doc(include = "os/raw/double.md"))]
+#[cfg_attr(not(stage0), doc(include = "double.md"))]
 #[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
 
 #[stable(feature = "raw_os", since = "1.1.0")]
index ae72f1fd108ed99f87b76ef9c244992d42db887b..6cfcfdfbf7d85419f8d20e2dfbc8ecf6d7ab3ece 100644 (file)
@@ -17,6 +17,7 @@
 use crate::tokenstream::{TokenStream, TokenTree};
 use crate::visit::{self, Visitor};
 use crate::util::map_in_place::MapInPlace;
+use crate::util::path;
 
 use errors::{Applicability, FatalError};
 use smallvec::{smallvec, SmallVec};
@@ -1253,7 +1254,7 @@ fn visit_attribute(&mut self, at: &mut ast::Attribute) {
                         return noop_visit_attribute(at, self);
                     }
 
-                    let filename = self.cx.root_path.join(file.to_string());
+                    let filename = path::resolve(&*file.as_str(), it.span(), self.cx.source_map());
                     match fs::read_to_string(&filename) {
                         Ok(src) => {
                             let src_interned = Symbol::intern(&src);
@@ -1302,10 +1303,6 @@ fn visit_attribute(&mut self, at: &mut ast::Attribute) {
                                 );
                                 err.span_label(lit.span, "couldn't read file");
 
-                                if e.kind() == ErrorKind::NotFound {
-                                    err.help("external doc paths are relative to the crate root");
-                                }
-
                                 err.emit();
                             }
                         }