Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfba5f44

Browse files
committed
Auto merge of#125098 - jhpratt:rollup-2qm4gga, r=jhpratt
Rollup of 4 pull requestsSuccessful merges: -#116675 ([ptr] Document maximum allocation size) -#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 parents9105c57 +32d74f1 commitfba5f44

File tree

7 files changed

+157
-20
lines changed

7 files changed

+157
-20
lines changed

‎compiler/rustc_hir_typeck/src/cast.rs‎

Lines changed: 4 additions & 1 deletion
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+
returnErr(guar);
145148
}
146149
})
147150
}

‎library/core/src/ptr/mod.rs‎

Lines changed: 33 additions & 5 deletions
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‎

Lines changed: 11 additions & 14 deletions
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
Lines changed: 18 additions & 0 deletions
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+
structMyType<'a>(Cell<Option<&'unpinnedmutMyType<'a>>>,Pin);
8+
//~^ ERROR use of undeclared lifetime name `'unpinned`
9+
//~| ERROR cannot find type `Pin` in this scope
10+
11+
fnmain(){
12+
letmut unpinned =MyType(Cell::new(None));
13+
//~^ ERROR his struct takes 2 arguments but 1 argument was supplied
14+
let bad_addr =&unpinnedas*constCell<Option<&'amutMyType<'a>>>asusize;
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+
}
Lines changed: 63 additions & 0 deletions
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`.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use std::marker::PhantomPinned;
2+
use std::pin::Pin;
3+
4+
traitMyUnpinTrait{
5+
fninto_pinned_type(self:Pin<&mutSelf>) ->Pin<&mutPhantomPinned>;
6+
}
7+
implMyUnpinTraitforPhantomPinned{
8+
fninto_pinned_type(self:Pin<&mutSelf>) ->Pin<&mutPhantomPinned>{
9+
self
10+
}
11+
}
12+
implUnpinfordynMyUnpinTrait{}//~ ERROR E0321
13+
14+
// It would be unsound for this function to compile.
15+
fnpin_it(not_yet_pinned:&mutPhantomPinned) ->Pin<&mutPhantomPinned>{
16+
Pin::new(not_yet_pinnedas&mutdynMyUnpinTrait).into_pinned_type()
17+
}
18+
19+
fnmain(){}
Lines changed: 9 additions & 0 deletions
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)

[8]ページ先頭

©2009-2025 Movatter.jp