From 5e31cd30aae245aaa1374e12521667b8c728402d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Mon, 26 May 2025 12:19:34 +0000 Subject: [PATCH 1/8] Support opaque_types_defined_by for SyntheticCoroutineBody --- compiler/rustc_ty_utils/src/opaque_types.rs | 8 +++++--- .../async-await/async-closures/promote-in-body.rs | 13 +++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/ui/async-await/async-closures/promote-in-body.rs diff --git a/compiler/rustc_ty_utils/src/opaque_types.rs b/compiler/rustc_ty_utils/src/opaque_types.rs index 841f602d985cd..3b4482146d4f1 100644 --- a/compiler/rustc_ty_utils/src/opaque_types.rs +++ b/compiler/rustc_ty_utils/src/opaque_types.rs @@ -321,7 +321,10 @@ fn opaque_types_defined_by<'tcx>( collector.collect_taits_declared_in_body(); } // Closures and coroutines are type checked with their parent - DefKind::Closure | DefKind::InlineConst => { + // Note that we also support `SyntheticCoroutineBody` since we create + // a MIR body for the def kind, and some MIR passes (like promotion) + // may require doing analysis using its typing env. + DefKind::Closure | DefKind::InlineConst | DefKind::SyntheticCoroutineBody => { collector.opaques.extend(tcx.opaque_types_defined_by(tcx.local_parent(item))); } DefKind::AssocTy | DefKind::TyAlias | DefKind::GlobalAsm => {} @@ -343,8 +346,7 @@ fn opaque_types_defined_by<'tcx>( | DefKind::ForeignMod | DefKind::Field | DefKind::LifetimeParam - | DefKind::Impl { .. } - | DefKind::SyntheticCoroutineBody => { + | DefKind::Impl { .. } => { span_bug!( tcx.def_span(item), "`opaque_types_defined_by` not defined for {} `{item:?}`", diff --git a/tests/ui/async-await/async-closures/promote-in-body.rs b/tests/ui/async-await/async-closures/promote-in-body.rs new file mode 100644 index 0000000000000..ea95d680987e0 --- /dev/null +++ b/tests/ui/async-await/async-closures/promote-in-body.rs @@ -0,0 +1,13 @@ +//@ build-pass +//@ compile-flags: --crate-type=lib +//@ edition: 2024 + +union U { + f: i32, +} + +fn foo() { + async || { + &U { f: 1 } + }; +} From 1d35ac9ce0e5e5265fae1b2a4754013c1e479960 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 26 May 2025 14:47:19 +0200 Subject: [PATCH 2/8] Add missing edition directives for async-await tests --- .../async-fn/edition-2015-not-async-bound.rs | 1 + tests/ui/async-await/async-fn/edition-2015.rs | 1 + .../async-await/async-fn/edition-2015.stderr | 8 +++---- .../2015-edition-error-various-positions.rs | 1 + ...015-edition-error-various-positions.stderr | 22 +++++++++---------- .../await-keyword/2015-edition-warning.fixed | 1 + .../await-keyword/2015-edition-warning.rs | 1 + .../await-keyword/2015-edition-warning.stderr | 14 ++++++------ tests/ui/async-await/for-await-2015.rs | 1 + ...34-raw-ident-suggestion.edition2015.stderr | 6 ++--- ...34-raw-ident-suggestion.edition2018.stderr | 6 ++--- .../issue-65634-raw-ident-suggestion.rs | 1 + ...uggest-switching-edition-on-await-cargo.rs | 1 + ...st-switching-edition-on-await-cargo.stderr | 8 +++---- .../suggest-switching-edition-on-await.rs | 1 + .../suggest-switching-edition-on-await.stderr | 8 +++---- 16 files changed, 45 insertions(+), 36 deletions(-) diff --git a/tests/ui/async-await/async-fn/edition-2015-not-async-bound.rs b/tests/ui/async-await/async-fn/edition-2015-not-async-bound.rs index d222ddc081eff..60a7dff7d499a 100644 --- a/tests/ui/async-await/async-fn/edition-2015-not-async-bound.rs +++ b/tests/ui/async-await/async-fn/edition-2015-not-async-bound.rs @@ -1,3 +1,4 @@ +//@ edition:2015 //@ check-pass // Make sure that we don't eagerly recover `async ::Bound` in edition 2015. diff --git a/tests/ui/async-await/async-fn/edition-2015.rs b/tests/ui/async-await/async-fn/edition-2015.rs index 341b9b10e6711..5a81df3a4e4d9 100644 --- a/tests/ui/async-await/async-fn/edition-2015.rs +++ b/tests/ui/async-await/async-fn/edition-2015.rs @@ -1,3 +1,4 @@ +//@ edition:2015 fn foo(x: impl async Fn()) -> impl async Fn() { x } //~^ ERROR `async` trait bounds are only allowed in Rust 2018 or later //~| ERROR `async` trait bounds are only allowed in Rust 2018 or later diff --git a/tests/ui/async-await/async-fn/edition-2015.stderr b/tests/ui/async-await/async-fn/edition-2015.stderr index ca9e64cd1bb08..0bec00c162c9d 100644 --- a/tests/ui/async-await/async-fn/edition-2015.stderr +++ b/tests/ui/async-await/async-fn/edition-2015.stderr @@ -1,5 +1,5 @@ error: `async` trait bounds are only allowed in Rust 2018 or later - --> $DIR/edition-2015.rs:1:16 + --> $DIR/edition-2015.rs:2:16 | LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } | ^^^^^ @@ -8,7 +8,7 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } = note: for more on editions, read https://doc.rust-lang.org/edition-guide error: `async` trait bounds are only allowed in Rust 2018 or later - --> $DIR/edition-2015.rs:1:36 + --> $DIR/edition-2015.rs:2:36 | LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } | ^^^^^ @@ -17,7 +17,7 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0658]: `async` trait bounds are unstable - --> $DIR/edition-2015.rs:1:16 + --> $DIR/edition-2015.rs:2:16 | LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } | ^^^^^ @@ -28,7 +28,7 @@ LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } = help: use the desugared name of the async trait, such as `AsyncFn` error[E0658]: `async` trait bounds are unstable - --> $DIR/edition-2015.rs:1:36 + --> $DIR/edition-2015.rs:2:36 | LL | fn foo(x: impl async Fn()) -> impl async Fn() { x } | ^^^^^ diff --git a/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.rs b/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.rs index 50c1639996ee5..714a3328ecf68 100644 --- a/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.rs +++ b/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.rs @@ -1,3 +1,4 @@ +//@ edition:2015 #![allow(non_camel_case_types)] #![deny(keyword_idents)] diff --git a/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr b/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr index 8cea73f865148..70900e612f483 100644 --- a/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr +++ b/tests/ui/async-await/await-keyword/2015-edition-error-various-positions.stderr @@ -1,5 +1,5 @@ error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:5:13 + --> $DIR/2015-edition-error-various-positions.rs:6:13 | LL | pub mod await { | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -7,14 +7,14 @@ LL | pub mod await { = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! = note: for more information, see issue #49716 note: the lint level is defined here - --> $DIR/2015-edition-error-various-positions.rs:2:9 + --> $DIR/2015-edition-error-various-positions.rs:3:9 | LL | #![deny(keyword_idents)] | ^^^^^^^^^^^^^^ = note: `#[deny(keyword_idents_2018)]` implied by `#[deny(keyword_idents)]` error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:7:20 + --> $DIR/2015-edition-error-various-positions.rs:8:20 | LL | pub struct await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -23,7 +23,7 @@ LL | pub struct await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:11:16 + --> $DIR/2015-edition-error-various-positions.rs:12:16 | LL | use outer_mod::await::await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -32,7 +32,7 @@ LL | use outer_mod::await::await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:11:23 + --> $DIR/2015-edition-error-various-positions.rs:12:23 | LL | use outer_mod::await::await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -41,7 +41,7 @@ LL | use outer_mod::await::await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:16:14 + --> $DIR/2015-edition-error-various-positions.rs:17:14 | LL | struct Foo { await: () } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -50,7 +50,7 @@ LL | struct Foo { await: () } = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:20:15 + --> $DIR/2015-edition-error-various-positions.rs:21:15 | LL | impl Foo { fn await() {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -59,7 +59,7 @@ LL | impl Foo { fn await() {} } = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:24:14 + --> $DIR/2015-edition-error-various-positions.rs:25:14 | LL | macro_rules! await { | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -68,7 +68,7 @@ LL | macro_rules! await { = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:31:5 + --> $DIR/2015-edition-error-various-positions.rs:32:5 | LL | await!(); | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -77,7 +77,7 @@ LL | await!(); = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:34:11 + --> $DIR/2015-edition-error-various-positions.rs:35:11 | LL | match await { await => {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -86,7 +86,7 @@ LL | match await { await => {} } = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-error-various-positions.rs:34:19 + --> $DIR/2015-edition-error-various-positions.rs:35:19 | LL | match await { await => {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` diff --git a/tests/ui/async-await/await-keyword/2015-edition-warning.fixed b/tests/ui/async-await/await-keyword/2015-edition-warning.fixed index 4cb8017c7ee36..45758cb10391d 100644 --- a/tests/ui/async-await/await-keyword/2015-edition-warning.fixed +++ b/tests/ui/async-await/await-keyword/2015-edition-warning.fixed @@ -1,3 +1,4 @@ +//@ edition:2015 //@ run-rustfix #![allow(non_camel_case_types)] diff --git a/tests/ui/async-await/await-keyword/2015-edition-warning.rs b/tests/ui/async-await/await-keyword/2015-edition-warning.rs index d591a5af8218c..ea26abe072b37 100644 --- a/tests/ui/async-await/await-keyword/2015-edition-warning.rs +++ b/tests/ui/async-await/await-keyword/2015-edition-warning.rs @@ -1,3 +1,4 @@ +//@ edition:2015 //@ run-rustfix #![allow(non_camel_case_types)] diff --git a/tests/ui/async-await/await-keyword/2015-edition-warning.stderr b/tests/ui/async-await/await-keyword/2015-edition-warning.stderr index 70b7fa52a19c7..9d19a09092b94 100644 --- a/tests/ui/async-await/await-keyword/2015-edition-warning.stderr +++ b/tests/ui/async-await/await-keyword/2015-edition-warning.stderr @@ -1,5 +1,5 @@ error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:7:13 + --> $DIR/2015-edition-warning.rs:8:13 | LL | pub mod await { | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -7,14 +7,14 @@ LL | pub mod await { = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018! = note: for more information, see issue #49716 note: the lint level is defined here - --> $DIR/2015-edition-warning.rs:4:9 + --> $DIR/2015-edition-warning.rs:5:9 | LL | #![deny(keyword_idents)] | ^^^^^^^^^^^^^^ = note: `#[deny(keyword_idents_2018)]` implied by `#[deny(keyword_idents)]` error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:10:20 + --> $DIR/2015-edition-warning.rs:11:20 | LL | pub struct await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -23,7 +23,7 @@ LL | pub struct await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:15:16 + --> $DIR/2015-edition-warning.rs:16:16 | LL | use outer_mod::await::await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -32,7 +32,7 @@ LL | use outer_mod::await::await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:15:23 + --> $DIR/2015-edition-warning.rs:16:23 | LL | use outer_mod::await::await; | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -41,7 +41,7 @@ LL | use outer_mod::await::await; = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:22:11 + --> $DIR/2015-edition-warning.rs:23:11 | LL | match await { await => {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` @@ -50,7 +50,7 @@ LL | match await { await => {} } = note: for more information, see issue #49716 error: `await` is a keyword in the 2018 edition - --> $DIR/2015-edition-warning.rs:22:19 + --> $DIR/2015-edition-warning.rs:23:19 | LL | match await { await => {} } | ^^^^^ help: you can use a raw identifier to stay compatible: `r#await` diff --git a/tests/ui/async-await/for-await-2015.rs b/tests/ui/async-await/for-await-2015.rs index 89ff256da1ddf..c2bd39c844663 100644 --- a/tests/ui/async-await/for-await-2015.rs +++ b/tests/ui/async-await/for-await-2015.rs @@ -1,3 +1,4 @@ +//@ edition:2015 //@ check-pass #![feature(async_for_loop)] diff --git a/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2015.stderr b/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2015.stderr index 2bdc1347c815d..8ce4d4ea06ac8 100644 --- a/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2015.stderr +++ b/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2015.stderr @@ -1,16 +1,16 @@ error[E0034]: multiple applicable items in scope - --> $DIR/issue-65634-raw-ident-suggestion.rs:24:13 + --> $DIR/issue-65634-raw-ident-suggestion.rs:25:13 | LL | r#fn {}.r#struct(); | ^^^^^^^^ multiple `r#struct` found | note: candidate #1 is defined in an impl of the trait `async` for the type `r#fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:7:5 + --> $DIR/issue-65634-raw-ident-suggestion.rs:8:5 | LL | fn r#struct(&self) { | ^^^^^^^^^^^^^^^^^^ note: candidate #2 is defined in an impl of the trait `await` for the type `r#fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:13:5 + --> $DIR/issue-65634-raw-ident-suggestion.rs:14:5 | LL | fn r#struct(&self) { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2018.stderr b/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2018.stderr index ab10ab749fedf..d910ef9872cdb 100644 --- a/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2018.stderr +++ b/tests/ui/async-await/issue-65634-raw-ident-suggestion.edition2018.stderr @@ -1,16 +1,16 @@ error[E0034]: multiple applicable items in scope - --> $DIR/issue-65634-raw-ident-suggestion.rs:24:13 + --> $DIR/issue-65634-raw-ident-suggestion.rs:25:13 | LL | r#fn {}.r#struct(); | ^^^^^^^^ multiple `r#struct` found | note: candidate #1 is defined in an impl of the trait `r#async` for the type `r#fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:7:5 + --> $DIR/issue-65634-raw-ident-suggestion.rs:8:5 | LL | fn r#struct(&self) { | ^^^^^^^^^^^^^^^^^^ note: candidate #2 is defined in an impl of the trait `r#await` for the type `r#fn` - --> $DIR/issue-65634-raw-ident-suggestion.rs:13:5 + --> $DIR/issue-65634-raw-ident-suggestion.rs:14:5 | LL | fn r#struct(&self) { | ^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/async-await/issue-65634-raw-ident-suggestion.rs b/tests/ui/async-await/issue-65634-raw-ident-suggestion.rs index ef5760f4846b7..98f5b6dd9f98e 100644 --- a/tests/ui/async-await/issue-65634-raw-ident-suggestion.rs +++ b/tests/ui/async-await/issue-65634-raw-ident-suggestion.rs @@ -1,4 +1,5 @@ //@ revisions: edition2015 edition2018 +//@[edition2015]edition:2015 //@[edition2018]edition:2018 #![allow(non_camel_case_types)] diff --git a/tests/ui/async-await/suggest-switching-edition-on-await-cargo.rs b/tests/ui/async-await/suggest-switching-edition-on-await-cargo.rs index bcb5cb94b77c8..555b011052158 100644 --- a/tests/ui/async-await/suggest-switching-edition-on-await-cargo.rs +++ b/tests/ui/async-await/suggest-switching-edition-on-await-cargo.rs @@ -1,3 +1,4 @@ +//@ edition:2015 //@ rustc-env:CARGO_CRATE_NAME=foo use std::pin::Pin; diff --git a/tests/ui/async-await/suggest-switching-edition-on-await-cargo.stderr b/tests/ui/async-await/suggest-switching-edition-on-await-cargo.stderr index 11f5825c232ea..c5f1793731ea4 100644 --- a/tests/ui/async-await/suggest-switching-edition-on-await-cargo.stderr +++ b/tests/ui/async-await/suggest-switching-edition-on-await-cargo.stderr @@ -1,5 +1,5 @@ error[E0609]: no field `await` on type `await_on_struct_missing::S` - --> $DIR/suggest-switching-edition-on-await-cargo.rs:11:7 + --> $DIR/suggest-switching-edition-on-await-cargo.rs:12:7 | LL | x.await; | ^^^^^ unknown field @@ -9,7 +9,7 @@ LL | x.await; = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `await_on_struct_similar::S` - --> $DIR/suggest-switching-edition-on-await-cargo.rs:24:7 + --> $DIR/suggest-switching-edition-on-await-cargo.rs:25:7 | LL | x.await; | ^^^^^ unknown field @@ -24,7 +24,7 @@ LL + x.awai; | error[E0609]: no field `await` on type `Pin<&mut dyn Future>` - --> $DIR/suggest-switching-edition-on-await-cargo.rs:34:7 + --> $DIR/suggest-switching-edition-on-await-cargo.rs:35:7 | LL | x.await; | ^^^^^ unknown field @@ -34,7 +34,7 @@ LL | x.await; = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `impl Future` - --> $DIR/suggest-switching-edition-on-await-cargo.rs:43:7 + --> $DIR/suggest-switching-edition-on-await-cargo.rs:44:7 | LL | x.await; | ^^^^^ unknown field diff --git a/tests/ui/async-await/suggest-switching-edition-on-await.rs b/tests/ui/async-await/suggest-switching-edition-on-await.rs index 0907a87e02cf3..6b639fa0b4ea5 100644 --- a/tests/ui/async-await/suggest-switching-edition-on-await.rs +++ b/tests/ui/async-await/suggest-switching-edition-on-await.rs @@ -1,3 +1,4 @@ +//@ edition:2015 use std::pin::Pin; use std::future::Future; diff --git a/tests/ui/async-await/suggest-switching-edition-on-await.stderr b/tests/ui/async-await/suggest-switching-edition-on-await.stderr index 2ede8d5b7f42e..bf03016222eaf 100644 --- a/tests/ui/async-await/suggest-switching-edition-on-await.stderr +++ b/tests/ui/async-await/suggest-switching-edition-on-await.stderr @@ -1,5 +1,5 @@ error[E0609]: no field `await` on type `await_on_struct_missing::S` - --> $DIR/suggest-switching-edition-on-await.rs:9:7 + --> $DIR/suggest-switching-edition-on-await.rs:10:7 | LL | x.await; | ^^^^^ unknown field @@ -9,7 +9,7 @@ LL | x.await; = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `await_on_struct_similar::S` - --> $DIR/suggest-switching-edition-on-await.rs:22:7 + --> $DIR/suggest-switching-edition-on-await.rs:23:7 | LL | x.await; | ^^^^^ unknown field @@ -24,7 +24,7 @@ LL + x.awai; | error[E0609]: no field `await` on type `Pin<&mut dyn Future>` - --> $DIR/suggest-switching-edition-on-await.rs:32:7 + --> $DIR/suggest-switching-edition-on-await.rs:33:7 | LL | x.await; | ^^^^^ unknown field @@ -34,7 +34,7 @@ LL | x.await; = note: for more on editions, read https://doc.rust-lang.org/edition-guide error[E0609]: no field `await` on type `impl Future` - --> $DIR/suggest-switching-edition-on-await.rs:41:7 + --> $DIR/suggest-switching-edition-on-await.rs:42:7 | LL | x.await; | ^^^^^ unknown field From c27aff35caad45093b52988994c2bc9b5631b544 Mon Sep 17 00:00:00 2001 From: Boxy Date: Mon, 26 May 2025 16:35:36 +0100 Subject: [PATCH 3/8] Add test --- .../copy-check-when-count-inferred-later.rs | 11 +++++++++++ .../copy-check-when-count-inferred-later.stderr | 14 ++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs create mode 100644 tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr diff --git a/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs new file mode 100644 index 0000000000000..b9d123cbefae6 --- /dev/null +++ b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.rs @@ -0,0 +1,11 @@ +#![feature(generic_arg_infer)] + +// Test that we enforce repeat expr element types are `Copy` even +// when the repeat count is only inferred at a later point in type +// checking. + +fn main() { + let a = [String::new(); _]; + //~^ ERROR: the trait bound `String: Copy` is not satisfied + let b: [_; 2] = a; +} diff --git a/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr new file mode 100644 index 0000000000000..d974f5add5052 --- /dev/null +++ b/tests/ui/repeat-expr/copy-check-when-count-inferred-later.stderr @@ -0,0 +1,14 @@ +error[E0277]: the trait bound `String: Copy` is not satisfied + --> $DIR/copy-check-when-count-inferred-later.rs:8:14 + | +LL | let a = [String::new(); _]; + | ^^^^^^^^^^^^^ + | | + | the trait `Copy` is not implemented for `String` + | help: create an inline `const` block: `const { String::new() }` + | + = note: the `Copy` trait is required because this value will be copied for each element of the array + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. From 0497f31122e0c5908bf68d83f3e8ba5b559ae3d6 Mon Sep 17 00:00:00 2001 From: Tshepang Mbambo Date: Mon, 26 May 2025 17:55:03 +0200 Subject: [PATCH 4/8] rustc book: fix erratic sentence by making it more simple --- src/doc/rustc/src/check-cfg/cargo-specifics.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/rustc/src/check-cfg/cargo-specifics.md b/src/doc/rustc/src/check-cfg/cargo-specifics.md index 371bbd26e943f..62a4dd1a3901d 100644 --- a/src/doc/rustc/src/check-cfg/cargo-specifics.md +++ b/src/doc/rustc/src/check-cfg/cargo-specifics.md @@ -9,8 +9,8 @@ rustc, not Cargo. --> This document is intended to summarize the principal ways Cargo interacts with -the `unexpected_cfgs` lint and `--check-cfg` flag. It is not intended to provide -individual details, for that refer to the [`--check-cfg` documentation](../check-cfg.md) and +the `unexpected_cfgs` lint and `--check-cfg` flag. +For individual details, refer to the [`--check-cfg` documentation](../check-cfg.md) and to the [Cargo book](../../cargo/index.html). > The full list of well known cfgs (aka builtins) can be found under [Checking conditional configurations / Well known names and values](../check-cfg.md#well-known-names-and-values). From 19802e8e9cf2732768c89dcfe1c5fa0eb88cd558 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 02:06:40 +1000 Subject: [PATCH 5/8] Remove an unnecessary use of `Box::into_inner`. --- compiler/rustc_errors/src/diagnostic.rs | 2 +- compiler/rustc_errors/src/lib.rs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 539ecfbb42e2c..a11f81b55bb84 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -1325,7 +1325,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { )); self.note("consider using `--verbose` to print the full type name to the console"); } - Box::into_inner(self.diag.take().unwrap()) + *self.diag.take().unwrap() } /// This method allows us to access the path of the file where "long types" are written to. diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index f8e19e5077893..bd421a441f95c 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -12,7 +12,6 @@ #![feature(array_windows)] #![feature(assert_matches)] #![feature(associated_type_defaults)] -#![feature(box_into_inner)] #![feature(box_patterns)] #![feature(default_field_values)] #![feature(error_reporter)] From 6a8663ae2602f3fdaf49a8f116b8a78ea3325f65 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 26 May 2025 12:01:43 -0700 Subject: [PATCH 6/8] Update mdbook to 0.4.51 This fixes a silly regression introduced in 0.4.50 that broke the search hotkey (https://github.com/rust-lang/rust/pull/141457). Changelog: https://github.com/rust-lang/mdBook/blob/master/CHANGELOG.md#mdbook-0451 --- src/tools/rustbook/Cargo.lock | 4 ++-- src/tools/rustbook/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/rustbook/Cargo.lock b/src/tools/rustbook/Cargo.lock index 5c862e9540075..07c5106331bf5 100644 --- a/src/tools/rustbook/Cargo.lock +++ b/src/tools/rustbook/Cargo.lock @@ -885,9 +885,9 @@ dependencies = [ [[package]] name = "mdbook" -version = "0.4.50" +version = "0.4.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f72bc08f096e1fb15cfc382babe218317c2897d2040f967c4db40d156ca28e21" +checksum = "a87e65420ab45ca9c1b8cdf698f95b710cc826d373fa550f0f7fad82beac9328" dependencies = [ "ammonia", "anyhow", diff --git a/src/tools/rustbook/Cargo.toml b/src/tools/rustbook/Cargo.toml index ee2ada5aa2b38..69c0cfaf5c99d 100644 --- a/src/tools/rustbook/Cargo.toml +++ b/src/tools/rustbook/Cargo.toml @@ -15,6 +15,6 @@ mdbook-i18n-helpers = "0.3.3" mdbook-spec = { path = "../../doc/reference/mdbook-spec" } [dependencies.mdbook] -version = "0.4.50" +version = "0.4.51" default-features = false features = ["search"] From c8ed2a74236816072c8361994dd92d21a87cc36c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 26 May 2025 18:13:54 -0300 Subject: [PATCH 7/8] Remove spastorino from vacations --- triagebot.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 9d7a0ef5aec0c..308e8db34384a 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1170,7 +1170,6 @@ contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" users_on_vacation = [ "fmease", "jyn514", - "spastorino", ] [[assign.warn_non_default_branch.exceptions]] From 7fe82632854ce64dd98044163b0e0e61be51fb04 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Tue, 27 May 2025 01:18:54 +0200 Subject: [PATCH 8/8] use custom types to clarify arguments to `emit_ptr_va_arg` --- compiler/rustc_codegen_llvm/src/va_arg.rs | 83 +++++++++++++++++------ 1 file changed, 61 insertions(+), 22 deletions(-) diff --git a/compiler/rustc_codegen_llvm/src/va_arg.rs b/compiler/rustc_codegen_llvm/src/va_arg.rs index c216f0f4a09d0..b91b6efed4522 100644 --- a/compiler/rustc_codegen_llvm/src/va_arg.rs +++ b/compiler/rustc_codegen_llvm/src/va_arg.rs @@ -63,14 +63,33 @@ fn emit_direct_ptr_va_arg<'ll, 'tcx>( } } +enum PassMode { + Direct, + Indirect, +} + +enum SlotSize { + Bytes8 = 8, + Bytes4 = 4, +} + +enum AllowHigherAlign { + No, + Yes, +} + fn emit_ptr_va_arg<'ll, 'tcx>( bx: &mut Builder<'_, 'll, 'tcx>, list: OperandRef<'tcx, &'ll Value>, target_ty: Ty<'tcx>, - indirect: bool, - slot_size: Align, - allow_higher_align: bool, + pass_mode: PassMode, + slot_size: SlotSize, + allow_higher_align: AllowHigherAlign, ) -> &'ll Value { + let indirect = matches!(pass_mode, PassMode::Indirect); + let allow_higher_align = matches!(allow_higher_align, AllowHigherAlign::Yes); + let slot_size = Align::from_bytes(slot_size as u64).unwrap(); + let layout = bx.cx.layout_of(target_ty); let (llty, size, align) = if indirect { ( @@ -179,8 +198,14 @@ fn emit_aapcs_va_arg<'ll, 'tcx>( // On Stack block bx.switch_to_block(on_stack); - let stack_value = - emit_ptr_va_arg(bx, list, target_ty, false, Align::from_bytes(8).unwrap(), true); + let stack_value = emit_ptr_va_arg( + bx, + list, + target_ty, + PassMode::Direct, + SlotSize::Bytes8, + AllowHigherAlign::Yes, + ); bx.br(end); bx.switch_to_block(end); @@ -386,29 +411,43 @@ pub(super) fn emit_va_arg<'ll, 'tcx>( // Determine the va_arg implementation to use. The LLVM va_arg instruction // is lacking in some instances, so we should only use it as a fallback. let target = &bx.cx.tcx.sess.target; - let arch = &bx.cx.tcx.sess.target.arch; - match &**arch { - // Windows x86 - "x86" if target.is_like_windows => { - emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), false) - } - // Generic x86 - "x86" => emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(4).unwrap(), true), - // Windows AArch64 - "aarch64" | "arm64ec" if target.is_like_windows => { - emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false) - } - // macOS / iOS AArch64 - "aarch64" if target.is_like_darwin => { - emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true) + + match &*target.arch { + "x86" => emit_ptr_va_arg( + bx, + addr, + target_ty, + PassMode::Direct, + SlotSize::Bytes4, + if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, + ), + "aarch64" | "arm64ec" if target.is_like_windows || target.is_like_darwin => { + emit_ptr_va_arg( + bx, + addr, + target_ty, + PassMode::Direct, + SlotSize::Bytes8, + if target.is_like_windows { AllowHigherAlign::No } else { AllowHigherAlign::Yes }, + ) } "aarch64" => emit_aapcs_va_arg(bx, addr, target_ty), "s390x" => emit_s390x_va_arg(bx, addr, target_ty), // Windows x86_64 "x86_64" if target.is_like_windows => { let target_ty_size = bx.cx.size_of(target_ty).bytes(); - let indirect: bool = target_ty_size > 8 || !target_ty_size.is_power_of_two(); - emit_ptr_va_arg(bx, addr, target_ty, indirect, Align::from_bytes(8).unwrap(), false) + emit_ptr_va_arg( + bx, + addr, + target_ty, + if target_ty_size > 8 || !target_ty_size.is_power_of_two() { + PassMode::Indirect + } else { + PassMode::Direct + }, + SlotSize::Bytes8, + AllowHigherAlign::No, + ) } "xtensa" => emit_xtensa_va_arg(bx, addr, target_ty), // For all other architecture/OS combinations fall back to using