Skip to content

Commit 5228c08

Browse files
committed
Auto merge of #125096 - jhpratt:rollup-aj2qwsg, r=jhpratt
Rollup of 5 pull requests Successful merges: - #116675 ([ptr] Document maximum allocation size) - #124807 (Migrate `run-make/rustdoc-io-error` to `rmake.rs`) - #124997 (Fix ICE while casting a type with error) - #125072 (Add test for dynamic dispatch + Pin::new soundness) - #125090 (Migrate fuchsia docs from `pm` to `ffx`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3458211 + 47faa8b commit 5228c08

File tree

10 files changed

+189
-41
lines changed

10 files changed

+189
-41
lines changed

compiler/rustc_hir_typeck/src/cast.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
141141
| ty::Never
142142
| ty::Dynamic(_, _, ty::DynStar)
143143
| ty::Error(_) => {
144-
self.dcx().span_bug(span, format!("`{t:?}` should be sized but is not?"));
144+
let guar = self
145+
.dcx()
146+
.span_delayed_bug(span, format!("`{t:?}` should be sized but is not?"));
147+
return Err(guar);
145148
}
146149
})
147150
}

library/core/src/ptr/mod.rs

+33-5
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,39 @@
6363
//!
6464
//! ## Allocated object
6565
//!
66-
//! For several operations, such as [`offset`] or field projections (`expr.field`), the notion of an
67-
//! "allocated object" becomes relevant. An allocated object is a contiguous region of memory.
68-
//! Common examples of allocated objects include stack-allocated variables (each variable is a
69-
//! separate allocated object), heap allocations (each allocation created by the global allocator is
70-
//! a separate allocated object), and `static` variables.
66+
//! An *allocated object* is a subset of program memory which is addressable
67+
//! from Rust, and within which pointer arithmetic is possible. Examples of
68+
//! allocated objects include heap allocations, stack-allocated variables,
69+
//! statics, and consts. The safety preconditions of some Rust operations -
70+
//! such as `offset` and field projections (`expr.field`) - are defined in
71+
//! terms of the allocated objects on which they operate.
72+
//!
73+
//! An allocated object has a base address, a size, and a set of memory
74+
//! addresses. It is possible for an allocated object to have zero size, but
75+
//! such an allocated object will still have a base address. The base address
76+
//! of an allocated object is not necessarily unique. While it is currently the
77+
//! case that an allocated object always has a set of memory addresses which is
78+
//! fully contiguous (i.e., has no "holes"), there is no guarantee that this
79+
//! will not change in the future.
80+
//!
81+
//! For any allocated object with `base` address, `size`, and a set of
82+
//! `addresses`, the following are guaranteed:
83+
//! - For all addresses `a` in `addresses`, `a` is in the range `base .. (base +
84+
//! size)` (note that this requires `a < base + size`, not `a <= base + size`)
85+
//! - `base` is not equal to [`null()`] (i.e., the address with the numerical
86+
//! value 0)
87+
//! - `base + size <= usize::MAX`
88+
//! - `size <= isize::MAX`
89+
//!
90+
//! As a consequence of these guarantees, given any address `a` within the set
91+
//! of addresses of an allocated object:
92+
//! - It is guaranteed that `a - base` does not overflow `isize`
93+
//! - It is guaranteed that `a - base` is non-negative
94+
//! - It is guaranteed that, given `o = a - base` (i.e., the offset of `a` within
95+
//! the allocated object), `base + o` will not wrap around the address space (in
96+
//! other words, will not overflow `usize`)
97+
//!
98+
//! [`null()`]: null
7199
//!
72100
//! # Strict Provenance
73101
//!

