Skip to content

Commit 8417d68

Browse files
committed
Auto merge of #68803 - Dylan-DPC:rollup-b4x6ghj, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #68678 (Install robots.txt into rust-docs tarballs) - #68711 (Added upper bound of what vecs and boxes can allocate) - #68744 (Do not ICE in `type-alias-impl-trait` with save-analysis) - #68777 (Clean up E0263 explanation) - #68787 (Optimize core::ptr::align_offset (part 1)) - #68797 (Fix links to types instead of modules) - #68798 (Test that `#[track_caller]` as `fn()` respects RT / CTFE equivalence) - #68800 (Stabilize `core::iter::once_with()`) Failed merges: r? @ghost
2 parents bdd946d + af3c315 commit 8417d68

File tree

19 files changed

+123
-42
lines changed

19 files changed

+123
-42
lines changed

src/bootstrap/dist.rs

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Step for Docs {
105105
t!(fs::create_dir_all(&dst));
106106
let src = builder.doc_out(host);
107107
builder.cp_r(&src, &dst);
108+
builder.install(&builder.src.join("src/doc/robots.txt"), &dst, 0o644);
108109

109110
let mut cmd = rust_installer(builder);
110111
cmd.arg("generate")

src/doc/robots.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# NB: This file is not automatically deployed. After changes, it needs to be uploaded manually to doc.rust-lang.org
21
User-agent: *
32
Disallow: /0.3/
43
Disallow: /0.4/

src/liballoc/boxed.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
//!
33
//! [`Box<T>`], casually referred to as a 'box', provides the simplest form of
44
//! heap allocation in Rust. Boxes provide ownership for this allocation, and
5-
//! drop their contents when they go out of scope.
5+
//! drop their contents when they go out of scope. Boxes also ensure that they
6+
//! never allocate more than `isize::MAX` bytes.
67
//!
78
//! # Examples
89
//!

src/liballoc/vec.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
//! Vectors have `O(1)` indexing, amortized `O(1)` push (to the end) and
55
//! `O(1)` pop (from the end).
66
//!
7+
//! Vectors ensure they never allocate more than `isize::MAX` bytes.
8+
//!
79
//! # Examples
810
//!
911
//! You can explicitly create a [`Vec<T>`] with [`new`]:

src/libcore/iter/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ pub use self::sources::{empty, Empty};
327327
pub use self::sources::{from_fn, FromFn};
328328
#[stable(feature = "iter_once", since = "1.2.0")]
329329
pub use self::sources::{once, Once};
330-
#[unstable(feature = "iter_once_with", issue = "57581")]
330+
#[stable(feature = "iter_once_with", since = "1.43.0")]
331331
pub use self::sources::{once_with, OnceWith};
332332
#[stable(feature = "rust1", since = "1.0.0")]
333333
pub use self::sources::{repeat, Repeat};

src/libcore/iter/sources.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,12 @@ pub fn once<T>(value: T) -> Once<T> {
399399
///
400400
/// [`once_with`]: fn.once_with.html
401401
#[derive(Copy, Clone, Debug)]
402-
#[unstable(feature = "iter_once_with", issue = "57581")]
402+
#[stable(feature = "iter_once_with", since = "1.43.0")]
403403
pub struct OnceWith<F> {
404404
gen: Option<F>,
405405
}
406406

407-
#[unstable(feature = "iter_once_with", issue = "57581")]
407+
#[stable(feature = "iter_once_with", since = "1.43.0")]
408408
impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
409409
type Item = A;
410410

@@ -420,24 +420,24 @@ impl<A, F: FnOnce() -> A> Iterator for OnceWith<F> {
420420
}
421421
}
422422

423-
#[unstable(feature = "iter_once_with", issue = "57581")]
423+
#[stable(feature = "iter_once_with", since = "1.43.0")]
424424
impl<A, F: FnOnce() -> A> DoubleEndedIterator for OnceWith<F> {
425425
fn next_back(&mut self) -> Option<A> {
426426
self.next()
427427
}
428428
}
429429

430-
#[unstable(feature = "iter_once_with", issue = "57581")]
430+
#[stable(feature = "iter_once_with", since = "1.43.0")]
431431
impl<A, F: FnOnce() -> A> ExactSizeIterator for OnceWith<F> {
432432
fn len(&self) -> usize {
433433
self.gen.iter().len()
434434
}
435435
}
436436

437-
#[unstable(feature = "iter_once_with", issue = "57581")]
437+
#[stable(feature = "iter_once_with", since = "1.43.0")]
438438
impl<A, F: FnOnce() -> A> FusedIterator for OnceWith<F> {}
439439

440-
#[unstable(feature = "iter_once_with", issue = "57581")]
440+
#[stable(feature = "iter_once_with", since = "1.43.0")]
441441
unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
442442

443443
/// Creates an iterator that lazily generates a value exactly once by invoking
@@ -458,8 +458,6 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
458458
/// Basic usage:
459459
///
460460
/// ```
461-
/// #![feature(iter_once_with)]
462-
///
463461
/// use std::iter;
464462
///
465463
/// // one is the loneliest number
@@ -476,8 +474,6 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
476474
/// `.foorc`:
477475
///
478476
/// ```no_run
479-
/// #![feature(iter_once_with)]
480-
///
481477
/// use std::iter;
482478
/// use std::fs;
483479
/// use std::path::PathBuf;
@@ -500,7 +496,7 @@ unsafe impl<A, F: FnOnce() -> A> TrustedLen for OnceWith<F> {}
500496
/// }
501497
/// ```
502498
#[inline]
503-
#[unstable(feature = "iter_once_with", issue = "57581")]
499+
#[stable(feature = "iter_once_with", since = "1.43.0")]
504500
pub fn once_with<A, F: FnOnce() -> A>(gen: F) -> OnceWith<F> {
505501
OnceWith { gen: Some(gen) }
506502
}

src/libcore/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
#![feature(intrinsics)]
8888
#![feature(try_find)]
8989
#![feature(is_sorted)]
90-
#![feature(iter_once_with)]
9190
#![feature(lang_items)]
9291
#![feature(link_llvm_intrinsics)]
9392
#![feature(never_type)]

src/libcore/ptr/mod.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,8 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
10811081
// uses e.g., subtraction `mod n`. It is entirely fine to do them `mod
10821082
// usize::max_value()` instead, because we take the result `mod n` at the end
10831083
// anyway.
1084-
inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse)))
1085-
& (going_mod - 1);
1086-
if going_mod > m {
1084+
inverse = inverse.wrapping_mul(2usize.wrapping_sub(x.wrapping_mul(inverse)));
1085+
if going_mod >= m {
10871086
return inverse & (m - 1);
10881087
}
10891088
going_mod = going_mod.wrapping_mul(going_mod);
@@ -1115,26 +1114,33 @@ pub(crate) unsafe fn align_offset<T: Sized>(p: *const T, a: usize) -> usize {
11151114
let gcdpow = intrinsics::cttz_nonzero(stride).min(intrinsics::cttz_nonzero(a));
11161115
let gcd = 1usize << gcdpow;
11171116

1118-
if p as usize & (gcd - 1) == 0 {
1117+
if p as usize & (gcd.wrapping_sub(1)) == 0 {
11191118
// This branch solves for the following linear congruence equation:
11201119
//
1121-
// $$ p + so 0 mod a $$
1120+
// ` p + so = 0 mod a `
11221121
//
1123-
// $p$ here is the pointer value, $s$ – stride of `T`, $o$ offset in `T`s, and $a$ – the
1122+
// `p` here is the pointer value, `s` - stride of `T`, `o` offset in `T`s, and `a` - the
11241123
// requested alignment.
11251124
//
1126-
// g = gcd(a, s)
1127-
// o = (a - (p mod a))/g * ((s/g)⁻¹ mod a)
1125+
// With `g = gcd(a, s)`, and the above asserting that `p` is also divisible by `g`, we can
1126+
// denote `a' = a/g`, `s' = s/g`, `p' = p/g`, then this becomes equivalent to:
11281127
//
1129-
// The first term is “the relative alignment of p to a”, the second term is “how does
1130-
// incrementing p by s bytes change the relative alignment of p”. Division by `g` is
1131-
// necessary to make this equation well formed if $a$ and $s$ are not co-prime.
1128+
// ` p' + s'o = 0 mod a' `
1129+
// ` o = (a' - (p' mod a')) * (s'^-1 mod a') `
11321130
//
1133-
// Furthermore, the result produced by this solution is not “minimal”, so it is necessary
1134-
// to take the result $o mod lcm(s, a)$. We can replace $lcm(s, a)$ with just a $a / g$.
1135-
let j = a.wrapping_sub(pmoda) >> gcdpow;
1136-
let k = smoda >> gcdpow;
1137-
return intrinsics::unchecked_rem(j.wrapping_mul(mod_inv(k, a)), a >> gcdpow);
1131+
// The first term is "the relative alignment of `p` to `a`" (divided by the `g`), the second
1132+
// term is "how does incrementing `p` by `s` bytes change the relative alignment of `p`" (again
1133+
// divided by `g`).
1134+
// Division by `g` is necessary to make the inverse well formed if `a` and `s` are not
1135+
// co-prime.
1136+
//
1137+
// Furthermore, the result produced by this solution is not "minimal", so it is necessary
1138+
// to take the result `o mod lcm(s, a)`. We can replace `lcm(s, a)` with just a `a'`.
1139+
let a2 = a >> gcdpow;
1140+
let a2minus1 = a2.wrapping_sub(1);
1141+
let s2 = smoda >> gcdpow;
1142+
let minusp2 = a2.wrapping_sub(pmoda >> gcdpow);
1143+
return (minusp2.wrapping_mul(mod_inv(s2, a2))) & a2minus1;
11381144
}
11391145

11401146
// Cannot be aligned at all.

src/libcore/tests/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#![feature(hashmap_internals)]
1414
#![feature(try_find)]
1515
#![feature(is_sorted)]
16-
#![feature(iter_once_with)]
1716
#![feature(pattern)]
1817
#![feature(range_is_empty)]
1918
#![feature(raw)]
+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
A lifetime name cannot be declared more than once in the same scope. For
2-
example:
1+
A lifetime was declared more than once in the same scope.
2+
3+
Erroneous code example:
34

45
```compile_fail,E0263
5-
// error, lifetime name `'a` declared twice in the same scope
6-
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str) { }
6+
fn foo<'a, 'b, 'a>(x: &'a str, y: &'b str, z: &'a str) { // error!
7+
}
8+
```
9+
10+
Two lifetimes cannot have the same name. To fix this example, change
11+
the second `'a` lifetime into something else (`'c` for example):
12+
13+
```
14+
fn foo<'a, 'b, 'c>(x: &'a str, y: &'b str, z: &'c str) { // ok!
15+
}
716
```

src/librustc_typeck/check/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,11 @@ fn has_typeck_tables(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
837837
return tcx.has_typeck_tables(outer_def_id);
838838
}
839839

840-
let id = tcx.hir().as_local_hir_id(def_id).unwrap();
841-
primary_body_of(tcx, id).is_some()
840+
if let Some(id) = tcx.hir().as_local_hir_id(def_id) {
841+
primary_body_of(tcx, id).is_some()
842+
} else {
843+
false
844+
}
842845
}
843846

844847
fn used_trait_imports(tcx: TyCtxt<'_>, def_id: DefId) -> &DefIdSet {

src/libstd/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@
163163
//! [`Iterator`]: iter/trait.Iterator.html
164164
//! [`Mutex`]: sync/struct.Mutex.html
165165
//! [`Option<T>`]: option/enum.Option.html
166-
//! [`Rc`]: rc/index.html
166+
//! [`Rc`]: rc/struct.Rc.html
167167
//! [`RefCell`]: cell/struct.RefCell.html
168168
//! [`Result<T, E>`]: result/enum.Result.html
169169
//! [`String`]: string/struct.String.html
170-
//! [`Vec<T>`]: vec/index.html
170+
//! [`Vec<T>`]: vec/struct.Vec.html
171171
//! [array]: primitive.array.html
172172
//! [slice]: primitive.slice.html
173173
//! [`atomic`]: sync/atomic/index.html
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Ensure that a `#[track_caller]` function, returning `caller_location()`,
2+
// which coerced (to a function pointer) and called, inside a `const fn`,
3+
// in turn called, results in the same output irrespective of whether
4+
// we're in a const or runtime context.
5+
6+
// run-pass
7+
// compile-flags: -Z unleash-the-miri-inside-of-you
8+
9+
#![feature(core_intrinsics, const_caller_location, track_caller, const_fn)]
10+
11+
type L = &'static std::panic::Location<'static>;
12+
13+
#[track_caller]
14+
const fn attributed() -> L {
15+
std::intrinsics::caller_location()
16+
}
17+
18+
const fn calling_attributed() -> L {
19+
// We need `-Z unleash-the-miri-inside-of-you` for this as we don't have `const fn` pointers.
20+
let ptr: fn() -> L = attributed;
21+
ptr() //~ WARN skipping const checks
22+
}
23+
24+
fn main() {
25+
const CONSTANT: L = calling_attributed();
26+
let runtime = calling_attributed();
27+
28+
assert_eq!(
29+
(runtime.file(), runtime.line(), runtime.column()),
30+
(CONSTANT.file(), CONSTANT.line(), CONSTANT.column()),
31+
);
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
warning: skipping const checks
2+
--> $DIR/caller-location-fnptr-rt-ctfe-equiv.rs:21:5
3+
|
4+
LL | ptr()
5+
| ^^^^^
6+
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Zsave-analysis
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
trait Trait {}
6+
7+
trait Service {
8+
type Future: Trait;
9+
}
10+
11+
struct Struct;
12+
13+
impl Service for Struct {
14+
type Future = impl Trait; //~ ERROR: could not find defining uses
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: could not find defining uses
2+
--> $DIR/issue-68621.rs:14:5
3+
|
4+
LL | type Future = impl Trait;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

src/test/ui/type-alias-impl-trait/issue-63279.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Zsave-analysis
2+
13
#![feature(type_alias_impl_trait)]
24

35
type Closure = impl FnOnce(); //~ ERROR: type mismatch resolving

src/test/ui/type-alias-impl-trait/issue-63279.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:6:5: 6:28] as std::ops::FnOnce<()>>::Output == ()`
2-
--> $DIR/issue-63279.rs:3:1
1+
error[E0271]: type mismatch resolving `<[closure@$DIR/issue-63279.rs:8:5: 8:28] as std::ops::FnOnce<()>>::Output == ()`
2+
--> $DIR/issue-63279.rs:5:1
33
|
44
LL | type Closure = impl FnOnce();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected opaque type, found `()`

src/test/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: -Zsave-analysis
12
// check-pass
23

34
#![feature(type_alias_impl_trait)]

0 commit comments

Comments
 (0)