Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7037eae

Browse files
committed
Auto merge of rust-lang#124258 - GuillaumeGomez:rollup-2d3albo, r=GuillaumeGomez
Rollup of 5 pull requests Successful merges: - rust-lang#104087 (Stabilise inline_const) - rust-lang#123792 (Require explicitly marking closures as coroutines) - rust-lang#124057 (Fix ICE when ADT tail has type error) - rust-lang#124178 ([cleanup] [llvm backend] Prevent creating the same `Instance::mono` multiple times) - rust-lang#124220 (Miri: detect wrong vtables in wide pointers) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7f2fc33 + 23e24c7 commit 7037eae

File tree

397 files changed

+1784
-1279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+1784
-1279
lines changed

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,6 @@ ast_lowering_underscore_expr_lhs_assign =
163163
.label = `_` not allowed here
164164
165165
ast_lowering_use_angle_brackets = use angle brackets instead
166+
ast_lowering_yield_in_closure =
167+
`yield` can only be used in `#[coroutine]` closures, or `gen` blocks
168+
.suggestion = use `#[coroutine]` to make this closure a coroutine

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,12 @@ pub(crate) struct NoPreciseCapturesOnApit {
421421
#[primary_span]
422422
pub span: Span,
423423
}
424+
425+
#[derive(Diagnostic)]
426+
#[diag(ast_lowering_yield_in_closure)]
427+
pub(crate) struct YieldInClosure {
428+
#[primary_span]
429+
pub span: Span,
430+
#[suggestion(code = "#[coroutine] ", applicability = "maybe-incorrect", style = "verbose")]
431+
pub suggestion: Option<Span>,
432+
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use super::errors::{
88
};
99
use super::ResolverAstLoweringExt;
1010
use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
11+
use crate::errors::YieldInClosure;
1112
use crate::{FnDeclKind, ImplTraitPosition};
1213
use rustc_ast::ptr::P as AstP;
1314
use rustc_ast::*;
@@ -217,6 +218,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
217218
binder,
218219
*capture_clause,
219220
e.id,
221+
hir_id,
220222
*constness,
221223
*movability,
222224
fn_decl,
@@ -955,6 +957,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
955957
binder: &ClosureBinder,
956958
capture_clause: CaptureBy,
957959
closure_id: NodeId,
960+
closure_hir_id: hir::HirId,
958961
constness: Const,
959962
movability: Movability,
960963
decl: &FnDecl,
@@ -965,8 +968,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
965968
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
966969

967970
let (body_id, closure_kind) = self.with_new_scopes(fn_decl_span, move |this| {
968-
let mut coroutine_kind = None;
971+
let mut coroutine_kind = if this
972+
.attrs
973+
.get(&closure_hir_id.local_id)
974+
.is_some_and(|attrs| attrs.iter().any(|attr| attr.has_name(sym::coroutine)))
975+
{
976+
Some(hir::CoroutineKind::Coroutine(Movability::Movable))
977+
} else {
978+
None
979+
};
969980
let body_id = this.lower_fn_body(decl, |this| {
981+
this.coroutine_kind = coroutine_kind;
970982
let e = this.lower_expr_mut(body);
971983
coroutine_kind = this.coroutine_kind;
972984
e
@@ -1565,7 +1577,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
15651577
)
15661578
.emit();
15671579
}
1580+
let suggestion = self.current_item.map(|s| s.shrink_to_lo());
1581+
self.dcx().emit_err(YieldInClosure { span, suggestion });
15681582
self.coroutine_kind = Some(hir::CoroutineKind::Coroutine(Movability::Movable));
1583+
15691584
false
15701585
}
15711586
};

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
203203
body,
204204
..
205205
}) => {
206-
self.with_new_scopes(ident.span, |this| {
206+
self.with_new_scopes(*fn_sig_span, |this| {
207207
// Note: we don't need to change the return type from `T` to
208208
// `impl Future<Output = T>` here because lower_body
209209
// only cares about the input argument patterns in the function

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
556556
half_open_range_patterns_in_slices,
557557
"half-open range patterns in slices are unstable"
558558
);
559-
gate_all!(inline_const, "inline-const is experimental");
560559
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
561560
gate_all!(associated_const_equality, "associated const equality is incomplete");
562561
gate_all!(yeet_expr, "`do yeet` expression is experimental");

compiler/rustc_codegen_cranelift/example/polymorphize_coroutine.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(coroutines, coroutine_trait)]
1+
#![feature(coroutines, coroutine_trait, stmt_expr_attributes)]
22

33
use std::ops::Coroutine;
44
use std::pin::Pin;
@@ -8,7 +8,8 @@ fn main() {
88
}
99

1010
fn run_coroutine<T>() {
11-
let mut coroutine = || {
11+
let mut coroutine = #[coroutine]
12+
|| {
1213
yield;
1314
return;
1415
};

compiler/rustc_codegen_cranelift/example/std_example.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(
22
core_intrinsics,
33
coroutines,
4+
stmt_expr_attributes,
45
coroutine_trait,
56
is_sorted,
67
repr_simd,
@@ -122,9 +123,12 @@ fn main() {
122123
test_simd();
123124
}
124125

125-
Box::pin(move |mut _task_context| {
126-
yield ();
127-
})
126+
Box::pin(
127+
#[coroutine]
128+
move |mut _task_context| {
129+
yield ();
130+
},
131+
)
128132
.as_mut()
129133
.resume(0);
130134

compiler/rustc_codegen_gcc/example/std_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(internal_features)]
2-
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted)]
2+
#![feature(core_intrinsics, coroutines, coroutine_trait, is_sorted, stmt_expr_attributes)]
33

44
#[cfg(feature="master")]
55
#[cfg(target_arch="x86_64")]
@@ -103,7 +103,7 @@ fn main() {
103103
test_simd();
104104
}
105105

106-
Box::pin(move |mut _task_context| {
106+
Box::pin(#[coroutine] move |mut _task_context| {
107107
yield ();
108108
}).as_mut().resume(0);
109109

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ impl<'ll> CodegenCx<'ll, '_> {
260260

261261
#[instrument(level = "debug", skip(self, llty))]
262262
pub(crate) fn get_static_inner(&self, def_id: DefId, llty: &'ll Type) -> &'ll Value {
263-
if let Some(&g) = self.instances.borrow().get(&Instance::mono(self.tcx, def_id)) {
263+
let instance = Instance::mono(self.tcx, def_id);
264+
if let Some(&g) = self.instances.borrow().get(&instance) {
264265
trace!("used cached value");
265266
return g;
266267
}
@@ -273,7 +274,7 @@ impl<'ll> CodegenCx<'ll, '_> {
273274
statics defined in the same CGU, but did not for `{def_id:?}`"
274275
);
275276

276-
let sym = self.tcx.symbol_name(Instance::mono(self.tcx, def_id)).name;
277+
let sym = self.tcx.symbol_name(instance).name;
277278
let fn_attrs = self.tcx.codegen_fn_attrs(def_id);
278279

279280
debug!(?sym, ?fn_attrs);
@@ -363,7 +364,7 @@ impl<'ll> CodegenCx<'ll, '_> {
363364
}
364365
}
365366

366-
self.instances.borrow_mut().insert(Instance::mono(self.tcx, def_id), g);
367+
self.instances.borrow_mut().insert(instance, g);
367368
g
368369
}
369370

compiler/rustc_const_eval/messages.ftl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ const_eval_double_storage_live =
8282
const_eval_dyn_call_not_a_method =
8383
`dyn` call trying to call something that is not a method
8484
85-
const_eval_dyn_call_vtable_mismatch =
86-
`dyn` call on a pointer whose vtable does not match its type
87-
88-
const_eval_dyn_star_call_vtable_mismatch =
89-
`dyn*` call on a pointer whose vtable does not match its type
90-
9185
const_eval_error = {$error_kind ->
9286
[static] could not evaluate static initializer
9387
[const] evaluation of constant value failed
@@ -192,6 +186,8 @@ const_eval_invalid_uninit_bytes_unknown =
192186
const_eval_invalid_vtable_pointer =
193187
using {$pointer} as vtable pointer but it does not point to a vtable
194188
189+
const_eval_invalid_vtable_trait =
190+
using vtable for trait `{$vtable_trait}` but trait `{$expected_trait}` was expected
195191
196192
const_eval_live_drop =
197193
destructor of `{$dropped_ty}` cannot be evaluated at compile-time
@@ -401,9 +397,6 @@ const_eval_unterminated_c_string =
401397
const_eval_unwind_past_top =
402398
unwinding past the topmost frame of the stack
403399
404-
const_eval_upcast_mismatch =
405-
upcast on a pointer whose vtable does not match its type
406-
407400
## The `front_matter`s here refer to either `const_eval_front_matter_invalid_value` or `const_eval_front_matter_invalid_value_with_path`.
408401
## (We'd love to sort this differently to make that more clear but tidy won't let us...)
409402
const_eval_validation_box_to_static = {$front_matter}: encountered a box pointing to a static variable in a constant
@@ -450,6 +443,7 @@ const_eval_validation_invalid_fn_ptr = {$front_matter}: encountered {$value}, bu
450443
const_eval_validation_invalid_ref_meta = {$front_matter}: encountered invalid reference metadata: total size is bigger than largest supported object
451444
const_eval_validation_invalid_ref_slice_meta = {$front_matter}: encountered invalid reference metadata: slice is bigger than largest supported object
452445
const_eval_validation_invalid_vtable_ptr = {$front_matter}: encountered {$value}, but expected a vtable pointer
446+
const_eval_validation_invalid_vtable_trait = {$front_matter}: wrong trait in wide pointer vtable: expected `{$ref_trait}`, but encountered `{$vtable_trait}`
453447
const_eval_validation_mutable_ref_to_immutable = {$front_matter}: encountered mutable reference or box pointing to read-only memory
454448
const_eval_validation_never_val = {$front_matter}: encountered a value of the never type `!`
455449
const_eval_validation_null_box = {$front_matter}: encountered a null box

0 commit comments

Comments
 (0)