Skip to content

Commit 394e1b4

Browse files
committedJun 27, 2020
Auto merge of rust-lang#73779 - Manishearth:rollup-lwqd9jm, r=Manishearth
Rollup of 12 pull requests Successful merges: - rust-lang#72771 (Warn if linking to a private item) - rust-lang#72937 (Fortanix SGX target libunwind build process changes) - rust-lang#73485 (Perform obligation deduplication to avoid buggy `ExistentialMismatch`) - rust-lang#73529 (Add liballoc impl SpecFromElem for i8) - rust-lang#73579 (add missing doc links) - rust-lang#73627 (Shortcuts for min/max on double-ended BTreeMap/BTreeSet iterators) - rust-lang#73691 (Bootstrap: detect Windows based on sys.platform) - rust-lang#73694 (Document the Self keyword) - rust-lang#73718 (Document the super keyword) - rust-lang#73728 (Document some invariants correctly/more) - rust-lang#73738 (Remove irrelevant comment) - rust-lang#73765 (Remove blank line) Failed merges: r? @ghost
2 parents dda8a7f + 50026ae commit 394e1b4

29 files changed

+445
-116
lines changed
 

‎src/bootstrap/bootstrap.py

+6
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def default_build_triple():
184184
ostype = require(["uname", "-s"], exit=required)
185185
cputype = require(['uname', '-m'], exit=required)
186186

187+
# If we do not have `uname`, assume Windows.
187188
if ostype is None or cputype is None:
188189
return 'x86_64-pc-windows-msvc'
189190

@@ -236,6 +237,11 @@ def default_build_triple():
236237
if ostype.endswith('WOW64'):
237238
cputype = 'x86_64'
238239
ostype = 'pc-windows-gnu'
240+
elif sys.platform == 'win32':
241+
# Some Windows platforms might have a `uname` command that returns a
242+
# non-standard string (e.g. gnuwin32 tools returns `windows32`). In
243+
# these cases, fall back to using sys.platform.
244+
return 'x86_64-pc-windows-msvc'
239245
else:
240246
err = "unknown OS type: {}".format(ostype)
241247
sys.exit(err)

‎src/bootstrap/compile.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -131,26 +131,13 @@ fn copy_third_party_objects(
131131
compiler: &Compiler,
132132
target: Interned<String>,
133133
) -> Vec<(PathBuf, DependencyType)> {
134-
let libdir = builder.sysroot_libdir(*compiler, target);
135134
let mut target_deps = vec![];
136135

137-
// Copies libunwind.a compiled to be linked with x86_64-fortanix-unknown-sgx.
138-
//
139-
// This target needs to be linked to Fortanix's port of llvm's libunwind.
140-
// libunwind requires support for rwlock and printing to stderr,
141-
// which is provided by std for this target.
136+
// FIXME: remove this in 2021
142137
if target == "x86_64-fortanix-unknown-sgx" {
143-
let src_path_env = "X86_FORTANIX_SGX_LIBS";
144-
let src =
145-
env::var(src_path_env).unwrap_or_else(|_| panic!("{} not found in env", src_path_env));
146-
copy_and_stamp(
147-
builder,
148-
&*libdir,
149-
Path::new(&src),
150-
"libunwind.a",
151-
&mut target_deps,
152-
DependencyType::Target,
153-
);
138+
if env::var_os("X86_FORTANIX_SGX_LIBS").is_some() {
139+
builder.info("Warning: X86_FORTANIX_SGX_LIBS environment variable is ignored, libunwind is now compiled as part of rustbuild");
140+
}
154141
}
155142

156143
if builder.config.sanitizers && compiler.stage != 0 {

‎src/ci/docker/dist-various-2/Dockerfile

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ RUN /tmp/build-solaris-toolchain.sh sparcv9 sparcv9 solaris-sparc
7171
COPY dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh /tmp/
7272
COPY dist-various-2/x86_64-fortanix-unknown-sgx-clang-wrap.sh /usr/bin/x86_64-fortanix-unknown-sgx-clang-11
7373
RUN ln -s /usr/bin/x86_64-fortanix-unknown-sgx-clang-11 /usr/bin/x86_64-fortanix-unknown-sgx-clang++-11
74-
# We pass the commit id of the port of LLVM's libunwind to the build script.
75-
# Any update to the commit id here, should cause the container image to be re-built from this point on.
76-
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh "800f95131fe6acd20b96b6f4723ca3c820f3d379"
74+
RUN /tmp/build-x86_64-fortanix-unknown-sgx-toolchain.sh
7775

7876
COPY dist-various-2/build-wasi-toolchain.sh /tmp/
7977
RUN /tmp/build-wasi-toolchain.sh
@@ -105,8 +103,6 @@ ENV TARGETS=$TARGETS,nvptx64-nvidia-cuda
105103
ENV TARGETS=$TARGETS,armv7-unknown-linux-gnueabi
106104
ENV TARGETS=$TARGETS,armv7-unknown-linux-musleabi
107105

108-
ENV X86_FORTANIX_SGX_LIBS="/x86_64-fortanix-unknown-sgx/lib/"
109-
110106
# As per https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211
111107
# we need asm in the search path for gcc-7 (for gnux32) but not in the search path of the
112108
# cross compilers.

‎src/ci/docker/dist-various-2/build-x86_64-fortanix-unknown-sgx-toolchain.sh

-42
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,7 @@
33
set -eu
44
source shared.sh
55

6-
if [ -z "$1" ]; then
7-
echo "Usage: ${0} <commit_id>"
8-
exit -1
9-
fi
10-
116
target="x86_64-fortanix-unknown-sgx"
12-
url="https://github.com/fortanix/llvm-project/archive/${1}.tar.gz"
13-
repo_name="llvm-project"
147

158
install_prereq() {
169
curl https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add -
@@ -24,39 +17,4 @@ install_prereq() {
2417
clang-11
2518
}
2619

27-
build_unwind() {
28-
set -x
29-
dir_name="${target}_temp"
30-
rm -rf ${dir_name}
31-
mkdir -p ${dir_name}
32-
pushd ${dir_name}
33-
34-
# Clone Fortanix's fork of llvm-project which has a port of libunwind
35-
fetch_github_commit_archive "$repo_name" "$url"
36-
cd "${repo_name}/libunwind"
37-
38-
# Build libunwind
39-
mkdir -p build
40-
cd build
41-
target_CC="CC_${target//-/_}"
42-
target_CXX="CXX_${target//-/_}"
43-
target_CFLAGS="CFLAGS_${target//-/_}"
44-
target_CXXFLAGS="CXXFLAGS_${target//-/_}"
45-
cmake -DCMAKE_BUILD_TYPE="RELEASE" -DRUST_SGX=1 -G "Unix Makefiles" \
46-
-DCMAKE_C_COMPILER="${!target_CC}" -DCMAKE_CXX_COMPILER="${!target_CXX}" \
47-
-DCMAKE_C_FLAGS="${!target_CFLAGS}" -DCMAKE_CXX_FLAGS="${!target_CXXFLAGS}" \
48-
-DCMAKE_C_COMPILER_TARGET=$target -DCMAKE_CXX_COMPILER_TARGET=$target \
49-
-DLLVM_ENABLE_WARNINGS=1 -DLIBUNWIND_ENABLE_WERROR=1 -DLIBUNWIND_ENABLE_PEDANTIC=0 \
50-
-DLLVM_PATH=../../llvm/ ../
51-
make unwind_static
52-
install -D "lib/libunwind.a" "/${target}/lib/libunwind.a"
53-
54-
popd
55-
rm -rf ${dir_name}
56-
57-
{ set +x; } 2>/dev/null
58-
}
59-
60-
set -x
6120
hide_output install_prereq
62-
build_unwind

‎src/liballoc/collections/btree/map.rs

+40
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,14 @@ impl<'a, K: 'a, V: 'a> Iterator for Iter<'a, K, V> {
13961396
fn last(mut self) -> Option<(&'a K, &'a V)> {
13971397
self.next_back()
13981398
}
1399+
1400+
fn min(mut self) -> Option<(&'a K, &'a V)> {
1401+
self.next()
1402+
}
1403+
1404+
fn max(mut self) -> Option<(&'a K, &'a V)> {
1405+
self.next_back()
1406+
}
13991407
}
14001408

14011409
#[stable(feature = "fused", since = "1.26.0")]
@@ -1458,6 +1466,14 @@ impl<'a, K: 'a, V: 'a> Iterator for IterMut<'a, K, V> {
14581466
fn last(mut self) -> Option<(&'a K, &'a mut V)> {
14591467
self.next_back()
14601468
}
1469+
1470+
fn min(mut self) -> Option<(&'a K, &'a mut V)> {
1471+
self.next()
1472+
}
1473+
1474+
fn max(mut self) -> Option<(&'a K, &'a mut V)> {
1475+
self.next_back()
1476+
}
14611477
}
14621478

14631479
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1595,6 +1611,14 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
15951611
fn last(mut self) -> Option<&'a K> {
15961612
self.next_back()
15971613
}
1614+
1615+
fn min(mut self) -> Option<&'a K> {
1616+
self.next()
1617+
}
1618+
1619+
fn max(mut self) -> Option<&'a K> {
1620+
self.next_back()
1621+
}
15981622
}
15991623

