Skip to content

Commit a60a9e5

Browse files
committed
Auto merge of #129464 - GuillaumeGomez:rollup-ckfqd7h, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #128511 (Document WebAssembly target feature expectations) - #129243 (do not build `cargo-miri` by default on stable channel) - #129263 (Add a missing compatibility note in the 1.80.0 release notes) - #129276 (Stabilize feature `char_indices_offset`) - #129350 (adapt integer comparison tests for LLVM 20 IR changes) - #129408 (Fix handling of macro arguments within the `dropping_copy_types` lint) - #129426 (rustdoc-search: use tighter json for names and parents) - #129437 (Fix typo in a help diagnostic) - #129457 (kobzol vacation) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c8b14ba + 0369e85 commit a60a9e5

File tree

22 files changed

+375
-45
lines changed

22 files changed

+375
-45
lines changed

RELEASES.md

+2
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ Compatibility Notes
143143
- [Turn `proc_macro_back_compat` lint into a hard error.](https://github.com/rust-lang/rust/pull/125596/)
144144
- [Detect unused structs even when implementing private traits](https://github.com/rust-lang/rust/pull/122382/)
145145
- [`std::sync::ReentrantLockGuard<T>` is no longer `Sync` if `T: !Sync`](https://github.com/rust-lang/rust/pull/125527) which means [`std::io::StdoutLock` and `std::io::StderrLock` are no longer Sync](https://github.com/rust-lang/rust/issues/127340)
146+
- [Type inference will fail in some cases due to new implementations of `FromIterator for Box<str>`.](https://github.com/rust-lang/rust/pull/99969/)
147+
Notably, this breaks versions of the `time` crate before 0.3.35, due to no longer inferring the implementation for `Box<[_]>`.
146148

147149
<a id="1.80-Internal-Changes"></a>
148150

compiler/rustc_lint/src/drop_forget_useless.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless {
151151
&& let Node::Stmt(stmt) = node
152152
&& let StmtKind::Semi(e) = stmt.kind
153153
&& e.hir_id == expr.hir_id
154+
&& let Some(arg_span) = arg.span.find_ancestor_inside(expr.span)
154155
{
155156
UseLetUnderscoreIgnoreSuggestion::Suggestion {
156-
start_span: expr.span.shrink_to_lo().until(arg.span),
157-
end_span: arg.span.shrink_to_hi().until(expr.span.shrink_to_hi()),
157+
start_span: expr.span.shrink_to_lo().until(arg_span),
158+
end_span: arg_span.shrink_to_hi().until(expr.span.shrink_to_hi()),
158159
}
159160
} else {
160161
UseLetUnderscoreIgnoreSuggestion::Note

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16931693
StringPart::highlighted("multiple different versions".to_string()),
16941694
StringPart::normal(" of crate `".to_string()),
16951695
StringPart::highlighted(format!("{name}")),
1696-
StringPart::normal("` the your dependency graph".to_string()),
1696+
StringPart::normal("` in the dependency graph".to_string()),
16971697
],
16981698
);
16991699
let candidates = if impl_candidates.is_empty() {

config.example.toml

+1
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@
337337
# "analysis",
338338
# "src",
339339
# "wasm-component-ld",
340+
# "miri", "cargo-miri" # for dev/nightly channels
340341
#]
341342

342343
# Verbosity level: 0 == not verbose, 1 == verbose, 2 == very verbose, 3 == print environment variables on each rustc invocation

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@
110110
#![cfg_attr(bootstrap, feature(offset_of_nested))]
111111
#![feature(array_ptr_get)]
112112
#![feature(asm_experimental_arch)]
113-
#![feature(char_indices_offset)]
114113
#![feature(const_align_of_val)]
115114
#![feature(const_align_of_val_raw)]
116115
#![feature(const_align_offset)]

library/core/src/str/iter.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,35 @@ impl<'a> CharIndices<'a> {
241241
/// Returns the byte position of the next character, or the length
242242
/// of the underlying string if there are no more characters.
243243
///
244+
/// This means that, when the iterator has not been fully consumed,
245+
/// the returned value will match the index that will be returned
246+
/// by the next call to [`next()`](Self::next).
247+
///
244248
/// # Examples
245249
///
246250
/// ```
247-
/// #![feature(char_indices_offset)]
248251
/// let mut chars = "a楽".char_indices();
249252
///
253+
/// // `next()` has not been called yet, so `offset()` returns the byte
254+
/// // index of the first character of the string, which is always 0.
250255
/// assert_eq!(chars.offset(), 0);
256+
/// // As expected, the first call to `next()` also returns 0 as index.
251257
/// assert_eq!(chars.next(), Some((0, 'a')));
252258
///
259+
/// // `next()` has been called once, so `offset()` returns the byte index
260+
/// // of the second character ...
253261
/// assert_eq!(chars.offset(), 1);
262+
/// // ... which matches the index returned by the next call to `next()`.
254263
/// assert_eq!(chars.next(), Some((1, '楽')));
255264
///
265+
/// // Once the iterator has been consumed, `offset()` returns the length
266+
/// // in bytes of the string.
256267
/// assert_eq!(chars.offset(), 4);
257268
/// assert_eq!(chars.next(), None);
258269
/// ```
259270
#[inline]
260271
#[must_use]
261-
#[unstable(feature = "char_indices_offset", issue = "83871")]
272+
#[stable(feature = "char_indices_offset", since = "CURRENT_RUSTC_VERSION")]
262273
pub fn offset(&self) -> usize {
263274
self.front_offset
264275
}

src/bootstrap/src/core/build_steps/tool.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ tool_extended!((self, builder),
10961096
CargoClippy, "src/tools/clippy", "cargo-clippy", stable=true;
10971097
Clippy, "src/tools/clippy", "clippy-driver", stable=true, add_bins_to_sysroot = ["clippy-driver", "cargo-clippy"];
10981098
Miri, "src/tools/miri", "miri", stable=false, add_bins_to_sysroot = ["miri"];
1099-
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=true, add_bins_to_sysroot = ["cargo-miri"];
1099+
CargoMiri, "src/tools/miri/cargo-miri", "cargo-miri", stable=false, add_bins_to_sysroot = ["cargo-miri"];
11001100
Rls, "src/tools/rls", "rls", stable=true;
11011101
Rustfmt, "src/tools/rustfmt", "rustfmt", stable=true, add_bins_to_sysroot = ["rustfmt", "cargo-fmt"];
11021102
);

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
- [wasm32-wasip1](platform-support/wasm32-wasip1.md)
8282
- [wasm32-wasip1-threads](platform-support/wasm32-wasip1-threads.md)
8383
- [wasm32-wasip2](platform-support/wasm32-wasip2.md)
84+
- [wasm32-unknown-unknown](platform-support/wasm32-unknown-unknown.md)
8485
- [wasm64-unknown-unknown](platform-support/wasm64-unknown-unknown.md)
8586
- [\*-win7-windows-msvc](platform-support/win7-windows-msvc.md)
8687
- [x86_64-fortanix-unknown-sgx](platform-support/x86_64-fortanix-unknown-sgx.md)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ target | std | notes
192192
[`thumbv8m.main-none-eabi`](platform-support/thumbv8m.main-none-eabi.md) | * | Bare Armv8-M Mainline
193193
[`thumbv8m.main-none-eabihf`](platform-support/thumbv8m.main-none-eabi.md) | * | Bare Armv8-M Mainline, hardfloat
194194
`wasm32-unknown-emscripten` | ✓ | WebAssembly via Emscripten
195-
`wasm32-unknown-unknown` | ✓ | WebAssembly
195+
[`wasm32-unknown-unknown`](platform-support/wasm32-unknown-unknown.md) | ✓ | WebAssembly
196196
`wasm32-wasi` | ✓ | WebAssembly with WASI (undergoing a [rename to `wasm32-wasip1`][wasi-rename])
197197
[`wasm32-wasip1`](platform-support/wasm32-wasip1.md) | ✓ | WebAssembly with WASI
198198
[`wasm32-wasip1-threads`](platform-support/wasm32-wasip1-threads.md) | ✓ | WebAssembly with WASI Preview 1 and threads
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# `wasm32-unknown-unknown`
2+
3+
**Tier: 2**
4+
5+
The `wasm32-unknown-unknown` target is a WebAssembly compilation target which
6+
does not import any functions from the host for the standard library. This is
7+
the "minimal" WebAssembly in the sense of making the fewest assumptions about
8+
the host environment. This target is often used when compiling to the web or
9+
JavaScript environments as there is no standard for what functions can be
10+
imported on the web. This target can also be useful for creating minimal or
11+
bare-bones WebAssembly binaries.
12+
13+
The `wasm32-unknown-unknown` target has support for the Rust standard library
14+
but many parts of the standard library do not work and return errors. For
15+
example `println!` does nothing, `std::fs` always return errors, and
16+
`std::thread::spawn` will panic. There is no means by which this can be
17+
overridden. For a WebAssembly target that more fully supports the standard
18+
library see the [`wasm32-wasip1`](./wasm32-wasip1.md) or
19+
[`wasm32-wasip2`](./wasm32-wasip2.md) targets.
20+
21+
The `wasm32-unknown-unknown` target has full support for the `core` and `alloc`
22+
crates. It additionally supports the `HashMap` type in the `std` crate, although
23+
hash maps are not randomized like they are on other platforms.
24+
25+
One existing user of this target (please feel free to edit and expand this list
26+
too) is the [`wasm-bindgen` project](https://github.com/rustwasm/wasm-bindgen)
27+
which facilitates Rust code interoperating with JavaScript code. Note, though,
28+
that not all uses of `wasm32-unknown-unknown` are using JavaScript and the web.
29+
30+
## Target maintainers
31+
32+
When this target was added to the compiler platform-specific documentation here
33+
was not maintained at that time. This means that the list below is not
34+
exhaustive and there are more interested parties in this target. That being
35+
said since when this document was last updated those interested in maintaining
36+
this target are:
37+
38+
- Alex Crichton, https://github.com/alexcrichton
39+
40+
## Requirements
41+
42+
This target is cross-compiled. The target includes support for `std` itself,
43+
but as mentioned above many pieces of functionality that require an operating
44+
system do not work and will return errors.
45+
46+
This target currently has no equivalent in C/C++. There is no C/C++ toolchain
47+
for this target. While interop is theoretically possible it's recommended to
48+
instead use one of:
49+
50+
* `wasm32-unknown-emscripten` - for web-based use cases the Emscripten
51+
toolchain is typically chosen for running C/C++.
52+
* [`wasm32-wasip1`](./wasm32-wasip1.md) - the wasi-sdk toolchain is used to
53+
compile C/C++ on this target and can interop with Rust code. WASI works on
54+
the web so far as there's no blocker, but an implementation of WASI APIs
55+
must be either chosen or reimplemented.
56+
57+
This target has no build requirements beyond what's in-tree in the Rust
58+
repository. Linking binaries requires LLD to be enabled for the `wasm-ld`
59+
driver. This target uses the `dlmalloc` crate as the default global allocator.
60+
61+
## Building the target
62+
63+
Building this target can be done by:
64+
65+
* Configure the `wasm32-unknown-unknown` target to get built.
66+
* Configure LLD to be built.
67+
* Ensure the `WebAssembly` target backend is not disabled in LLVM.
68+
69+
These are all controlled through `config.toml` options. It should be possible
70+
to build this target on any platform.
71+
72+
## Building Rust programs
73+
74+
Rust programs can be compiled by adding this target via rustup:
75+
76+
```sh
77+
$ rustup target add wasm32-unknown-unknown
78+
```
79+
80+
and then compiling with the target:
81+
82+
```sh
83+
$ rustc foo.rs --target wasm32-unknown-unknown
84+
$ file foo.wasm
85+
```
86+
87+
## Cross-compilation
88+
89+
This target can be cross-compiled from any host.
90+
91+
## Testing
92+
93+
This target is not tested in CI for the rust-lang/rust repository. Many tests
94+
must be disabled to run on this target and failures are non-obvious because
95+
`println!` doesn't work in the standard library. It's recommended to test the
96+
`wasm32-wasip1` target instead for WebAssembly compatibility.
97+
98+
## Conditionally compiling code
99+
100+
It's recommended to conditionally compile code for this target with:
101+
102+
```text
103+
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
104+
```
105+
106+
Note that there is no way to tell via `#[cfg]` whether code will be running on
107+
the web or not.
108+
109+
## Enabled WebAssembly features
110+
111+
WebAssembly is an evolving standard which adds new features such as new
112+
instructions over time. This target's default set of supported WebAssembly
113+
features will additionally change over time. The `wasm32-unknown-unknown` target
114+
inherits the default settings of LLVM which typically matches the default
115+
settings of Emscripten as well.
116+
117+
Changes to WebAssembly go through a [proposals process][proposals] but reaching
118+
the final stage (stage 5) does not automatically mean that the feature will be
119+
enabled in LLVM and Rust by default. At this time the general guidance is that
120+
features must be present in most engines for a "good chunk of time" before
121+
they're enabled in LLVM by default. There is currently no exact number of
122+
months or engines that are required to enable features by default.
123+
124+
[proposals]: https://github.com/WebAssembly/proposals
125+
126+
As of the time of this writing the proposals that are enabled by default (the
127+
`generic` CPU in LLVM terminology) are:
128+
129+
* `multivalue`
130+
* `mutable-globals`
131+
* `reference-types`
132+
* `sign-ext`
133+
134+
If you're compiling WebAssembly code for an engine that does not support a
135+
feature in LLVM's default feature set then the feature must be disabled at
136+
compile time. Note, though, that enabled features may be used in the standard
137+
library or precompiled libraries shipped via rustup. This means that not only
138+
does your own code need to be compiled with the correct set of flags but the
139+
Rust standard library additionally must be recompiled.
140+
141+
Compiling all code for the initial release of WebAssembly looks like:
142+
143+
```sh
144+
$ export RUSTFLAGS=-Ctarget-cpu=mvp
145+
$ cargo +nightly build -Zbuild-std=panic_abort,std --target wasm32-unknown-unknown
146+
```
147+
148+
Here the `mvp` "cpu" is a placeholder in LLVM for disabling all supported
149+
features by default. Cargo's `-Zbuild-std` feature, a Nightly Rust feature, is
150+
then used to recompile the standard library in addition to your own code. This
151+
will produce a binary that uses only the original WebAssembly features by
152+
default and no proposals since its inception.
153+
154+
To enable individual features it can be done with `-Ctarget-feature=+foo`.
155+
Available features for Rust code itself are documented in the [reference] and
156+
can also be found through:
157+
158+
```sh
159+
$ rustc -Ctarget-feature=help --target wasm32-unknown-unknown
160+
```
161+
162+
You'll need to consult your WebAssembly engine's documentation to learn more
163+
about the supported WebAssembly features the engine has.
164+
165+
[reference]: https://doc.rust-lang.org/reference/attributes/codegen.html#wasm32-or-wasm64
166+
167+
Note that it is still possible for Rust crates and libraries to enable
168+
WebAssembly features on a per-function level. This means that the build
169+
command above may not be sufficient to disable all WebAssembly features. If the
170+
final binary still has SIMD instructions, for example, the function in question
171+
will need to be found and the crate in question will likely contain something
172+
like:
173+
174+
```rust,ignore (not-always-compiled-to-wasm)
175+
#[target_feature(enable = "simd128")]
176+
fn foo() {
177+
// ...
178+
}
179+
```
180+
181+
In this situation there is no compiler flag to disable emission of SIMD
182+
instructions and the crate must instead be modified to not include this function
183+
at compile time either by default or through a Cargo feature. For crate authors
184+
it's recommended to avoid `#[target_feature(enable = "...")]` except where
185+
necessary and instead use:
186+
187+
```rust,ignore (not-always-compiled-to-wasm)
188+
#[cfg(target_feature = "simd128")]
189+
fn foo() {
190+
// ...
191+
}
192+
```
193+
194+
That is to say instead of enabling target features it's recommended to
195+
conditionally compile code instead. This is notably different to the way native
196+
platforms such as x86\_64 work, and this is due to the fact that WebAssembly
197+
binaries must only contain code the engine understands. Native binaries work so
198+
long as the CPU doesn't execute unknown code dynamically at runtime.

src/doc/rustc/src/platform-support/wasm32-wasip1-threads.md

+14
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,17 @@ It's recommended to conditionally compile code for this target with:
162162
Prior to Rust 1.80 the `target_env = "p1"` key was not set. Currently the
163163
`target_feature = "atomics"` is Nightly-only. Note that the precise `#[cfg]`
164164
necessary to detect this target may change as the target becomes more stable.
165+
166+
## Enabled WebAssembly features
167+
168+
The default set of WebAssembly features enabled for compilation includes two
169+
more features in addition to that which
170+
[`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md) enables:
171+
172+
* `bulk-memory`
173+
* `atomics`
174+
175+
For more information about features see the documentation for
176+
[`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md), but note that the
177+
`mvp` CPU in LLVM does not support this target as it's required that
178+
`bulk-memory`, `atomics`, and `mutable-globals` are all enabled.

src/doc/rustc/src/platform-support/wasm32-wasip1.md

+6
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,9 @@ It's recommended to conditionally compile code for this target with:
132132

133133
Note that the `target_env = "p1"` condition first appeared in Rust 1.80. Prior
134134
to Rust 1.80 the `target_env` condition was not set.
135+
136+
## Enabled WebAssembly features
137+
138+
The default set of WebAssembly features enabled for compilation is currently the
139+
same as [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md). See the
140+
documentation there for more information.

src/doc/rustc/src/platform-support/wasm32-wasip2.md

+6
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,9 @@ It's recommended to conditionally compile code for this target with:
6161
```text
6262
#[cfg(all(target_os = "wasi", target_env = "p2"))]
6363
```
64+
65+
## Enabled WebAssembly features
66+
67+
The default set of WebAssembly features enabled for compilation is currently the
68+
same as [`wasm32-unknown-unknown`](./wasm32-unknown-unknown.md). See the
69+
documentation there for more information.

0 commit comments

Comments
 (0)