Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
dd79b03
Add docs about SDKs on armv7a-vex-v5
lewisfm Apr 10, 2026
c25fbeb
Add C compilation instructions
lewisfm Apr 10, 2026
ae6376a
Instruct users to build `std` (not `core`) on armv7a-vex-v5
lewisfm Apr 10, 2026
df9fb65
Fix grammar issues in armv7a-vex-v5 docs
lewisfm Apr 10, 2026
70cf3f4
Put `#[diagnostic::on_move]` on `File`
mejrs Apr 21, 2026
0548502
tests/ui/macros: add annotations for reference rules
DanielEScherzer Mar 6, 2026
4f7a26f
Update maintainers of armv7a-vex-v5
lewisfm Apr 23, 2026
3c5e7e8
Simplify `Config::track_state`.
nnethercote Apr 23, 2026
ce880a4
Document `#[diagnostic::on_move]` in the unstable book
mejrs Apr 23, 2026
2f99ab1
Fix classify_union to return Union for regular unions
fneddy Apr 23, 2026
c1936ba
fix `get_child_at_index` return type hints
Walnut356 Apr 23, 2026
b86c9e7
fix array template arg lookup behavior
Walnut356 Apr 23, 2026
294388f
Rollup merge of #155621 - mejrs:document_diagnostic_on_move, r=chenyu…
JonathanBrouwer Apr 23, 2026
f4e00ff
Rollup merge of #155671 - nnethercote:simplify-Config-track_state, r=…
JonathanBrouwer Apr 23, 2026
85d9a59
Rollup merge of #153482 - DanielEScherzer:test-references-macros, r=e…
JonathanBrouwer Apr 23, 2026
93e05f5
Rollup merge of #155075 - vexide:more-docs, r=ehuss
JonathanBrouwer Apr 23, 2026
dfbdd83
Rollup merge of #155685 - Walnut356:ret_type, r=jieyouxu
JonathanBrouwer Apr 23, 2026
09999c7
Rollup merge of #155686 - Walnut356:array_type, r=jieyouxu
JonathanBrouwer Apr 23, 2026
e16f20b
Rollup merge of #155690 - fneddy:fix_classify_union, r=jieyouxu
JonathanBrouwer Apr 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions compiler/rustc_interface/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_ast::{LitKind, MetaItemKind, token};
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::jobserver::{self, Proxy};
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed};
use rustc_lint::LintStore;
use rustc_middle::ty;
Expand Down Expand Up @@ -339,11 +338,7 @@ pub struct Config {
/// This is a callback to track otherwise untracked state used by the caller.
///
/// You can write to `sess.env_depinfo` and `sess.file_depinfo` to track env vars and files.
/// To track any other state you can write to the given hasher. If the hash changes between
/// runs the incremental cache will be cleared.
///
/// The hashing functionality has no known user. FIXME should this be removed?
pub track_state: Option<Box<dyn FnOnce(&Session, &mut StableHasher) + Send>>,
pub track_state: Option<Box<dyn FnOnce(&Session) + Send>>,

/// This is a callback from the driver that is called when we're registering lints;
/// it is called during lint loading when we have the LintStore in a non-shared state.
Expand Down Expand Up @@ -468,9 +463,7 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
}

if let Some(track_state) = config.track_state {
let mut hasher = StableHasher::new();
track_state(&sess, &mut hasher);
sess.opts.untracked_state_hash = hasher.finish()
track_state(&sess);
}

