Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 41d97c8

Browse files
committedMar 5, 2024
Auto merge of #122012 - matthiaskrgr:rollup-bzqjj2n, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #121213 (Add an example to demonstrate how Rc::into_inner works) - #121262 (Add vector time complexity) - #121287 (Clarify/add `must_use` message for Rc/Arc/Weak::into_raw.) - #121664 (Adjust error `yield`/`await` lowering) - #121826 (Use root obligation on E0277 for some cases) - #121838 (Use the correct logic for nested impl trait in assoc types) - #121913 (Don't panic when waiting on poisoned queries) - #121987 (pattern analysis: abort on arity mismatch) - #121993 (Avoid using unnecessary queries when printing the query stack in panics) - #121997 (interpret/cast: make more matches on FloatTy properly exhaustive) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5a1e544 + 92ff43d commit 41d97c8

File tree

71 files changed

+435
-284
lines changed

Some content is hidden

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

71 files changed

+435
-284
lines changed
 

‎compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -760,10 +760,28 @@ impl<'hir> LoweringContext<'_, 'hir> {
760760
Some(hir::CoroutineKind::Coroutine(_))
761761
| Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _))
762762
| None => {
763-
return hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
764-
await_kw_span,
765-
item_span: self.current_item,
766-
}));
763+
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
764+
// is not accidentally orphaned.
765+
let stmt_id = self.next_id();
766+
let expr_err = self.expr(
767+
expr.span,
768+
hir::ExprKind::Err(self.dcx().emit_err(AwaitOnlyInAsyncFnAndBlocks {
769+
await_kw_span,
770+
item_span: self.current_item,
771+
})),
772+
);
773+
return hir::ExprKind::Block(
774+
self.block_all(
775+
expr.span,
776+
arena_vec![self; hir::Stmt {
777+
hir_id: stmt_id,
778+
kind: hir::StmtKind::Semi(expr),
779+
span: expr.span,
780+
}],
781+
Some(self.arena.alloc(expr_err)),
782+
),
783+
None,
784+
);
767785
}
768786
};
769787

@@ -1496,12 +1514,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
14961514
}
14971515

14981516
fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::ExprKind<'hir> {
1517+
let yielded =
1518+
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
1519+
14991520
let is_async_gen = match self.coroutine_kind {
15001521
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Gen, _)) => false,
15011522
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::AsyncGen, _)) => true,
15021523
Some(hir::CoroutineKind::Desugared(hir::CoroutineDesugaring::Async, _)) => {
1503-
return hir::ExprKind::Err(
1504-
self.dcx().emit_err(AsyncCoroutinesNotSupported { span }),
1524+
// Lower to a block `{ EXPR; <error> }` so that the awaited expr
1525+
// is not accidentally orphaned.
1526+
let stmt_id = self.next_id();
1527+
let expr_err = self.expr(
1528+
yielded.span,
1529+
hir::ExprKind::Err(self.dcx().emit_err(AsyncCoroutinesNotSupported { span })),
1530+
);
1531+
return hir::ExprKind::Block(
1532+
self.block_all(
1533+
yielded.span,
1534+
arena_vec![self; hir::Stmt {
1535+
hir_id: stmt_id,
1536+
kind: hir::StmtKind::Semi(yielded),
1537+
span: yielded.span,
1538+
}],
1539+
Some(self.arena.alloc(expr_err)),
1540+
),
1541+
None,
15051542
);
15061543
}
15071544
Some(hir::CoroutineKind::Coroutine(_)) => {
@@ -1531,9 +1568,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
15311568
}
15321569
};
15331570

1534-
let yielded =
1535-
opt_expr.as_ref().map(|x| self.lower_expr(x)).unwrap_or_else(|| self.expr_unit(span));
1536-
15371571
if is_async_gen {
15381572
// `yield $expr` is transformed into `task_context = yield async_gen_ready($expr)`.
15391573
// This ensures that we store our resumed `ResumeContext` correctly, and also that

‎compiler/rustc_const_eval/src/interpret/cast.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
182182
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
183183
use rustc_type_ir::TyKind::*;
184184

185-
let val = match src.layout.ty.kind() {
186-
// Floating point
187-
Float(FloatTy::F32) => self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
188-
Float(FloatTy::F64) => self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
189-
_ => {
190-
bug!("Can't cast 'Float' type into {}", cast_to.ty);
191-
}
185+
let Float(fty) = src.layout.ty.kind() else {
186+
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
187+
};
188+
let val = match fty {
189+
FloatTy::F16 => unimplemented!("f16_f128"),
190+
FloatTy::F32 => self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
191+
FloatTy::F64 => self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
192+
FloatTy::F128 => unimplemented!("f16_f128"),
192193
};
193194
Ok(ImmTy::from_scalar(val, cast_to))
194195
}
@@ -275,6 +276,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
275276
trace!("cast_from_scalar: {}, {} -> {}", v, src_layout.ty, cast_ty);
276277

277278
Ok(match *cast_ty.kind() {
279+
// int -> int
278280
Int(_) | Uint(_) => {
279281
let size = match *cast_ty.kind() {
280282
Int(t) => Integer::from_int_ty(self, t).size(),
@@ -285,15 +287,26 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
285287
Scalar::from_uint(v, size)
286288
}
287289

288-
Float(FloatTy::F32) if signed => Scalar::from_f32(Single::from_i128(v as i128).value),
289-
Float(FloatTy::F64) if signed => Scalar::from_f64(Double::from_i128(v as i128).value),
290-
Float(FloatTy::F32) => Scalar::from_f32(Single::from_u128(v).value),
291-
Float(FloatTy::F64) => Scalar::from_f64(Double::from_u128(v).value),
292-
293-
Char => {
294-
// `u8` to `char` cast
295-
Scalar::from_u32(u8::try_from(v).unwrap().into())
290+
// signed int -> float
291+
Float(fty) if signed => {
292+
let v = v as i128;
293+
match fty {
294+
FloatTy::F16 => unimplemented!("f16_f128"),
295+
FloatTy::F32 => Scalar::from_f32(Single::from_i128(v).value),
296+
FloatTy::F64 => Scalar::from_f64(Double::from_i128(v).value),
297+
FloatTy::F128 => unimplemented!("f16_f128"),
298+
}
296299
}
300+
// unsigned int -> float
301+
Float(fty) => match fty {
302+
FloatTy::F16 => unimplemented!("f16_f128"),
303+
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
304+
FloatTy::F64 => Scalar::from_f64(Double::from_u128(v).value),
305+
FloatTy::F128 => unimplemented!("f16_f128"),
306+
},
307+
308+
// u8 -> char
309+
Char => Scalar::from_u32(u8::try_from(v).unwrap().into()),
297310

298311
// Casts to bool are not permitted by rustc, no need to handle them here.
299312
_ => span_bug!(self.cur_span(), "invalid int to {} cast", cast_ty),
@@ -339,14 +352,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
339352
let v = f.to_i128(size.bits_usize()).value;
340353
Scalar::from_int(v, size)
341354
}
342-
// float -> f32
343-
Float(FloatTy::F32) => {
344-
Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value))
345-
}
346-
// float -> f64
347-
Float(FloatTy::F64) => {
348-
Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value))
349-
}
355+
// float -> float
356+
Float(fty) => match fty {
357+
FloatTy::F16 => unimplemented!("f16_f128"),
358+
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
359+
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
360+
FloatTy::F128 => unimplemented!("f16_f128"),
361+
},
350362
// That's it.
351363
_ => span_bug!(self.cur_span(), "invalid float to {} cast", dest_ty),
352364
}

0 commit comments

Comments
 (0)
Please sign in to comment.