Skip to content

Commit 695fe96

Browse files
committed
Auto merge of #66366 - JohnTitor:rollup-xlc1bj2, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #65932 (download .tar.xz if python3 is used) - #66094 (Fix documentation for `Iterator::count()`.) - #66166 (rename cfg(rustdoc) into cfg(doc)) - #66186 (Add long error explanation for E0623) - #66227 (docs: Fix link to BufWriter::flush) - #66248 (add raw ptr variant of UnsafeCell::get) - #66292 (add Result::map_or) - #66297 (Add a callback that allows compiler consumers to override queries.) - #66317 (Use a relative bindir for rustdoc to find rustc) - #66330 (Improve non-exhaustiveness handling in usefulness checking) - #66331 (Add some tests for fixed ICEs) - #66334 (Move Session fields to CrateStore) - #66335 (Move self-profile infrastructure to data structures) - #66337 (Remove dead code for encoding/decoding lint IDs) Failed merges: r? @ghost
2 parents 374ad1b + d52dafd commit 695fe96

File tree

125 files changed

+789
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+789
-318
lines changed

Cargo.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,6 @@ dependencies = [
31203120
"graphviz",
31213121
"jobserver",
31223122
"log",
3123-
"measureme",
31243123
"num_cpus",
31253124
"parking_lot 0.9.0",
31263125
"polonius-engine",
@@ -3470,6 +3469,7 @@ dependencies = [
34703469
name = "rustc_data_structures"
34713470
version = "0.0.0"
34723471
dependencies = [
3472+
"bitflags",
34733473
"cfg-if",
34743474
"crossbeam-utils 0.6.5",
34753475
"ena",
@@ -3478,6 +3478,7 @@ dependencies = [
34783478
"jobserver",
34793479
"lazy_static 1.3.0",
34803480
"log",
3481+
"measureme",
34813482
"parking_lot 0.9.0",
34823483
"rustc-hash",
34833484
"rustc-rayon 0.3.0",

src/bootstrap/bin/rustdoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
let mut dylib_path = bootstrap::util::dylib_path();
2626
dylib_path.insert(0, PathBuf::from(libdir.clone()));
2727

28-
//FIXME(misdreavus): once stdsimd uses cfg(rustdoc) instead of cfg(dox), remove the `--cfg dox`
28+
//FIXME(misdreavus): once stdsimd uses cfg(doc) instead of cfg(dox), remove the `--cfg dox`
2929
//arguments here
3030
let mut cmd = Command::new(rustdoc);
3131
cmd.args(&args)

src/bootstrap/bootstrap.py

+29-14
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ def verify(path, sha_path, verbose):
102102
return verified
103103

104104

105-
def unpack(tarball, dst, verbose=False, match=None):
105+
def unpack(tarball, tarball_suffix, dst, verbose=False, match=None):
106106
"""Unpack the given tarball file"""
107107
print("extracting", tarball)
108-
fname = os.path.basename(tarball).replace(".tar.gz", "")
108+
fname = os.path.basename(tarball).replace(tarball_suffix, "")
109109
with contextlib.closing(tarfile.open(tarball)) as tar:
110110
for member in tar.getnames():
111111
if "/" not in member:
@@ -331,6 +331,7 @@ def __init__(self):
331331
self.use_vendored_sources = ''
332332
self.verbose = False
333333

334+
334335
def download_stage0(self):
335336
"""Fetch the build system for Rust, written in Rust
336337
@@ -344,18 +345,30 @@ def download_stage0(self):
344345
rustc_channel = self.rustc_channel
345346
cargo_channel = self.cargo_channel
346347

348+
def support_xz():
349+
try:
350+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
351+
temp_path = temp_file.name
352+
with tarfile.open(temp_path, "w:xz") as tar:
353+
pass
354+
return True
355+
except tarfile.CompressionError:
356+
return False
357+
347358
if self.rustc().startswith(self.bin_root()) and \
348359
(not os.path.exists(self.rustc()) or
349360
self.program_out_of_date(self.rustc_stamp())):
350361
if os.path.exists(self.bin_root()):
351362
shutil.rmtree(self.bin_root())
352-
filename = "rust-std-{}-{}.tar.gz".format(
353-
rustc_channel, self.build)
363+
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
364+
filename = "rust-std-{}-{}{}".format(
365+
rustc_channel, self.build, tarball_suffix)
354366
pattern = "rust-std-{}".format(self.build)
355-
self._download_stage0_helper(filename, pattern)
367+
self._download_stage0_helper(filename, pattern, tarball_suffix)
356368

357-
filename = "rustc-{}-{}.tar.gz".format(rustc_channel, self.build)
358-
self._download_stage0_helper(filename, "rustc")
369+
filename = "rustc-{}-{}{}".format(rustc_channel, self.build,
370+
tarball_suffix)
371+
self._download_stage0_helper(filename, "rustc", tarball_suffix)
359372
self.fix_executable("{}/bin/rustc".format(self.bin_root()))
360373
self.fix_executable("{}/bin/rustdoc".format(self.bin_root()))
361374
with output(self.rustc_stamp()) as rust_stamp:
@@ -365,20 +378,22 @@ def download_stage0(self):
365378
# libraries/binaries that are included in rust-std with
366379
# the system MinGW ones.
367380
if "pc-windows-gnu" in self.build:
368-
filename = "rust-mingw-{}-{}.tar.gz".format(
369-
rustc_channel, self.build)
370-
self._download_stage0_helper(filename, "rust-mingw")
381+
filename = "rust-mingw-{}-{}{}".format(
382+
rustc_channel, self.build, tarball_suffix)
383+
self._download_stage0_helper(filename, "rust-mingw", tarball_suffix)
371384

372385
if self.cargo().startswith(self.bin_root()) and \
373386
(not os.path.exists(self.cargo()) or
374387
self.program_out_of_date(self.cargo_stamp())):
375-
filename = "cargo-{}-{}.tar.gz".format(cargo_channel, self.build)
376-
self._download_stage0_helper(filename, "cargo")
388+
tarball_suffix = '.tar.xz' if support_xz() else '.tar.gz'
389+
filename = "cargo-{}-{}{}".format(cargo_channel, self.build,
390+
tarball_suffix)
391+
self._download_stage0_helper(filename, "cargo", tarball_suffix)
377392
self.fix_executable("{}/bin/cargo".format(self.bin_root()))
378393
with output(self.cargo_stamp()) as cargo_stamp:
379394
cargo_stamp.write(self.date)
380395

381-
def _download_stage0_helper(self, filename, pattern):
396+
def _download_stage0_helper(self, filename, pattern, tarball_suffix):
382397
cache_dst = os.path.join(self.build_dir, "cache")
383398
rustc_cache = os.path.join(cache_dst, self.date)
384399
if not os.path.exists(rustc_cache):
@@ -388,7 +403,7 @@ def _download_stage0_helper(self, filename, pattern):
388403
tarball = os.path.join(rustc_cache, filename)
389404
if not os.path.exists(tarball):
390405
get("{}/{}".format(url, filename), tarball, verbose=self.verbose)
391-
unpack(tarball, self.bin_root(), match=pattern, verbose=self.verbose)
406+
unpack(tarball, tarball_suffix, self.bin_root(), match=pattern, verbose=self.verbose)
392407

393408
@staticmethod
394409
def fix_executable(fname):

src/bootstrap/builder.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,8 @@ impl<'a> Builder<'a> {
12421242
cargo.arg("--frozen");
12431243
}
12441244

1245-
cargo.env("RUSTC_INSTALL_BINDIR", &self.config.bindir);
1245+
// Try to use a sysroot-relative bindir, in case it was configured absolutely.
1246+
cargo.env("RUSTC_INSTALL_BINDIR", self.config.bindir_relative());
12461247

12471248
self.ci_env.force_coloring_in_ci(&mut cargo);
12481249

src/bootstrap/config.rs

+14
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,20 @@ impl Config {
647647
config
648648
}
649649

650+
/// Try to find the relative path of `bindir`, otherwise return it in full.
651+
pub fn bindir_relative(&self) -> &Path {
652+
let bindir = &self.bindir;
653+
if bindir.is_absolute() {
654+
// Try to make it relative to the prefix.
655+
if let Some(prefix) = &self.prefix {
656+
if let Ok(stripped) = bindir.strip_prefix(prefix) {
657+
return stripped;
658+
}
659+
}
660+
}
661+
bindir
662+
}
663+
650664
/// Try to find the relative path of `libdir`.
651665
pub fn libdir_relative(&self) -> Option<&Path> {
652666
let libdir = self.libdir.as_ref()?;

src/doc/rustdoc/src/unstable-features.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,24 +106,24 @@ item, it will be accompanied by a banner explaining that the item is only availa
106106
platforms.
107107

108108
For Rustdoc to document an item, it needs to see it, regardless of what platform it's currently
109-
running on. To aid this, Rustdoc sets the flag `#[cfg(rustdoc)]` when running on your crate.
109+
running on. To aid this, Rustdoc sets the flag `#[cfg(doc)]` when running on your crate.
110110
Combining this with the target platform of a given item allows it to appear when building your crate
111111
normally on that platform, as well as when building documentation anywhere.
112112

113-
For example, `#[cfg(any(windows, rustdoc))]` will preserve the item either on Windows or during the
113+
For example, `#[cfg(any(windows, doc))]` will preserve the item either on Windows or during the
114114
documentation process. Then, adding a new attribute `#[doc(cfg(windows))]` will tell Rustdoc that
115115
the item is supposed to be used on Windows. For example:
116116

117117
```rust
118118
#![feature(doc_cfg)]
119119

120120
/// Token struct that can only be used on Windows.
121-
#[cfg(any(windows, rustdoc))]
121+
#[cfg(any(windows, doc))]
122122
#[doc(cfg(windows))]
123123
pub struct WindowsToken;
124124

125125
/// Token struct that can only be used on Unix.
126-
#[cfg(any(unix, rustdoc))]
126+
#[cfg(any(unix, doc))]
127127
#[doc(cfg(unix))]
128128
pub struct UnixToken;
129129
```

src/doc/unstable-book/src/language-features/doc-cfg.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This attribute has two effects:
1313
2. The item's doc-tests will only run on the specific platform.
1414

1515
In addition to allowing the use of the `#[doc(cfg)]` attribute, this feature enables the use of a
16-
special conditional compilation flag, `#[cfg(rustdoc)]`, set whenever building documentation on your
16+
special conditional compilation flag, `#[cfg(doc)]`, set whenever building documentation on your
1717
crate.
1818

1919
This feature was introduced as part of PR [#43348] to allow the platform-specific parts of the
@@ -22,7 +22,7 @@ standard library be documented.
2222
```rust
2323
#![feature(doc_cfg)]
2424

25-
#[cfg(any(windows, rustdoc))]
25+
#[cfg(any(windows, doc))]
2626
#[doc(cfg(windows))]
2727
/// The application's icon in the notification area (a.k.a. system tray).
2828
///

src/libcore/cell.rs

+38-1
Original file line numberDiff line numberDiff line change
@@ -1545,9 +1545,46 @@ impl<T: ?Sized> UnsafeCell<T> {
15451545
#[stable(feature = "rust1", since = "1.0.0")]
15461546
pub const fn get(&self) -> *mut T {
15471547
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
1548-
// #[repr(transparent)]
1548+
// #[repr(transparent)]. This exploits libstd's special status, there is
1549+
// no guarantee for user code that this will work in future versions of the compiler!
15491550
self as *const UnsafeCell<T> as *const T as *mut T
15501551
}
1552+
1553+
/// Gets a mutable pointer to the wrapped value.
1554+
/// The difference to [`get`] is that this function accepts a raw pointer,
1555+
/// which is useful to avoid the creation of temporary references.
1556+
///
1557+
/// The result can be cast to a pointer of any kind.
1558+
/// Ensure that the access is unique (no active references, mutable or not)
1559+
/// when casting to `&mut T`, and ensure that there are no mutations
1560+
/// or mutable aliases going on when casting to `&T`.
1561+
///
1562+
/// [`get`]: #method.get
1563+
///
1564+
/// # Examples
1565+
///
1566+
/// Gradual initialization of an `UnsafeCell` requires `raw_get`, as
1567+
/// calling `get` would require creating a reference to uninitialized data:
1568+
///
1569+
/// ```
1570+
/// #![feature(unsafe_cell_raw_get)]
1571+
/// use std::cell::UnsafeCell;
1572+
/// use std::mem::MaybeUninit;
1573+
///
1574+
/// let m = MaybeUninit::<UnsafeCell<i32>>::uninit();
1575+
/// unsafe { UnsafeCell::raw_get(m.as_ptr()).write(5); }
1576+
/// let uc = unsafe { m.assume_init() };
1577+
///
1578+
/// assert_eq!(uc.into_inner(), 5);
1579+
/// ```
1580+
#[inline]
1581+
#[unstable(feature = "unsafe_cell_raw_get", issue = "66358")]
1582+
pub const fn raw_get(this: *const Self) -> *mut T {
1583+
// We can just cast the pointer from `UnsafeCell<T>` to `T` because of
1584+
// #[repr(transparent)]. This exploits libstd's special status, there is
1585+
// no guarantee for user code that this will work in future versions of the compiler!
1586+
this as *const T as *mut T
1587+
}
15511588
}
15521589

15531590
#[stable(feature = "unsafe_cell_default", since = "1.10.0")]

src/libcore/iter/traits/iterator.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ pub trait Iterator {
201201

202202
/// Consumes the iterator, counting the number of iterations and returning it.
203203
///
204-
/// This method will evaluate the iterator until its [`next`] returns
205-
/// [`None`]. Once [`None`] is encountered, `count()` returns the number of
206-
/// times it called [`next`].
204+
/// This method will call [`next`] repeatedly until [`None`] is encountered,
205+
/// returning the number of times it saw [`Some`]. Note that [`next`] has to be
206+
/// called at least once even if the iterator does not have any elements.
207207
///
208208
/// [`next`]: #tymethod.next
209209
/// [`None`]: ../../std/option/enum.Option.html#variant.None
210+
/// [`Some`]: ../../std/option/enum.Option.html#variant.Some
210211
///
211212
/// # Overflow Behavior
212213
///

src/libcore/result.rs

+22
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,28 @@ impl<T, E> Result<T, E> {
514514
}
515515
}
516516

517+
/// Applies a function to the contained value (if any),
518+
/// or returns the provided default (if not).
519+
///
520+
/// # Examples
521+
///
522+
/// ```
523+
/// #![feature(result_map_or)]
524+
/// let x: Result<_, &str> = Ok("foo");
525+
/// assert_eq!(x.map_or(42, |v| v.len()), 3);
526+
///
527+
/// let x: Result<&str, _> = Err("bar");
528+
/// assert_eq!(x.map_or(42, |v| v.len()), 42);
529+
/// ```
530+
#[inline]
531+
#[unstable(feature = "result_map_or", issue = "66293")]
532+
pub fn map_or<U, F: FnOnce(T) -> U>(self, default: U, f: F) -> U {
533+
match self {
534+
Ok(t) => f(t),
535+
Err(_) => default,
536+
}
537+
}
538+
517539
/// Maps a `Result<T, E>` to `U` by applying a function to a
518540
/// contained [`Ok`] value, or a fallback function to a
519541
/// contained [`Err`] value.

src/librustc/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,3 @@ byteorder = { version = "1.3" }
4040
chalk-engine = { version = "0.9.0", default-features=false }
4141
rustc_fs_util = { path = "../librustc_fs_util" }
4242
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
43-
measureme = "0.4"

src/librustc/error_codes.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -1896,6 +1896,51 @@ fn foo<'a>(x: &'a i32, y: &i32) -> &'a i32 {
18961896
```
18971897
"##,
18981898

1899+
E0623: r##"
1900+
A lifetime didn't match what was expected.
1901+
1902+
Erroneous code example:
1903+
1904+
```compile_fail,E0623
1905+
struct Foo<'a> {
1906+
x: &'a isize,
1907+
}
1908+
1909+
fn bar<'short, 'long>(c: Foo<'short>, l: &'long isize) {
1910+
let _: Foo<'long> = c; // error!
1911+
}
1912+
```
1913+
1914+
In this example, we tried to set a value with an incompatible lifetime to
1915+
another one (`'long` is unrelated to `'short`). We can solve this issue in
1916+
two different ways:
1917+
1918+
Either we make `'short` live at least as long as `'long`:
1919+
1920+
```
1921+
struct Foo<'a> {
1922+
x: &'a isize,
1923+
}
1924+
1925+
// we set 'short to live at least as long as 'long
1926+
fn bar<'short: 'long, 'long>(c: Foo<'short>, l: &'long isize) {
1927+
let _: Foo<'long> = c; // ok!
1928+
}
1929+
```
1930+
1931+
Or we use only one lifetime:
1932+
1933+
```
1934+
struct Foo<'a> {
1935+
x: &'a isize,
1936+
}
1937+
1938+
fn bar<'short>(c: Foo<'short>, l: &'short isize) {
1939+
let _: Foo<'short> = c; // ok!
1940+
}
1941+
```
1942+
"##,
1943+
18991944
E0635: r##"
19001945
The `#![feature]` attribute specified an unknown feature.
19011946
@@ -2329,7 +2374,6 @@ the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
23292374
E0488, // lifetime of variable does not enclose its declaration
23302375
E0489, // type/lifetime parameter not in scope here
23312376
E0490, // a value of type `..` is borrowed for too long
2332-
E0623, // lifetime mismatch where both parameters are anonymous regions
23332377
E0628, // generators cannot have explicit parameters
23342378
E0631, // type mismatch in closure arguments
23352379
E0637, // "'_" is not a valid lifetime bound

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ pub mod util {
124124
pub mod captures;
125125
pub mod common;
126126
pub mod nodemap;
127-
pub mod profiling;
128127
pub mod bug;
129128
}
130129

0 commit comments

Comments
 (0)