Skip to content

Commit c03d978

Browse files
committed
Auto merge of rust-lang#119237 - compiler-errors:rollup-umyyu7d, r=compiler-errors
Rollup of 6 pull requests Successful merges: - rust-lang#119012 (Extract `layout_of_{struct,enum}` fn) - rust-lang#119077 (Separate MIR lints from validation) - rust-lang#119171 (Cleanup error handlers: round 4) - rust-lang#119198 (Split coroutine desugaring kind from source) - rust-lang#119222 (Add `IntoAsyncIterator`) - rust-lang#119230 (Exhaustiveness: clean up after librarification) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 495203b + 8c50e3e commit c03d978

File tree

140 files changed

+2027
-1880
lines changed

Some content is hidden

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

140 files changed

+2027
-1880
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4340,6 +4340,7 @@ dependencies = [
43404340
name = "rustc_pattern_analysis"
43414341
version = "0.0.0"
43424342
dependencies = [
4343+
"derivative",
43434344
"rustc_apfloat",
43444345
"rustc_arena",
43454346
"rustc_data_structures",

compiler/rustc_abi/src/layout.rs

+634-584
Large diffs are not rendered by default.

compiler/rustc_ast_lowering/src/expr.rs

+42-13
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
670670
let params = arena_vec![self; param];
671671

672672
let body = self.lower_body(move |this| {
673-
this.coroutine_kind = Some(hir::CoroutineKind::Async(async_coroutine_source));
673+
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
674+
hir::CoroutineDesugaring::Async,
675+
async_coroutine_source,
676+
));
674677

675678
let old_ctx = this.task_context;
676679
this.task_context = Some(task_context_hid);
@@ -724,7 +727,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
724727
});
725728

726729
let body = self.lower_body(move |this| {
727-
this.coroutine_kind = Some(hir::CoroutineKind::Gen(coroutine_source));
730+
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
731+
hir::CoroutineDesugaring::Gen,
732+
coroutine_source,
733+
));
728734

729735
let res = body(this);
730736
(&[], res)
@@ -802,7 +808,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
802808
let params = arena_vec![self; param];
803809

804810
let body = self.lower_body(move |this| {
805-
this.coroutine_kind = Some(hir::CoroutineKind::AsyncGen(async_coroutine_source));
811+
this.coroutine_kind = Some(hir::CoroutineKind::Desugared(
812+
hir::CoroutineDesugaring::AsyncGen,
813+
async_coroutine_source,
814+
));
806815

807816
let old_ctx = this.task_context;
808817
this.task_context = Some(task_context_hid);
@@ -888,9 +897,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
888897
let full_span = expr.span.to(await_kw_span);
889898

890899
let is_async_gen = match self.coroutine_kind {
891-
Some(hir::CoroutineKind::Async(_)) => false,
892-
Some(hir::CoroutineKind::AsyncGen(_)) => true,
893-
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
900+
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => false,
901+
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
902+
Some(hir::CoroutineKind::Coroutine)
903+
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
904+
| None => {
894905
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
895906
await_kw_span,
896907
item_span: self.current_item,
@@ -1123,9 +1134,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
11231134
Some(movability)
11241135
}
11251136
Some(
1126-
hir::CoroutineKind::Gen(_)
1127-
| hir::CoroutineKind::Async(_)
1128-
| hir::CoroutineKind::AsyncGen(_),
1137+
hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)
1138+
| hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)
1139+
| hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _),
11291140
) => {
11301141
panic!("non-`async`/`gen` closure body turned `async`/`gen` during lowering");
11311142
}
@@ -1638,9 +1649,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
16381649

16391650
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
16401651
let is_async_gen = match self.coroutine_kind {
1641-
Some(hir::CoroutineKind::Gen(_)) => false,
1642-
Some(hir::CoroutineKind::AsyncGen(_)) => true,
1643-
Some(hir::CoroutineKind::Async(_)) => {
1652+
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
1653+
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
1654+
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
16441655
return hir::ExprKind::Err(
16451656
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }),
16461657
);
@@ -1803,7 +1814,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
18031814
arena_vec![self; head],
18041815
)
18051816
}
1806-
ForLoopKind::ForAwait => self.arena.alloc(head),
1817+
// ` unsafe { Pin::new_unchecked(&mut into_async_iter(<head>)) }`
1818+
ForLoopKind::ForAwait => {
1819+
// `::core::async_iter::IntoAsyncIterator::into_async_iter(<head>)`
1820+
let iter = self.expr_call_lang_item_fn(
1821+
head_span,
1822+
hir::LangItem::IntoAsyncIterIntoIter,
1823+
arena_vec![self; head],
1824+
);
1825+
let iter = self.expr_mut_addr_of(head_span, iter);
1826+
// `Pin::new_unchecked(...)`
1827+
let iter = self.arena.alloc(self.expr_call_lang_item_fn_mut(
1828+
head_span,
1829+
hir::LangItem::PinNewUnchecked,
1830+
arena_vec![self; iter],
1831+
));
1832+
// `unsafe { ... }`
1833+
let iter = self.arena.alloc(self.expr_unsafe(iter));
1834+
iter
1835+
}
18071836
};
18081837

