]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_ast_lowering/expr.rs
Rollup merge of #68292 - matthiaskrgr:clone_on_copy, r=eddyb
[rust.git] / src / librustc_ast_lowering / expr.rs
index a3e2bc04bd5fbbe270f51875c6026e61aef20b5b..2866a1624de5b8686d3d326b1157f1285c34987a 100644 (file)
@@ -1,16 +1,16 @@
 use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
 
 use rustc::bug;
-use rustc::hir;
-use rustc::hir::def::Res;
 use rustc_data_structures::thin_vec::ThinVec;
 use rustc_error_codes::*;
+use rustc_errors::struct_span_err;
+use rustc_hir as hir;
+use rustc_hir::def::Res;
 use rustc_span::source_map::{respan, DesugaringKind, Span, Spanned};
 use rustc_span::symbol::{sym, Symbol};
 use syntax::ast::*;
 use syntax::attr;
 use syntax::ptr::P as AstP;
-use syntax::{span_err, struct_span_err};
 
 impl<'hir> LoweringContext<'_, 'hir> {
     fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
@@ -202,14 +202,19 @@ pub(super) fn lower_expr_mut(&mut self, e: &Expr) -> hir::Expr<'hir> {
             ExprKind::Mac(_) => panic!("Shouldn't exist here"),
         };
 
-        hir::Expr { hir_id: self.lower_node_id(e.id), kind, span: e.span, attrs: e.attrs.clone() }
+        hir::Expr {
+            hir_id: self.lower_node_id(e.id),
+            kind,
+            span: e.span,
+            attrs: e.attrs.iter().map(|a| self.lower_attr(a)).collect::<Vec<_>>().into(),
+        }
     }
 
     fn lower_unop(&mut self, u: UnOp) -> hir::UnOp {
         match u {
-            UnOp::Deref => hir::UnDeref,
-            UnOp::Not => hir::UnNot,
-            UnOp::Neg => hir::UnNeg,
+            UnOp::Deref => hir::UnOp::UnDeref,
+            UnOp::Not => hir::UnOp::UnNot,
+            UnOp::Neg => hir::UnOp::UnNeg,
         }
     }
 
@@ -517,7 +522,7 @@ pub(super) fn make_async_expr(
 
     /// Desugar `<expr>.await` into:
     /// ```rust
-    /// match ::std::future::IntoFuture::into_future(<expr>) {
+    /// match <expr> {
     ///     mut pinned => loop {
     ///         match ::std::future::poll_with_tls_context(unsafe {
     ///             <::std::pin::Pin>::new_unchecked(&mut pinned)
@@ -641,27 +646,11 @@ fn lower_expr_await(&mut self, await_span: Span, expr: &Expr) -> hir::ExprKind<'
         // mut pinned => loop { ... }
         let pinned_arm = self.arm(pinned_pat, loop_expr);
 
-        // `match ::std::future::IntoFuture::into_future(<expr>) { ... }`
-        let into_future_span = self.mark_span_with_reason(
-            DesugaringKind::Await,
-            await_span,
-            self.allow_into_future.clone(),
-        );
-        let expr = self.lower_expr_mut(expr);
-        let into_future_expr = self.expr_call_std_path(
-            into_future_span,
-            &[sym::future, sym::IntoFuture, sym::into_future],
-            arena_vec![self; expr],
-        );
-
-        // match <into_future_expr> {
+        // match <expr> {
         //     mut pinned => loop { .. }
         // }
-        hir::ExprKind::Match(
-            into_future_expr,
-            arena_vec![self; pinned_arm],
-            hir::MatchSource::AwaitDesugar,
-        )
+        let expr = self.lower_expr(expr);
+        hir::ExprKind::Match(expr, arena_vec![self; pinned_arm], hir::MatchSource::AwaitDesugar)
     }
 
     fn lower_expr_closure(
@@ -701,12 +690,13 @@ fn generator_movability_for_fn(
         match generator_kind {
             Some(hir::GeneratorKind::Gen) => {
                 if !decl.inputs.is_empty() {
-                    span_err!(
+                    struct_span_err!(
                         self.sess,
                         fn_decl_span,
                         E0628,
                         "generators cannot have explicit parameters"
-                    );
+                    )
+                    .emit();
                 }
                 Some(movability)
             }
@@ -715,7 +705,8 @@ fn generator_movability_for_fn(
             }
             None => {
                 if movability == Movability::Static {
-                    span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static");
+                    struct_span_err!(self.sess, fn_decl_span, E0697, "closures cannot be static")
+                        .emit();
                 }
                 None
             }
@@ -918,18 +909,18 @@ fn with_loop_condition_scope<T, F>(&mut self, f: F) -> T
 
     fn lower_expr_asm(&mut self, asm: &InlineAsm) -> hir::ExprKind<'hir> {
         let inner = hir::InlineAsmInner {
-            inputs: asm.inputs.iter().map(|&(ref c, _)| c.clone()).collect(),
+            inputs: asm.inputs.iter().map(|&(c, _)| c).collect(),
             outputs: asm
                 .outputs
                 .iter()
                 .map(|out| hir::InlineAsmOutput {
-                    constraint: out.constraint.clone(),
+                    constraint: out.constraint,
                     is_rw: out.is_rw,
                     is_indirect: out.is_indirect,
                     span: out.expr.span,
                 })
                 .collect(),
-            asm: asm.asm.clone(),
+            asm: asm.asm,
             asm_str_style: asm.asm_str_style,
             clobbers: asm.clobbers.clone().into(),
             volatile: asm.volatile,
@@ -962,7 +953,13 @@ fn lower_expr_yield(&mut self, span: Span, opt_expr: Option<&Expr>) -> hir::Expr
         match self.generator_kind {
             Some(hir::GeneratorKind::Gen) => {}
             Some(hir::GeneratorKind::Async(_)) => {
-                span_err!(self.sess, span, E0727, "`async` generators are not yet supported",);
+                struct_span_err!(
+                    self.sess,
+                    span,
+                    E0727,
+                    "`async` generators are not yet supported"
+                )
+                .emit();
                 return hir::ExprKind::Err;
             }
             None => self.generator_kind = Some(hir::GeneratorKind::Gen),
@@ -1390,7 +1387,7 @@ fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
                     stmts: &[],
                     expr: Some(expr),
                     hir_id,
-                    rules: hir::UnsafeBlock(hir::CompilerGenerated),
+                    rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
                     span,
                     targeted_by_break: false,
                 }),