// Even though the session holds the lint store, we can't build the
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,6 @@ impl Default for Options {
target_triple: TargetTuple::from_tuple(host_tuple()),
test: false,
incremental: None,
untracked_state_hash: Default::default(),
unstable_opts,
prints: Vec::new(),
cg: Default::default(),
Expand Down Expand Up @@ -2770,7 +2769,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
target_triple,
test,
incremental,
untracked_state_hash: Default::default(),
unstable_opts,
prints,
cg,
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,6 @@ top_level_options!(
/// If `Some`, enable incremental compilation, using the given
/// directory to store intermediate results.
incremental: Option<PathBuf> [UNTRACKED],
/// Set based on the result of the `Config::track_state` callback
/// for custom drivers to invalidate the incremental cache.
#[rustc_lint_opt_deny_field_access("should only be used via `Config::track_state`")]
untracked_state_hash: Hash64 [TRACKED_NO_CRATE_HASH],

unstable_opts: UnstableOptions [SUBSTRUCT] { TARGET_MODIFIER: UnstableOptions(UnstableOptionsTargetModifiers) },
prints: Vec<PrintRequest> [UNTRACKED],
Expand Down
1 change: 1 addition & 0 deletions library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ use crate::{error, fmt};
/// [`read`]: File::read
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg_attr(not(test), rustc_diagnostic_item = "File")]
#[diagnostic::on_move(note = "you can use `File::try_clone` to duplicate a `File` instance")]
pub struct File {
inner: fs_imp::File,
}
Expand Down
1 change: 1 addition & 0 deletions library/std/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
#![feature(const_trait_impl)]
#![feature(decl_macro)]
#![feature(deprecated_suggestion)]
#![feature(diagnostic_on_move)]
#![feature(doc_cfg)]
#![feature(doc_masked)]
#![feature(doc_notable_trait)]
Expand Down
4 changes: 2 additions & 2 deletions src/doc/rustc-dev-guide/examples/rustc-interface-example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fn main() {
make_codegen_backend: None,
expanded_args: Vec::new(),
ice_file: None,
hash_untracked_state: None,
track_state: None,
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};
rustc_interface::run_compiler(config, |compiler| {
Expand All @@ -72,4 +72,4 @@ fn main() {
}
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn main() {
make_codegen_backend: None,
expanded_args: Vec::new(),
ice_file: None,
hash_untracked_state: None,
track_state: None,
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
};
rustc_interface::run_compiler(config, |compiler| {
Expand All @@ -97,4 +97,4 @@ fn main() {
buffer.lock().unwrap().iter().for_each(|diagnostic| {
println!("{diagnostic:#?}");
});
}
}
103 changes: 94 additions & 9 deletions src/doc/rustc/src/platform-support/armv7a-vex-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

Allows compiling user programs for the [VEX V5 Brain](https://www.vexrobotics.com/276-4810.html), a microcontroller for educational and competitive robotics.

Rust support for this target is not affiliated with VEX Robotics or IFI, and does not link to any official VEX SDK.
Rust support for this target is not affiliated with VEX Robotics or IFI, and does not link against any official VEX SDK.

## Target maintainers

This target is maintained by members of the [vexide](https://github.com/vexide) organization:

- [@lewisfm](https://github.com/lewisfm)
- [@Tropix126](https://github.com/Tropix126)
- [@tropicaaal](https://github.com/tropicaaal)
- [@Gavin-Niederman](https://github.com/Gavin-Niederman)
- [@max-niederman](https://github.com/max-niederman)

Expand All @@ -22,27 +22,37 @@ This target is cross-compiled. Dynamic linking is unsupported.
`#![no_std]` crates can be built using `build-std` to build `core` and `panic_abort` and optionally `alloc`. Unwinding panics are not yet supported on this target.

`std` has only partial support due to platform limitations. Notably:

- `std::process` and `std::net` are unimplemented. `std::thread` only supports sleeping and yielding, as this is a single-threaded environment.
- `std::time` has full support for `Instant`, but no support for `SystemTime`.
- `std::io` has full support for `stdin`/`stdout`/`stderr`. `stdout` and `stderr` both write to USB channel 1 on this platform and are not differentiated.
- `std::fs` has limited support for reading or writing to files. Directory operations, file deletion, and some file opening features are unsupported and will return errors.
- `std::fs` has limited support for reading or writing to files. The following features are unsupported:
- All directory operations (including `mkdir` and `readdir`), although reading directories is possible through [third-party crates](https://docs.rs/vex-sdk/latest/vex_sdk/file/fn.vexFileDirectoryGet.html)
- Deleting files and directories
- File metadata other than file size and type (that is, file vs. directory)
- Opening files with an uncommon combination of open options, such as read + write at the same time.
The supported modes for opening files are in read-only mode, append mode, or write mode (with or without truncation).
- A global allocator implemented on top of `dlmalloc` is provided.
- Modules that do not need to interact with the OS beyond allocation such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc are fully supported.
- Modules that do not need to interact with the OS beyond allocation, such as `std::collections`, `std::hash`, `std::future`, `std::sync`, etc., are fully supported.
- Random number generation and hashing is insecure, as there is no reliable source of entropy on this platform.

In order to support some APIs, users are expected to provide a supporting runtime SDK for `libstd` to link against. This library may be provided either by [`vex-sdk-build`](https://github.com/vexide/vex-sdk/tree/main/packages/vex-sdk-build) (which will download an official SDK from VEX) or through an open-source implementation such as [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable).

When compiling for this target, the "C" calling convention maps to AAPCS with VFP registers (hard float ABI) and the "system" calling convention maps to AAPCS without VFP registers (softfp ABI).

This target generates binaries in the ELF format that may be uploaded to the brain with external tools.

### Platform SDKs

To use most platform-specific APIs, users must configure a supporting runtime SDK for `libstd` to link against. Official *VEXcode* SDKs from VEX can be downloaded and linked via the [`vex-sdk-vexcode`](https://crates.io/crates/vex-sdk-vexcode) crate, but they have a restrictive redistribution policy that might not be suitable for all projects. The suggested SDK for open-source projects is the community-supported [`vex-sdk-jumptable`](https://crates.io/crates/vex-sdk-jumptable) crate. SDK implementations are generally thin wrappers over system calls, so projects should not expect to see significant differences in behavior depending on which SDK they use.

Libraries may access symbols from the active VEX SDK without depending on a specific implementation by using the [`vex-sdk`](https://crates.io/crates/vex-sdk) crate.

## Building the target

You can build Rust with support for this target by adding it to the `target` list in `bootstrap.toml`, and then running `./x build --target armv7a-vex-v5 compiler`.

## Building Rust programs

Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `core` by using `build-std` or similar.
Rust does not yet ship pre-compiled artifacts for this target. To compile for this target, you will either need to build Rust with the target enabled (see "Building the target" above), or build your own copy of `std` using `build-std` or similar.

When the compiler builds a binary, an ELF build artifact will be produced. Additional tools are required for this artifact to be recognizable to VEXos as a user program.

Expand Down Expand Up @@ -78,9 +88,19 @@ Programs can also be directly uploaded to the brain over a USB connection immedi
cargo v5 upload --release
```

### Hello World program

```rs
use ::vex_sdk_jumptable as _; // Bring VEX SDK symbols into scope

fn main() {
println!("Hello, world");
}
```

## Testing

Binaries built for this target can be run in an emulator (such as [vex-v5-qemu](https://github.com/vexide/vex-v5-qemu)), or uploaded to a physical device over a serial (USB) connection.
Binaries built for this target can be run in an emulator (such as [vex-v5-qemu](https://github.com/vexide/vex-v5-qemu)), or uploaded to a physical device over a USB serial connection.

The default Rust test runner is not supported.

Expand All @@ -90,4 +110,69 @@ The Rust test suite for `library/std` is not yet supported.

This target can be cross-compiled from any host.

Linking to C libraries is not supported.
The recommended configuration for compiling compatible C code is to use the [Arm Toolchain for Embedded](https://github.com/arm/arm-toolchain/tree/arm-software/arm-software/embedded#readme) with the following compilation flags:

```sh
clang --target=arm-none-eabi -mcpu=cortex-a9 -mfpu=neon -mfloat-abi=hard -fno-pic -fno-exceptions -fno-rtti -funwind-tables
```

The following Cargo configuration can be used to link with picolibc (the libc used by the Arm Toolchain for Embedded):

```toml
[target.armv7a-vex-v5]
# We use ARM Clang as a linker because ld.lld by itself doesn't include the
# multilib logic for resolving static libraries.
linker = "clang"

rustflags = [
# These link flags resolve to this sysroot:
# `…/arm-none-eabi/armv7a_hard_vfpv3_d16_unaligned`
# (hard float / VFP version 3 with 16 regs / unaligned access)
"-Clink-arg=--target=armv7a-none-eabihf",

# To disable crt0 and use Rust's _boot implementation
# (or something custom):
#"-Clink-arg=-nostartfiles",

# Explicit `-lc` required because Rust calls the linker with
# `-nodefaultlibs` which disables libc, libm, etc.
"-Clink-arg=-lc",
]
```

You may also want to set these environment variables so that third-party crates use the correct C compiler:

```sh
PATH=/path/to/arm-toolchain/bin:$PATH
CC_armv7a_vex_v5=clang
AR_armv7a_vex_v5=clang
CFLAGS_armv7a_vex_v5=[See above]
```

### CMake

It may be helpful to create a CMake toolchain like the following if you are depending on the `cmake` crate:

```cmake
# toolchain.cmake
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(triple armv7a-none-eabihf)

set(CMAKE_C_COMPILER clang)
set(CMAKE_C_COMPILER_TARGET ${triple})
set(CMAKE_CXX_COMPILER clang++)
set(CMAKE_CXX_COMPILER_TARGET ${triple})
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
```

You can enable it by setting the following environment variable alongside the previously mentioned environment variables:

```sh
CMAKE_TOOLCHAIN_FILE_armv7a_vex_v5=/path/to/toolchain.cmake
```

### Implementation of libc functions

You may have to implement [certain system support functions](https://github.com/picolibc/picolibc/blob/main/doc/os.md) for some parts of libc to work properly.
92 changes: 92 additions & 0 deletions src/doc/unstable-book/src/language-features/diagnostic-on-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# `diagnostic_on_move`

The tracking issue for this feature is: [#154181]

------------------------

The `diagnostic_on_move` feature allows use of the `#[diagnostic::on_move]` attribute. It should be
placed on struct, enum and union declarations, though it is not an error to be located in other
positions. This attribute is a hint to the compiler to supplement the error message when the
annotated type is involved in a borrowcheck error.

For example, [`File`] is annotated as such:
```rust
#![feature(diagnostic_on_move)]

#[diagnostic::on_move(note = "you can use `File::try_clone` \
to duplicate a `File` instance")]
pub struct File {
// ...
}
```

When you try to use a `File` after it's already been moved, it will helpfully tell you about `try_clone`.

The message and label can also be customized:

```rust
#![feature(diagnostic_on_move)]

use std::marker::PhantomData;

#[diagnostic::on_move(
message = "`{Self}` cannot be used multiple times",
label = "this token may only be used once",
note = "you can create a new `Token` with `Token::conjure()`"
)]
pub struct Token<'brand> {
spooky: PhantomData<&'brand ()>,
}

impl Token<'_> {
pub fn conjure<'u>() -> Token<'u> {
Token {
spooky: PhantomData,
}
}
}
```
The user may try to use it like this:
```rust,compile_fail,E0382
# #![feature(diagnostic_on_move)]
#
# use std::marker::PhantomData;
#
# #[diagnostic::on_move(
# message = "`{Self}` cannot be used multiple times",
# label = "this token may only be used once",
# note = "you can create a new `Token` with `Token::conjure()`"
# )]
# pub struct Token<'brand> {
# spooky: PhantomData<&'brand ()>,
# }
#
# impl Token<'_> {
# pub fn conjure<'u>() -> Token<'u> {
# Token {
# spooky: PhantomData,
# }
# }
# }
# fn main() {
let token = Token::conjure();
let _ = (token, token);
# }
```
This will result in the following error:
```text
error[E0382]: `Token` cannot be used multiple times
--> src/main.rs:24:21
|
1 | let token = Token::conjure();
| ----- this token may only be used once
2 | let _ = (token, token);
| ----- ^^^^^ value used here after move
| |
| value moved here
|
= note: you can create a new `Token` with `Token::conjure()`
```

[`File`]: https://doc.rust-lang.org/nightly/std/fs/struct.File.html "File in std::fs"
[#154181]: https://github.com/rust-lang/rust/issues/154181 "Tracking Issue for #[diagnostic::on_move]"
Loading
Loading