]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/build/expr/as_place.rs
Use a struct for user type annotations
[rust.git] / src / librustc_mir / build / expr / as_place.rs
index cb3c88876a3a803b7d5a327c3bccd37db88f34ab..5429ce2a2e3dfe34214aff6804bc03d802722729 100644 (file)
@@ -1,13 +1,3 @@
-// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
 //! See docs in build/expr/mod.rs
 
 use build::expr::category::Category;
@@ -16,7 +6,7 @@
 use hair::*;
 use rustc::mir::interpret::EvalErrorKind::BoundsCheck;
 use rustc::mir::*;
-use rustc::ty::Variance;
+use rustc::ty::{CanonicalUserTypeAnnotation, Variance};
 
 use rustc_data_structures::indexed_vec::Idx;
 
@@ -143,6 +133,9 @@ fn expr_as_place(
             ExprKind::PlaceTypeAscription { source, user_ty } => {
                 let place = unpack!(block = this.as_place(block, source));
                 if let Some(user_ty) = user_ty {
+                    let annotation_index = this.canonical_user_type_annotations.push(
+                        CanonicalUserTypeAnnotation { span: source_info.span, user_ty }
+                    );
                     this.cfg.push(
                         block,
                         Statement {
@@ -150,7 +143,7 @@ fn expr_as_place(
                             kind: StatementKind::AscribeUserType(
                                 place.clone(),
                                 Variance::Invariant,
-                                box UserTypeProjection { base: user_ty, projs: vec![], },
+                                box UserTypeProjection { base: annotation_index, projs: vec![], },
                             ),
                         },
                     );
@@ -163,6 +156,9 @@ fn expr_as_place(
                     block = this.as_temp(block, source.temp_lifetime, source, mutability)
                 );
                 if let Some(user_ty) = user_ty {
+                    let annotation_index = this.canonical_user_type_annotations.push(
+                        CanonicalUserTypeAnnotation { span: source_info.span, user_ty }
+                    );
                     this.cfg.push(
                         block,
                         Statement {
@@ -170,7 +166,7 @@ fn expr_as_place(
                             kind: StatementKind::AscribeUserType(
                                 Place::Local(temp.clone()),
                                 Variance::Invariant,
-                                box UserTypeProjection { base: user_ty, projs: vec![], },
+                                box UserTypeProjection { base: annotation_index, projs: vec![], },
                             ),
                         },
                     );