18091838
let match_expr = self.arena.alloc(self.expr_match(

compiler/rustc_borrowck/src/borrowck_errors.rs

+26-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_errors::{
2-
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan,
2+
struct_span_err, DiagnosticBuilder, DiagnosticId, DiagnosticMessage, MultiSpan,
33
};
44
use rustc_middle::ty::{self, Ty, TyCtxt};
55
use rustc_span::Span;
@@ -12,7 +12,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
1212
place: &str,
1313
borrow_place: &str,
1414
value_place: &str,
15-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
15+
) -> DiagnosticBuilder<'tcx> {
1616
self.infcx.tcx.sess.create_err(crate::session_diagnostics::MoveBorrow {
1717
place,
1818
span,
@@ -28,7 +28,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
2828
desc: &str,
2929
borrow_span: Span,
3030
borrow_desc: &str,
31-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
31+
) -> DiagnosticBuilder<'tcx> {
3232
let mut err = struct_span_err!(
3333
self,
3434
span,
@@ -50,7 +50,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
5050
old_loan_span: Span,
5151
old_opt_via: &str,
5252
old_load_end_span: Option<Span>,
53-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
53+
) -> DiagnosticBuilder<'tcx> {
5454
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
5555
let mut err = struct_span_err!(
5656
self,
@@ -97,7 +97,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
9797
desc: &str,
9898
old_loan_span: Span,
9999
old_load_end_span: Option<Span>,
100-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
100+
) -> DiagnosticBuilder<'tcx> {
101101
let mut err = struct_span_err!(
102102
self,
103103
new_loan_span,
@@ -130,7 +130,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
130130
noun_old: &str,
131131
old_opt_via: &str,
132132
previous_end_span: Option<Span>,
133-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
133+
) -> DiagnosticBuilder<'cx> {
134134
let mut err = struct_span_err!(
135135
self,
136136
new_loan_span,
@@ -162,7 +162,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
162162
old_opt_via: &str,
163163
previous_end_span: Option<Span>,
164164
second_borrow_desc: &str,
165-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
165+
) -> DiagnosticBuilder<'cx> {
166166
let mut err = struct_span_err!(
167167
self,
168168
new_loan_span,
@@ -194,7 +194,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
194194
kind_old: &str,
195195
msg_old: &str,
196196
old_load_end_span: Option<Span>,
197-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
197+
) -> DiagnosticBuilder<'cx> {
198198
let via = |msg: &str| if msg.is_empty() { "".to_string() } else { format!(" (via {msg})") };
199199
let mut err = struct_span_err!(
200200
self,
@@ -235,7 +235,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
235235
span: Span,
236236
borrow_span: Span,
237237
desc: &str,
238-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
238+
) -> DiagnosticBuilder<'cx> {
239239
let mut err = struct_span_err!(
240240
self,
241241
span,
@@ -254,24 +254,20 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
254254
span: Span,
255255
desc: &str,
256256
is_arg: bool,
257-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
257+
) -> DiagnosticBuilder<'cx> {
258258
let msg = if is_arg { "to immutable argument" } else { "twice to immutable variable" };
259259
struct_span_err!(self, span, E0384, "cannot assign {} {}", msg, desc)
260260
}
261261

262-
pub(crate) fn cannot_assign(
263-
&self,
264-
span: Span,
265-
desc: &str,
266-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
262+
pub(crate) fn cannot_assign(&self, span: Span, desc: &str) -> DiagnosticBuilder<'tcx> {
267263
struct_span_err!(self, span, E0594, "cannot assign to {}", desc)
268264
}
269265

270266
pub(crate) fn cannot_move_out_of(
271267
&self,
272268
move_from_span: Span,
273269
move_from_desc: &str,
274-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
270+
) -> DiagnosticBuilder<'cx> {
275271
struct_span_err!(self, move_from_span, E0507, "cannot move out of {}", move_from_desc)
276272
}
277273