src/doc/rustc/src/platform-support/fuchsia.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ meta/hello_fuchsia.cm=pkg/meta/hello_fuchsia.cm
387387
```
388388

389389
*Note: Relative manifest paths are resolved starting from the working directory
390-
of `pm`. Make sure to fill out `<SDK_PATH>` with the path to the downloaded
390+
of `ffx`. Make sure to fill out `<SDK_PATH>` with the path to the downloaded
391391
SDK.*
392392

393393
The `.manifest` file will be used to describe the contents of the package by
@@ -459,12 +459,10 @@ hello_fuchsia/
459459
Next, we'll build a package manifest as defined by our manifest:
460460

461461
```sh
462-
${SDK_PATH}/tools/${ARCH}/pm \
463-
-api-level $(${SDK_PATH}/tools/${ARCH}/ffx version -v | grep "api-level" | head -1 | awk -F ' ' '{print $2}') \
464-
-o pkg/hello_fuchsia_manifest \
465-
-m pkg/hello_fuchsia.manifest \
466-
build \
467-
-output-package-manifest pkg/hello_fuchsia_package_manifest
462+
${SDK_PATH}/tools/${ARCH}/ffx package build \
463+
--api-level $(${SDK_PATH}/tools/${ARCH}/ffx --machine json version | jq .tool_version.api_level) \
464+
--out pkg/hello_fuchsia_manifest \
465+
pkg/hello_fuchsia.manifest
468466
```
469467

470468
This will produce `pkg/hello_fuchsia_manifest/` which is a package manifest we can
@@ -498,8 +496,7 @@ to.
498496
We can set up our repository with:
499497

500498
```sh
501-
${SDK_PATH}/tools/${ARCH}/pm newrepo \
502-
-repo pkg/repo
499+
${SDK_PATH}/tools/${ARCH}/ffx repository create pkg/repo
503500
```
504501

505502
**Current directory structure**
@@ -523,17 +520,17 @@ hello_fuchsia/
523520
We can publish our new package to that repository with:
524521

525522
```sh
526-
${SDK_PATH}/tools/${ARCH}/pm publish \
527-
-repo pkg/repo \
528-
-lp -f <(echo "pkg/hello_fuchsia_package_manifest")
523+
${SDK_PATH}/tools/${ARCH}/ffx repository publish \
524+
--package pkg/hello_fuchsia_package_manifest \
525+
pkg/repo
529526
```
530527

531528
Then we can add the repository to `ffx`'s package server as `hello-fuchsia` using:
532529

533530
```sh
534531
${SDK_PATH}/tools/${ARCH}/ffx repository add-from-pm \
535-
pkg/repo \
536-
-r hello-fuchsia
532+
--repository hello-fuchsia \
533+
pkg/repo
537534
```
538535

539536
## Running a Fuchsia component on an emulator

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ run-make/rlib-format-packed-bundled-libs-3/Makefile
241241
run-make/rlib-format-packed-bundled-libs/Makefile
242242
run-make/rmeta-preferred/Makefile
243243
run-make/rustc-macro-dep-files/Makefile
244-
run-make/rustdoc-io-error/Makefile
245244
run-make/rustdoc-scrape-examples-invalid-expr/Makefile
246245
run-make/rustdoc-scrape-examples-macros/Makefile
247246
run-make/rustdoc-scrape-examples-multiple/Makefile

tests/run-make/rustdoc-io-error/Makefile

-20
This file was deleted.
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This test verifies that rustdoc doesn't ICE when it encounters an IO error
2+
// while generating files. Ideally this would be a rustdoc-ui test, so we could
3+
// verify the error message as well.
4+
//
5+
// It operates by creating a temporary directory and modifying its
6+
// permissions so that it is not writable. We have to take special care to set
7+
// the permissions back to normal so that it's able to be deleted later.
8+
9+
use run_make_support::{rustdoc, tmp_dir};
10+
use std::fs;
11+
12+
fn main() {
13+
let out_dir = tmp_dir().join("rustdoc-io-error");
14+
let output = fs::create_dir(&out_dir).unwrap();
15+
let mut permissions = fs::metadata(&out_dir).unwrap().permissions();
16+
let original_permissions = permissions.clone();
17+
permissions.set_readonly(true);
18+
fs::set_permissions(&out_dir, permissions.clone()).unwrap();
19+
20+
let output = rustdoc().input("foo.rs").output(&out_dir).command_output();
21+
22+
// Changing back permissions.
23+
fs::set_permissions(&out_dir, original_permissions).unwrap();
24+
25+
// Checks that rustdoc failed with the error code 1.
26+
#[cfg(unix)]
27+
assert_eq!(output.status.code().unwrap(), 1);
28+
assert!(!output.status.success());
29+
let stderr = String::from_utf8(output.stderr).unwrap();
30+
31+
assert!(stderr.contains("error: couldn't generate documentation: Permission denied"));
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Regression test for ICE #124848
2+
// Tests that there is no ICE when a cast
3+
// involves a type with error
4+
5+
use std::cell::Cell;
6+
7+
struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
8+
//~^ ERROR use of undeclared lifetime name `'unpinned`
9+
//~| ERROR cannot find type `Pin` in this scope
10+
11+
fn main() {
12+
let mut unpinned = MyType(Cell::new(None));
13+
//~^ ERROR his struct takes 2 arguments but 1 argument was supplied
14+
let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
15+
//~^ ERROR use of undeclared lifetime name `'a`
16+
//~| ERROR use of undeclared lifetime name `'a`
17+
//~| ERROR casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
error[E0261]: use of undeclared lifetime name `'unpinned`
2+
--> $DIR/ice-cast-type-with-error-124848.rs:7:32
3+
|
4+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
5+
| - ^^^^^^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'unpinned` here: `'unpinned,`
8+
9+
error[E0261]: use of undeclared lifetime name `'a`
10+
--> $DIR/ice-cast-type-with-error-124848.rs:14:53
11+
|
12+
LL | fn main() {
13+
| - help: consider introducing lifetime `'a` here: `<'a>`
14+
...
15+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
16+
| ^^ undeclared lifetime
17+
18+
error[E0261]: use of undeclared lifetime name `'a`
19+
--> $DIR/ice-cast-type-with-error-124848.rs:14:67
20+
|
21+
LL | fn main() {
22+
| - help: consider introducing lifetime `'a` here: `<'a>`
23+
...
24+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
25+
| ^^ undeclared lifetime
26+
27+
error[E0412]: cannot find type `Pin` in this scope
28+
--> $DIR/ice-cast-type-with-error-124848.rs:7:60
29+
|
30+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
31+
| ^^^ not found in this scope
32+
|
33+
help: consider importing this struct
34+
|
35+
LL + use std::pin::Pin;
36+
|
37+
38+
error[E0061]: this struct takes 2 arguments but 1 argument was supplied
39+
--> $DIR/ice-cast-type-with-error-124848.rs:12:24
40+
|
41+
LL | let mut unpinned = MyType(Cell::new(None));
42+
| ^^^^^^----------------- an argument is missing
43+
|
44+
note: tuple struct defined here
45+
--> $DIR/ice-cast-type-with-error-124848.rs:7:8
46+
|
47+
LL | struct MyType<'a>(Cell<Option<&'unpinned mut MyType<'a>>>, Pin);
48+
| ^^^^^^
49+
help: provide the argument
50+
|
51+
LL | let mut unpinned = MyType(Cell::new(None), /* value */);
52+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53+
54+
error[E0606]: casting `&MyType<'_>` as `*const Cell<Option<&mut MyType<'_>>>` is invalid
55+
--> $DIR/ice-cast-type-with-error-124848.rs:14:20
56+
|
57+
LL | let bad_addr = &unpinned as *const Cell<Option<&'a mut MyType<'a>>> as usize;
58+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
59+
60+
error: aborting due to 6 previous errors
61+
62+
Some errors have detailed explanations: E0061, E0261, E0412, E0606.
63+
For more information about an error, try `rustc --explain E0061`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::marker::PhantomPinned;
2+
use std::pin::Pin;
3+
4+
trait MyUnpinTrait {
5+
fn into_pinned_type(self: Pin<&mut Self>) -> Pin<&mut PhantomPinned>;
6+
}
7+
impl MyUnpinTrait for PhantomPinned {
8+
fn into_pinned_type(self: Pin<&mut Self>) -> Pin<&mut PhantomPinned> {
9+
self
10+
}
11+
}
12+
impl Unpin for dyn MyUnpinTrait {} //~ ERROR E0321
13+
14+
// It would be unsound for this function to compile.
15+
fn pin_it(not_yet_pinned: &mut PhantomPinned) -> Pin<&mut PhantomPinned> {
16+
Pin::new(not_yet_pinned as &mut dyn MyUnpinTrait).into_pinned_type()
17+
}
18+
19+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0321]: cross-crate traits with a default impl, like `Unpin`, can only be implemented for a struct/enum type, not `(dyn MyUnpinTrait + 'static)`
2+
--> $DIR/pin-dyn-dispatch-sound.rs:12:1
3+
|
4+
LL | impl Unpin for dyn MyUnpinTrait {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't implement cross-crate trait with a default impl for non-struct/enum type
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0321`.

0 commit comments

Comments
 (0)