Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions compiler/rustc_mir_transform/src/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,26 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
),
);
}

// Call arguments are moved by reference, so they must be plain locals
// or the contents of a box; other moved places violate MIR invariants.
if self.tcx.sess.opts.unstable_opts.validate_mir
&& self.body.phase < MirPhase::Runtime(RuntimePhase::Initial)
{
let is_plain_local = place.projection.is_empty();
let is_box_deref =
matches!(place.projection.as_ref(), [ProjectionElem::Deref])
&& self.body.local_decls[place.local].ty.is_box();
if !is_plain_local && !is_box_deref {
self.fail(
location,
format!(
"encountered `Move` of a non-local, non-box place in `Call` terminator: {:?}",
terminator.kind,
),
);
}
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_type_ir_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ decl_derive!(
/// struct Foo {
/// #[generic_type_visitable(bounds())]
/// just_self: Box<Self>,
/// #[generic_type_visitable(bounds(Bar: GenericTypeVisitable))]
/// #[generic_type_visitable(bounds(Bar: GenericTypeVisitable<__V>))]
/// contains_self: (Box<Self>, Bar),
/// }
/// struct Bar;
/// ```
///
/// Note: the `__V` lifetime is an implementation detail of the derive macro.
/// We could probably handle this in a nicer way, but we don't expect this form
/// to really be necessary any time soon, so for now we don't.
customizable_type_visitable_derive
);

Expand Down Expand Up @@ -461,7 +465,7 @@ mod kw {
/// Parses a bound like:
///
/// ```ignore (would need to import GenericTypeVisitable to get this to compile)
/// #[generic_type_visitable(bounds(Foo: GenericTypeVisitable, Bar: GenericTypeVisitable))]
/// #[generic_type_visitable(bounds(Foo: GenericTypeVisitable<__V>, Bar: GenericTypeVisitable<__V>))]
/// ```
fn parse_generic_type_visitable_bound(
attr: &Attribute,
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ impl Duration {

/// Creates a new `Duration` from the specified number of weeks.
///
/// For this method, one week is defined as 7 days, or 604,800 seconds.
/// For this function, one week is defined as 7 days, or 604,800 seconds.
///
/// # Panics
///
Expand Down Expand Up @@ -375,7 +375,7 @@ impl Duration {

/// Creates a new `Duration` from the specified number of days.
///
/// For this method, one day is defined as 24 hours, or 86,400 seconds.
/// For this function, one day is defined as 24 hours, or 86,400 seconds.
///
/// # Panics
///
Expand Down Expand Up @@ -405,7 +405,7 @@ impl Duration {

/// Creates a new `Duration` from the specified number of hours.
///
/// For this method, one hour is defined as 60 minutes, or 3,600 seconds.
/// For this function, one hour is defined as 60 minutes, or 3,600 seconds.
///
/// # Panics
///
Expand Down Expand Up @@ -435,7 +435,7 @@ impl Duration {

/// Creates a new `Duration` from the specified number of minutes.
///
/// For this method, one minute is defined as 60 seconds.
/// For this function, one minute is defined as 60 seconds.
///
/// # Panics
///
Expand Down
2 changes: 1 addition & 1 deletion src/doc/edition-guide
2 changes: 1 addition & 1 deletion src/doc/reference
Submodule reference updated 51 files
+3 −1 .github/workflows/daily-grammar-check.yml
+1 −1 book.toml
+1 −1 src/attributes.md
+1 −0 src/attributes/codegen.md
+1 −0 src/attributes/debugger.md
+13 −10 src/attributes/diagnostics.md
+1 −0 src/attributes/limits.md
+1 −0 src/attributes/testing.md
+1 −0 src/attributes/type_system.md
+6 −8 src/behavior-considered-undefined.md
+11 −10 src/comments.md
+5 −5 src/conditional-compilation.md
+14 −10 src/destructors.md
+0 −4 src/divergence.md
+4 −22 src/expressions/block-expr.md
+1 −3 src/expressions/match-expr.md
+21 −21 src/inline-assembly.md
+1 −1 src/introduction.md
+1 −1 src/items/associated-items.md
+35 −3 src/items/enumerations.md
+19 −18 src/items/external-blocks.md
+6 −6 src/items/generics.md
+1 −1 src/items/implementations.md
+1 −1 src/items/static-items.md
+1 −1 src/items/unions.md
+6 −5 src/items/use-declarations.md
+1 −0 src/keywords.md
+1 −0 src/lifetime-elision.md
+1 −1 src/linkage.md
+1 −0 src/macro-ambiguity.md
+2 −1 src/macros-by-example.md
+1 −0 src/memory-model.md
+2 −2 src/names/name-resolution.md
+1 −0 src/names/namespaces.md
+2 −0 src/names/scopes.md
+1 −0 src/paths.md
+2 −2 src/patterns.md
+1 −0 src/runtime.md
+1 −0 src/special-types-and-traits.md
+4 −4 src/syntax-index.md
+1 −0 src/tokens.md
+65 −3 src/type-layout.md
+2 −1 src/types/boolean.md
+1 −2 src/types/closure.md
+2 −2 src/types/impl-trait.md
+47 −17 src/types/never.md
+0 −30 src/types/textual.md
+1 −0 src/unsafe-keyword.md
+1 −0 tools/grammar-check/src/main.rs
+27 −0 tools/grammar-check/src/test_cases.rs
+1 −1 tools/grammar/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ For rust-analyzer, the corresponding implementations are located across several
These two traits correspond to the role of [`InferCtxt`][rustc inferctxt] in rustc.

[`InferCtxtLike`][ir inferctxtlike] must be defined in `rustc_infer` due to coherence
constraints(orphan rules).
constraints (orphan rules).
As a result, it cannot provide functionality that lives in `rustc_trait_selection`.
Instead, behavior that depends on trait-solving logic is abstracted into a separate trait,
[`SolverDelegate`][ir solverdelegate].
Expand Down Expand Up @@ -214,9 +214,9 @@ non-obvious considerations:

1. The generic parameters `I` and `J` are reserved for `I: Interner` and `J`
being the interner it is being lifted to.
2. `PhantomData` is handled automatically, creating a new `PhantomData` but
_has_ to be included in the file through; `use std::marker::PhantomData;`
you cannot use `std::marker::PhantomData` directly on the field of a struct.
2. `PhantomData` is handled automatically, creating a new `PhantomData`. But it
_has_ to be used in the fully unqualified form -- you cannot use
`std::marker::PhantomData` directly in the field.
3. The bounds are deliberately written as associated type bounds on the `Interner`
trait rather than as `where` clauses on `LiftInto`. Given only `I: LiftInto<J>`,
Rust can then treat bounds such as the following as implied:
Expand Down Expand Up @@ -255,12 +255,6 @@ There is intentionally no ignore attribute. The traversal must visit every
field. This is a soundness requirement for rust-analyzer's use of the traversal
when tracing and garbage-collecting interned types.

When the macro crate's `nightly` feature is enabled, the derive macro remains
registered but emits no tokens. The `GenericTypeVisitable` trait and its
traversal module are also excluded from the nightly configuration of
`rustc_type_ir`; they exist only in its non-nightly configuration.


## Long-term plans for supporting rust-analyzer

In general, we aim to support rust-analyzer just as well as rustc in these shared crates—provided
Expand Down Expand Up @@ -310,4 +304,4 @@ There are still duplicated implementations between rustc and rust-analyzer—suc
[r-a coerce]: https://github.com/rust-lang/rust-analyzer/blob/34f47d9298c478c12c6c4c0348771d1b05706e09/crates/hir-ty/src/infer/coerce.rs
[rustc_lift]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/lift.rs#L18
[rustc_typevisitable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/visit.rs#L62
[rustc_typefoldable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/fold.rs#L71
[rustc_typefoldable]: https://github.com/rust-lang/rust/blob/0913b18e489ac1011b580e31fa5559654be12bfc/compiler/rustc_type_ir/src/fold.rs#L71
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide/src/solve/the-solver.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ as it is very similar to this implementation and also talks about limitations of

## A rough walkthrough

The entry-point of the solver is `InferCtxtEvalExt::evaluate_root_goal`.
The entry-point of the solver is `SolverDelegateEvalExt::evaluate_root_goal`.
This function sets up the root `EvalCtxt` and then calls `EvalCtxt::evaluate_goal`,
to actually enter the trait solver.

Expand Down
1 change: 1 addition & 0 deletions src/doc/rustc/src/platform-support/windows-gnu.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ The targets are built and tested using a reasonably modern C toolchain, and it s
* GCC 14.2
* mingw-w64 12.0.0
* MSVCRT library as the default
* Libgcc with DWARF-2 exception handling for i686 and SEH for x86_64

Using older tools (especially Binutils) may not work properly, due to the number of issues plaguing older versions of Binutils.
The supported toolchain versions are subject to change.
Expand Down
19 changes: 19 additions & 0 deletions tests/ui-fulldeps/derive-generic-type-visitable-missing-bound.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//@ edition: 2024
//@ check-fail

#![crate_type = "rlib"]
#![feature(rustc_private)]

extern crate rustc_type_ir;
extern crate rustc_type_ir_macros;

use rustc_type_ir_macros::GenericTypeVisitable;

#[derive(GenericTypeVisitable)]
struct MissingBound<T> {
// This should fail, as `T: GenericTypeVisitable<__V>` wasn't specified
#[generic_type_visitable(bounds())]
//~^ ERROR: the trait bound `T: GenericTypeVisitable<__V>` is not satisfied
partially_rec: (Vec<Self>, T),
other: u32,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0277]: the trait bound `T: GenericTypeVisitable<__V>` is not satisfied
--> $DIR/derive-generic-type-visitable-missing-bound.rs:15:5
|
LL | #[derive(GenericTypeVisitable)]
| --------------------
| |
| required by a bound introduced by this call
| in this derive macro expansion
...
LL | #[generic_type_visitable(bounds())]
| ^ the nightly-only, unstable trait `GenericTypeVisitable<__V>` is not implemented for `T`
|
= note: required for `(Vec<MissingBound<T>>, T)` to implement `GenericTypeVisitable<__V>`
= note: this error originates in the derive macro `GenericTypeVisitable` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
119 changes: 119 additions & 0 deletions tests/ui-fulldeps/derive-generic-type-visitable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//@ edition: 2024
//@ run-pass

#![feature(rustc_private)]

extern crate rustc_type_ir;
extern crate rustc_type_ir_macros;

use rustc_type_ir::GenericTypeVisitable;
use rustc_type_ir_macros::GenericTypeVisitable;

// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
// files.
#[expect(unused_extern_crates)]
extern crate rustc_driver;

#[derive(GenericTypeVisitable)]
struct DerivesGenericTypeVisitable;

#[derive(GenericTypeVisitable)]
struct Foo {
one: Incrementer,
two: Vec<Incrementer>,
}

#[derive(GenericTypeVisitable)]
enum Enum {
A,
B(Incrementer),
C { one: Incrementer, two: Vec<Incrementer> },
}

#[derive(GenericTypeVisitable)]
struct Generic<T>(Vec<T>);

#[derive(GenericTypeVisitable)]
struct Recursive {
#[generic_type_visitable(bounds())]
rec: Vec<Self>,
other: Incrementer,
}

#[derive(GenericTypeVisitable)]
struct PartiallyRecursiveField<T> {
#[generic_type_visitable(bounds(T: GenericTypeVisitable<__V>))]
partially_rec: (Vec<Self>, T),
other: Incrementer,
}

// start testing setup

use std::sync::atomic::{AtomicU8, Ordering};

static COUNT: AtomicU8 = AtomicU8::new(0);

/// A type that, when visited, increments a global counter.
///
/// Used to (weakly) test the correctness of the derive by making sure that
/// it traverses all the fields, and thus reaches all the incrementers.
#[derive(Clone)]
struct Incrementer;

unsafe impl<V> GenericTypeVisitable<V> for Incrementer {
fn generic_visit_with(&self, _visitor: &mut V) {
COUNT.fetch_add(1, Ordering::Relaxed);
}
}

// end testing setup

fn main() {
use Incrementer as Inc; // for brevity

#[track_caller]
fn check<T: GenericTypeVisitable<()>>(item: T, count: u8) {
let mut v = ();
item.generic_visit_with(&mut v);
assert_eq!(COUNT.swap(0, Ordering::Relaxed), count);
}

check(DerivesGenericTypeVisitable, 0);
check(Foo { one: Inc, two: vec![] }, 1);
check(Foo { one: Inc, two: vec![Inc; 2] }, 1 + 2);
check(Enum::A, 0);
check(Enum::B(Inc), 1);
check(Enum::C { one: Inc, two: vec![] }, 1);
check(Enum::C { one: Inc, two: vec![Inc; 3] }, 1 + 3);
check(Generic::<Inc>(vec![]), 0);
// visits each of the nested `Inc`s
check(Generic(vec![Inc; 5]), 5);

// Every (nested) `rec!` adds another `Recursive`, and thus 1 more visited `Inc`.
macro_rules! rec {
[$($i:expr),* $(,)?] => {
Recursive { rec: vec![$($i),*], other: Inc }
}
}
check(rec![], 1);
check(rec![rec![]], 2);
check(rec![rec![], rec![]], 3);
check(rec![rec![rec![]]], 3);

// Every (nested) `prec!` adds another `PartiallyRecursiveField`, and thus 1 more visited `Inc`.
macro_rules! prec {
([$($i:expr),* $(,)?], $o:expr) => {
PartiallyRecursiveField { partially_rec: (vec![$($i),*], $o), other: Inc }
}
}
// Every nested `a()`, `b()`, and `c()` adds 0, 1, and 2 more visited `Inc`s, respectively.
let a = || Enum::A;
let b = || Enum::B(Inc);
let c = || Enum::C { one: Inc, two: vec![Inc] };
check(prec!([], a()), 1 + 0);
check(prec!([], b()), 1 + 1);
check(prec!([], c()), 1 + 2);
check(prec!([prec!([], a())], a()), 1 + (1 + 0) + 0);
check(prec!([prec!([], b())], a()), 1 + (1 + 1) + 0);
check(prec!([prec!([], b())], b()), 1 + (1 + 1) + 1);
}
14 changes: 7 additions & 7 deletions tests/ui/explicit-tail-calls/tailcc-no-signature-restriction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//@ run-pass
//@ ignore-backends: gcc
//@ min-llvm-version: 22
//@ revisions: x86_64 aarch64
//@ min-llvm-version: 23
//@ revisions: x86 x86_64 aarch64
//
// FIXME: enable x86 on LLVM 23.
//@ [x86] only-x86
//@ [x86_64] only-x86_64
//@ [aarch64] only-aarch64
#![feature(explicit_tail_calls, rust_tail_cc)]
Expand All @@ -18,6 +18,7 @@ pub extern "tail" fn add() -> u64 {
become add(1, 2);
}

#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(windows)))]
#[inline(never)]
pub extern "tail" fn pass_struct(a: u64, d: u64) -> u64 {
#[derive(Clone, Copy)]
Expand All @@ -42,8 +43,7 @@ pub extern "tail" fn pass_struct(a: u64, d: u64) -> u64 {
fn main() {
assert_eq!(add(), 3);

// FIXME: LLVM 22 has a bug which makes this miscompile.
if false {
assert_eq!(pass_struct(5, 6), 5 + 6);
}
// Windows and Aarch64 in LLVM 23 does not support byval arguments.
#[cfg(all(any(target_arch = "x86", target_arch = "x86_64"), not(windows)))]
assert_eq!(pass_struct(5, 6), 5 + 6);
}
28 changes: 28 additions & 0 deletions tests/ui/mir/validate/call-move-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Check that validation rejects moving a non-local, non-box place as a
// `Call` argument.
//
//@ failure-status: 101
//@ dont-check-compiler-stderr
//@ compile-flags: -Zvalidate-mir

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;

fn bar(_x: i32) {}

#[custom_mir(dialect = "built")]
pub fn main() {
mir! {
let a: (i32, i32);
{
a = (1, 2);
Call(RET = bar(Move(a.0)), ReturnTo(retblock), UnwindContinue())
//~^ ERROR broken MIR in
//~| ERROR encountered `Move` of a non-local, non-box place in `Call` terminator
}
retblock = {
Return()
}
}
}
Loading