@@ -283,7 +279,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
283279
move_from_span: Span,
284280
ty: Ty<'_>,
285281
is_index: Option<bool>,
286-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
282+
) -> DiagnosticBuilder<'cx> {
287283
let type_name = match (&ty.kind(), is_index) {
288284
(&ty::Array(_, _), Some(true)) | (&ty::Array(_, _), None) => "array",
289285
(&ty::Slice(_), _) => "slice",
@@ -305,7 +301,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
305301
&self,
306302
move_from_span: Span,
307303
container_ty: Ty<'_>,
308-
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
304+
) -> DiagnosticBuilder<'cx> {
309305
let mut err = struct_span_err!(
310306
self,
311307
move_from_span,
@@ -323,7 +319,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
323319
verb: &str,
324320
optional_adverb_for_moved: &str,
325321
moved_path: Option<String>,
326-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
322+
) -> DiagnosticBuilder<'tcx> {
327323
let moved_path = moved_path.map(|mp| format!(": `{mp}`")).unwrap_or_default();
328324

329325
struct_span_err!(
@@ -342,7 +338,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
342338
span: Span,
343339
path: &str,
344340
reason: &str,
345-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
341+
) -> DiagnosticBuilder<'tcx> {
346342
struct_span_err!(self, span, E0596, "cannot borrow {} as mutable{}", path, reason,)
347343
}
348344

@@ -353,7 +349,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
353349
immutable_place: &str,
354350
immutable_section: &str,
355351
action: &str,
356-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
352+
) -> DiagnosticBuilder<'tcx> {
357353
let mut err = struct_span_err!(
358354
self,
359355
mutate_span,
@@ -372,7 +368,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
372368
&self,
373369
span: Span,
374370
yield_span: Span,
375-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
371+
) -> DiagnosticBuilder<'tcx> {
376372
let coroutine_kind = self.body.coroutine.as_ref().unwrap().coroutine_kind;
377373
let mut err = struct_span_err!(
378374
self,
@@ -387,7 +383,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
387383
pub(crate) fn cannot_borrow_across_destructor(
388384
&self,
389385
borrow_span: Span,
390-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
386+
) -> DiagnosticBuilder<'tcx> {
391387
struct_span_err!(
392388
self,
393389
borrow_span,
@@ -400,7 +396,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
400396
&self,
401397
span: Span,
402398
path: &str,
403-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
399+
) -> DiagnosticBuilder<'tcx> {
404400
struct_span_err!(self, span, E0597, "{} does not live long enough", path,)
405401
}
406402

@@ -410,7 +406,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
410406
return_kind: &str,
411407
reference_desc: &str,
412408
path_desc: &str,
413-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
409+
) -> DiagnosticBuilder<'tcx> {
414410
let mut err = struct_span_err!(
415411
self,
416412
span,
@@ -436,7 +432,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
436432
borrowed_path: &str,
437433
capture_span: Span,
438434
scope: &str,
439-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
435+
) -> DiagnosticBuilder<'tcx> {
440436
let mut err = struct_span_err!(
441437
self,
442438
closure_span,
@@ -452,14 +448,14 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
452448
pub(crate) fn thread_local_value_does_not_live_long_enough(
453449
&self,
454450
span: Span,
455-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
451+
) -> DiagnosticBuilder<'tcx> {
456452
struct_span_err!(self, span, E0712, "thread-local variable borrowed past end of function",)
457453
}
458454

459455
pub(crate) fn temporary_value_borrowed_for_too_long(
460456
&self,
461457
span: Span,
462-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
458+
) -> DiagnosticBuilder<'tcx> {
463459
struct_span_err!(self, span, E0716, "temporary value dropped while borrowed",)
464460
}
465461

@@ -470,7 +466,7 @@ impl<'cx, 'tcx> crate::MirBorrowckCtxt<'cx, 'tcx> {
470466
sp: S,
471467
msg: impl Into<DiagnosticMessage>,
472468
code: DiagnosticId,
473-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
469+
) -> DiagnosticBuilder<'tcx> {
474470
self.infcx.tcx.sess.struct_span_err_with_code(sp, msg, code)
475471
}
476472
}
@@ -479,7 +475,7 @@ pub(crate) fn borrowed_data_escapes_closure<'tcx>(
479475
tcx: TyCtxt<'tcx>,
480476
escape_span: Span,
481477
escapes_from: &str,
482-
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
478+
) -> DiagnosticBuilder<'tcx> {
483479
struct_span_err!(
484480
tcx.sess,
485481
escape_span,

0 commit comments

Comments
 (0)