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