Skip to content

Commit 138e08c

Browse files
Make #[doc(include)] paths behave like other paths
This makes them relative to the containing file instead of the crate root
1 parent ba78db3 commit 138e08c

File tree

2 files changed

+34
-21
lines changed

2 files changed

+34
-21
lines changed

src/libstd/os/raw/mod.rs

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
99
#![stable(feature = "raw_os", since = "1.1.0")]
1010

11-
#[doc(include = "os/raw/char.md")]
11+
#[cfg_attr(stage0, doc(include = "os/raw/char.md"))]
12+
#[cfg_attr(not(stage0), doc(include = "char.md"))]
1213
#[cfg(any(all(target_os = "linux", any(target_arch = "aarch64",
1314
target_arch = "arm",
1415
target_arch = "powerpc",
@@ -31,7 +32,8 @@
3132
target_arch = "powerpc")),
3233
all(target_os = "fuchsia", target_arch = "aarch64")))]
3334
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8;
34-
#[doc(include = "os/raw/char.md")]
35+
#[cfg_attr(stage0, doc(include = "os/raw/char.md"))]
36+
#[cfg_attr(not(stage0), doc(include = "char.md"))]
3537
#[cfg(not(any(all(target_os = "linux", any(target_arch = "aarch64",
3638
target_arch = "arm",
3739
target_arch = "powerpc",
@@ -54,37 +56,51 @@
5456
target_arch = "powerpc")),
5557
all(target_os = "fuchsia", target_arch = "aarch64"))))]
5658
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8;
57-
#[doc(include = "os/raw/schar.md")]
59+
#[cfg_attr(stage0, doc(include = "os/raw/schar.md"))]
60+
#[cfg_attr(not(stage0), doc(include = "schar.md"))]
5861
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_schar = i8;
59-
#[doc(include = "os/raw/uchar.md")]
62+
#[cfg_attr(stage0, doc(include = "os/raw/uchar.md"))]
63+
#[cfg_attr(not(stage0), doc(include = "uchar.md"))]
6064
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uchar = u8;
61-
#[doc(include = "os/raw/short.md")]
65+
#[cfg_attr(stage0, doc(include = "os/raw/short.md"))]
66+
#[cfg_attr(not(stage0), doc(include = "short.md"))]
6267
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_short = i16;
63-
#[doc(include = "os/raw/ushort.md")]
68+
#[cfg_attr(stage0, doc(include = "os/raw/ushort.md"))]
69+
#[cfg_attr(not(stage0), doc(include = "ushort.md"))]
6470
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ushort = u16;
65-
#[doc(include = "os/raw/int.md")]
71+
#[cfg_attr(stage0, doc(include = "os/raw/int.md"))]
72+
#[cfg_attr(not(stage0), doc(include = "int.md"))]
6673
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_int = i32;
67-
#[doc(include = "os/raw/uint.md")]
74+
#[cfg_attr(stage0, doc(include = "os/raw/uint.md"))]
75+
#[cfg_attr(not(stage0), doc(include = "uint.md"))]
6876
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_uint = u32;
69-
#[doc(include = "os/raw/long.md")]
77+
#[cfg_attr(stage0, doc(include = "os/raw/long.md"))]
78+
#[cfg_attr(not(stage0), doc(include = "long.md"))]
7079
#[cfg(any(target_pointer_width = "32", windows))]
7180
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i32;
72-
#[doc(include = "os/raw/ulong.md")]
81+
#[cfg_attr(stage0, doc(include = "os/raw/ulong.md"))]
82+
#[cfg_attr(not(stage0), doc(include = "ulong.md"))]
7383
#[cfg(any(target_pointer_width = "32", windows))]
7484
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u32;
75-
#[doc(include = "os/raw/long.md")]
85+
#[cfg_attr(stage0, doc(include = "os/raw/long.md"))]
86+
#[cfg_attr(not(stage0), doc(include = "long.md"))]
7687
#[cfg(all(target_pointer_width = "64", not(windows)))]
7788
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_long = i64;
78-
#[doc(include = "os/raw/ulong.md")]
89+
#[cfg_attr(stage0, doc(include = "os/raw/ulong.md"))]
90+
#[cfg_attr(not(stage0), doc(include = "ulong.md"))]
7991
#[cfg(all(target_pointer_width = "64", not(windows)))]
8092
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulong = u64;
81-
#[doc(include = "os/raw/longlong.md")]
93+
#[cfg_attr(stage0, doc(include = "os/raw/longlong.md"))]
94+
#[cfg_attr(not(stage0), doc(include = "longlong.md"))]
8295
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_longlong = i64;
83-
#[doc(include = "os/raw/ulonglong.md")]
96+
#[cfg_attr(stage0, doc(include = "os/raw/ulonglong.md"))]
97+
#[cfg_attr(not(stage0), doc(include = "ulonglong.md"))]
8498
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_ulonglong = u64;
85-
#[doc(include = "os/raw/float.md")]
99+
#[cfg_attr(stage0, doc(include = "os/raw/float.md"))]
100+
#[cfg_attr(not(stage0), doc(include = "float.md"))]
86101
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_float = f32;
87-
#[doc(include = "os/raw/double.md")]
102+
#[cfg_attr(stage0, doc(include = "os/raw/double.md"))]
103+
#[cfg_attr(not(stage0), doc(include = "double.md"))]
88104
#[stable(feature = "raw_os", since = "1.1.0")] pub type c_double = f64;
89105

90106
#[stable(feature = "raw_os", since = "1.1.0")]

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::symbol::{sym, Symbol};
1717
use crate::tokenstream::{TokenStream, TokenTree};
1818
use crate::visit::{self, Visitor};
1919
use crate::util::map_in_place::MapInPlace;
20+
use crate::util::path;
2021

2122
use errors::{Applicability, FatalError};
2223
use smallvec::{smallvec, SmallVec};
@@ -1253,7 +1254,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12531254
return noop_visit_attribute(at, self);
12541255
}
12551256

1256-
let filename = self.cx.root_path.join(file.to_string());
1257+
let filename = path::resolve(&*file.as_str(), it.span(), self.cx.source_map());
12571258
match fs::read_to_string(&filename) {
12581259
Ok(src) => {
12591260
let src_interned = Symbol::intern(&src);
@@ -1302,10 +1303,6 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
13021303
);
13031304
err.span_label(lit.span, "couldn't read file");
13041305

1305-
if e.kind() == ErrorKind::NotFound {
1306-
err.help("external doc paths are relative to the crate root");
1307-
}
1308-
13091306
err.emit();
13101307
}
13111308
}

0 commit comments

Comments
 (0)