From 39e502744c7db993eb0269285082ac5c7b7d4bdd Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 30 Jan 2020 15:24:56 -0500 Subject: [PATCH 01/11] Install robots.txt into rust-docs tarballs --- src/bootstrap/dist.rs | 1 + src/doc/robots.txt | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 8d13df3ee21..facf816857f 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -105,6 +105,7 @@ impl Step for Docs { t!(fs::create_dir_all(&dst)); let src = builder.doc_out(host); builder.cp_r(&src, &dst); + builder.install(&builder.src.join("src/doc/robots.txt"), &dst, 0o644); let mut cmd = rust_installer(builder); cmd.arg("generate") diff --git a/src/doc/robots.txt b/src/doc/robots.txt index 61ee12739fb..d119cc46473 100644 --- a/src/doc/robots.txt +++ b/src/doc/robots.txt @@ -1,4 +1,3 @@ -# NB: This file is not automatically deployed. After changes, it needs to be uploaded manually to doc.rust-lang.org User-agent: * Disallow: /0.3/ Disallow: /0.4/ From 346920c3c844e650aff6428c6b5c6e70cbce9954 Mon Sep 17 00:00:00 2001 From: hman523 Date: Fri, 31 Jan 2020 13:41:07 -0600 Subject: [PATCH 02/11] Fixed issue 68593 --- src/liballoc/boxed.rs | 3 ++- src/liballoc/vec.rs | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 8735c2c8f36..7e5efbe3078 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -2,7 +2,8 @@ //! //! [`Box`], casually referred to as a 'box', provides the simplest form of //! heap allocation in Rust. Boxes provide ownership for this allocation, and -//! drop their contents when they go out of scope. +//! drop their contents when they go out of scope. Boxes also ensure that they +//! never allocate more than `isize::MAX` bytes. //! //! # Examples //! diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index 26a7812f58e..4f6b7870e2e 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -4,6 +4,8 @@ //! Vectors have `O(1)` indexing, amortized `O(1)` push (to the end) and //! `O(1)` pop (from the end). //! +//! Vectors ensure they never allocate more than `isize::MAX` bytes. +//! //! # Examples //! //! You can explicitly create a [`Vec`] with [`new`]: From 9d8058fb423ff21a6c05945ef83f0d5eb4b33fb8 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 2 Feb 2020 06:39:50 +0900 Subject: [PATCH 03/11] Do not ICE in `type-alias-impl-trait` with save-analysis --- src/librustc_typeck/check/mod.rs | 7 +++++-- src/test/ui/save-analysis/issue-68621.rs | 17 +++++++++++++++++ src/test/ui/save-analysis/issue-68621.stderr | 8 ++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/save-analysis/issue-68621.rs create mode 100644 src/test/ui/save-analysis/issue-68621.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4d1f92d19ce..c87ef250dcf 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -837,8 +837,11 @@ fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool { return tcx.has_typeck_tables(outer_def_id); } - let id = tcx.hir().as_local_hir_id(def_id).unwrap(); - primary_body_of(tcx, id).is_some() + if let Some(id) = tcx.hir().as_local_hir_id(def_id) { + primary_body_of(tcx, id).is_some() + } else { + false + } } fn used_trait_imports(tcx: TyCtxt<'_>, def_id: DefId) -> &DefIdSet { diff --git a/src/test/ui/save-analysis/issue-68621.rs b/src/test/ui/save-analysis/issue-68621.rs new file mode 100644 index 00000000000..96af085c5b6 --- /dev/null +++ b/src/test/ui/save-analysis/issue-68621.rs @@ -0,0 +1,17 @@ +// compile-flags: -Zsave-analysis + +#![feature(type_alias_impl_trait)] + +trait Trait {} + +trait Service { + type Future: Trait; +} + +struct Struct; + +impl Service for Struct { + type Future = impl Trait; //~ ERROR: could not find defining uses +} + +fn main() {} diff --git a/src/test/ui/save-analysis/issue-68621.stderr b/src/test/ui/save-analysis/issue-68621.stderr new file mode 100644 index 00000000000..2c5bbd7782b --- /dev/null +++ b/src/test/ui/save-analysis/issue-68621.stderr @@ -0,0 +1,8 @@ +error: could not find defining uses + --> $DIR/issue-68621.rs:14:5 + | +LL | type Future = impl Trait; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + From ae22bf9d42abb7fc5ae4619a5feaafc61aa0c539 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Sun, 2 Feb 2020 09:02:54 +0900 Subject: [PATCH 04/11] Catch more ICEs --- src/test/ui/type-alias-impl-trait/issue-63279.rs | 2 ++ src/test/ui/type-alias-impl-trait/issue-63279.stderr | 4 ++-- .../issue-65679-inst-opaque-ty-from-val-twice.rs | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.rs b/src/test/ui/type-alias-impl-trait/issue-63279.rs index 586ff7a3158..b97192a2aed 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.rs +++ b/src/test/ui/type-alias-impl-trait/issue-63279.rs @@ -1,3 +1,5 @@ +// compile-flags: -Zsave-analysis + #![feature(type_alias_impl_trait)] type Closure = impl FnOnce(); //~ ERROR: type mismatch resolving diff --git a/src/test/ui/type-alias-impl-trait/issue-63279.stderr b/src/test/ui/type-alias-impl-trait/issue-63279.stderr index 053ccee3785..bef4d01093c 100644 --- a/src/test/ui/type-alias-impl-trait/issue-63279.stderr +++ b/src/test/ui/type-alias-impl-trait/issue-63279.stderr @@ -1,5 +1,5 @@ -error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:6:5: 6:28] as std::ops::FnOnce<()>>::Output == ()` - --> $DIR/issue-63279.rs:3:1 +error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:8:5: 8:28] as std::ops::FnOnce<()>>::Output == ()` + --> $DIR/issue-63279.rs:5:1 | LL | type Closure = impl FnOnce(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found `()` diff --git a/src/test/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs b/src/test/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs index 12eb75ae4c0..26d97cea989 100644 --- a/src/test/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs +++ b/src/test/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs @@ -1,3 +1,4 @@ +// compile-flags: -Zsave-analysis // check-pass #![feature(type_alias_impl_trait)] From 019ca55b45f0b4e1de74c19bca06c20134ac9103 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 2 Feb 2020 15:28:18 +0100 Subject: [PATCH 05/11] Clean up E0263 explanation --- src/librustc_error_codes/error_codes/E0263.md | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/librustc_error_codes/error_codes/E0263.md b/src/librustc_error_codes/error_codes/E0263.md index bb4da43b3f5..37271ac692d 100644 --- a/src/librustc_error_codes/error_codes/E0263.md +++ b/src/librustc_error_codes/error_codes/E0263.md @@ -1,7 +1,16 @@ -A lifetime name cannot be declared more than once in the same scope. For -example: +A lifetime was declared more than once in the same scope. + +Erroneous code example: ```compile_fail,E0263 -// error, lifetime name `'a` declared twice in the same scope -fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { } +fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error! +} +``` + +Two lifetimes cannot have the same name. To fix this example, change +the second `'a` lifetime into something else (`'c` for example): + +``` +fn foo<'a, 'b, 'c>(x: &'a str, y: &'b str, z: &'c str) { // ok! +} ``` From e835d0d761945bb242d271f5ccedf0aee54a4ca8 Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Thu, 30 Jan 2020 20:04:24 +0100 Subject: [PATCH 06/11] Optimize core::ptr::align_offset - Stopping condition inside mod_inv can be >= instead of > - Remove intrinsics::unchecked_rem, we are working modulu powers-of-2 so we can simply mask --- src/libcore/ptr/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 9727e4face5..8d839378027 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1083,7 +1083,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // anyway. inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse))) & (going_mod - 1); - if going_mod > m { + if going_mod >= m { return inverse & (m - 1); } going_mod = going_mod.wrapping_mul(going_mod); @@ -1134,7 +1134,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // to take the result $o mod lcm(s, a)$. We can replace $lcm(s, a)$ with just a $a / g$. let j = a.wrapping_sub(pmoda) >> gcdpow; let k = smoda >> gcdpow; - return intrinsics::unchecked_rem(j.wrapping_mul(mod_inv(k, a)), a >> gcdpow); + return (j.wrapping_mul(mod_inv(k, a))) & ((a >> gcdpow).wrapping_sub(1)); } // Cannot be aligned at all. From 3173cd1473eeebcc9567b686e63d281a761fd936 Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Tue, 28 Jan 2020 22:14:04 +0100 Subject: [PATCH 07/11] Optimize core::ptr::align_offset - When calculating the inverse, it's enough to work `mod a/g` instead of `mod a`. --- src/libcore/ptr/mod.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 8d839378027..805404b101b 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1115,26 +1115,33 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { let gcdpow = intrinsics::cttz_nonzero(stride).min(intrinsics::cttz_nonzero(a)); let gcd = 1usize << gcdpow; - if p as usize & (gcd - 1) == 0 { + if p as usize & (gcd.wrapping_sub(1)) == 0 { // This branch solves for the following linear congruence equation: // - // $$ p + so ≡ 0 mod a $$ + // ` p + so = 0 mod a ` // - // $p$ here is the pointer value, $s$ – stride of `T`, $o$ offset in `T`s, and $a$ – the + // `p` here is the pointer value, `s` - stride of `T`, `o` offset in `T`s, and `a` - the // requested alignment. // - // g = gcd(a, s) - // o = (a - (p mod a))/g * ((s/g)⁻¹ mod a) + // With `g = gcd(a, s)`, and the above asserting that `p` is also divisible by `g`, we can + // denote `a' = a/g`, `s' = s/g`, `p' = p/g`, then this becomes equivalent to: // - // The first term is “the relative alignment of p to a”, the second term is “how does - // incrementing p by s bytes change the relative alignment of p”. Division by `g` is - // necessary to make this equation well formed if $a$ and $s$ are not co-prime. + // ` p' + s'o = 0 mod a' ` + // ` o = (a' - (p' mod a')) * (s'^-1 mod a') ` // - // Furthermore, the result produced by this solution is not “minimal”, so it is necessary - // to take the result $o mod lcm(s, a)$. We can replace $lcm(s, a)$ with just a $a / g$. - let j = a.wrapping_sub(pmoda) >> gcdpow; - let k = smoda >> gcdpow; - return (j.wrapping_mul(mod_inv(k, a))) & ((a >> gcdpow).wrapping_sub(1)); + // The first term is "the relative alignment of `p` to `a`" (divided by the `g`), the second + // term is "how does incrementing `p` by `s` bytes change the relative alignment of `p`" (again + // divided by `g`). + // Division by `g` is necessary to make the inverse well formed if `a` and `s` are not + // co-prime. + // + // Furthermore, the result produced by this solution is not "minimal", so it is necessary + // to take the result `o mod lcm(s, a)`. We can replace `lcm(s, a)` with just a `a'`. + let a2 = a >> gcdpow; + let a2minus1 = a2.wrapping_sub(1); + let s2 = smoda >> gcdpow; + let minusp2 = a2.wrapping_sub(pmoda >> gcdpow); + return (minusp2.wrapping_mul(mod_inv(s2, a2))) & a2minus1; } // Cannot be aligned at all. From 22b263ae1837ab6a64fe4bcdbfa07aa8883f57db Mon Sep 17 00:00:00 2001 From: Amos Onn Date: Sun, 2 Feb 2020 02:18:33 +0100 Subject: [PATCH 08/11] Optimize core::ptr::align_offset - As explained in the comment inside mod_inv, it is valid to work mod `usize::max_value()` right until the end. --- src/libcore/ptr/mod.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libcore/ptr/mod.rs b/src/libcore/ptr/mod.rs index 805404b101b..0ee50966f96 100644 --- a/src/libcore/ptr/mod.rs +++ b/src/libcore/ptr/mod.rs @@ -1081,8 +1081,7 @@ pub(crate) unsafe fn align_offset(p: *const T, a: usize) -> usize { // uses e.g., subtraction `mod n`. It is entirely fine to do them `mod // usize::max_value()` instead, because we take the result `mod n` at the end // anyway. - inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse))) - & (going_mod - 1); + inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse))); if going_mod >= m { return inverse & (m - 1); } From 46f6dad1010be9fc609e706f7452b1df4b0afa45 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 3 Feb 2020 16:12:35 +0100 Subject: [PATCH 09/11] Fix links to types instead of modules --- src/libstd/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index dc93ac90482..0884d602b5b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -163,11 +163,11 @@ //! [`Iterator`]: iter/trait.Iterator.html //! [`Mutex`]: sync/struct.Mutex.html //! [`Option`]: option/enum.Option.html -//! [`Rc`]: rc/index.html +//! [`Rc`]: rc/struct.Rc.html //! [`RefCell`]: cell/struct.RefCell.html //! [`Result`]: result/enum.Result.html //! [`String`]: string/struct.String.html -//! [`Vec`]: vec/index.html +//! [`Vec`]: vec/struct.Vec.html //! [array]: primitive.array.html //! [slice]: primitive.slice.html //! [`atomic`]: sync/atomic/index.html From f0eec8858173868d2d266c5d7fe4ef83a2d9412c Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Mon, 3 Feb 2020 16:15:30 +0100 Subject: [PATCH 10/11] track_caller test caller_location ctfe/rt equivalence wrt. fnptrs --- .../caller-location-fnptr-rt-ctfe-equiv.rs | 32 +++++++++++++++++++ ...caller-location-fnptr-rt-ctfe-equiv.stderr | 6 ++++ 2 files changed, 38 insertions(+) create mode 100644 src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs create mode 100644 src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs new file mode 100644 index 00000000000..fe2b92eafdb --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.rs @@ -0,0 +1,32 @@ +// Ensure that a `#[track_caller]` function, returning `caller_location()`, +// which coerced (to a function pointer) and called, inside a `const fn`, +// in turn called, results in the same output irrespective of whether +// we're in a const or runtime context. + +// run-pass +// compile-flags: -Z unleash-the-miri-inside-of-you + +#![feature(core_intrinsics, const_caller_location, track_caller, const_fn)] + +type L = &'static std::panic::Location<'static>; + +#[track_caller] +const fn attributed() -> L { + std::intrinsics::caller_location() +} + +const fn calling_attributed() -> L { + // We need `-Z unleash-the-miri-inside-of-you` for this as we don't have `const fn` pointers. + let ptr: fn() -> L = attributed; + ptr() //~ WARN skipping const checks +} + +fn main() { + const CONSTANT: L = calling_attributed(); + let runtime = calling_attributed(); + + assert_eq!( + (runtime.file(), runtime.line(), runtime.column()), + (CONSTANT.file(), CONSTANT.line(), CONSTANT.column()), + ); +} diff --git a/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr new file mode 100644 index 00000000000..fcf0945ed4c --- /dev/null +++ b/src/test/ui/rfc-2091-track-caller/caller-location-fnptr-rt-ctfe-equiv.stderr @@ -0,0 +1,6 @@ +warning: skipping const checks + --> $DIR/caller-location-fnptr-rt-ctfe-equiv.rs:21:5 + | +LL | ptr() + | ^^^^^ + From 7e2d7e0bbcc8c20320a32778dafd07a3aa111384 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 4 Feb 2020 00:47:04 +0900 Subject: [PATCH 11/11] Stabilize `core::iter::once_with()` --- src/libcore/iter/mod.rs | 2 +- src/libcore/iter/sources.rs | 18 +++++++----------- src/libcore/lib.rs | 1 - src/libcore/tests/lib.rs | 1 - 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs index d8a56cb3ae5..5fa9962f811 100644 --- a/src/libcore/iter/mod.rs +++ b/src/libcore/iter/mod.rs @@ -327,7 +327,7 @@ pub use self::sources::{empty, Empty}; pub use self::sources::{from_fn, FromFn}; #[stable(feature = "iter_once", since = "1.2.0")] pub use self::sources::{once, Once}; -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] pub use self::sources::{once_with, OnceWith}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::sources::{repeat, Repeat}; diff --git a/src/libcore/iter/sources.rs b/src/libcore/iter/sources.rs index 25dfc573e41..5a31acab273 100644 --- a/src/libcore/iter/sources.rs +++ b/src/libcore/iter/sources.rs @@ -399,12 +399,12 @@ pub fn once(value: T) -> Once { /// /// [`once_with`]: fn.once_with.html #[derive(Copy, Clone, Debug)] -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] pub struct OnceWith { gen: Option, } -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] impl A> Iterator for OnceWith { type Item = A; @@ -420,24 +420,24 @@ impl A> Iterator for OnceWith { } } -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] impl A> DoubleEndedIterator for OnceWith { fn next_back(&mut self) -> Option { self.next() } } -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] impl A> ExactSizeIterator for OnceWith { fn len(&self) -> usize { self.gen.iter().len() } } -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] impl A> FusedIterator for OnceWith {} -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] unsafe impl A> TrustedLen for OnceWith {} /// Creates an iterator that lazily generates a value exactly once by invoking @@ -458,8 +458,6 @@ unsafe impl A> TrustedLen for OnceWith {} /// Basic usage: /// /// ``` -/// #![feature(iter_once_with)] -/// /// use std::iter; /// /// // one is the loneliest number @@ -476,8 +474,6 @@ unsafe impl A> TrustedLen for OnceWith {} /// `.foorc`: /// /// ```no_run -/// #![feature(iter_once_with)] -/// /// use std::iter; /// use std::fs; /// use std::path::PathBuf; @@ -500,7 +496,7 @@ unsafe impl A> TrustedLen for OnceWith {} /// } /// ``` #[inline] -#[unstable(feature = "iter_once_with", issue = "57581")] +#[stable(feature = "iter_once_with", since = "1.43.0")] pub fn once_with A>(gen: F) -> OnceWith { OnceWith { gen: Some(gen) } } diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index ce7ddffd825..7738ea2ac57 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -87,7 +87,6 @@ #![feature(intrinsics)] #![feature(try_find)] #![feature(is_sorted)] -#![feature(iter_once_with)] #![feature(lang_items)] #![feature(link_llvm_intrinsics)] #![feature(never_type)] diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 8fd19ef67fc..bfc3ee09dce 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -13,7 +13,6 @@ #![feature(hashmap_internals)] #![feature(try_find)] #![feature(is_sorted)] -#![feature(iter_once_with)] #![feature(pattern)] #![feature(range_is_empty)] #![feature(raw)]