16001624
#[stable(feature = "rust1", since = "1.0.0")]
@@ -1768,6 +1792,14 @@ impl<'a, K, V> Iterator for Range<'a, K, V> {
17681792
fn last(mut self) -> Option<(&'a K, &'a V)> {
17691793
self.next_back()
17701794
}
1795+
1796+
fn min(mut self) -> Option<(&'a K, &'a V)> {
1797+
self.next()
1798+
}
1799+
1800+
fn max(mut self) -> Option<(&'a K, &'a V)> {
1801+
self.next_back()
1802+
}
17711803
}
17721804

17731805
#[stable(feature = "map_values_mut", since = "1.10.0")]
@@ -1853,6 +1885,14 @@ impl<'a, K, V> Iterator for RangeMut<'a, K, V> {
18531885
fn last(mut self) -> Option<(&'a K, &'a mut V)> {
18541886
self.next_back()
18551887
}
1888+
1889+
fn min(mut self) -> Option<(&'a K, &'a mut V)> {
1890+
self.next()
1891+
}
1892+
1893+
fn max(mut self) -> Option<(&'a K, &'a mut V)> {
1894+
self.next_back()
1895+
}
18561896
}
18571897

18581898
impl<'a, K, V> RangeMut<'a, K, V> {

‎src/liballoc/collections/btree/set.rs

+35
Original file line numberDiff line numberDiff line change
@@ -1291,12 +1291,22 @@ impl<'a, T> Iterator for Iter<'a, T> {
12911291
fn next(&mut self) -> Option<&'a T> {
12921292
self.iter.next()
12931293
}
1294+
12941295
fn size_hint(&self) -> (usize, Option<usize>) {
12951296
self.iter.size_hint()
12961297
}
1298+
12971299
fn last(mut self) -> Option<&'a T> {
12981300
self.next_back()
12991301
}
1302+
1303+
fn min(mut self) -> Option<&'a T> {
1304+
self.next()
1305+
}
1306+
1307+
fn max(mut self) -> Option<&'a T> {
1308+
self.next_back()
1309+
}
13001310
}
13011311
#[stable(feature = "rust1", since = "1.0.0")]
13021312
impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
@@ -1321,6 +1331,7 @@ impl<T> Iterator for IntoIter<T> {
13211331
fn next(&mut self) -> Option<T> {
13221332
self.iter.next().map(|(k, _)| k)
13231333
}
1334+
13241335
fn size_hint(&self) -> (usize, Option<usize>) {
13251336
self.iter.size_hint()
13261337
}
@@ -1359,6 +1370,14 @@ impl<'a, T> Iterator for Range<'a, T> {
13591370
fn last(mut self) -> Option<&'a T> {
13601371
self.next_back()
13611372
}
1373+
1374+
fn min(mut self) -> Option<&'a T> {
1375+
self.next()
1376+
}
1377+
1378+
fn max(mut self) -> Option<&'a T> {
1379+
self.next_back()
1380+
}
13621381
}
13631382

