]> git.lizzy.rs Git - rust.git/blob - src/librustc_typeck/check/intrinsic.rs
e7c7b5831d0fc97c20bf9c1fd3f681c7d25e80eb
[rust.git] / src / librustc_typeck / check / intrinsic.rs
1 // Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Type-checking for the rust-intrinsic and platform-intrinsic
12 //! intrinsics that the compiler exposes.
13
14 use astconv::AstConv;
15 use intrinsics;
16 use middle::def_id::DefId;
17 use middle::subst;
18 use middle::ty::FnSig;
19 use middle::ty::{self, Ty};
20 use middle::ty::fold::TypeFolder;
21 use {CrateCtxt, require_same_types};
22
23 use std::collections::{HashMap};
24 use syntax::abi;
25 use syntax::attr::AttrMetaMethods;
26 use syntax::codemap::Span;
27 use syntax::parse::token;
28
29 use rustc_front::hir;
30
31 fn equate_intrinsic_type<'a, 'tcx>(tcx: &ty::ctxt<'tcx>, it: &hir::ForeignItem,
32                                    n_tps: usize,
33                                    abi: abi::Abi,
34                                    inputs: Vec<ty::Ty<'tcx>>,
35                                    output: ty::FnOutput<'tcx>) {
36     let fty = tcx.mk_fn(None, tcx.mk_bare_fn(ty::BareFnTy {
37         unsafety: hir::Unsafety::Unsafe,
38         abi: abi,
39         sig: ty::Binder(FnSig {
40             inputs: inputs,
41             output: output,
42             variadic: false,
43         }),
44     }));
45     let i_ty = tcx.lookup_item_type(DefId::local(it.id));
46     let i_n_tps = i_ty.generics.types.len(subst::FnSpace);
47     if i_n_tps != n_tps {
48         span_err!(tcx.sess, it.span, E0094,
49             "intrinsic has wrong number of type \
50              parameters: found {}, expected {}",
51              i_n_tps, n_tps);
52     } else {
53         require_same_types(tcx,
54                            None,
55                            false,
56                            it.span,
57                            i_ty.ty,
58                            fty,
59                            || {
60                 format!("intrinsic has wrong type: expected `{}`",
61                          fty)
62             });
63     }
64 }
65
66 /// Remember to add all intrinsics here, in librustc_trans/trans/intrinsic.rs,
67 /// and in libcore/intrinsics.rs
68 pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &hir::ForeignItem) {
69     fn param<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, n: u32) -> Ty<'tcx> {
70         let name = token::intern(&format!("P{}", n));
71         ccx.tcx.mk_param(subst::FnSpace, n, name)
72     }
73
74     let tcx = ccx.tcx;
75     let name = it.ident.name.as_str();
76     let (n_tps, inputs, output) = if name.starts_with("atomic_") {
77         let split : Vec<&str> = name.split('_').collect();
78         assert!(split.len() >= 2, "Atomic intrinsic not correct format");
79
80         //We only care about the operation here
81         let (n_tps, inputs, output) = match split[1] {
82             "cxchg" => (1, vec!(tcx.mk_mut_ptr(param(ccx, 0)),
83                                 param(ccx, 0),
84                                 param(ccx, 0)),
85                         param(ccx, 0)),
86             "load" => (1, vec!(tcx.mk_imm_ptr(param(ccx, 0))),
87                        param(ccx, 0)),
88             "store" => (1, vec!(tcx.mk_mut_ptr(param(ccx, 0)), param(ccx, 0)),
89                         tcx.mk_nil()),
90
91             "xchg" | "xadd" | "xsub" | "and"  | "nand" | "or" | "xor" | "max" |
92             "min"  | "umax" | "umin" => {
93                 (1, vec!(tcx.mk_mut_ptr(param(ccx, 0)), param(ccx, 0)),
94                  param(ccx, 0))
95             }
96             "fence" | "singlethreadfence" => {
97                 (0, Vec::new(), tcx.mk_nil())
98             }
99             op => {
100                 span_err!(tcx.sess, it.span, E0092,
101                     "unrecognized atomic operation function: `{}`", op);
102                 return;
103             }
104         };
105         (n_tps, inputs, ty::FnConverging(output))
106     } else if &name[..] == "abort" || &name[..] == "unreachable" {
107         (0, Vec::new(), ty::FnDiverging)
108     } else {
109         let (n_tps, inputs, output) = match &name[..] {
110             "breakpoint" => (0, Vec::new(), tcx.mk_nil()),
111             "size_of" |
112             "pref_align_of" | "min_align_of" => (1, Vec::new(), ccx.tcx.types.usize),
113             "size_of_val" |  "min_align_of_val" => {
114                 (1, vec![
115                     tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
116                                                                   ty::BrAnon(0))),
117                                     param(ccx, 0))
118                  ], ccx.tcx.types.usize)
119             }
120             "init" | "init_dropped" => (1, Vec::new(), param(ccx, 0)),
121             "uninit" => (1, Vec::new(), param(ccx, 0)),
122             "forget" => (1, vec!( param(ccx, 0) ), tcx.mk_nil()),
123             "transmute" => (2, vec!( param(ccx, 0) ), param(ccx, 1)),
124             "move_val_init" => {
125                 (1,
126                  vec!(
127                     tcx.mk_mut_ptr(param(ccx, 0)),
128                     param(ccx, 0)
129                   ),
130                tcx.mk_nil())
131             }
132             "drop_in_place" => {
133                 (1, vec![tcx.mk_mut_ptr(param(ccx, 0))], tcx.mk_nil())
134             }
135             "needs_drop" => (1, Vec::new(), ccx.tcx.types.bool),
136
137             "type_name" => (1, Vec::new(), tcx.mk_static_str()),
138             "type_id" => (1, Vec::new(), ccx.tcx.types.u64),
139             "offset" | "arith_offset" => {
140               (1,
141                vec!(
142                   tcx.mk_ptr(ty::TypeAndMut {
143                       ty: param(ccx, 0),
144                       mutbl: hir::MutImmutable
145                   }),
146                   ccx.tcx.types.isize
147                ),
148                tcx.mk_ptr(ty::TypeAndMut {
149                    ty: param(ccx, 0),
150                    mutbl: hir::MutImmutable
151                }))
152             }
153             "copy" | "copy_nonoverlapping" => {
154               (1,
155                vec!(
156                   tcx.mk_ptr(ty::TypeAndMut {
157                       ty: param(ccx, 0),
158                       mutbl: hir::MutImmutable
159                   }),
160                   tcx.mk_ptr(ty::TypeAndMut {
161                       ty: param(ccx, 0),
162                       mutbl: hir::MutMutable
163                   }),
164                   tcx.types.usize,
165                ),
166                tcx.mk_nil())
167             }
168             "volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => {
169               (1,
170                vec!(
171                   tcx.mk_ptr(ty::TypeAndMut {
172                       ty: param(ccx, 0),
173                       mutbl: hir::MutMutable
174                   }),
175                   tcx.mk_ptr(ty::TypeAndMut {
176                       ty: param(ccx, 0),
177                       mutbl: hir::MutImmutable
178                   }),
179                   tcx.types.usize,
180                ),
181                tcx.mk_nil())
182             }
183             "write_bytes" | "volatile_set_memory" => {
184               (1,
185                vec!(
186                   tcx.mk_ptr(ty::TypeAndMut {
187                       ty: param(ccx, 0),
188                       mutbl: hir::MutMutable
189                   }),
190                   tcx.types.u8,
191                   tcx.types.usize,
192                ),
193                tcx.mk_nil())
194             }
195             "sqrtf32" => (0, vec!( tcx.types.f32 ), tcx.types.f32),
196             "sqrtf64" => (0, vec!( tcx.types.f64 ), tcx.types.f64),
197             "powif32" => {
198                (0,
199                 vec!( tcx.types.f32, tcx.types.i32 ),
200                 tcx.types.f32)
201             }
202             "powif64" => {
203                (0,
204                 vec!( tcx.types.f64, tcx.types.i32 ),
205                 tcx.types.f64)
206             }
207             "sinf32" => (0, vec!( tcx.types.f32 ), tcx.types.f32),
208             "sinf64" => (0, vec!( tcx.types.f64 ), tcx.types.f64),
209             "cosf32" => (0, vec!( tcx.types.f32 ), tcx.types.f32),
210             "cosf64" => (0, vec!( tcx.types.f64 ), tcx.types.f64),
211             "powf32" => {
212                (0,
213                 vec!( tcx.types.f32, tcx.types.f32 ),
214                 tcx.types.f32)
215             }
216             "powf64" => {
217                (0,
218                 vec!( tcx.types.f64, tcx.types.f64 ),
219                 tcx.types.f64)
220             }
221             "expf32"   => (0, vec!( tcx.types.f32 ), tcx.types.f32),
222             "expf64"   => (0, vec!( tcx.types.f64 ), tcx.types.f64),
223             "exp2f32"  => (0, vec!( tcx.types.f32 ), tcx.types.f32),
224             "exp2f64"  => (0, vec!( tcx.types.f64 ), tcx.types.f64),
225             "logf32"   => (0, vec!( tcx.types.f32 ), tcx.types.f32),
226             "logf64"   => (0, vec!( tcx.types.f64 ), tcx.types.f64),
227             "log10f32" => (0, vec!( tcx.types.f32 ), tcx.types.f32),
228             "log10f64" => (0, vec!( tcx.types.f64 ), tcx.types.f64),
229             "log2f32"  => (0, vec!( tcx.types.f32 ), tcx.types.f32),
230             "log2f64"  => (0, vec!( tcx.types.f64 ), tcx.types.f64),
231             "fmaf32" => {
232                 (0,
233                  vec!( tcx.types.f32, tcx.types.f32, tcx.types.f32 ),
234                  tcx.types.f32)
235             }
236             "fmaf64" => {
237                 (0,
238                  vec!( tcx.types.f64, tcx.types.f64, tcx.types.f64 ),
239                  tcx.types.f64)
240             }
241             "fabsf32"      => (0, vec!( tcx.types.f32 ), tcx.types.f32),
242             "fabsf64"      => (0, vec!( tcx.types.f64 ), tcx.types.f64),
243             "copysignf32"  => (0, vec!( tcx.types.f32, tcx.types.f32 ), tcx.types.f32),
244             "copysignf64"  => (0, vec!( tcx.types.f64, tcx.types.f64 ), tcx.types.f64),
245             "floorf32"     => (0, vec!( tcx.types.f32 ), tcx.types.f32),
246             "floorf64"     => (0, vec!( tcx.types.f64 ), tcx.types.f64),
247             "ceilf32"      => (0, vec!( tcx.types.f32 ), tcx.types.f32),
248             "ceilf64"      => (0, vec!( tcx.types.f64 ), tcx.types.f64),
249             "truncf32"     => (0, vec!( tcx.types.f32 ), tcx.types.f32),
250             "truncf64"     => (0, vec!( tcx.types.f64 ), tcx.types.f64),
251             "rintf32"      => (0, vec!( tcx.types.f32 ), tcx.types.f32),
252             "rintf64"      => (0, vec!( tcx.types.f64 ), tcx.types.f64),
253             "nearbyintf32" => (0, vec!( tcx.types.f32 ), tcx.types.f32),
254             "nearbyintf64" => (0, vec!( tcx.types.f64 ), tcx.types.f64),
255             "roundf32"     => (0, vec!( tcx.types.f32 ), tcx.types.f32),
256             "roundf64"     => (0, vec!( tcx.types.f64 ), tcx.types.f64),
257             "ctpop8"       => (0, vec!( tcx.types.u8  ), tcx.types.u8),
258             "ctpop16"      => (0, vec!( tcx.types.u16 ), tcx.types.u16),
259             "ctpop32"      => (0, vec!( tcx.types.u32 ), tcx.types.u32),
260             "ctpop64"      => (0, vec!( tcx.types.u64 ), tcx.types.u64),
261             "ctlz8"        => (0, vec!( tcx.types.u8  ), tcx.types.u8),
262             "ctlz16"       => (0, vec!( tcx.types.u16 ), tcx.types.u16),
263             "ctlz32"       => (0, vec!( tcx.types.u32 ), tcx.types.u32),
264             "ctlz64"       => (0, vec!( tcx.types.u64 ), tcx.types.u64),
265             "cttz8"        => (0, vec!( tcx.types.u8  ), tcx.types.u8),
266             "cttz16"       => (0, vec!( tcx.types.u16 ), tcx.types.u16),
267             "cttz32"       => (0, vec!( tcx.types.u32 ), tcx.types.u32),
268             "cttz64"       => (0, vec!( tcx.types.u64 ), tcx.types.u64),
269             "bswap16"      => (0, vec!( tcx.types.u16 ), tcx.types.u16),
270             "bswap32"      => (0, vec!( tcx.types.u32 ), tcx.types.u32),
271             "bswap64"      => (0, vec!( tcx.types.u64 ), tcx.types.u64),
272
273             "volatile_load" =>
274                 (1, vec!( tcx.mk_imm_ptr(param(ccx, 0)) ), param(ccx, 0)),
275             "volatile_store" =>
276                 (1, vec!( tcx.mk_mut_ptr(param(ccx, 0)), param(ccx, 0) ), tcx.mk_nil()),
277
278             "i8_add_with_overflow" | "i8_sub_with_overflow" | "i8_mul_with_overflow" =>
279                 (0, vec!(tcx.types.i8, tcx.types.i8),
280                 tcx.mk_tup(vec!(tcx.types.i8, tcx.types.bool))),
281
282             "i16_add_with_overflow" | "i16_sub_with_overflow" | "i16_mul_with_overflow" =>
283                 (0, vec!(tcx.types.i16, tcx.types.i16),
284                 tcx.mk_tup(vec!(tcx.types.i16, tcx.types.bool))),
285
286             "i32_add_with_overflow" | "i32_sub_with_overflow" | "i32_mul_with_overflow" =>
287                 (0, vec!(tcx.types.i32, tcx.types.i32),
288                 tcx.mk_tup(vec!(tcx.types.i32, tcx.types.bool))),
289
290             "i64_add_with_overflow" | "i64_sub_with_overflow" | "i64_mul_with_overflow" =>
291                 (0, vec!(tcx.types.i64, tcx.types.i64),
292                 tcx.mk_tup(vec!(tcx.types.i64, tcx.types.bool))),
293
294             "u8_add_with_overflow" | "u8_sub_with_overflow" | "u8_mul_with_overflow" =>
295                 (0, vec!(tcx.types.u8, tcx.types.u8),
296                 tcx.mk_tup(vec!(tcx.types.u8, tcx.types.bool))),
297
298             "u16_add_with_overflow" | "u16_sub_with_overflow" | "u16_mul_with_overflow" =>
299                 (0, vec!(tcx.types.u16, tcx.types.u16),
300                 tcx.mk_tup(vec!(tcx.types.u16, tcx.types.bool))),
301
302             "u32_add_with_overflow" | "u32_sub_with_overflow" | "u32_mul_with_overflow"=>
303                 (0, vec!(tcx.types.u32, tcx.types.u32),
304                 tcx.mk_tup(vec!(tcx.types.u32, tcx.types.bool))),
305
306             "u64_add_with_overflow" | "u64_sub_with_overflow"  | "u64_mul_with_overflow" =>
307                 (0, vec!(tcx.types.u64, tcx.types.u64),
308                 tcx.mk_tup(vec!(tcx.types.u64, tcx.types.bool))),
309
310             "unchecked_udiv" | "unchecked_sdiv" | "unchecked_urem" | "unchecked_srem" =>
311                 (1, vec![param(ccx, 0), param(ccx, 0)], param(ccx, 0)),
312
313             "overflowing_add" | "overflowing_sub" | "overflowing_mul" =>
314                 (1, vec![param(ccx, 0), param(ccx, 0)], param(ccx, 0)),
315
316             "return_address" => (0, vec![], tcx.mk_imm_ptr(tcx.types.u8)),
317
318             "assume" => (0, vec![tcx.types.bool], tcx.mk_nil()),
319
320             "discriminant_value" => (1, vec![
321                     tcx.mk_imm_ref(tcx.mk_region(ty::ReLateBound(ty::DebruijnIndex::new(1),
322                                                                   ty::BrAnon(0))),
323                                    param(ccx, 0))], tcx.types.u64),
324
325             "try" => {
326                 let mut_u8 = tcx.mk_mut_ptr(tcx.types.u8);
327                 let fn_ty = ty::BareFnTy {
328                     unsafety: hir::Unsafety::Normal,
329                     abi: abi::Rust,
330                     sig: ty::Binder(FnSig {
331                         inputs: vec![mut_u8],
332                         output: ty::FnOutput::FnConverging(tcx.mk_nil()),
333                         variadic: false,
334                     }),
335                 };
336                 let fn_ty = tcx.mk_bare_fn(fn_ty);
337                 (0, vec![tcx.mk_fn(None, fn_ty), mut_u8], mut_u8)
338             }
339
340             ref other => {
341                 span_err!(tcx.sess, it.span, E0093,
342                           "unrecognized intrinsic function: `{}`", *other);
343                 return;
344             }
345         };
346         (n_tps, inputs, ty::FnConverging(output))
347     };
348     equate_intrinsic_type(
349         tcx,
350         it,
351         n_tps,
352         abi::RustIntrinsic,
353         inputs,
354         output
355         )
356 }
357
358 /// Type-check `extern "platform-intrinsic" { ... }` functions.
359 pub fn check_platform_intrinsic_type(ccx: &CrateCtxt,
360                                      it: &hir::ForeignItem) {
361     let param = |n| {
362         let name = token::intern(&format!("P{}", n));
363         ccx.tcx.mk_param(subst::FnSpace, n, name)
364     };
365
366     let tcx = ccx.tcx;
367     let i_ty = tcx.lookup_item_type(DefId::local(it.id));
368     let i_n_tps = i_ty.generics.types.len(subst::FnSpace);
369     let name = it.ident.name.as_str();
370
371     let (n_tps, inputs, output) = match &*name {
372         "simd_eq" | "simd_ne" | "simd_lt" | "simd_le" | "simd_gt" | "simd_ge" => {
373             (2, vec![param(0), param(0)], param(1))
374         }
375         "simd_add" | "simd_sub" | "simd_mul" |
376         "simd_div" | "simd_shl" | "simd_shr" |
377         "simd_and" | "simd_or" | "simd_xor" => {
378             (1, vec![param(0), param(0)], param(0))
379         }
380         "simd_insert" => (2, vec![param(0), tcx.types.u32, param(1)], param(0)),
381         "simd_extract" => (2, vec![param(0), tcx.types.u32], param(1)),
382         "simd_cast" => (2, vec![param(0)], param(1)),
383         name if name.starts_with("simd_shuffle") => {
384             match name["simd_shuffle".len()..].parse() {
385                 Ok(n) => {
386                     let params = vec![param(0), param(0),
387                                       tcx.mk_ty(ty::TyArray(tcx.types.u32, n))];
388                     (2, params, param(1))
389                 }
390                 Err(_) => {
391                     span_err!(tcx.sess, it.span, E0439,
392                               "invalid `simd_shuffle`, needs length: `{}`", name);
393                     return
394                 }
395             }
396         }
397         _ => {
398             match intrinsics::Intrinsic::find(tcx, &name) {
399                 Some(intr) => {
400                     // this function is a platform specific intrinsic
401                     if i_n_tps != 0 {
402                         span_err!(tcx.sess, it.span, E0440,
403                                   "platform-specific intrinsic has wrong number of type \
404                                    parameters: found {}, expected 0",
405                                   i_n_tps);
406                         return
407                     }
408
409                     let mut structural_to_nomimal = HashMap::new();
410
411                     let sig = tcx.no_late_bound_regions(i_ty.ty.fn_sig()).unwrap();
412                     if intr.inputs.len() != sig.inputs.len() {
413                         span_err!(tcx.sess, it.span, E0444,
414                                   "platform-specific intrinsic has invalid number of \
415                                    arguments: found {}, expected {}",
416                                   intr.inputs.len(), sig.inputs.len());
417                         return
418                     }
419                     let input_pairs = intr.inputs.iter().zip(&sig.inputs);
420                     for (i, (expected_arg, arg)) in input_pairs.enumerate() {
421                         match_intrinsic_type_to_type(tcx, &format!("argument {}", i + 1), it.span,
422                                                      &mut structural_to_nomimal, expected_arg, arg);
423                     }
424                     match_intrinsic_type_to_type(tcx, "return value", it.span,
425                                                  &mut structural_to_nomimal,
426                                                  &intr.output, sig.output.unwrap());
427                     return
428                 }
429                 None => {
430                     span_err!(tcx.sess, it.span, E0441,
431                               "unrecognized platform-specific intrinsic function: `{}`", name);
432                     return;
433                 }
434             }
435         }
436     };
437
438     equate_intrinsic_type(
439         tcx,
440         it,
441         n_tps,
442         abi::PlatformIntrinsic,
443         inputs,
444         ty::FnConverging(output)
445         )
446 }
447
448 // walk the expected type and the actual type in lock step, checking they're
449 // the same, in a kinda-structural way, i.e. `Vector`s have to be simd structs with
450 // exactly the right element type
451 fn match_intrinsic_type_to_type<'tcx, 'a>(
452         tcx: &ty::ctxt<'tcx>,
453         position: &str,
454         span: Span,
455         structural_to_nominal: &mut HashMap<&'a intrinsics::Type, ty::Ty<'tcx>>,
456         expected: &'a intrinsics::Type, t: ty::Ty<'tcx>)
457 {
458     use intrinsics::Type::*;
459
460     let simple_error = |real: &str, expected: &str| {
461         span_err!(tcx.sess, span, E0442,
462                   "intrinsic {} has wrong type: found {}, expected {}",
463                   position, real, expected)
464     };
465
466     match *expected {
467         Void => match t.sty {
468             ty::TyTuple(ref v) if v.is_empty() => {},
469             _ => simple_error(&format!("`{}`", t), "()"),
470         },
471         // (The width we pass to LLVM doesn't concern the type checker.)
472         Integer(signed, bits, _llvm_width) => match (signed, bits, &t.sty) {
473             (true,  8,  &ty::TyInt(hir::IntTy::TyI8)) |
474             (false, 8,  &ty::TyUint(hir::UintTy::TyU8)) |
475             (true,  16, &ty::TyInt(hir::IntTy::TyI16)) |
476             (false, 16, &ty::TyUint(hir::UintTy::TyU16)) |
477             (true,  32, &ty::TyInt(hir::IntTy::TyI32)) |
478             (false, 32, &ty::TyUint(hir::UintTy::TyU32)) |
479             (true,  64, &ty::TyInt(hir::IntTy::TyI64)) |
480             (false, 64, &ty::TyUint(hir::UintTy::TyU64)) => {},
481             _ => simple_error(&format!("`{}`", t),
482                               &format!("`{}{n}`",
483                                        if signed {"i"} else {"u"},
484                                        n = bits)),
485         },
486         Float(bits) => match (bits, &t.sty) {
487             (32, &ty::TyFloat(hir::FloatTy::TyF32)) |
488             (64, &ty::TyFloat(hir::FloatTy::TyF64)) => {},
489             _ => simple_error(&format!("`{}`", t),
490                               &format!("`f{n}`", n = bits)),
491         },
492         Pointer(ref inner_expected, ref _llvm_type, const_) => {
493             match t.sty {
494                 ty::TyRawPtr(ty::TypeAndMut { ty, mutbl }) => {
495                     if (mutbl == hir::MutImmutable) != const_ {
496                         simple_error(&format!("`{}`", t),
497                                      if const_ {"const pointer"} else {"mut pointer"})
498                     }
499                     match_intrinsic_type_to_type(tcx, position, span, structural_to_nominal,
500                                                  inner_expected, ty)
501                 }
502                 _ => simple_error(&format!("`{}`", t),
503                                   &format!("raw pointer")),
504             }
505         }
506         Vector(ref inner_expected, ref _llvm_type, len) => {
507             if !t.is_simd() {
508                 simple_error(&format!("non-simd type `{}`", t),
509                              "simd type");
510                 return;
511             }
512             let t_len = t.simd_size(tcx);
513             if len as usize != t_len {
514                 simple_error(&format!("vector with length {}", t_len),
515                              &format!("length {}", len));
516                 return;
517             }
518             let t_ty = t.simd_type(tcx);
519             {
520                 // check that a given structural type always has the same an intrinsic definition
521                 let previous = structural_to_nominal.entry(expected).or_insert(t);
522                 if *previous != t {
523                     // this gets its own error code because it is non-trivial
524                     span_err!(tcx.sess, span, E0443,
525                               "intrinsic {} has wrong type: found `{}`, expected `{}` which \
526                                was used for this vector type previously in this signature",
527                               position,
528                               t,
529                               *previous);
530                     return;
531                 }
532             }
533             match_intrinsic_type_to_type(tcx,
534                                          position,
535                                          span,
536                                          structural_to_nominal,
537                                          inner_expected,
538                                          t_ty)
539         }
540         Aggregate(_flatten, ref expected_contents) => {
541             match t.sty {
542                 ty::TyTuple(ref contents) => {
543                     if contents.len() != expected_contents.len() {
544                         simple_error(&format!("tuple with length {}", contents.len()),
545                                      &format!("tuple with length {}", expected_contents.len()));
546                         return
547                     }
548                     for (e, c) in expected_contents.iter().zip(contents) {
549                         match_intrinsic_type_to_type(tcx, position, span, structural_to_nominal,
550                                                      e, c)
551                     }
552                 }
553                 _ => simple_error(&format!("`{}`", t),
554                                   &format!("tuple")),
555             }
556         }
557     }
558 }