Skip to content

Commit ec1f21c

Browse files
committed
Auto merge of rust-lang#118433 - matthiaskrgr:rollup-fi9lrwg, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#116839 (Implement thread parking for xous) - rust-lang#118265 (remove the memcpy-on-equal-ptrs assumption) - rust-lang#118269 (Unify `TraitRefs` and `PolyTraitRefs` in `ValuePairs`) - rust-lang#118394 (Remove HIR opkinds) - rust-lang#118398 (Add proper cfgs in std) - rust-lang#118419 (Eagerly return `ExprKind::Err` on `yield`/`await` in wrong coroutine context) - rust-lang#118422 (Fix coroutine validation for mixed panic strategy) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e9b7bf0 + e8d0c56 commit ec1f21c

File tree

39 files changed

+220
-325
lines changed

39 files changed

+220
-325
lines changed

Diff for: compiler/rustc_ast/src/ast.rs

+19-8
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ pub enum BorrowKind {
817817
Raw,
818818
}
819819

820-
#[derive(Clone, PartialEq, Encodable, Decodable, Debug, Copy)]
820+
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
821821
pub enum BinOpKind {
822822
/// The `+` operator (addition)
823823
Add,
@@ -858,9 +858,9 @@ pub enum BinOpKind {
858858
}
859859

860860
impl BinOpKind {
861-
pub fn to_string(&self) -> &'static str {
861+
pub fn as_str(&self) -> &'static str {
862862
use BinOpKind::*;
863-
match *self {
863+
match self {
864864
Add => "+",
865865
Sub => "-",
866866
Mul => "*",
@@ -881,27 +881,33 @@ impl BinOpKind {
881881
Gt => ">",
882882
}
883883
}
884-
pub fn lazy(&self) -> bool {
884+
885+
pub fn is_lazy(&self) -> bool {
885886
matches!(self, BinOpKind::And | BinOpKind::Or)
886887
}
887888

888889
pub fn is_comparison(&self) -> bool {
889890
use BinOpKind::*;
890-
// Note for developers: please keep this as is;
891+
// Note for developers: please keep this match exhaustive;
891892
// we want compilation to fail if another variant is added.
892893
match *self {
893894
Eq | Lt | Le | Ne | Gt | Ge => true,
894895
And | Or | Add | Sub | Mul | Div | Rem | BitXor | BitAnd | BitOr | Shl | Shr => false,
895896
}
896897
}
898+
899+
/// Returns `true` if the binary operator takes its arguments by value.
900+
pub fn is_by_value(self) -> bool {
901+
!self.is_comparison()
902+
}
897903
}
898904

899905
pub type BinOp = Spanned<BinOpKind>;
900906

901907
/// Unary operator.
902908
///
903909
/// Note that `&data` is not an operator, it's an `AddrOf` expression.
904-
#[derive(Clone, Encodable, Decodable, Debug, Copy)]
910+
#[derive(Clone, Copy, Debug, PartialEq, Encodable, Decodable, HashStable_Generic)]
905911
pub enum UnOp {
906912
/// The `*` operator for dereferencing
907913
Deref,
@@ -912,13 +918,18 @@ pub enum UnOp {
912918
}
913919

914920
impl UnOp {
915-
pub fn to_string(op: UnOp) -> &'static str {
916-
match op {
921+
pub fn as_str(&self) -> &'static str {
922+
match self {
917923
UnOp::Deref => "*",
918924
UnOp::Not => "!",
919925
UnOp::Neg => "-",
920926
}
921927
}
928+
929+
/// Returns `true` if the unary operator takes its argument by value.
930+
pub fn is_by_value(self) -> bool {
931+
matches!(self, Self::Neg | Self::Not)
932+
}
922933
}
923934

924935
/// A statement

Diff for: compiler/rustc_ast_lowering/src/expr.rs

+13-36
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
7272
let kind = match &e.kind {
7373
ExprKind::Array(exprs) => hir::ExprKind::Array(self.lower_exprs(exprs)),
7474
ExprKind::ConstBlock(c) => {
75-
let c = self.with_new_scopes(|this| hir::ConstBlock {
75+
let c = self.with_new_scopes(c.value.span, |this| hir::ConstBlock {
7676
def_id: this.local_def_id(c.id),
7777
hir_id: this.lower_node_id(c.id),
7878
body: this.lower_const_body(c.value.span, Some(&c.value)),
@@ -189,7 +189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
189189
None,
190190
e.span,
191191
hir::CoroutineSource::Block,
192-
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
192+
|this| this.with_new_scopes(e.span, |this| this.lower_block_expr(block)),
193193
),
194194
ExprKind::Await(expr, await_kw_span) => self.lower_expr_await(*await_kw_span, expr),
195195
ExprKind::Closure(box Closure {
@@ -323,7 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
323323
None,
324324
e.span,
325325
hir::CoroutineSource::Block,
326-
|this| this.with_new_scopes(|this| this.lower_block_expr(block)),
326+
|this| this.with_new_scopes(e.span, |this| this.lower_block_expr(block)),
327327
),
328328
ExprKind::Yield(opt_expr) => self.lower_expr_yield(e.span, opt_expr.as_deref()),
329329
ExprKind::Err => hir::ExprKind::Err(
@@ -350,30 +350,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
350350
}
351351
}
352352

353-
fn lower_binop(&mut self, b: BinOp) -> hir::BinOp {
354-
Spanned {
355-
node: match b.node {
356-
BinOpKind::Add => hir::BinOpKind::Add,
357-
BinOpKind::Sub => hir::BinOpKind::Sub,
358-
BinOpKind::Mul => hir::BinOpKind::Mul,
359-
BinOpKind::Div => hir::BinOpKind::Div,
360-
BinOpKind::Rem => hir::BinOpKind::Rem,
361-
BinOpKind::And => hir::BinOpKind::And,
362-
BinOpKind::Or => hir::BinOpKind::Or,
363-
BinOpKind::BitXor => hir::BinOpKind::BitXor,
364-
BinOpKind::BitAnd => hir::BinOpKind::BitAnd,
365-
BinOpKind::BitOr => hir::BinOpKind::BitOr,
366-
BinOpKind::Shl => hir::BinOpKind::Shl,
367-
BinOpKind::Shr => hir::BinOpKind::Shr,
368-
BinOpKind::Eq => hir::BinOpKind::Eq,
369-
BinOpKind::Lt => hir::BinOpKind::Lt,
370-
BinOpKind::Le => hir::BinOpKind::Le,
371-
BinOpKind::Ne => hir::BinOpKind::Ne,
372-
BinOpKind::Ge => hir::BinOpKind::Ge,
373-
BinOpKind::Gt => hir::BinOpKind::Gt,
374-
},
375-
span: self.lower_span(b.span),
376-
}
353+
fn lower_binop(&mut self, b: BinOp) -> BinOp {
354+
Spanned { node: b.node, span: self.lower_span(b.span) }
377355
}
378356

379357
fn lower_legacy_const_generics(
@@ -781,10 +759,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
781759
match self.coroutine_kind {
782760
Some(hir::CoroutineKind::Async(_)) => {}
783761
Some(hir::CoroutineKind::Coroutine) | Some(hir::CoroutineKind::Gen(_)) | None => {
784-
self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
762+
return hir::ExprKind::Err(self.tcx.sess.emit_err(AwaitOnlyInAsyncFnAndBlocks {
785763
await_kw_span,
786764
item_span: self.current_item,
787-
});
765+
}));
788766
}
789767
}
790768
let span = self.mark_span_with_reason(DesugaringKind::Await, await_kw_span, None);
@@ -944,9 +922,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
944922
) -> hir::ExprKind<'hir> {
945923
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
946924

947-
let (body_id, coroutine_option) = self.with_new_scopes(move |this| {
948-
let prev = this.current_item;
949-
this.current_item = Some(fn_decl_span);
925+
let (body_id, coroutine_option) = self.with_new_scopes(fn_decl_span, move |this| {
950926
let mut coroutine_kind = None;
951927
let body_id = this.lower_fn_body(decl, |this| {
952928
let e = this.lower_expr_mut(body);
@@ -955,7 +931,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
955931
});
956932
let coroutine_option =
957933
this.coroutine_movability_for_fn(decl, fn_decl_span, coroutine_kind, movability);
958-
this.current_item = prev;
959934
(body_id, coroutine_option)
960935
});
961936

@@ -1041,7 +1016,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10411016
let outer_decl =
10421017
FnDecl { inputs: decl.inputs.clone(), output: FnRetTy::Default(fn_decl_span) };
10431018

1044-
let body = self.with_new_scopes(|this| {
1019+
let body = self.with_new_scopes(fn_decl_span, |this| {
10451020
// FIXME(cramertj): allow `async` non-`move` closures with arguments.
10461021
if capture_clause == CaptureBy::Ref && !decl.inputs.is_empty() {
10471022
this.tcx.sess.emit_err(AsyncNonMoveClosureNotSupported { fn_decl_span });
@@ -1063,7 +1038,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10631038
async_ret_ty,
10641039
body.span,
10651040
hir::CoroutineSource::Closure,
1066-
|this| this.with_new_scopes(|this| this.lower_expr_mut(body)),
1041+
|this| this.with_new_scopes(fn_decl_span, |this| this.lower_expr_mut(body)),
10671042
);
10681043
let hir_id = this.lower_node_id(inner_closure_id);
10691044
this.maybe_forward_track_caller(body.span, closure_hir_id, hir_id);
@@ -1503,7 +1478,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
15031478
match self.coroutine_kind {
15041479
Some(hir::CoroutineKind::Gen(_)) => {}
15051480
Some(hir::CoroutineKind::Async(_)) => {
1506-
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span });
1481+
return hir::ExprKind::Err(
1482+
self.tcx.sess.emit_err(AsyncCoroutinesNotSupported { span }),
1483+
);
15071484
}
15081485
Some(hir::CoroutineKind::Coroutine) | None => {
15091486
if !self.tcx.features().coroutines {

Diff for: compiler/rustc_ast_lowering/src/item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
202202
body,
203203
..
204204
}) => {
205-
self.with_new_scopes(|this| {
206-
this.current_item = Some(ident.span);
207-
205+
self.with_new_scopes(ident.span, |this| {
208206
// Note: we don't need to change the return type from `T` to
209207
// `impl Future<Output = T>` here because lower_body
210208
// only cares about the input argument patterns in the function
@@ -837,7 +835,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
837835
},
838836
),
839837
AssocItemKind::Fn(box Fn { sig, generics, body, .. }) => {
840-
self.current_item = Some(i.span);
841838
let asyncness = sig.header.asyncness;
842839
let body_id = self.lower_maybe_async_body(
843840
i.span,

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
878878
result
879879
}
880880

881-
fn with_new_scopes<T>(&mut self, f: impl FnOnce(&mut Self) -> T) -> T {
881+
fn with_new_scopes<T>(&mut self, scope_span: Span, f: impl FnOnce(&mut Self) -> T) -> T {
882+
let current_item = self.current_item;
883+
self.current_item = Some(scope_span);
884+
882885
let was_in_loop_condition = self.is_in_loop_condition;
883886
self.is_in_loop_condition = false;
884887

@@ -890,6 +893,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
890893

891894
self.is_in_loop_condition = was_in_loop_condition;
892895

896+
self.current_item = current_item;
897+
893898
ret
894899
}
895900

@@ -1239,7 +1244,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12391244
tokens: None,
12401245
};
12411246

1242-
let ct = self.with_new_scopes(|this| hir::AnonConst {
1247+
let ct = self.with_new_scopes(span, |this| hir::AnonConst {
12431248
def_id,
12441249
hir_id: this.lower_node_id(node_id),
12451250
body: this.lower_const_body(path_expr.span, Some(&path_expr)),
@@ -2246,7 +2251,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22462251
}
22472252

22482253
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
2249-
self.with_new_scopes(|this| hir::AnonConst {
2254+
self.with_new_scopes(c.value.span, |this| hir::AnonConst {
22502255
def_id: this.local_def_id(c.id),
22512256
hir_id: this.lower_node_id(c.id),
22522257
body: this.lower_const_body(c.value.span, Some(&c.value)),

Diff for: compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -255,12 +255,12 @@ impl<'a> State<'a> {
255255

256256
self.print_expr_maybe_paren(lhs, left_prec);
257257
self.space();
258-
self.word_space(op.node.to_string());
258+
self.word_space(op.node.as_str());
259259
self.print_expr_maybe_paren(rhs, right_prec)
260260
}
261261

262262
fn print_expr_unary(&mut self, op: ast::UnOp, expr: &ast::Expr) {
263-
self.word(ast::UnOp::to_string(op));
263+
self.word(op.as_str());
264264
self.print_expr_maybe_paren(expr, parser::PREC_PREFIX)
265265
}
266266

@@ -470,7 +470,7 @@ impl<'a> State<'a> {
470470
let prec = AssocOp::Assign.precedence() as i8;
471471
self.print_expr_maybe_paren(lhs, prec + 1);
472472
self.space();
473-
self.word(op.node.to_string());
473+
self.word(op.node.as_str());
474474
self.word_space("=");
475475
self.print_expr_maybe_paren(rhs, prec);
476476
}

Diff for: compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -653,3 +653,4 @@ E0795: include_str!("./error_codes/E0795.md"),
653653
// E0721, // `await` keyword
654654
// E0723, // unstable feature in `const` context
655655
// E0738, // Removed; errored on `#[track_caller] fn`s in `extern "Rust" { ... }`.
656+
// E0744, // merged into E0728

Diff for: compiler/rustc_error_codes/src/error_codes/E0744.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
An unsupported expression was used inside a const context.
24

35
Erroneous code example:
46

5-
```compile_fail,edition2018,E0744
7+
```ignore (removed error code)
68
const _: i32 = {
79
async { 0 }.await
810
};

0 commit comments

Comments
 (0)