13641383
#[stable(feature = "btree_range", since = "1.17.0")]
@@ -1429,6 +1448,10 @@ impl<'a, T: Ord> Iterator for Difference<'a, T> {
14291448
};
14301449
(self_len.saturating_sub(other_len), Some(self_len))
14311450
}
1451+
1452+
fn min(mut self) -> Option<&'a T> {
1453+
self.next()
1454+
}
14321455
}
14331456

14341457
#[stable(feature = "fused", since = "1.26.0")]
@@ -1460,6 +1483,10 @@ impl<'a, T: Ord> Iterator for SymmetricDifference<'a, T> {
14601483
// the number of elements to less than half the range of usize.
14611484
(0, Some(a_len + b_len))
14621485
}
1486+
1487+
fn min(mut self) -> Option<&'a T> {
1488+
self.next()
1489+
}
14631490
}
14641491

14651492
#[stable(feature = "fused", since = "1.26.0")]
@@ -1516,6 +1543,10 @@ impl<'a, T: Ord> Iterator for Intersection<'a, T> {
15161543
IntersectionInner::Answer(Some(_)) => (1, Some(1)),
15171544
}
15181545
}
1546+
1547+
fn min(mut self) -> Option<&'a T> {
1548+
self.next()
1549+
}
15191550
}
15201551

15211552
#[stable(feature = "fused", since = "1.26.0")]
@@ -1541,6 +1572,10 @@ impl<'a, T: Ord> Iterator for Union<'a, T> {
15411572
// No checked_add - see SymmetricDifference::size_hint.
15421573
(max(a_len, b_len), Some(a_len + b_len))
15431574
}
1575+
1576+
fn min(mut self) -> Option<&'a T> {
1577+
self.next()
1578+
}
15441579
}
15451580

15461581
#[stable(feature = "fused", since = "1.26.0")]

‎src/liballoc/raw_vec/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ fn allocator_param() {
1212
//
1313
// Instead, this just checks that the `RawVec` methods do at
1414
// least go through the Allocator API when it reserves
15-
1615
// storage.
1716

1817
// A dumb allocator that consumes a fixed amount of fuel

‎src/liballoc/tests/btree/map.rs

+35
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,41 @@ fn test_iter_mixed() {
309309
test(size, map.into_iter());
310310
}
311311

312+
#[test]
313+
fn test_iter_min_max() {
314+
let mut a = BTreeMap::new();
315+
assert_eq!(a.iter().min(), None);
316+
assert_eq!(a.iter().max(), None);
317+
assert_eq!(a.iter_mut().min(), None);
318+
assert_eq!(a.iter_mut().max(), None);
319+
assert_eq!(a.range(..).min(), None);
320+
assert_eq!(a.range(..).max(), None);
321+
assert_eq!(a.range_mut(..).min(), None);
322+
assert_eq!(a.range_mut(..).max(), None);
323+
assert_eq!(a.keys().min(), None);
324+
assert_eq!(a.keys().max(), None);
325+
assert_eq!(a.values().min(), None);
326+
assert_eq!(a.values().max(), None);
327+
assert_eq!(a.values_mut().min(), None);
328+
assert_eq!(a.values_mut().max(), None);
329+
a.insert(1, 42);
330+
a.insert(2, 24);
331+
assert_eq!(a.iter().min(), Some((&1, &42)));
332+
assert_eq!(a.iter().max(), Some((&2, &24)));
333+
assert_eq!(a.iter_mut().min(), Some((&1, &mut 42)));
334+
assert_eq!(a.iter_mut().max(), Some((&2, &mut 24)));
335+
assert_eq!(a.range(..).min(), Some((&1, &42)));
336+
assert_eq!(a.range(..).max(), Some((&2, &24)));
337+
assert_eq!(a.range_mut(..).min(), Some((&1, &mut 42)));
338+
assert_eq!(a.range_mut(..).max(), Some((&2, &mut 24)));
339+
assert_eq!(a.keys().min(), Some(&1));
340+
assert_eq!(a.keys().max(), Some(&2));
341+
assert_eq!(a.values().min(), Some(&24));
342+
assert_eq!(a.values().max(), Some(&42));
343+
assert_eq!(a.values_mut().min(), Some(&mut 24));
344+
assert_eq!(a.values_mut().max(), Some(&mut 42));
345+
}
346+
312347
fn range_keys(map: &BTreeMap<i32, i32>, range: impl RangeBounds<i32>) -> Vec<i32> {
313348
map.range(range)
314349
.map(|(&k, &v)| {

‎src/liballoc/tests/btree/set.rs

+31
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ fn test_hash() {
3333
assert_eq!(hash(&x), hash(&y));
3434
}
3535

36+
#[test]
37+
fn test_iter_min_max() {
38+
let mut a = BTreeSet::new();
39+
assert_eq!(a.iter().min(), None);
40+
assert_eq!(a.iter().max(), None);
41+
assert_eq!(a.range(..).min(), None);
42+
assert_eq!(a.range(..).max(), None);
43+
assert_eq!(a.difference(&BTreeSet::new()).min(), None);
44+
assert_eq!(a.difference(&BTreeSet::new()).max(), None);
45+
assert_eq!(a.intersection(&a).min(), None);
46+
assert_eq!(a.intersection(&a).max(), None);
47+
assert_eq!(a.symmetric_difference(&BTreeSet::new()).min(), None);
48+
assert_eq!(a.symmetric_difference(&BTreeSet::new()).max(), None);
49+
assert_eq!(a.union(&a).min(), None);
50+
assert_eq!(a.union(&a).max(), None);
51+
a.insert(1);
52+
a.insert(2);
53+
assert_eq!(a.iter().min(), Some(&1));
54+
assert_eq!(a.iter().max(), Some(&2));
55+
assert_eq!(a.range(..).min(), Some(&1));
56+
assert_eq!(a.range(..).max(), Some(&2));
57+
assert_eq!(a.difference(&BTreeSet::new()).min(), Some(&1));
58+
assert_eq!(a.difference(&BTreeSet::new()).max(), Some(&2));
59+
assert_eq!(a.intersection(&a).min(), Some(&1));
60+
assert_eq!(a.intersection(&a).max(), Some(&2));
61+
assert_eq!(a.symmetric_difference(&BTreeSet::new()).min(), Some(&1));
62+
assert_eq!(a.symmetric_difference(&BTreeSet::new()).max(), Some(&2));
63+
assert_eq!(a.union(&a).min(), Some(&1));
64+
assert_eq!(a.union(&a).max(), Some(&2));
65+
}
66+
3667
fn check<F>(a: &[i32], b: &[i32], expected: &[i32], f: F)
3768
where
3869
F: FnOnce(&BTreeSet<i32>, &BTreeSet<i32>, &mut dyn FnMut(&i32) -> bool) -> bool,

‎src/liballoc/vec.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1801,6 +1801,21 @@ impl<T: Clone> SpecFromElem for T {
18011801
}
18021802
}
18031803

1804+
impl SpecFromElem for i8 {
1805+
#[inline]
1806+
fn from_elem(elem: i8, n: usize) -> Vec<i8> {
1807+
if elem == 0 {
1808+
return Vec { buf: RawVec::with_capacity_zeroed(n), len: n };
1809+
}
1810+
unsafe {
1811+
let mut v = Vec::with_capacity(n);
1812+
ptr::write_bytes(v.as_mut_ptr(), elem as u8, n);
1813+
v.set_len(n);
1814+
v
1815+
}
1816+
}
1817+
}
1818+
18041819
impl SpecFromElem for u8 {
18051820
#[inline]
18061821
fn from_elem(elem: u8, n: usize) -> Vec<u8> {
@@ -1845,7 +1860,6 @@ macro_rules! impl_is_zero {
18451860
};
18461861
}
18471862

1848-
impl_is_zero!(i8, |x| x == 0);
18491863
impl_is_zero!(i16, |x| x == 0);
18501864
impl_is_zero!(i32, |x| x == 0);
18511865
impl_is_zero!(i64, |x| x == 0);

‎src/libcore/mem/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -358,12 +358,13 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
358358
/// - an (unstable) [extern type], then this function is always safe to
359359
/// call, but may panic or otherwise return the wrong value, as the
360360
/// extern type's layout is not known. This is the same behavior as
361-
/// [`size_of_val`] on a reference to an extern type tail.
361+
/// [`size_of_val`] on a reference to a type with an extern type tail.
362362
/// - otherwise, it is conservatively not allowed to call this function.
363363
///
364364
/// [slice]: ../../std/primitive.slice.html
365365
/// [trait object]: ../../book/ch17-02-trait-objects.html
366366
/// [extern type]: ../../unstable-book/language-features/extern-types.html
367+
/// [`size_of_val`]: ../../core/mem/fn.size_of_val.html
367368
///
368369
/// # Examples
369370
///
@@ -492,12 +493,13 @@ pub fn align_of_val<T: ?Sized>(val: &T) -> usize {
492493
/// - an (unstable) [extern type], then this function is always safe to
493494
/// call, but may panic or otherwise return the wrong value, as the
494495
/// extern type's layout is not known. This is the same behavior as
495-
/// [`align_of_val`] on a reference to an extern type tail.
496+
/// [`align_of_val`] on a reference to a type with an extern type tail.
496497
/// - otherwise, it is conservatively not allowed to call this function.
497498
///
498499
/// [slice]: ../../std/primitive.slice.html
499500
/// [trait object]: ../../book/ch17-02-trait-objects.html
500501
/// [extern type]: ../../unstable-book/language-features/extern-types.html
502+
/// [`align_of_val`]: ../../core/mem/fn.align_of_val.html
501503
///
502504
/// # Examples
503505
///

‎src/libcore/option.rs

-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ use crate::{
142142
ops::{self, Deref, DerefMut},
143143
};
144144

145-
// Note that this is not a lang item per se, but it has a hidden dependency on
146-
// `Iterator`, which is one. The compiler assumes that the `next` method of
147-
// `Iterator` is an enumeration with one type parameter and two variants,
148-
// which basically means it must be `Option`.
149-
150145
/// The `Option` type. See [the module level documentation](index.html) for more.
151146
#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
152147
#[rustc_diagnostic_item = "option_type"]

‎src/librustc_middle/ty/relate.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -617,12 +617,22 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::ExistentialPredicate<'tcx>> {
617617
a: &Self,
618618
b: &Self,
619619
) -> RelateResult<'tcx, Self> {
620-
if a.len() != b.len() {
620+
let tcx = relation.tcx();
621+
622+
// FIXME: this is wasteful, but want to do a perf run to see how slow it is.
623+
// We need to perform this deduplication as we sometimes generate duplicate projections
624+
// in `a`.
625+
let mut a_v: Vec<_> = a.into_iter().collect();
626+
let mut b_v: Vec<_> = b.into_iter().collect();
627+
a_v.sort_by(|a, b| a.stable_cmp(tcx, b));
628+
a_v.dedup();
629+
b_v.sort_by(|a, b| a.stable_cmp(tcx, b));
630+
b_v.dedup();
631+
if a_v.len() != b_v.len() {
621632
return Err(TypeError::ExistentialMismatch(expected_found(relation, a, b)));
622633
}
623634

624-
let tcx = relation.tcx();
625-
let v = a.iter().zip(b.iter()).map(|(ep_a, ep_b)| {
635+
let v = a_v.into_iter().zip(b_v.into_iter()).map(|(ep_a, ep_b)| {
626636
use crate::ty::ExistentialPredicate::*;
627637
match (ep_a, ep_b) {
628638
(Trait(ref a), Trait(ref b)) => Ok(Trait(relation.relate(a, b)?)),

‎src/librustc_mir/transform/const_prop.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
350350
}
351351

352352
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
353-
let op = self.ecx.eval_place_to_op(place, None).ok();
353+
let op = match self.ecx.eval_place_to_op(place, None) {
354+
Ok(op) => op,
355+
Err(e) => {
356+
trace!("get_const failed: {}", e);
357+
return None;
358+
}
359+
};
354360

355361
// Try to read the local as an immediate so that if it is representable as a scalar, we can
356362
// handle it as such, but otherwise, just return the value as is.
357-
match op.map(|ret| self.ecx.try_read_immediate(ret)) {
358-
Some(Ok(Ok(imm))) => Some(imm.into()),
363+
Some(match self.ecx.try_read_immediate(op) {
364+
Ok(Ok(imm)) => imm.into(),
359365
_ => op,
360-
}
366+
})
361367
}
362368

363369
/// Remove `local` from the pool of `Locals`. Allows writing to them,
@@ -872,8 +878,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
872878
if let Ok(place_layout) = self.tcx.layout_of(self.param_env.and(place_ty)) {
873879
let can_const_prop = self.can_const_prop[place.local];
874880
if let Some(()) = self.const_prop(rval, place_layout, source_info, place) {
875-
// This will return None for variables that are from other blocks,
876-
// so it should be okay to propagate from here on down.
881+
// This will return None if the above `const_prop` invocation only "wrote" a
882+
// type whose creation requires no write. E.g. a generator whose initial state
883+
// consists solely of uninitialized memory (so it doesn't capture any locals).
877884
if let Some(value) = self.get_const(place) {
878885
if self.should_const_prop(value) {
879886
trace!("replacing {:?} with {:?}", rval, value);

‎src/librustc_target/spec/x86_64_fortanix_unknown_sgx.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ pub fn target() -> Result<Target, String> {
4848
"ENCLAVE_SIZE",
4949
"CFGDATA_BASE",
5050
"DEBUG",
51-
"EH_FRM_HDR_BASE",
52-
"EH_FRM_HDR_SIZE",
51+
"EH_FRM_HDR_OFFSET",
52+
"EH_FRM_HDR_LEN",
53+
"EH_FRM_OFFSET",
54+
"EH_FRM_LEN",
5355
"TEXT_BASE",
5456
"TEXT_SIZE",
5557
];

‎src/librustdoc/config.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,6 @@ pub struct Options {
123123
///
124124
/// Be aware: This option can come both from the CLI and from crate attributes!
125125
pub default_passes: DefaultPassOption,
126-
/// Document items that have lower than `pub` visibility.
127-
pub document_private: bool,
128-
/// Document items that have `doc(hidden)`.
129-
pub document_hidden: bool,
130126
/// Any passes manually selected by the user.
131127
///
132128
/// Be aware: This option can come both from the CLI and from crate attributes!
@@ -177,8 +173,6 @@ impl fmt::Debug for Options {
177173
.field("test_args", &self.test_args)
178174
.field("persist_doctests", &self.persist_doctests)
179175
.field("default_passes", &self.default_passes)
180-
.field("document_private", &self.document_private)
181-
.field("document_hidden", &self.document_hidden)
182176
.field("manual_passes", &self.manual_passes)
183177
.field("display_warnings", &self.display_warnings)
184178
.field("show_coverage", &self.show_coverage)
@@ -250,6 +244,10 @@ pub struct RenderOptions {
250244
pub generate_search_filter: bool,
251245
/// Option (disabled by default) to generate files used by RLS and some other tools.
252246
pub generate_redirect_pages: bool,
247+
/// Document items that have lower than `pub` visibility.
248+
pub document_private: bool,
249+
/// Document items that have `doc(hidden)`.
250+
pub document_hidden: bool,
253251
}
254252

255253
impl Options {
@@ -567,8 +565,6 @@ impl Options {
567565
should_test,
568566
test_args,
569567
default_passes,
570-
document_private,
571-
document_hidden,
572568
manual_passes,
573569
display_warnings,
574570
show_coverage,
@@ -597,6 +593,8 @@ impl Options {
597593
markdown_playground_url,
598594
generate_search_filter,
599595
generate_redirect_pages,
596+
document_private,
597+
document_hidden,
600598
},
601599
output_format,
602600
})

‎src/librustdoc/core.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub struct DocContext<'tcx> {
6262
// FIXME(eddyb) make this a `ty::TraitRef<'tcx>` set.
6363
pub generated_synthetics: RefCell<FxHashSet<(Ty<'tcx>, DefId)>>,
6464
pub auto_traits: Vec<DefId>,
65+
/// The options given to rustdoc that could be relevant to a pass.
66+
pub render_options: RenderOptions,
6567
}
6668

6769
impl<'tcx> DocContext<'tcx> {
@@ -281,8 +283,6 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
281283
describe_lints,
282284
lint_cap,
283285
mut default_passes,
284-
mut document_private,
285-
document_hidden,
286286
mut manual_passes,
287287
display_warnings,
288288
render_options,
@@ -448,6 +448,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
448448
.cloned()
449449
.filter(|trait_def_id| tcx.trait_is_auto(*trait_def_id))
450450
.collect(),
451+
render_options,
451452
};
452453
debug!("crate: {:?}", tcx.hir().krate());
453454

@@ -524,7 +525,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
524525
}
525526

526527
if attr.is_word() && name == sym::document_private_items {
527-
document_private = true;
528+
ctxt.render_options.document_private = true;
528529
}
529530
}
530531

@@ -544,9 +545,9 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
544545
for p in passes {
545546
let run = match p.condition {
546547
Always => true,
547-
WhenDocumentPrivate => document_private,
548-
WhenNotDocumentPrivate => !document_private,
549-
WhenNotDocumentHidden => !document_hidden,
548+
WhenDocumentPrivate => ctxt.render_options.document_private,
549+
WhenNotDocumentPrivate => !ctxt.render_options.document_private,
550+
WhenNotDocumentHidden => !ctxt.render_options.document_hidden,
550551
};
551552
if run {
552553
debug!("running pass {}", p.pass.name);
@@ -556,7 +557,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
556557

557558
ctxt.sess().abort_if_errors();
558559

559-
(krate, ctxt.renderinfo.into_inner(), render_options)
560+
(krate, ctxt.renderinfo.into_inner(), ctxt.render_options)
560561
})
561562
})
562563
})

‎src/librustdoc/html/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ impl clean::Path {
468468

469469
pub fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
470470
let cache = cache();
471-
if !did.is_local() && !cache.access_levels.is_public(did) {
471+
if !did.is_local() && !cache.access_levels.is_public(did) && !cache.document_private {
472472
return None;
473473
}
474474

‎src/librustdoc/html/render.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ pub fn run(
469469
static_root_path,
470470
generate_search_filter,
471471
generate_redirect_pages,
472+
document_private,
472473
..
473474
} = options;
474475

@@ -546,7 +547,7 @@ pub fn run(
546547
scx.ensure_dir(&dst)?;
547548
krate = sources::render(&dst, &mut scx, krate)?;
548549
let (new_crate, index, cache) =
549-
Cache::from_krate(renderinfo, &extern_html_root_urls, &dst, krate);
550+
Cache::from_krate(renderinfo, document_private, &extern_html_root_urls, &dst, krate);
550551
krate = new_crate;
551552
let cache = Arc::new(cache);
552553
let mut cx = Context {

‎src/librustdoc/html/render/cache.rs

+6
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ crate struct Cache {
9191
/// The version of the crate being documented, if given from the `--crate-version` flag.
9292
pub crate_version: Option<String>,
9393

94+
/// Whether to document private items.
95+
/// This is stored in `Cache` so it doesn't need to be passed through all rustdoc functions.
96+
pub document_private: bool,
97+
9498
// Private fields only used when initially crawling a crate to build a cache
9599
stack: Vec<String>,
96100
parent_stack: Vec<DefId>,
@@ -126,6 +130,7 @@ crate struct Cache {
126130
impl Cache {
127131
pub fn from_krate(
128132
renderinfo: RenderInfo,
133+
document_private: bool,
129134
extern_html_root_urls: &BTreeMap<String, String>,
130135
dst: &Path,
131136
mut krate: clean::Crate,
@@ -160,6 +165,7 @@ impl Cache {
160165
stripped_mod: false,
161166
access_levels,
162167
crate_version: krate.version.take(),
168+
document_private,
163169
orphan_impl_items: Vec::new(),
164170
orphan_trait_impls: Vec::new(),
165171
traits: krate.external_traits.replace(Default::default()),

‎src/librustdoc/passes/collect_intra_doc_links.rs

+39-6
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
178178
let result = cx.enter_resolver(|resolver| {
179179
resolver.resolve_str_path_error(DUMMY_SP, &path_str, ns, module_id)
180180
});
181+
debug!("{} resolved to {:?} in namespace {:?}", path_str, result, ns);
181182
let result = match result {
182183
Ok((_, Res::Err)) => Err(ErrorKind::ResolutionFailure),
183184
_ => result.map_err(|_| ErrorKind::ResolutionFailure),
@@ -202,7 +203,13 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> {
202203
}
203204
return Ok((res, Some(path_str.to_owned())));
204205
}
205-
_ => return Ok((res, extra_fragment.clone())),
206+
other => {
207+
debug!(
208+
"failed to resolve {} in namespace {:?} (got {:?})",
209+
path_str, ns, other
210+
);
211+
return Ok((res, extra_fragment.clone()));
212+
}
206213
};
207214

208215
if value != (ns == ValueNS) {
@@ -555,12 +562,13 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
555562
} else {
556563
(parts[0].to_owned(), None)
557564
};
565+
let resolved_self;
566+
let mut path_str;
558567
let (res, fragment) = {
559568
let mut kind = None;
560-
let mut path_str = if let Some(prefix) =
561-
["struct@", "enum@", "type@", "trait@", "union@"]
562-
.iter()
563-
.find(|p| link.starts_with(**p))
569+
path_str = if let Some(prefix) = ["struct@", "enum@", "type@", "trait@", "union@"]
570+
.iter()
571+
.find(|p| link.starts_with(**p))
564572
{
565573
kind = Some(TypeNS);
566574
link.trim_start_matches(prefix)
@@ -614,7 +622,6 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
614622
let base_node =
615623
if item.is_mod() && item.attrs.inner_docs { None } else { parent_node };
616624

617-
let resolved_self;
618625
// replace `Self` with suitable item's parent name
619626
if path_str.starts_with("Self::") {
620627
if let Some(ref name) = parent_name {
@@ -760,6 +767,32 @@ impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {
760767
if let Res::PrimTy(_) = res {
761768
item.attrs.links.push((ori_link, None, fragment));
762769
} else {
770+
debug!("intra-doc link to {} resolved to {:?}", path_str, res);
771+
if let Some(local) = res.opt_def_id().and_then(|def_id| def_id.as_local()) {
772+
use rustc_hir::def_id::LOCAL_CRATE;
773+
774+
let hir_id = self.cx.tcx.hir().as_local_hir_id(local);
775+
if !self.cx.tcx.privacy_access_levels(LOCAL_CRATE).is_exported(hir_id)
776+
&& !self.cx.render_options.document_private
777+
{
778+
let item_name = item.name.as_deref().unwrap_or("<unknown>");
779+
let err_msg = format!(
780+
"public documentation for `{}` links to a private item",
781+
item_name
782+
);
783+
build_diagnostic(
784+
cx,
785+
&item,
786+
path_str,
787+
&dox,
788+
link_range,
789+
&err_msg,
790+
"this item is private",
791+
None,
792+
);
793+
continue;
794+
}
795+
}
763796
let id = register_res(cx, res);
764797
item.attrs.links.push((ori_link, Some(id), fragment));
765798
}

‎src/libstd/keyword_docs.rs

+75-4
Original file line numberDiff line numberDiff line change
@@ -1217,11 +1217,66 @@ mod self_keyword {}
12171217
/// The implementing type within a [`trait`] or [`impl`] block, or the current type within a type
12181218
/// definition.
12191219
///
1220-
/// The documentation for this keyword is [not yet complete]. Pull requests welcome!
1220+
/// Within a type definition:
1221+
///
1222+
/// ```
1223+
/// # #![allow(dead_code)]
1224+
/// struct Node {
1225+
/// elem: i32,
1226+
/// // `Self` is a `Node` here.
1227+
/// next: Option<Box<Self>>,
1228+
/// }
1229+
/// ```
1230+
///
1231+
/// In an [`impl`] block:
1232+
///
1233+
/// ```
1234+
/// struct Foo(i32);
1235+
///
1236+
/// impl Foo {
1237+
/// fn new() -> Self {
1238+
/// Self(0)
1239+
/// }
1240+
/// }
1241+
///
1242+
/// assert_eq!(Foo::new().0, Foo(0).0);
1243+
/// ```
1244+
///
1245+
/// Generic parameters are implicit with `Self`:
1246+
///
1247+
/// ```
1248+
/// # #![allow(dead_code)]
1249+
/// struct Wrap<T> {
1250+
/// elem: T,
1251+
/// }
1252+
///
1253+
/// impl<T> Wrap<T> {
1254+
/// fn new(elem: T) -> Self {
1255+
/// Self { elem }
1256+
/// }
1257+
/// }
1258+
/// ```
1259+
///
1260+
/// In a [`trait`] definition and related [`impl`] block:
1261+
///
1262+
/// ```
1263+
/// trait Example {
1264+
/// fn example() -> Self;
1265+
/// }
1266+
///
1267+
/// struct Foo(i32);
1268+
///
1269+
/// impl Example for Foo {
1270+
/// fn example() -> Self {
1271+
/// Self(42)
1272+
/// }
1273+
/// }
1274+
///
1275+
/// assert_eq!(Foo::example().0, Foo(42).0);
1276+
/// ```
12211277
///
12221278
/// [`impl`]: keyword.impl.html
12231279
/// [`trait`]: keyword.trait.html
1224-
/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
12251280
mod self_upper_keyword {}
12261281

12271282
#[doc(keyword = "static")]
@@ -1345,10 +1400,26 @@ mod struct_keyword {}
13451400
//
13461401
/// The parent of the current [module].
13471402
///
1348-
/// The documentation for this keyword is [not yet complete]. Pull requests welcome!
1403+
/// ```rust
1404+
/// # #![allow(dead_code)]
1405+
/// # fn main() {}
1406+
/// mod a {
1407+
/// pub fn foo() {}
1408+
/// }
1409+
/// mod b {
1410+
/// pub fn foo() {
1411+
/// super::a::foo(); // call a's foo function
1412+
/// }
1413+
/// }
1414+
/// ```
1415+
///
1416+
/// It is also possible to use `super` multiple times: `super::super::foo`,
1417+
/// going up the ancestor chain.
1418+
///
1419+
/// See the [Reference] for more information.
13491420
///
13501421
/// [module]: ../reference/items/modules.html
1351-
/// [not yet complete]: https://github.com/rust-lang/rust/issues/34601
1422+
/// [Reference]: ../reference/paths.html#super
13521423
mod super_keyword {}
13531424

13541425
#[doc(keyword = "trait")]

‎src/libstd/sys/sgx/abi/entry.S

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ IMAGE_BASE:
1111
.long 1 /* type = NT_VERSION */
1212
0: .asciz "toolchain-version" /* name */
1313
1: .align 4
14-
2: .long 0 /* desc - toolchain version number, 32-bit LE */
14+
2: .long 1 /* desc - toolchain version number, 32-bit LE */
1515
3: .align 4
1616

1717
.section .rodata
@@ -60,10 +60,14 @@ IMAGE_BASE:
6060
globvar TEXT_BASE 8
6161
/* The size in bytes of enclacve text section */
6262
globvar TEXT_SIZE 8
63-
/* The base address (relative to enclave start) of the enclave EH_FRM_HDR section */
64-
globvar EH_FRM_HDR_BASE 8
65-
/* The size in bytes of enclacve EH_FRM_HDR section */
66-
globvar EH_FRM_HDR_SIZE 8
63+
/* The base address (relative to enclave start) of the enclave .eh_frame_hdr section */
64+
globvar EH_FRM_HDR_OFFSET 8
65+
/* The size in bytes of enclave .eh_frame_hdr section */
66+
globvar EH_FRM_HDR_LEN 8
67+
/* The base address (relative to enclave start) of the enclave .eh_frame section */
68+
globvar EH_FRM_OFFSET 8
69+
/* The size in bytes of enclacve .eh_frame section */
70+
globvar EH_FRM_LEN 8
6771

6872
.org .Lxsave_clear+512
6973
.Lxsave_header:

‎src/libunwind/build.rs

+36
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ fn main() {
99
{
1010
// Build the unwinding from libunwind C/C++ source code.
1111
llvm_libunwind::compile();
12+
} else if target.contains("x86_64-fortanix-unknown-sgx") {
13+
llvm_libunwind::compile();
1214
} else if target.contains("linux") {
1315
if target.contains("musl") {
1416
// linking for musl is handled in lib.rs
@@ -55,6 +57,7 @@ mod llvm_libunwind {
5557

5658
/// Compile the libunwind C/C++ source code.
5759
pub fn compile() {
60+
let target = env::var("TARGET").expect("TARGET was not set");
5861
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
5962
let target_vendor = env::var("CARGO_CFG_TARGET_VENDOR").unwrap();
6063
let target_endian_little = env::var("CARGO_CFG_TARGET_ENDIAN").unwrap() != "big";
@@ -75,6 +78,35 @@ mod llvm_libunwind {
7578
cfg.flag("/EHsc");
7679
cfg.define("_CRT_SECURE_NO_WARNINGS", None);
7780
cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
81+
} else if target.contains("x86_64-fortanix-unknown-sgx") {
82+
cfg.cpp(false);
83+
84+
cfg.static_flag(true);
85+
cfg.opt_level(3);
86+
87+
cfg.flag("-nostdinc++");
88+
cfg.flag("-fno-exceptions");
89+
cfg.flag("-fno-rtti");
90+
cfg.flag("-fstrict-aliasing");
91+
cfg.flag("-funwind-tables");
92+
cfg.flag("-fvisibility=hidden");
93+
cfg.flag("-fno-stack-protector");
94+
cfg.flag("-ffreestanding");
95+
cfg.flag("-fexceptions");
96+
97+
// easiest way to undefine since no API available in cc::Build to undefine
98+
cfg.flag("-U_FORTIFY_SOURCE");
99+
cfg.define("_FORTIFY_SOURCE", "0");
100+
101+
cfg.flag_if_supported("-fvisibility-global-new-delete-hidden");
102+
103+
cfg.define("_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS", None);
104+
cfg.define("RUST_SGX", "1");
105+
cfg.define("__NO_STRING_INLINES", None);
106+
cfg.define("__NO_MATH_INLINES", None);
107+
cfg.define("_LIBUNWIND_IS_BAREMETAL", None);
108+
cfg.define("__LIBUNWIND_IS_NATIVE_ONLY", None);
109+
cfg.define("NDEBUG", None);
78110
} else {
79111
cfg.flag("-std=c99");
80112
cfg.flag("-std=c++11");
@@ -103,6 +135,10 @@ mod llvm_libunwind {
103135
unwind_sources.push("Unwind_AppleExtras.cpp");
104136
}
105137

138+
if target.contains("x86_64-fortanix-unknown-sgx") {
139+
unwind_sources.push("UnwindRustSgx.c");
140+
}
141+
106142
let root = Path::new("../llvm-project/libunwind");
107143
cfg.include(root.join("include"));
108144
for src in unwind_sources {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: `[DontDocMe]` public documentation for `DocMe` links to a private item
2+
--> $DIR/intra-links-private.rs:6:11
3+
|
4+
LL | /// docs [DontDocMe]
5+
| ^^^^^^^^^ this item is private
6+
|
7+
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
9+
warning: 1 warning emitted
10+
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// check-pass
2+
// revisions: public private
3+
// [private]compile-flags: --document-private-items
4+
#![cfg_attr(private, deny(intra_doc_resolution_failure))]
5+
6+
/// docs [DontDocMe]
7+
//[public]~^ WARNING `[DontDocMe]` public documentation for `DocMe` links to a private item
8+
// FIXME: for [private] we should also make sure the link was actually generated
9+
pub struct DocMe;
10+
struct DontDocMe;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// ignore-test
2+
// check-pass
3+
4+
/// docs [label][with#anchor#error]
5+
//~^ WARNING has an issue with the link anchor
6+
pub struct S;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
warning: `[with#anchor#error]` has an issue with the link anchor.
2+
--> $DIR/reference-link-has-one-warning.rs:3:18
3+
|
4+
LL | /// docs [label][with#anchor#error]
5+
| ^^^^^^^^^^^^^^^^^ only one `#` is allowed in a link
6+
|
7+
= note: `#[warn(intra_doc_link_resolution_failure)]` on by default
8+
9+
warning: 1 warning emitted
10+

‎src/test/ui/issues/issue-59326.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// check-pass
2+
trait Service {
3+
type S;
4+
}
5+
6+
trait Framing {
7+
type F;
8+
}
9+
10+
impl Framing for () {
11+
type F = ();
12+
}
13+
14+
trait HttpService<F: Framing>: Service<S = F::F> {}
15+
16+
type BoxService = Box<dyn HttpService<(), S = ()>>;
17+
18+
fn build_server<F: FnOnce() -> BoxService>(_: F) {}
19+
20+
fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
21+
unimplemented!()
22+
}
23+
24+
fn main() {
25+
build_server(|| make_server())
26+
}

0 commit comments

Comments
 (0)
Please sign in to comment.