(index<- ) ./librustc/middle/ty.rs
git branch: * master 5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
modified: Fri May 9 13:02:28 2014
1 // Copyright 2012-2014 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 #![allow(non_camel_case_types)]
12
13 use back::svh::Svh;
14 use driver::session::Session;
15 use metadata::csearch;
16 use mc = middle::mem_categorization;
17 use middle::const_eval;
18 use middle::dependency_format;
19 use middle::lang_items::{ExchangeHeapLangItem, OpaqueStructLangItem};
20 use middle::lang_items::{TyDescStructLangItem, TyVisitorTraitLangItem};
21 use middle::freevars;
22 use middle::resolve;
23 use middle::resolve_lifetime;
24 use middle::ty;
25 use middle::subst::Subst;
26 use middle::typeck;
27 use middle::typeck::MethodCall;
28 use middle::ty_fold;
29 use middle::ty_fold::TypeFolder;
30 use middle;
31 use util::ppaux::{note_and_explain_region, bound_region_ptr_to_str};
32 use util::ppaux::{trait_store_to_str, ty_to_str};
33 use util::ppaux::{Repr, UserString};
34 use util::common::{indenter};
35 use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet, FnvHashMap};
36
37 use std::cast;
38 use std::cell::{Cell, RefCell};
39 use std::cmp;
40 use std::fmt::Show;
41 use std::fmt;
42 use std::hash::{Hash, sip};
43 use std::iter::AdditiveIterator;
44 use std::ops;
45 use std::rc::Rc;
46 use collections::{HashMap, HashSet};
47 use syntax::abi;
48 use syntax::ast::*;
49 use syntax::ast_util::{is_local, lit_is_str};
50 use syntax::ast_util;
51 use syntax::attr;
52 use syntax::attr::AttrMetaMethods;
53 use syntax::codemap::Span;
54 use syntax::parse::token;
55 use syntax::parse::token::InternedString;
56 use syntax::{ast, ast_map};
57 use syntax::owned_slice::OwnedSlice;
58 use syntax::util::small_vector::SmallVector;
59 use collections::enum_set::{EnumSet, CLike};
60
61 pub type Disr = u64;
62
63 pub static INITIAL_DISCRIMINANT_VALUE: Disr = 0;
64
65 // Data types
66
67 #[deriving(Eq, TotalEq, Hash)]
68 pub struct field {
69 pub ident: ast::Ident,
70 pub mt: mt
71 }
72
73 #[deriving(Clone)]
74 pub enum MethodContainer {
75 TraitContainer(ast::DefId),
76 ImplContainer(ast::DefId),
77 }
78
79 #[deriving(Clone)]
80 pub struct Method {
81 pub ident: ast::Ident,
82 pub generics: ty::Generics,
83 pub fty: BareFnTy,
84 pub explicit_self: ast::ExplicitSelf_,
85 pub vis: ast::Visibility,
86 pub def_id: ast::DefId,
87 pub container: MethodContainer,
88
89 // If this method is provided, we need to know where it came from
90 pub provided_source: Option<ast::DefId>
91 }
92
93 impl Method {
94 pub fn new(ident: ast::Ident,
95 generics: ty::Generics,
96 fty: BareFnTy,
97 explicit_self: ast::ExplicitSelf_,
98 vis: ast::Visibility,
99 def_id: ast::DefId,
100 container: MethodContainer,
101 provided_source: Option<ast::DefId>)
102 -> Method {
103 Method {
104 ident: ident,
105 generics: generics,
106 fty: fty,
107 explicit_self: explicit_self,
108 vis: vis,
109 def_id: def_id,
110 container: container,
111 provided_source: provided_source
112 }
113 }
114
115 pub fn container_id(&self) -> ast::DefId {
116 match self.container {
117 TraitContainer(id) => id,
118 ImplContainer(id) => id,
119 }
120 }
121 }
122
123 #[deriving(Clone, Eq, TotalEq, Hash)]
124 pub struct mt {
125 pub ty: t,
126 pub mutbl: ast::Mutability,
127 }
128
129 #[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)]
130 pub enum TraitStore {
131 /// Box<Trait>
132 UniqTraitStore,
133 /// &Trait and &mut Trait
134 RegionTraitStore(Region, ast::Mutability),
135 }
136
137 #[deriving(Clone)]
138 pub struct field_ty {
139 pub name: Name,
140 pub id: DefId,
141 pub vis: ast::Visibility,
142 pub origin: ast::DefId, // The DefId of the struct in which the field is declared.
143 }
144
145 // Contains information needed to resolve types and (in the future) look up
146 // the types of AST nodes.
147 #[deriving(Eq, TotalEq, Hash)]
148 pub struct creader_cache_key {
149 pub cnum: CrateNum,
150 pub pos: uint,
151 pub len: uint
152 }
153
154 pub type creader_cache = RefCell<HashMap<creader_cache_key, t>>;
155
156 pub struct intern_key {
157 sty: *sty,
158 }
159
160 // NB: Do not replace this with #[deriving(Eq)]. The automatically-derived
161 // implementation will not recurse through sty and you will get stack
162 // exhaustion.
163 impl cmp::Eq for intern_key {
164 fn eq(&self, other: &intern_key) -> bool {
165 unsafe {
166 *self.sty == *other.sty
167 }
168 }
169 fn ne(&self, other: &intern_key) -> bool {
170 !self.eq(other)
171 }
172 }
173
174 impl TotalEq for intern_key {}
175
176 impl<W:Writer> Hash<W> for intern_key {
177 fn hash(&self, s: &mut W) {
178 unsafe { (*self.sty).hash(s) }
179 }
180 }
181
182 pub enum ast_ty_to_ty_cache_entry {
183 atttce_unresolved, /* not resolved yet */
184 atttce_resolved(t) /* resolved to a type, irrespective of region */
185 }
186
187 #[deriving(Clone, Eq, Decodable, Encodable)]
188 pub struct ItemVariances {
189 pub self_param: Option<Variance>,
190 pub type_params: OwnedSlice<Variance>,
191 pub region_params: OwnedSlice<Variance>
192 }
193
194 #[deriving(Clone, Eq, Decodable, Encodable, Show)]
195 pub enum Variance {
196 Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
197 Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
198 Contravariant, // T<A> <: T<B> iff B <: A -- e.g., function param type
199 Bivariant, // T<A> <: T<B> -- e.g., unused type parameter
200 }
201
202 #[deriving(Clone)]
203 pub enum AutoAdjustment {
204 AutoAddEnv(ty::TraitStore),
205 AutoDerefRef(AutoDerefRef),
206 AutoObject(ty::TraitStore,
207 ty::BuiltinBounds,
208 ast::DefId, /* Trait ID */
209 ty::substs /* Trait substitutions */)
210 }
211
212 #[deriving(Clone, Decodable, Encodable)]
213 pub struct AutoDerefRef {
214 pub autoderefs: uint,
215 pub autoref: Option<AutoRef>
216 }
217
218 #[deriving(Clone, Decodable, Encodable, Eq, Show)]
219 pub enum AutoRef {
220 /// Convert from T to &T
221 AutoPtr(Region, ast::Mutability),
222
223 /// Convert from ~[]/&[] to &[] (or str)
224 AutoBorrowVec(Region, ast::Mutability),
225
226 /// Convert from ~[]/&[] to &&[] (or str)
227 AutoBorrowVecRef(Region, ast::Mutability),
228
229 /// Convert from T to *T
230 AutoUnsafe(ast::Mutability),
231
232 /// Convert from Box<Trait>/&Trait to &Trait
233 AutoBorrowObj(Region, ast::Mutability),
234 }
235
236 /// The data structure to keep track of all the information that typechecker
237 /// generates so that so that it can be reused and doesn't have to be redone
238 /// later on.
239 pub struct ctxt {
240 // Specifically use a speedy hash algorithm for this hash map, it's used
241 // quite often.
242 pub interner: RefCell<FnvHashMap<intern_key, Box<t_box_>>>,
243 pub next_id: Cell<uint>,
244 pub sess: Session,
245 pub def_map: resolve::DefMap,
246
247 pub named_region_map: resolve_lifetime::NamedRegionMap,
248
249 pub region_maps: middle::region::RegionMaps,
250
251 // Stores the types for various nodes in the AST. Note that this table
252 // is not guaranteed to be populated until after typeck. See
253 // typeck::check::fn_ctxt for details.
254 pub node_types: node_type_table,
255
256 // Stores the type parameters which were substituted to obtain the type
257 // of this node. This only applies to nodes that refer to entities
258 // parameterized by type parameters, such as generic fns, types, or
259 // other items.
260 pub node_type_substs: RefCell<NodeMap<Vec<t>>>,
261
262 // Maps from a method to the method "descriptor"
263 pub methods: RefCell<DefIdMap<Rc<Method>>>,
264
265 // Maps from a trait def-id to a list of the def-ids of its methods
266 pub trait_method_def_ids: RefCell<DefIdMap<Rc<Vec<DefId>>>>,
267
268 // A cache for the trait_methods() routine
269 pub trait_methods_cache: RefCell<DefIdMap<Rc<Vec<Rc<Method>>>>>,
270
271 pub impl_trait_cache: RefCell<DefIdMap<Option<Rc<ty::TraitRef>>>>,
272
273 pub trait_refs: RefCell<NodeMap<Rc<TraitRef>>>,
274 pub trait_defs: RefCell<DefIdMap<Rc<TraitDef>>>,
275
276 pub map: ast_map::Map,
277 pub intrinsic_defs: RefCell<DefIdMap<t>>,
278 pub freevars: RefCell<freevars::freevar_map>,
279 pub tcache: type_cache,
280 pub rcache: creader_cache,
281 pub short_names_cache: RefCell<HashMap<t, ~str>>,
282 pub needs_unwind_cleanup_cache: RefCell<HashMap<t, bool>>,
283 pub tc_cache: RefCell<HashMap<uint, TypeContents>>,
284 pub ast_ty_to_ty_cache: RefCell<NodeMap<ast_ty_to_ty_cache_entry>>,
285 pub enum_var_cache: RefCell<DefIdMap<Rc<Vec<Rc<VariantInfo>>>>>,
286 pub ty_param_defs: RefCell<NodeMap<TypeParameterDef>>,
287 pub adjustments: RefCell<NodeMap<AutoAdjustment>>,
288 pub normalized_cache: RefCell<HashMap<t, t>>,
289 pub lang_items: middle::lang_items::LanguageItems,
290 // A mapping of fake provided method def_ids to the default implementation
291 pub provided_method_sources: RefCell<DefIdMap<ast::DefId>>,
292 pub supertraits: RefCell<DefIdMap<Rc<Vec<Rc<TraitRef>>>>>,
293 pub superstructs: RefCell<DefIdMap<Option<ast::DefId>>>,
294 pub struct_fields: RefCell<DefIdMap<Rc<Vec<field_ty>>>>,
295
296 // Maps from def-id of a type or region parameter to its
297 // (inferred) variance.
298 pub item_variance_map: RefCell<DefIdMap<Rc<ItemVariances>>>,
299
300 // A mapping from the def ID of an enum or struct type to the def ID
301 // of the method that implements its destructor. If the type is not
302 // present in this map, it does not have a destructor. This map is
303 // populated during the coherence phase of typechecking.
304 pub destructor_for_type: RefCell<DefIdMap<ast::DefId>>,
305
306 // A method will be in this list if and only if it is a destructor.
307 pub destructors: RefCell<DefIdSet>,
308
309 // Maps a trait onto a list of impls of that trait.
310 pub trait_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
311
312 // Maps a DefId of a type to a list of its inherent impls.
313 // Contains implementations of methods that are inherent to a type.
314 // Methods in these implementations don't need to be exported.
315 pub inherent_impls: RefCell<DefIdMap<Rc<RefCell<Vec<ast::DefId>>>>>,
316
317 // Maps a DefId of an impl to a list of its methods.
318 // Note that this contains all of the impls that we know about,
319 // including ones in other crates. It's not clear that this is the best
320 // way to do it.
321 pub impl_methods: RefCell<DefIdMap<Vec<ast::DefId>>>,
322
323 // Set of used unsafe nodes (functions or blocks). Unsafe nodes not
324 // present in this set can be warned about.
325 pub used_unsafe: RefCell<NodeSet>,
326
327 // Set of nodes which mark locals as mutable which end up getting used at
328 // some point. Local variable definitions not in this set can be warned
329 // about.
330 pub used_mut_nodes: RefCell<NodeSet>,
331
332 // vtable resolution information for impl declarations
333 pub impl_vtables: typeck::impl_vtable_map,
334
335 // The set of external nominal types whose implementations have been read.
336 // This is used for lazy resolution of methods.
337 pub populated_external_types: RefCell<DefIdSet>,
338
339 // The set of external traits whose implementations have been read. This
340 // is used for lazy resolution of traits.
341 pub populated_external_traits: RefCell<DefIdSet>,
342
343 // Borrows
344 pub upvar_borrow_map: RefCell<UpvarBorrowMap>,
345
346 // These two caches are used by const_eval when decoding external statics
347 // and variants that are found.
348 pub extern_const_statics: RefCell<DefIdMap<Option<@ast::Expr>>>,
349 pub extern_const_variants: RefCell<DefIdMap<Option<@ast::Expr>>>,
350
351 pub method_map: typeck::MethodMap,
352 pub vtable_map: typeck::vtable_map,
353
354 pub dependency_formats: RefCell<dependency_format::Dependencies>,
355 }
356
357 pub enum tbox_flag {
358 has_params = 1,
359 has_self = 2,
360 needs_infer = 4,
361 has_regions = 8,
362 has_ty_err = 16,
363 has_ty_bot = 32,
364
365 // a meta-pub flag: subst may be required if the type has parameters, a self
366 // type, or references bound regions
367 needs_subst = 1 | 2 | 8
368 }
369
370 pub type t_box = &'static t_box_;
371
372 pub struct t_box_ {
373 pub sty: sty,
374 pub id: uint,
375 pub flags: uint,
376 }
377
378 // To reduce refcounting cost, we're representing types as unsafe pointers
379 // throughout the compiler. These are simply casted t_box values. Use ty::get
380 // to cast them back to a box. (Without the cast, compiler performance suffers
381 // ~15%.) This does mean that a t value relies on the ctxt to keep its box
382 // alive, and using ty::get is unsafe when the ctxt is no longer alive.
383 enum t_opaque {}
384
385 #[allow(raw_pointer_deriving)]
386 #[deriving(Clone, Eq, TotalEq, Hash)]
387 pub struct t { inner: *t_opaque }
388
389 impl fmt::Show for t {
390 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
391 f.buf.write_str("*t_opaque")
392 }
393 }
394
395 pub fn get(t: t) -> t_box {
396 unsafe {
397 let t2: t_box = cast::transmute(t);
398 t2
399 }
400 }
401
402 pub fn tbox_has_flag(tb: t_box, flag: tbox_flag) -> bool {
403 (tb.flags & (flag as uint)) != 0u
404 }
405 pub fn type_has_params(t: t) -> bool {
406 tbox_has_flag(get(t), has_params)
407 }
408 pub fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), has_self) }
409 pub fn type_needs_infer(t: t) -> bool {
410 tbox_has_flag(get(t), needs_infer)
411 }
412 pub fn type_id(t: t) -> uint { get(t).id }
413
414 #[deriving(Clone, Eq, TotalEq, Hash)]
415 pub struct BareFnTy {
416 pub fn_style: ast::FnStyle,
417 pub abi: abi::Abi,
418 pub sig: FnSig,
419 }
420
421 #[deriving(Clone, Eq, TotalEq, Hash)]
422 pub struct ClosureTy {
423 pub fn_style: ast::FnStyle,
424 pub onceness: ast::Onceness,
425 pub store: TraitStore,
426 pub bounds: BuiltinBounds,
427 pub sig: FnSig,
428 }
429
430 /**
431 * Signature of a function type, which I have arbitrarily
432 * decided to use to refer to the input/output types.
433 *
434 * - `binder_id` is the node id where this fn type appeared;
435 * it is used to identify all the bound regions appearing
436 * in the input/output types that are bound by this fn type
437 * (vs some enclosing or enclosed fn type)
438 * - `inputs` is the list of arguments and their modes.
439 * - `output` is the return type.
440 * - `variadic` indicates whether this is a varidic function. (only true for foreign fns)
441 */
442 #[deriving(Clone, Eq, TotalEq, Hash)]
443 pub struct FnSig {
444 pub binder_id: ast::NodeId,
445 pub inputs: Vec<t>,
446 pub output: t,
447 pub variadic: bool
448 }
449
450 #[deriving(Clone, Eq, TotalEq, Hash)]
451 pub struct param_ty {
452 pub idx: uint,
453 pub def_id: DefId
454 }
455
456 /// Representation of regions:
457 #[deriving(Clone, Eq, TotalEq, Hash, Encodable, Decodable, Show)]
458 pub enum Region {
459 // Region bound in a type or fn declaration which will be
460 // substituted 'early' -- that is, at the same time when type
461 // parameters are substituted.
462 ReEarlyBound(/* param id */ ast::NodeId, /*index*/ uint, ast::Name),
463
464 // Region bound in a function scope, which will be substituted when the
465 // function is called. The first argument must be the `binder_id` of
466 // some enclosing function signature.
467 ReLateBound(/* binder_id */ ast::NodeId, BoundRegion),
468
469 /// When checking a function body, the types of all arguments and so forth
470 /// that refer to bound region parameters are modified to refer to free
471 /// region parameters.
472 ReFree(FreeRegion),
473
474 /// A concrete region naming some expression within the current function.
475 ReScope(NodeId),
476
477 /// Static data that has an "infinite" lifetime. Top in the region lattice.
478 ReStatic,
479
480 /// A region variable. Should not exist after typeck.
481 ReInfer(InferRegion),
482
483 /// Empty lifetime is for data that is never accessed.
484 /// Bottom in the region lattice. We treat ReEmpty somewhat
485 /// specially; at least right now, we do not generate instances of
486 /// it during the GLB computations, but rather
487 /// generate an error instead. This is to improve error messages.
488 /// The only way to get an instance of ReEmpty is to have a region
489 /// variable with no constraints.
490 ReEmpty,
491 }
492
493 /**
494 * Upvars do not get their own node-id. Instead, we use the pair of
495 * the original var id (that is, the root variable that is referenced
496 * by the upvar) and the id of the closure expression.
497 */
498 #[deriving(Clone, Eq, TotalEq, Hash)]
499 pub struct UpvarId {
500 pub var_id: ast::NodeId,
501 pub closure_expr_id: ast::NodeId,
502 }
503
504 #[deriving(Clone, Eq, TotalEq, Hash, Show)]
505 pub enum BorrowKind {
506 /// Data must be immutable and is aliasable.
507 ImmBorrow,
508
509 /// Data must be immutable but not aliasable. This kind of borrow
510 /// cannot currently be expressed by the user and is used only in
511 /// implicit closure bindings. It is needed when you the closure
512 /// is borrowing or mutating a mutable referent, e.g.:
513 ///
514 /// let x: &mut int = ...;
515 /// let y = || *x += 5;
516 ///
517 /// If we were to try to translate this closure into a more explicit
518 /// form, we'd encounter an error with the code as written:
519 ///
520 /// struct Env { x: & &mut int }
521 /// let x: &mut int = ...;
522 /// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
523 /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
524 ///
525 /// This is then illegal because you cannot mutate a `&mut` found
526 /// in an aliasable location. To solve, you'd have to translate with
527 /// an `&mut` borrow:
528 ///
529 /// struct Env { x: & &mut int }
530 /// let x: &mut int = ...;
531 /// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
532 /// fn fn_ptr(env: &mut Env) { **env.x += 5; }
533 ///
534 /// Now the assignment to `**env.x` is legal, but creating a
535 /// mutable pointer to `x` is not because `x` is not mutable. We
536 /// could fix this by declaring `x` as `let mut x`. This is ok in
537 /// user code, if awkward, but extra weird for closures, since the
538 /// borrow is hidden.
539 ///
540 /// So we introduce a "unique imm" borrow -- the referent is
541 /// immutable, but not aliasable. This solves the problem. For
542 /// simplicity, we don't give users the way to express this
543 /// borrow, it's just used when translating closures.
544 UniqueImmBorrow,
545
546 /// Data is mutable and not aliasable.
547 MutBorrow
548 }
549
550 /**
551 * Information describing the borrowing of an upvar. This is computed
552 * during `typeck`, specifically by `regionck`. The general idea is
553 * that the compiler analyses treat closures like:
554 *
555 * let closure: &'e fn() = || {
556 * x = 1; // upvar x is assigned to
557 * use(y); // upvar y is read
558 * foo(&z); // upvar z is borrowed immutably
559 * };
560 *
561 * as if they were "desugared" to something loosely like:
562 *
563 * struct Vars<'x,'y,'z> { x: &'x mut int,
564 * y: &'y const int,
565 * z: &'z int }
566 * let closure: &'e fn() = {
567 * fn f(env: &Vars) {
568 * *env.x = 1;
569 * use(*env.y);
570 * foo(env.z);
571 * }
572 * let env: &'e mut Vars<'x,'y,'z> = &mut Vars { x: &'x mut x,
573 * y: &'y const y,
574 * z: &'z z };
575 * (env, f)
576 * };
577 *
578 * This is basically what happens at runtime. The closure is basically
579 * an existentially quantified version of the `(env, f)` pair.
580 *
581 * This data structure indicates the region and mutability of a single
582 * one of the `x...z` borrows.
583 *
584 * It may not be obvious why each borrowed variable gets its own
585 * lifetime (in the desugared version of the example, these are indicated
586 * by the lifetime parameters `'x`, `'y`, and `'z` in the `Vars` definition).
587 * Each such lifetime must encompass the lifetime `'e` of the closure itself,
588 * but need not be identical to it. The reason that this makes sense:
589 *
590 * - Callers are only permitted to invoke the closure, and hence to
591 * use the pointers, within the lifetime `'e`, so clearly `'e` must
592 * be a sublifetime of `'x...'z`.
593 * - The closure creator knows which upvars were borrowed by the closure
594 * and thus `x...z` will be reserved for `'x...'z` respectively.
595 * - Through mutation, the borrowed upvars can actually escape
596 * the closure, so sometimes it is necessary for them to be larger
597 * than the closure lifetime itself.
598 */
599 #[deriving(Eq, Clone)]
600 pub struct UpvarBorrow {
601 pub kind: BorrowKind,
602 pub region: ty::Region,
603 }
604
605 pub type UpvarBorrowMap = HashMap<UpvarId, UpvarBorrow>;
606
607 impl Region {
608 pub fn is_bound(&self) -> bool {
609 match self {
610 &ty::ReEarlyBound(..) => true,
611 &ty::ReLateBound(..) => true,
612 _ => false
613 }
614 }
615 }
616
617 #[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Hash, Encodable, Decodable, Show)]
618 pub struct FreeRegion {
619 pub scope_id: NodeId,
620 pub bound_region: BoundRegion
621 }
622
623 #[deriving(Clone, Eq, Ord, TotalEq, TotalOrd, Hash, Encodable, Decodable, Show)]
624 pub enum BoundRegion {
625 /// An anonymous region parameter for a given fn (&T)
626 BrAnon(uint),
627
628 /// Named region parameters for functions (a in &'a T)
629 ///
630 /// The def-id is needed to distinguish free regions in
631 /// the event of shadowing.
632 BrNamed(ast::DefId, ast::Name),
633
634 /// Fresh bound identifiers created during GLB computations.
635 BrFresh(uint),
636 }
637
638 /**
639 * Represents the values to use when substituting lifetime parameters.
640 * If the value is `ErasedRegions`, then this subst is occurring during
641 * trans, and all region parameters will be replaced with `ty::ReStatic`. */
642 #[deriving(Clone, Eq, TotalEq, Hash)]
643 pub enum RegionSubsts {
644 ErasedRegions,
645 NonerasedRegions(OwnedSlice<ty::Region>)
646 }
647
648 /**
649 * The type substs represents the kinds of things that can be substituted to
650 * convert a polytype into a monotype. Note however that substituting bound
651 * regions other than `self` is done through a different mechanism:
652 *
653 * - `tps` represents the type parameters in scope. They are indexed
654 * according to the order in which they were declared.
655 *
656 * - `self_r` indicates the region parameter `self` that is present on nominal
657 * types (enums, structs) declared as having a region parameter. `self_r`
658 * should always be none for types that are not region-parameterized and
659 * Some(_) for types that are. The only bound region parameter that should
660 * appear within a region-parameterized type is `self`.
661 *
662 * - `self_ty` is the type to which `self` should be remapped, if any. The
663 * `self` type is rather funny in that it can only appear on traits and is
664 * always substituted away to the implementing type for a trait. */
665 #[deriving(Clone, Eq, TotalEq, Hash)]
666 pub struct substs {
667 pub self_ty: Option<ty::t>,
668 pub tps: Vec<t>,
669 pub regions: RegionSubsts,
670 }
671
672 mod primitives {
673 use super::t_box_;
674
675 use syntax::ast;
676
677 macro_rules! def_prim_ty(
678 ($name:ident, $sty:expr, $id:expr) => (
679 pub static $name: t_box_ = t_box_ {
680 sty: $sty,
681 id: $id,
682 flags: 0,
683 };
684 )
685 )
686
687 def_prim_ty!(TY_NIL, super::ty_nil, 0)
688 def_prim_ty!(TY_BOOL, super::ty_bool, 1)
689 def_prim_ty!(TY_CHAR, super::ty_char, 2)
690 def_prim_ty!(TY_INT, super::ty_int(ast::TyI), 3)
691 def_prim_ty!(TY_I8, super::ty_int(ast::TyI8), 4)
692 def_prim_ty!(TY_I16, super::ty_int(ast::TyI16), 5)
693 def_prim_ty!(TY_I32, super::ty_int(ast::TyI32), 6)
694 def_prim_ty!(TY_I64, super::ty_int(ast::TyI64), 7)
695 def_prim_ty!(TY_UINT, super::ty_uint(ast::TyU), 8)
696 def_prim_ty!(TY_U8, super::ty_uint(ast::TyU8), 9)
697 def_prim_ty!(TY_U16, super::ty_uint(ast::TyU16), 10)
698 def_prim_ty!(TY_U32, super::ty_uint(ast::TyU32), 11)
699 def_prim_ty!(TY_U64, super::ty_uint(ast::TyU64), 12)
700 def_prim_ty!(TY_F32, super::ty_float(ast::TyF32), 14)
701 def_prim_ty!(TY_F64, super::ty_float(ast::TyF64), 15)
702 def_prim_ty!(TY_F128, super::ty_float(ast::TyF128), 16)
703
704 pub static TY_BOT: t_box_ = t_box_ {
705 sty: super::ty_bot,
706 id: 16,
707 flags: super::has_ty_bot as uint,
708 };
709
710 pub static TY_ERR: t_box_ = t_box_ {
711 sty: super::ty_err,
712 id: 17,
713 flags: super::has_ty_err as uint,
714 };
715
716 pub static LAST_PRIMITIVE_ID: uint = 18;
717 }
718
719 // NB: If you change this, you'll probably want to change the corresponding
720 // AST structure in libsyntax/ast.rs as well.
721 #[deriving(Clone, Eq, TotalEq, Hash)]
722 pub enum sty {
723 ty_nil,
724 ty_bot,
725 ty_bool,
726 ty_char,
727 ty_int(ast::IntTy),
728 ty_uint(ast::UintTy),
729 ty_float(ast::FloatTy),
730 ty_enum(DefId, substs),
731 ty_box(t),
732 ty_uniq(t),
733 ty_str,
734 ty_vec(mt, Option<uint>), // Second field is length.
735 ty_ptr(mt),
736 ty_rptr(Region, mt),
737 ty_bare_fn(BareFnTy),
738 ty_closure(Box<ClosureTy>),
739 ty_trait(Box<TyTrait>),
740 ty_struct(DefId, substs),
741 ty_tup(Vec<t>),
742
743 ty_param(param_ty), // type parameter
744 ty_self(DefId), /* special, implicit `self` type parameter;
745 * def_id is the id of the trait */
746
747 ty_infer(InferTy), // something used only during inference/typeck
748 ty_err, // Also only used during inference/typeck, to represent
749 // the type of an erroneous expression (helps cut down
750 // on non-useful type error messages)
751 }
752
753 #[deriving(Clone, Eq, TotalEq, Hash)]
754 pub struct TyTrait {
755 pub def_id: DefId,
756 pub substs: substs,
757 pub store: TraitStore,
758 pub bounds: BuiltinBounds
759 }
760
761 #[deriving(Eq, TotalEq, Hash)]
762 pub struct TraitRef {
763 pub def_id: DefId,
764 pub substs: substs
765 }
766
767 #[deriving(Clone, Eq)]
768 pub enum IntVarValue {
769 IntType(ast::IntTy),
770 UintType(ast::UintTy),
771 }
772
773 #[deriving(Clone, Show)]
774 pub enum terr_vstore_kind {
775 terr_vec,
776 terr_str,
777 terr_fn,
778 terr_trait
779 }
780
781 #[deriving(Clone, Show)]
782 pub struct expected_found<T> {
783 pub expected: T,
784 pub found: T
785 }
786
787 // Data structures used in type unification
788 #[deriving(Clone, Show)]
789 pub enum type_err {
790 terr_mismatch,
791 terr_fn_style_mismatch(expected_found<FnStyle>),
792 terr_onceness_mismatch(expected_found<Onceness>),
793 terr_abi_mismatch(expected_found<abi::Abi>),
794 terr_mutability,
795 terr_sigil_mismatch(expected_found<TraitStore>),
796 terr_box_mutability,
797 terr_ptr_mutability,
798 terr_ref_mutability,
799 terr_vec_mutability,
800 terr_tuple_size(expected_found<uint>),
801 terr_ty_param_size(expected_found<uint>),
802 terr_record_size(expected_found<uint>),
803 terr_record_mutability,
804 terr_record_fields(expected_found<Ident>),
805 terr_arg_count,
806 terr_regions_does_not_outlive(Region, Region),
807 terr_regions_not_same(Region, Region),
808 terr_regions_no_overlap(Region, Region),
809 terr_regions_insufficiently_polymorphic(BoundRegion, Region),
810 terr_regions_overly_polymorphic(BoundRegion, Region),
811 terr_trait_stores_differ(terr_vstore_kind, expected_found<TraitStore>),
812 terr_sorts(expected_found<t>),
813 terr_integer_as_char,
814 terr_int_mismatch(expected_found<IntVarValue>),
815 terr_float_mismatch(expected_found<ast::FloatTy>),
816 terr_traits(expected_found<ast::DefId>),
817 terr_builtin_bounds(expected_found<BuiltinBounds>),
818 terr_variadic_mismatch(expected_found<bool>)
819 }
820
821 #[deriving(Eq, TotalEq, Hash)]
822 pub struct ParamBounds {
823 pub builtin_bounds: BuiltinBounds,
824 pub trait_bounds: Vec<Rc<TraitRef>>
825 }
826
827 pub type BuiltinBounds = EnumSet<BuiltinBound>;
828
829 #[deriving(Clone, Encodable, Eq, TotalEq, Decodable, Hash, Show)]
830 #[repr(uint)]
831 pub enum BuiltinBound {
832 BoundStatic,
833 BoundSend,
834 BoundSized,
835 BoundCopy,
836 BoundShare,
837 }
838
839 pub fn EmptyBuiltinBounds() -> BuiltinBounds {
840 EnumSet::empty()
841 }
842
843 pub fn AllBuiltinBounds() -> BuiltinBounds {
844 let mut set = EnumSet::empty();
845 set.add(BoundStatic);
846 set.add(BoundSend);
847 set.add(BoundSized);
848 set.add(BoundShare);
849 set
850 }
851
852 impl CLike for BuiltinBound {
853 fn to_uint(&self) -> uint {
854 *self as uint
855 }
856 fn from_uint(v: uint) -> BuiltinBound {
857 unsafe { cast::transmute(v) }
858 }
859 }
860
861 #[deriving(Clone, Eq, TotalEq, Hash)]
862 pub struct TyVid(pub uint);
863
864 #[deriving(Clone, Eq, TotalEq, Hash)]
865 pub struct IntVid(pub uint);
866
867 #[deriving(Clone, Eq, TotalEq, Hash)]
868 pub struct FloatVid(pub uint);
869
870 #[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
871 pub struct RegionVid {
872 pub id: uint
873 }
874
875 #[deriving(Clone, Eq, TotalEq, Hash)]
876 pub enum InferTy {
877 TyVar(TyVid),
878 IntVar(IntVid),
879 FloatVar(FloatVid)
880 }
881
882 #[deriving(Clone, Encodable, Decodable, TotalEq, Hash, Show)]
883 pub enum InferRegion {
884 ReVar(RegionVid),
885 ReSkolemized(uint, BoundRegion)
886 }
887
888 impl cmp::Eq for InferRegion {
889 fn eq(&self, other: &InferRegion) -> bool {
890 match ((*self), *other) {
891 (ReVar(rva), ReVar(rvb)) => {
892 rva == rvb
893 }
894 (ReSkolemized(rva, _), ReSkolemized(rvb, _)) => {
895 rva == rvb
896 }
897 _ => false
898 }
899 }
900 fn ne(&self, other: &InferRegion) -> bool {
901 !((*self) == (*other))
902 }
903 }
904
905 pub trait Vid {
906 fn to_uint(&self) -> uint;
907 }
908
909 impl Vid for TyVid {
910 fn to_uint(&self) -> uint { let TyVid(v) = *self; v }
911 }
912
913 impl fmt::Show for TyVid {
914 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
915 write!(f.buf, "<generic \\#{}>", self.to_uint())
916 }
917 }
918
919 impl Vid for IntVid {
920 fn to_uint(&self) -> uint { let IntVid(v) = *self; v }
921 }
922
923 impl fmt::Show for IntVid {
924 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
925 write!(f.buf, "<generic integer \\#{}>", self.to_uint())
926 }
927 }
928
929 impl Vid for FloatVid {
930 fn to_uint(&self) -> uint { let FloatVid(v) = *self; v }
931 }
932
933 impl fmt::Show for FloatVid {
934 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
935 write!(f.buf, "<generic float \\#{}>", self.to_uint())
936 }
937 }
938
939 impl Vid for RegionVid {
940 fn to_uint(&self) -> uint { self.id }
941 }
942
943 impl fmt::Show for RegionVid {
944 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
945 self.id.fmt(f)
946 }
947 }
948
949 impl fmt::Show for FnSig {
950 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
951 // grr, without tcx not much we can do.
952 write!(f.buf, "(...)")
953 }
954 }
955
956 impl fmt::Show for InferTy {
957 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
958 match *self {
959 TyVar(ref v) => v.fmt(f),
960 IntVar(ref v) => v.fmt(f),
961 FloatVar(ref v) => v.fmt(f),
962 }
963 }
964 }
965
966 impl fmt::Show for IntVarValue {
967 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
968 match *self {
969 IntType(ref v) => v.fmt(f),
970 UintType(ref v) => v.fmt(f),
971 }
972 }
973 }
974
975 #[deriving(Clone)]
976 pub struct TypeParameterDef {
977 pub ident: ast::Ident,
978 pub def_id: ast::DefId,
979 pub bounds: Rc<ParamBounds>,
980 pub default: Option<ty::t>
981 }
982
983 #[deriving(Encodable, Decodable, Clone)]
984 pub struct RegionParameterDef {
985 pub name: ast::Name,
986 pub def_id: ast::DefId,
987 }
988
989 /// Information about the type/lifetime parameters associated with an item.
990 /// Analogous to ast::Generics.
991 #[deriving(Clone)]
992 pub struct Generics {
993 /// List of type parameters declared on the item.
994 pub type_param_defs: Rc<Vec<TypeParameterDef>>,
995
996 /// List of region parameters declared on the item.
997 /// For a fn or method, only includes *early-bound* lifetimes.
998 pub region_param_defs: Rc<Vec<RegionParameterDef>>,
999 }
1000
1001 impl Generics {
1002 pub fn has_type_params(&self) -> bool {
1003 !self.type_param_defs.is_empty()
1004 }
1005 pub fn type_param_defs<'a>(&'a self) -> &'a [TypeParameterDef] {
1006 self.type_param_defs.as_slice()
1007 }
1008 pub fn region_param_defs<'a>(&'a self) -> &'a [RegionParameterDef] {
1009 self.region_param_defs.as_slice()
1010 }
1011 }
1012
1013 /// When type checking, we use the `ParameterEnvironment` to track
1014 /// details about the type/lifetime parameters that are in scope.
1015 /// It primarily stores the bounds information.
1016 ///
1017 /// Note: This information might seem to be redundant with the data in
1018 /// `tcx.ty_param_defs`, but it is not. That table contains the
1019 /// parameter definitions from an "outside" perspective, but this
1020 /// struct will contain the bounds for a parameter as seen from inside
1021 /// the function body. Currently the only real distinction is that
1022 /// bound lifetime parameters are replaced with free ones, but in the
1023 /// future I hope to refine the representation of types so as to make
1024 /// more distinctions clearer.
1025 pub struct ParameterEnvironment {
1026 /// A substitution that can be applied to move from
1027 /// the "outer" view of a type or method to the "inner" view.
1028 /// In general, this means converting from bound parameters to
1029 /// free parameters. Since we currently represent bound/free type
1030 /// parameters in the same way, this only has an affect on regions.
1031 pub free_substs: ty::substs,
1032
1033 /// Bound on the Self parameter
1034 pub self_param_bound: Option<Rc<TraitRef>>,
1035
1036 /// Bounds on each numbered type parameter
1037 pub type_param_bounds: Vec<ParamBounds> ,
1038 }
1039
1040 /// A polytype.
1041 ///
1042 /// - `bounds`: The list of bounds for each type parameter. The length of the
1043 /// list also tells you how many type parameters there are.
1044 ///
1045 /// - `rp`: true if the type is region-parameterized. Types can have at
1046 /// most one region parameter, always called `&self`.
1047 ///
1048 /// - `ty`: the base type. May have reference to the (unsubstituted) bound
1049 /// region `&self` or to (unsubstituted) ty_param types
1050 #[deriving(Clone)]
1051 pub struct ty_param_bounds_and_ty {
1052 pub generics: Generics,
1053 pub ty: t
1054 }
1055
1056 /// As `ty_param_bounds_and_ty` but for a trait ref.
1057 pub struct TraitDef {
1058 pub generics: Generics,
1059 pub bounds: BuiltinBounds,
1060 pub trait_ref: Rc<ty::TraitRef>,
1061 }
1062
1063 pub struct ty_param_substs_and_ty {
1064 pub substs: ty::substs,
1065 pub ty: ty::t
1066 }
1067
1068 pub type type_cache = RefCell<DefIdMap<ty_param_bounds_and_ty>>;
1069
1070 pub type node_type_table = RefCell<HashMap<uint,t>>;
1071
1072 pub fn mk_ctxt(s: Session,
1073 dm: resolve::DefMap,
1074 named_region_map: resolve_lifetime::NamedRegionMap,
1075 map: ast_map::Map,
1076 freevars: freevars::freevar_map,
1077 region_maps: middle::region::RegionMaps,
1078 lang_items: middle::lang_items::LanguageItems)
1079 -> ctxt {
1080 ctxt {
1081 named_region_map: named_region_map,
1082 item_variance_map: RefCell::new(DefIdMap::new()),
1083 interner: RefCell::new(FnvHashMap::new()),
1084 next_id: Cell::new(primitives::LAST_PRIMITIVE_ID),
1085 sess: s,
1086 def_map: dm,
1087 region_maps: region_maps,
1088 node_types: RefCell::new(HashMap::new()),
1089 node_type_substs: RefCell::new(NodeMap::new()),
1090 trait_refs: RefCell::new(NodeMap::new()),
1091 trait_defs: RefCell::new(DefIdMap::new()),
1092 map: map,
1093 intrinsic_defs: RefCell::new(DefIdMap::new()),
1094 freevars: RefCell::new(freevars),
1095 tcache: RefCell::new(DefIdMap::new()),
1096 rcache: RefCell::new(HashMap::new()),
1097 short_names_cache: RefCell::new(HashMap::new()),
1098 needs_unwind_cleanup_cache: RefCell::new(HashMap::new()),
1099 tc_cache: RefCell::new(HashMap::new()),
1100 ast_ty_to_ty_cache: RefCell::new(NodeMap::new()),
1101 enum_var_cache: RefCell::new(DefIdMap::new()),
1102 methods: RefCell::new(DefIdMap::new()),
1103 trait_method_def_ids: RefCell::new(DefIdMap::new()),
1104 trait_methods_cache: RefCell::new(DefIdMap::new()),
1105 impl_trait_cache: RefCell::new(DefIdMap::new()),
1106 ty_param_defs: RefCell::new(NodeMap::new()),
1107 adjustments: RefCell::new(NodeMap::new()),
1108 normalized_cache: RefCell::new(HashMap::new()),
1109 lang_items: lang_items,
1110 provided_method_sources: RefCell::new(DefIdMap::new()),
1111 supertraits: RefCell::new(DefIdMap::new()),
1112 superstructs: RefCell::new(DefIdMap::new()),
1113 struct_fields: RefCell::new(DefIdMap::new()),
1114 destructor_for_type: RefCell::new(DefIdMap::new()),
1115 destructors: RefCell::new(DefIdSet::new()),
1116 trait_impls: RefCell::new(DefIdMap::new()),
1117 inherent_impls: RefCell::new(DefIdMap::new()),
1118 impl_methods: RefCell::new(DefIdMap::new()),
1119 used_unsafe: RefCell::new(NodeSet::new()),
1120 used_mut_nodes: RefCell::new(NodeSet::new()),
1121 impl_vtables: RefCell::new(DefIdMap::new()),
1122 populated_external_types: RefCell::new(DefIdSet::new()),
1123 populated_external_traits: RefCell::new(DefIdSet::new()),
1124 upvar_borrow_map: RefCell::new(HashMap::new()),
1125 extern_const_statics: RefCell::new(DefIdMap::new()),
1126 extern_const_variants: RefCell::new(DefIdMap::new()),
1127 method_map: RefCell::new(FnvHashMap::new()),
1128 vtable_map: RefCell::new(FnvHashMap::new()),
1129 dependency_formats: RefCell::new(HashMap::new()),
1130 }
1131 }
1132
1133 // Type constructors
1134
1135 // Interns a type/name combination, stores the resulting box in cx.interner,
1136 // and returns the box as cast to an unsafe ptr (see comments for t above).
1137 pub fn mk_t(cx: &ctxt, st: sty) -> t {
1138 // Check for primitive types.
1139 match st {
1140 ty_nil => return mk_nil(),
1141 ty_err => return mk_err(),
1142 ty_bool => return mk_bool(),
1143 ty_int(i) => return mk_mach_int(i),
1144 ty_uint(u) => return mk_mach_uint(u),
1145 ty_float(f) => return mk_mach_float(f),
1146 ty_char => return mk_char(),
1147 ty_bot => return mk_bot(),
1148 _ => {}
1149 };
1150
1151 let key = intern_key { sty: &st };
1152
1153 match cx.interner.borrow().find(&key) {
1154 Some(t) => unsafe { return cast::transmute(&t.sty); },
1155 _ => ()
1156 }
1157
1158 let mut flags = 0u;
1159 fn rflags(r: Region) -> uint {
1160 (has_regions as uint) | {
1161 match r {
1162 ty::ReInfer(_) => needs_infer as uint,
1163 _ => 0u
1164 }
1165 }
1166 }
1167 fn sflags(substs: &substs) -> uint {
1168 let mut f = 0u;
1169 for tt in substs.tps.iter() { f |= get(*tt).flags; }
1170 match substs.regions {
1171 ErasedRegions => {}
1172 NonerasedRegions(ref regions) => {
1173 for r in regions.iter() {
1174 f |= rflags(*r)
1175 }
1176 }
1177 }
1178 return f;
1179 }
1180 match &st {
1181 &ty_nil | &ty_bool | &ty_char | &ty_int(_) | &ty_float(_) | &ty_uint(_) |
1182 &ty_str => {}
1183 // You might think that we could just return ty_err for
1184 // any type containing ty_err as a component, and get
1185 // rid of the has_ty_err flag -- likewise for ty_bot (with
1186 // the exception of function types that return bot).
1187 // But doing so caused sporadic memory corruption, and
1188 // neither I (tjc) nor nmatsakis could figure out why,
1189 // so we're doing it this way.
1190 &ty_bot => flags |= has_ty_bot as uint,
1191 &ty_err => flags |= has_ty_err as uint,
1192 &ty_param(_) => flags |= has_params as uint,
1193 &ty_infer(_) => flags |= needs_infer as uint,
1194 &ty_self(_) => flags |= has_self as uint,
1195 &ty_enum(_, ref substs) | &ty_struct(_, ref substs) => {
1196 flags |= sflags(substs);
1197 }
1198 &ty_trait(box ty::TyTrait { ref substs, store, .. }) => {
1199 flags |= sflags(substs);
1200 match store {
1201 RegionTraitStore(r, _) => {
1202 flags |= rflags(r);
1203 }
1204 _ => {}
1205 }
1206 }
1207 &ty_box(tt) | &ty_uniq(tt) => {
1208 flags |= get(tt).flags
1209 }
1210 &ty_ptr(ref m) | &ty_vec(ref m, _) => {
1211 flags |= get(m.ty).flags;
1212 }
1213 &ty_rptr(r, ref m) => {
1214 flags |= rflags(r);
1215 flags |= get(m.ty).flags;
1216 }
1217 &ty_tup(ref ts) => for tt in ts.iter() { flags |= get(*tt).flags; },
1218 &ty_bare_fn(ref f) => {
1219 for a in f.sig.inputs.iter() { flags |= get(*a).flags; }
1220 flags |= get(f.sig.output).flags;
1221 // T -> _|_ is *not* _|_ !
1222 flags &= !(has_ty_bot as uint);
1223 }
1224 &ty_closure(ref f) => {
1225 match f.store {
1226 RegionTraitStore(r, _) => {
1227 flags |= rflags(r);
1228 }
1229 _ => {}
1230 }
1231 for a in f.sig.inputs.iter() { flags |= get(*a).flags; }
1232 flags |= get(f.sig.output).flags;
1233 // T -> _|_ is *not* _|_ !
1234 flags &= !(has_ty_bot as uint);
1235 }
1236 }
1237
1238 let t = box t_box_ {
1239 sty: st,
1240 id: cx.next_id.get(),
1241 flags: flags,
1242 };
1243
1244 let sty_ptr = &t.sty as *sty;
1245
1246 let key = intern_key {
1247 sty: sty_ptr,
1248 };
1249
1250 cx.interner.borrow_mut().insert(key, t);
1251
1252 cx.next_id.set(cx.next_id.get() + 1);
1253
1254 unsafe {
1255 cast::transmute::<*sty, t>(sty_ptr)
1256 }
1257 }
1258
1259 #[inline]
1260 pub fn mk_prim_t(primitive: &'static t_box_) -> t {
1261 unsafe {
1262 cast::transmute::<&'static t_box_, t>(primitive)
1263 }
1264 }
1265
1266 #[inline]
1267 pub fn mk_nil() -> t { mk_prim_t(&primitives::TY_NIL) }
1268
1269 #[inline]
1270 pub fn mk_err() -> t { mk_prim_t(&primitives::TY_ERR) }
1271
1272 #[inline]
1273 pub fn mk_bot() -> t { mk_prim_t(&primitives::TY_BOT) }
1274
1275 #[inline]
1276 pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) }
1277
1278 #[inline]
1279 pub fn mk_int() -> t { mk_prim_t(&primitives::TY_INT) }
1280
1281 #[inline]
1282 pub fn mk_i8() -> t { mk_prim_t(&primitives::TY_I8) }
1283
1284 #[inline]
1285 pub fn mk_i16() -> t { mk_prim_t(&primitives::TY_I16) }
1286
1287 #[inline]
1288 pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) }
1289
1290 #[inline]
1291 pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) }
1292
1293 #[inline]
1294 pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
1295
1296 #[inline]
1297 pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
1298
1299 #[inline]
1300 pub fn mk_f128() -> t { mk_prim_t(&primitives::TY_F128) }
1301
1302 #[inline]
1303 pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) }
1304
1305 #[inline]
1306 pub fn mk_u8() -> t { mk_prim_t(&primitives::TY_U8) }
1307
1308 #[inline]
1309 pub fn mk_u16() -> t { mk_prim_t(&primitives::TY_U16) }
1310
1311 #[inline]
1312 pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) }
1313
1314 #[inline]
1315 pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
1316
1317 pub fn mk_mach_int(tm: ast::IntTy) -> t {
1318 match tm {
1319 ast::TyI => mk_int(),
1320 ast::TyI8 => mk_i8(),
1321 ast::TyI16 => mk_i16(),
1322 ast::TyI32 => mk_i32(),
1323 ast::TyI64 => mk_i64(),
1324 }
1325 }
1326
1327 pub fn mk_mach_uint(tm: ast::UintTy) -> t {
1328 match tm {
1329 ast::TyU => mk_uint(),
1330 ast::TyU8 => mk_u8(),
1331 ast::TyU16 => mk_u16(),
1332 ast::TyU32 => mk_u32(),
1333 ast::TyU64 => mk_u64(),
1334 }
1335 }
1336
1337 pub fn mk_mach_float(tm: ast::FloatTy) -> t {
1338 match tm {
1339 ast::TyF32 => mk_f32(),
1340 ast::TyF64 => mk_f64(),
1341 ast::TyF128 => mk_f128()
1342 }
1343 }
1344
1345 #[inline]
1346 pub fn mk_char() -> t { mk_prim_t(&primitives::TY_CHAR) }
1347
1348 pub fn mk_str(cx: &ctxt) -> t {
1349 mk_t(cx, ty_str)
1350 }
1351
1352 pub fn mk_str_slice(cx: &ctxt, r: Region, m: ast::Mutability) -> t {
1353 mk_rptr(cx, r,
1354 mt {
1355 ty: mk_t(cx, ty_str),
1356 mutbl: m
1357 })
1358 }
1359
1360 pub fn mk_enum(cx: &ctxt, did: ast::DefId, substs: substs) -> t {
1361 // take a copy of substs so that we own the vectors inside
1362 mk_t(cx, ty_enum(did, substs))
1363 }
1364
1365 pub fn mk_box(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_box(ty)) }
1366
1367 pub fn mk_uniq(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_uniq(ty)) }
1368
1369 pub fn mk_ptr(cx: &ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
1370
1371 pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
1372
1373 pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t {
1374 mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutMutable})
1375 }
1376 pub fn mk_imm_rptr(cx: &ctxt, r: Region, ty: t) -> t {
1377 mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutImmutable})
1378 }
1379
1380 pub fn mk_mut_ptr(cx: &ctxt, ty: t) -> t {
1381 mk_ptr(cx, mt {ty: ty, mutbl: ast::MutMutable})
1382 }
1383
1384 pub fn mk_imm_ptr(cx: &ctxt, ty: t) -> t {
1385 mk_ptr(cx, mt {ty: ty, mutbl: ast::MutImmutable})
1386 }
1387
1388 pub fn mk_nil_ptr(cx: &ctxt) -> t {
1389 mk_ptr(cx, mt {ty: mk_nil(), mutbl: ast::MutImmutable})
1390 }
1391
1392 pub fn mk_vec(cx: &ctxt, tm: mt, sz: Option<uint>) -> t {
1393 mk_t(cx, ty_vec(tm, sz))
1394 }
1395
1396 pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {
1397 mk_rptr(cx, r,
1398 mt {
1399 ty: mk_vec(cx, tm, None),
1400 mutbl: tm.mutbl
1401 })
1402 }
1403
1404 pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
1405
1406 pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
1407 mk_t(cx, ty_closure(box fty))
1408 }
1409
1410 pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t {
1411 mk_t(cx, ty_bare_fn(fty))
1412 }
1413
1414 pub fn mk_ctor_fn(cx: &ctxt,
1415 binder_id: ast::NodeId,
1416 input_tys: &[ty::t],
1417 output: ty::t) -> t {
1418 let input_args = input_tys.iter().map(|t| *t).collect();
1419 mk_bare_fn(cx,
1420 BareFnTy {
1421 fn_style: ast::NormalFn,
1422 abi: abi::Rust,
1423 sig: FnSig {
1424 binder_id: binder_id,
1425 inputs: input_args,
1426 output: output,
1427 variadic: false
1428 }
1429 })
1430 }
1431
1432
1433 pub fn mk_trait(cx: &ctxt,
1434 did: ast::DefId,
1435 substs: substs,
1436 store: TraitStore,
1437 bounds: BuiltinBounds)
1438 -> t {
1439 // take a copy of substs so that we own the vectors inside
1440 let inner = box TyTrait {
1441 def_id: did,
1442 substs: substs,
1443 store: store,
1444 bounds: bounds
1445 };
1446 mk_t(cx, ty_trait(inner))
1447 }
1448
1449 pub fn mk_struct(cx: &ctxt, struct_id: ast::DefId, substs: substs) -> t {
1450 // take a copy of substs so that we own the vectors inside
1451 mk_t(cx, ty_struct(struct_id, substs))
1452 }
1453
1454 pub fn mk_var(cx: &ctxt, v: TyVid) -> t { mk_infer(cx, TyVar(v)) }
1455
1456 pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) }
1457
1458 pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
1459
1460 pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
1461
1462 pub fn mk_self(cx: &ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }
1463
1464 pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
1465 mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
1466 }
1467
1468 pub fn walk_ty(ty: t, f: |t|) {
1469 maybe_walk_ty(ty, |t| { f(t); true });
1470 }
1471
1472 pub fn maybe_walk_ty(ty: t, f: |t| -> bool) {
1473 if !f(ty) {
1474 return;
1475 }
1476 match get(ty).sty {
1477 ty_nil | ty_bot | ty_bool | ty_char | ty_int(_) | ty_uint(_) | ty_float(_) |
1478 ty_str | ty_self(_) |
1479 ty_infer(_) | ty_param(_) | ty_err => {}
1480 ty_box(ty) | ty_uniq(ty) => maybe_walk_ty(ty, f),
1481 ty_ptr(ref tm) | ty_rptr(_, ref tm) | ty_vec(ref tm, _) => {
1482 maybe_walk_ty(tm.ty, f);
1483 }
1484 ty_enum(_, ref substs) | ty_struct(_, ref substs) |
1485 ty_trait(box TyTrait { ref substs, .. }) => {
1486 for subty in (*substs).tps.iter() { maybe_walk_ty(*subty, |x| f(x)); }
1487 }
1488 ty_tup(ref ts) => { for tt in ts.iter() { maybe_walk_ty(*tt, |x| f(x)); } }
1489 ty_bare_fn(ref ft) => {
1490 for a in ft.sig.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
1491 maybe_walk_ty(ft.sig.output, f);
1492 }
1493 ty_closure(ref ft) => {
1494 for a in ft.sig.inputs.iter() { maybe_walk_ty(*a, |x| f(x)); }
1495 maybe_walk_ty(ft.sig.output, f);
1496 }
1497 }
1498 }
1499
1500 // Folds types from the bottom up.
1501 pub fn fold_ty(cx: &ctxt, t0: t, fldop: |t| -> t) -> t {
1502 let mut f = ty_fold::BottomUpFolder {tcx: cx, fldop: fldop};
1503 f.fold_ty(t0)
1504 }
1505
1506 pub fn walk_regions_and_ty(cx: &ctxt, ty: t, fldr: |r: Region|, fldt: |t: t|)
1507 -> t {
1508 ty_fold::RegionFolder::general(cx,
1509 |r| { fldr(r); r },
1510 |t| { fldt(t); t }).fold_ty(ty)
1511 }
1512
1513 // Substitute *only* type parameters. Used in trans where regions are erased.
1514 pub fn subst_tps(tcx: &ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
1515 let mut subst = TpsSubst { tcx: tcx, self_ty_opt: self_ty_opt, tps: tps };
1516 return subst.fold_ty(typ);
1517
1518 struct TpsSubst<'a> {
1519 tcx: &'a ctxt,
1520 self_ty_opt: Option<t>,
1521 tps: &'a [t],
1522 }
1523
1524 impl<'a> TypeFolder for TpsSubst<'a> {
1525 fn tcx<'a>(&'a self) -> &'a ctxt { self.tcx }
1526
1527 fn fold_ty(&mut self, t: ty::t) -> ty::t {
1528 if self.tps.len() == 0u && self.self_ty_opt.is_none() {
1529 return t;
1530 }
1531
1532 let tb = ty::get(t);
1533 if self.self_ty_opt.is_none() && !tbox_has_flag(tb, has_params) {
1534 return t;
1535 }
1536
1537 match ty::get(t).sty {
1538 ty_param(p) => {
1539 self.tps[p.idx]
1540 }
1541
1542 ty_self(_) => {
1543 match self.self_ty_opt {
1544 None => self.tcx.sess.bug("ty_self unexpected here"),
1545 Some(self_ty) => self_ty
1546 }
1547 }
1548
1549 _ => {
1550 ty_fold::super_fold_ty(self, t)
1551 }
1552 }
1553 }
1554 }
1555 }
1556
1557 pub fn substs_is_noop(substs: &substs) -> bool {
1558 let regions_is_noop = match substs.regions {
1559 ErasedRegions => false, // may be used to canonicalize
1560 NonerasedRegions(ref regions) => regions.is_empty()
1561 };
1562
1563 substs.tps.len() == 0u &&
1564 regions_is_noop &&
1565 substs.self_ty.is_none()
1566 }
1567
1568 pub fn substs_to_str(cx: &ctxt, substs: &substs) -> ~str {
1569 substs.repr(cx)
1570 }
1571
1572 pub fn subst(cx: &ctxt,
1573 substs: &substs,
1574 typ: t)
1575 -> t {
1576 typ.subst(cx, substs)
1577 }
1578
1579 // Type utilities
1580
1581 pub fn type_is_nil(ty: t) -> bool { get(ty).sty == ty_nil }
1582
1583 pub fn type_is_bot(ty: t) -> bool {
1584 (get(ty).flags & (has_ty_bot as uint)) != 0
1585 }
1586
1587 pub fn type_is_error(ty: t) -> bool {
1588 (get(ty).flags & (has_ty_err as uint)) != 0
1589 }
1590
1591 pub fn type_needs_subst(ty: t) -> bool {
1592 tbox_has_flag(get(ty), needs_subst)
1593 }
1594
1595 pub fn trait_ref_contains_error(tref: &ty::TraitRef) -> bool {
1596 tref.substs.self_ty.iter().any(|&t| type_is_error(t)) ||
1597 tref.substs.tps.iter().any(|&t| type_is_error(t))
1598 }
1599
1600 pub fn type_is_ty_var(ty: t) -> bool {
1601 match get(ty).sty {
1602 ty_infer(TyVar(_)) => true,
1603 _ => false
1604 }
1605 }
1606
1607 pub fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool }
1608
1609 pub fn type_is_self(ty: t) -> bool {
1610 match get(ty).sty {
1611 ty_self(..) => true,
1612 _ => false
1613 }
1614 }
1615
1616 fn type_is_slice(ty:t) -> bool {
1617 match get(ty).sty {
1618 ty_rptr(_, mt) => match get(mt.ty).sty {
1619 ty_vec(_, None) | ty_str => true,
1620 _ => false,
1621 },
1622 _ => false
1623 }
1624 }
1625
1626 pub fn type_is_structural(ty: t) -> bool {
1627 match get(ty).sty {
1628 ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_closure(_) | ty_trait(..) |
1629 ty_vec(_, Some(_)) => true,
1630 _ => type_is_slice(ty)
1631 }
1632 }
1633
1634 pub fn type_is_simd(cx: &ctxt, ty: t) -> bool {
1635 match get(ty).sty {
1636 ty_struct(did, _) => lookup_simd(cx, did),
1637 _ => false
1638 }
1639 }
1640
1641 pub fn sequence_element_type(cx: &ctxt, ty: t) -> t {
1642 match get(ty).sty {
1643 ty_vec(mt, Some(_)) => mt.ty,
1644 ty_ptr(mt{ty: t, ..}) | ty_rptr(_, mt{ty: t, ..}) |
1645 ty_box(t) | ty_uniq(t) => match get(t).sty {
1646 ty_vec(mt, None) => mt.ty,
1647 ty_str => mk_mach_uint(ast::TyU8),
1648 _ => cx.sess.bug("sequence_element_type called on non-sequence value"),
1649 },
1650 _ => cx.sess.bug("sequence_element_type called on non-sequence value"),
1651 }
1652 }
1653
1654 pub fn simd_type(cx: &ctxt, ty: t) -> t {
1655 match get(ty).sty {
1656 ty_struct(did, ref substs) => {
1657 let fields = lookup_struct_fields(cx, did);
1658 lookup_field_type(cx, did, fields.get(0).id, substs)
1659 }
1660 _ => fail!("simd_type called on invalid type")
1661 }
1662 }
1663
1664 pub fn simd_size(cx: &ctxt, ty: t) -> uint {
1665 match get(ty).sty {
1666 ty_struct(did, _) => {
1667 let fields = lookup_struct_fields(cx, did);
1668 fields.len()
1669 }
1670 _ => fail!("simd_size called on invalid type")
1671 }
1672 }
1673
1674 pub fn type_is_boxed(ty: t) -> bool {
1675 match get(ty).sty {
1676 ty_box(_) => true,
1677 _ => false
1678 }
1679 }
1680
1681 pub fn type_is_region_ptr(ty: t) -> bool {
1682 match get(ty).sty {
1683 ty_rptr(_, mt) => match get(mt.ty).sty {
1684 // FIXME(nrc, DST) slices weren't regarded as rptrs, so we preserve this
1685 // odd behaviour for now. (But ~[] were unique. I have no idea why).
1686 ty_vec(_, None) | ty_str => false,
1687 _ => true
1688 },
1689 _ => false
1690 }
1691 }
1692
1693 pub fn type_is_unsafe_ptr(ty: t) -> bool {
1694 match get(ty).sty {
1695 ty_ptr(_) => return true,
1696 _ => return false
1697 }
1698 }
1699
1700 pub fn type_is_unique(ty: t) -> bool {
1701 match get(ty).sty {
1702 ty_uniq(_) => true,
1703 _ => false
1704 }
1705 }
1706
1707 /*
1708 A scalar type is one that denotes an atomic datum, with no sub-components.
1709 (A ty_ptr is scalar because it represents a non-managed pointer, so its
1710 contents are abstract to rustc.)
1711 */
1712 pub fn type_is_scalar(ty: t) -> bool {
1713 match get(ty).sty {
1714 ty_nil | ty_bool | ty_char | ty_int(_) | ty_float(_) | ty_uint(_) |
1715 ty_infer(IntVar(_)) | ty_infer(FloatVar(_)) |
1716 ty_bare_fn(..) | ty_ptr(_) => true,
1717 _ => false
1718 }
1719 }
1720
1721 pub fn type_needs_drop(cx: &ctxt, ty: t) -> bool {
1722 type_contents(cx, ty).needs_drop(cx)
1723 }
1724
1725 // Some things don't need cleanups during unwinding because the
1726 // task can free them all at once later. Currently only things
1727 // that only contain scalars and shared boxes can avoid unwind
1728 // cleanups.
1729 pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool {
1730 match cx.needs_unwind_cleanup_cache.borrow().find(&ty) {
1731 Some(&result) => return result,
1732 None => ()
1733 }
1734
1735 let mut tycache = HashSet::new();
1736 let needs_unwind_cleanup =
1737 type_needs_unwind_cleanup_(cx, ty, &mut tycache, false);
1738 cx.needs_unwind_cleanup_cache.borrow_mut().insert(ty, needs_unwind_cleanup);
1739 return needs_unwind_cleanup;
1740 }
1741
1742 fn type_needs_unwind_cleanup_(cx: &ctxt, ty: t,
1743 tycache: &mut HashSet<t>,
1744 encountered_box: bool) -> bool {
1745
1746 // Prevent infinite recursion
1747 if !tycache.insert(ty) {
1748 return false;
1749 }
1750
1751 let mut encountered_box = encountered_box;
1752 let mut needs_unwind_cleanup = false;
1753 maybe_walk_ty(ty, |ty| {
1754 let old_encountered_box = encountered_box;
1755 let result = match get(ty).sty {
1756 ty_box(_) => {
1757 encountered_box = true;
1758 true
1759 }
1760 ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
1761 ty_tup(_) | ty_ptr(_) => {
1762 true
1763 }
1764 ty_enum(did, ref substs) => {
1765 for v in (*enum_variants(cx, did)).iter() {
1766 for aty in v.args.iter() {
1767 let t = subst(cx, substs, *aty);
1768 needs_unwind_cleanup |=
1769 type_needs_unwind_cleanup_(cx, t, tycache,
1770 encountered_box);
1771 }
1772 }
1773 !needs_unwind_cleanup
1774 }
1775 ty_uniq(_) => {
1776 // Once we're inside a box, the annihilator will find
1777 // it and destroy it.
1778 if !encountered_box {
1779 needs_unwind_cleanup = true;
1780 false
1781 } else {
1782 true
1783 }
1784 }
1785 _ => {
1786 needs_unwind_cleanup = true;
1787 false
1788 }
1789 };
1790
1791 encountered_box = old_encountered_box;
1792 result
1793 });
1794
1795 return needs_unwind_cleanup;
1796 }
1797
1798 /**
1799 * Type contents is how the type checker reasons about kinds.
1800 * They track what kinds of things are found within a type. You can
1801 * think of them as kind of an "anti-kind". They track the kinds of values
1802 * and thinks that are contained in types. Having a larger contents for
1803 * a type tends to rule that type *out* from various kinds. For example,
1804 * a type that contains a reference is not sendable.
1805 *
1806 * The reason we compute type contents and not kinds is that it is
1807 * easier for me (nmatsakis) to think about what is contained within
1808 * a type than to think about what is *not* contained within a type.
1809 */
1810 pub struct TypeContents {
1811 pub bits: u64
1812 }
1813
1814 macro_rules! def_type_content_sets(
1815 (mod $mname:ident { $($name:ident = $bits:expr),+ }) => {
1816 mod $mname {
1817 use middle::ty::TypeContents;
1818 $(pub static $name: TypeContents = TypeContents { bits: $bits };)+
1819 }
1820 }
1821 )
1822
1823 def_type_content_sets!(
1824 mod TC {
1825 None = 0b0000_0000__0000_0000__0000,
1826
1827 // Things that are interior to the value (first nibble):
1828 InteriorUnsized = 0b0000_0000__0000_0000__0001,
1829 InteriorUnsafe = 0b0000_0000__0000_0000__0010,
1830 // InteriorAll = 0b00000000__00000000__1111,
1831
1832 // Things that are owned by the value (second and third nibbles):
1833 OwnsOwned = 0b0000_0000__0000_0001__0000,
1834 OwnsDtor = 0b0000_0000__0000_0010__0000,
1835 OwnsManaged /* see [1] below */ = 0b0000_0000__0000_0100__0000,
1836 OwnsAffine = 0b0000_0000__0000_1000__0000,
1837 OwnsAll = 0b0000_0000__1111_1111__0000,
1838
1839 // Things that are reachable by the value in any way (fourth nibble):
1840 ReachesNonsendAnnot = 0b0000_0001__0000_0000__0000,
1841 ReachesBorrowed = 0b0000_0010__0000_0000__0000,
1842 // ReachesManaged /* see [1] below */ = 0b0000_0100__0000_0000__0000,
1843 ReachesMutable = 0b0000_1000__0000_0000__0000,
1844 ReachesNoShare = 0b0001_0000__0000_0000__0000,
1845 ReachesAll = 0b0001_1111__0000_0000__0000,
1846
1847 // Things that cause values to *move* rather than *copy*
1848 Moves = 0b0000_0000__0000_1011__0000,
1849
1850 // Things that mean drop glue is necessary
1851 NeedsDrop = 0b0000_0000__0000_0111__0000,
1852
1853 // Things that prevent values from being sent
1854 //
1855 // Note: For checking whether something is sendable, it'd
1856 // be sufficient to have ReachesManaged. However, we include
1857 // both ReachesManaged and OwnsManaged so that when
1858 // a parameter has a bound T:Send, we are able to deduce
1859 // that it neither reaches nor owns a managed pointer.
1860 Nonsendable = 0b0000_0111__0000_0100__0000,
1861
1862 // Things that prevent values from being considered 'static
1863 Nonstatic = 0b0000_0010__0000_0000__0000,
1864
1865 // Things that prevent values from being considered sized
1866 Nonsized = 0b0000_0000__0000_0000__0001,
1867
1868 // Things that prevent values from being shared
1869 Nonsharable = 0b0001_0000__0000_0000__0000,
1870
1871 // Things that make values considered not POD (would be same
1872 // as `Moves`, but for the fact that managed data `@` is
1873 // not considered POD)
1874 Noncopy = 0b0000_0000__0000_1111__0000,
1875
1876 // Bits to set when a managed value is encountered
1877 //
1878 // [1] Do not set the bits TC::OwnsManaged or
1879 // TC::ReachesManaged directly, instead reference
1880 // TC::Managed to set them both at once.
1881 Managed = 0b0000_0100__0000_0100__0000,
1882
1883 // All bits
1884 All = 0b1111_1111__1111_1111__1111
1885 }
1886 )
1887
1888 impl TypeContents {
1889 pub fn meets_bound(&self, cx: &ctxt, bb: BuiltinBound) -> bool {
1890 match bb {
1891 BoundStatic => self.is_static(cx),
1892 BoundSend => self.is_sendable(cx),
1893 BoundSized => self.is_sized(cx),
1894 BoundCopy => self.is_copy(cx),
1895 BoundShare => self.is_sharable(cx),
1896 }
1897 }
1898
1899 pub fn when(&self, cond: bool) -> TypeContents {
1900 if cond {*self} else {TC::None}
1901 }
1902
1903 pub fn intersects(&self, tc: TypeContents) -> bool {
1904 (self.bits & tc.bits) != 0
1905 }
1906
1907 pub fn is_static(&self, _: &ctxt) -> bool {
1908 !self.intersects(TC::Nonstatic)
1909 }
1910
1911 pub fn is_sendable(&self, _: &ctxt) -> bool {
1912 !self.intersects(TC::Nonsendable)
1913 }
1914
1915 pub fn is_sharable(&self, _: &ctxt) -> bool {
1916 !self.intersects(TC::Nonsharable)
1917 }
1918
1919 pub fn owns_managed(&self) -> bool {
1920 self.intersects(TC::OwnsManaged)
1921 }
1922
1923 pub fn owns_owned(&self) -> bool {
1924 self.intersects(TC::OwnsOwned)
1925 }
1926
1927 pub fn is_sized(&self, _: &ctxt) -> bool {
1928 !self.intersects(TC::Nonsized)
1929 }
1930
1931 pub fn is_copy(&self, _: &ctxt) -> bool {
1932 !self.intersects(TC::Noncopy)
1933 }
1934
1935 pub fn interior_unsafe(&self) -> bool {
1936 self.intersects(TC::InteriorUnsafe)
1937 }
1938
1939 pub fn interior_unsized(&self) -> bool {
1940 self.intersects(TC::InteriorUnsized)
1941 }
1942
1943 pub fn moves_by_default(&self, _: &ctxt) -> bool {
1944 self.intersects(TC::Moves)
1945 }
1946
1947 pub fn needs_drop(&self, _: &ctxt) -> bool {
1948 self.intersects(TC::NeedsDrop)
1949 }
1950
1951 pub fn owned_pointer(&self) -> TypeContents {
1952 /*!
1953 * Includes only those bits that still apply
1954 * when indirected through a `Box` pointer
1955 */
1956 TC::OwnsOwned | (
1957 *self & (TC::OwnsAll | TC::ReachesAll))
1958 }
1959
1960 pub fn reference(&self, bits: TypeContents) -> TypeContents {
1961 /*!
1962 * Includes only those bits that still apply
1963 * when indirected through a reference (`&`)
1964 */
1965 bits | (
1966 *self & TC::ReachesAll)
1967 }
1968
1969 pub fn managed_pointer(&self) -> TypeContents {
1970 /*!
1971 * Includes only those bits that still apply
1972 * when indirected through a managed pointer (`@`)
1973 */
1974 TC::Managed | (
1975 *self & TC::ReachesAll)
1976 }
1977
1978 pub fn unsafe_pointer(&self) -> TypeContents {
1979 /*!
1980 * Includes only those bits that still apply
1981 * when indirected through an unsafe pointer (`*`)
1982 */
1983 *self & TC::ReachesAll
1984 }
1985
1986 pub fn union<T>(v: &[T], f: |&T| -> TypeContents) -> TypeContents {
1987 v.iter().fold(TC::None, |tc, t| tc | f(t))
1988 }
1989
1990 pub fn has_dtor(&self) -> bool {
1991 self.intersects(TC::OwnsDtor)
1992 }
1993 }
1994
1995 impl ops::BitOr<TypeContents,TypeContents> for TypeContents {
1996 fn bitor(&self, other: &TypeContents) -> TypeContents {
1997 TypeContents {bits: self.bits | other.bits}
1998 }
1999 }
2000
2001 impl ops::BitAnd<TypeContents,TypeContents> for TypeContents {
2002 fn bitand(&self, other: &TypeContents) -> TypeContents {
2003 TypeContents {bits: self.bits & other.bits}
2004 }
2005 }
2006
2007 impl ops::Sub<TypeContents,TypeContents> for TypeContents {
2008 fn sub(&self, other: &TypeContents) -> TypeContents {
2009 TypeContents {bits: self.bits & !other.bits}
2010 }
2011 }
2012
2013 impl fmt::Show for TypeContents {
2014 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2015 write!(f.buf, "TypeContents({:t})", self.bits)
2016 }
2017 }
2018
2019 pub fn type_is_static(cx: &ctxt, t: ty::t) -> bool {
2020 type_contents(cx, t).is_static(cx)
2021 }
2022
2023 pub fn type_is_sendable(cx: &ctxt, t: ty::t) -> bool {
2024 type_contents(cx, t).is_sendable(cx)
2025 }
2026
2027 pub fn type_interior_is_unsafe(cx: &ctxt, t: ty::t) -> bool {
2028 type_contents(cx, t).interior_unsafe()
2029 }
2030
2031 pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
2032 let ty_id = type_id(ty);
2033
2034 match cx.tc_cache.borrow().find(&ty_id) {
2035 Some(tc) => { return *tc; }
2036 None => {}
2037 }
2038
2039 let mut cache = HashMap::new();
2040 let result = tc_ty(cx, ty, &mut cache);
2041
2042 cx.tc_cache.borrow_mut().insert(ty_id, result);
2043 return result;
2044
2045 fn tc_ty(cx: &ctxt,
2046 ty: t,
2047 cache: &mut HashMap<uint, TypeContents>) -> TypeContents
2048 {
2049 // Subtle: Note that we are *not* using cx.tc_cache here but rather a
2050 // private cache for this walk. This is needed in the case of cyclic
2051 // types like:
2052 //
2053 // struct List { next: Box<Option<List>>, ... }
2054 //
2055 // When computing the type contents of such a type, we wind up deeply
2056 // recursing as we go. So when we encounter the recursive reference
2057 // to List, we temporarily use TC::None as its contents. Later we'll
2058 // patch up the cache with the correct value, once we've computed it
2059 // (this is basically a co-inductive process, if that helps). So in
2060 // the end we'll compute TC::OwnsOwned, in this case.
2061 //
2062 // The problem is, as we are doing the computation, we will also
2063 // compute an *intermediate* contents for, e.g., Option<List> of
2064 // TC::None. This is ok during the computation of List itself, but if
2065 // we stored this intermediate value into cx.tc_cache, then later
2066 // requests for the contents of Option<List> would also yield TC::None
2067 // which is incorrect. This value was computed based on the crutch
2068 // value for the type contents of list. The correct value is
2069 // TC::OwnsOwned. This manifested as issue #4821.
2070 let ty_id = type_id(ty);
2071 match cache.find(&ty_id) {
2072 Some(tc) => { return *tc; }
2073 None => {}
2074 }
2075 match cx.tc_cache.borrow().find(&ty_id) { // Must check both caches!
2076 Some(tc) => { return *tc; }
2077 None => {}
2078 }
2079 cache.insert(ty_id, TC::None);
2080
2081 let result = match get(ty).sty {
2082 // Scalar and unique types are sendable, and durable
2083 ty_nil | ty_bot | ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
2084 ty_bare_fn(_) | ty::ty_char | ty_str => {
2085 TC::None
2086 }
2087
2088 ty_closure(ref c) => {
2089 closure_contents(cx, *c)
2090 }
2091
2092 ty_box(typ) => {
2093 tc_ty(cx, typ, cache).managed_pointer()
2094 }
2095
2096 ty_uniq(typ) => {
2097 match get(typ).sty {
2098 ty_str => TC::OwnsOwned,
2099 _ => tc_ty(cx, typ, cache).owned_pointer(),
2100 }
2101 }
2102
2103 ty_trait(box ty::TyTrait { store, bounds, .. }) => {
2104 object_contents(cx, store, bounds)
2105 }
2106
2107 ty_ptr(ref mt) => {
2108 tc_ty(cx, mt.ty, cache).unsafe_pointer()
2109 }
2110
2111 ty_rptr(r, ref mt) => {
2112 match get(mt.ty).sty {
2113 ty_str => borrowed_contents(r, ast::MutImmutable),
2114 _ => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(r, mt.mutbl)),
2115 }
2116 }
2117
2118 ty_vec(mt, _) => {
2119 tc_mt(cx, mt, cache)
2120 }
2121
2122 ty_struct(did, ref substs) => {
2123 let flds = struct_fields(cx, did, substs);
2124 let mut res =
2125 TypeContents::union(flds.as_slice(),
2126 |f| tc_mt(cx, f.mt, cache));
2127 if ty::has_dtor(cx, did) {
2128 res = res | TC::OwnsDtor;
2129 }
2130 apply_lang_items(cx, did, res)
2131 }
2132
2133 ty_tup(ref tys) => {
2134 TypeContents::union(tys.as_slice(),
2135 |ty| tc_ty(cx, *ty, cache))
2136 }
2137
2138 ty_enum(did, ref substs) => {
2139 let variants = substd_enum_variants(cx, did, substs);
2140 let res =
2141 TypeContents::union(variants.as_slice(), |variant| {
2142 TypeContents::union(variant.args.as_slice(),
2143 |arg_ty| {
2144 tc_ty(cx, *arg_ty, cache)
2145 })
2146 });
2147 apply_lang_items(cx, did, res)
2148 }
2149
2150 ty_param(p) => {
2151 // We only ever ask for the kind of types that are defined in
2152 // the current crate; therefore, the only type parameters that
2153 // could be in scope are those defined in the current crate.
2154 // If this assertion failures, it is likely because of a
2155 // failure in the cross-crate inlining code to translate a
2156 // def-id.
2157 assert_eq!(p.def_id.krate, ast::LOCAL_CRATE);
2158
2159 let ty_param_defs = cx.ty_param_defs.borrow();
2160 let tp_def = ty_param_defs.get(&p.def_id.node);
2161 kind_bounds_to_contents(cx,
2162 tp_def.bounds.builtin_bounds,
2163 tp_def.bounds.trait_bounds.as_slice())
2164 }
2165
2166 ty_self(def_id) => {
2167 // FIXME(#4678)---self should just be a ty param
2168
2169 // Self may be bounded if the associated trait has builtin kinds
2170 // for supertraits. If so we can use those bounds.
2171 let trait_def = lookup_trait_def(cx, def_id);
2172 let traits = [trait_def.trait_ref.clone()];
2173 kind_bounds_to_contents(cx, trait_def.bounds, traits)
2174 }
2175
2176 ty_infer(_) => {
2177 // This occurs during coherence, but shouldn't occur at other
2178 // times.
2179 TC::All
2180 }
2181
2182 ty_err => {
2183 cx.sess.bug("asked to compute contents of error type");
2184 }
2185 };
2186
2187 cache.insert(ty_id, result);
2188 return result;
2189 }
2190
2191 fn tc_mt(cx: &ctxt,
2192 mt: mt,
2193 cache: &mut HashMap<uint, TypeContents>) -> TypeContents
2194 {
2195 let mc = TC::ReachesMutable.when(mt.mutbl == MutMutable);
2196 mc | tc_ty(cx, mt.ty, cache)
2197 }
2198
2199 fn apply_lang_items(cx: &ctxt,
2200 did: ast::DefId,
2201 tc: TypeContents)
2202 -> TypeContents {
2203 if Some(did) == cx.lang_items.no_send_bound() {
2204 tc | TC::ReachesNonsendAnnot
2205 } else if Some(did) == cx.lang_items.managed_bound() {
2206 tc | TC::Managed
2207 } else if Some(did) == cx.lang_items.no_copy_bound() {
2208 tc | TC::OwnsAffine
2209 } else if Some(did) == cx.lang_items.no_share_bound() {
2210 tc | TC::ReachesNoShare
2211 } else if Some(did) == cx.lang_items.unsafe_type() {
2212 // FIXME(#13231): This shouldn't be needed after
2213 // opt-in built-in bounds are implemented.
2214 (tc | TC::InteriorUnsafe) - TC::Nonsharable
2215 } else {
2216 tc
2217 }
2218 }
2219
2220 fn borrowed_contents(region: ty::Region,
2221 mutbl: ast::Mutability)
2222 -> TypeContents {
2223 /*!
2224 * Type contents due to containing a reference
2225 * with the region `region` and borrow kind `bk`
2226 */
2227
2228 let b = match mutbl {
2229 ast::MutMutable => TC::ReachesMutable | TC::OwnsAffine,
2230 ast::MutImmutable => TC::None,
2231 };
2232 b | (TC::ReachesBorrowed).when(region != ty::ReStatic)
2233 }
2234
2235 fn closure_contents(cx: &ctxt, cty: &ClosureTy) -> TypeContents {
2236 // Closure contents are just like trait contents, but with potentially
2237 // even more stuff.
2238 let st = object_contents(cx, cty.store, cty.bounds);
2239
2240 // This also prohibits "@once fn" from being copied, which allows it to
2241 // be called. Neither way really makes much sense.
2242 let ot = match cty.onceness {
2243 ast::Once => TC::OwnsAffine,
2244 ast::Many => TC::None,
2245 };
2246
2247 st | ot
2248 }
2249
2250 fn object_contents(cx: &ctxt,
2251 store: TraitStore,
2252 bounds: BuiltinBounds)
2253 -> TypeContents {
2254 // These are the type contents of the (opaque) interior
2255 let contents = kind_bounds_to_contents(cx, bounds, []);
2256
2257 match store {
2258 UniqTraitStore => {
2259 contents.owned_pointer()
2260 }
2261 RegionTraitStore(r, mutbl) => {
2262 contents.reference(borrowed_contents(r, mutbl))
2263 }
2264 }
2265 }
2266
2267 fn kind_bounds_to_contents(cx: &ctxt,
2268 bounds: BuiltinBounds,
2269 traits: &[Rc<TraitRef>])
2270 -> TypeContents {
2271 let _i = indenter();
2272 let mut tc = TC::All;
2273 each_inherited_builtin_bound(cx, bounds, traits, |bound| {
2274 tc = tc - match bound {
2275 BoundStatic => TC::Nonstatic,
2276 BoundSend => TC::Nonsendable,
2277 BoundSized => TC::Nonsized,
2278 BoundCopy => TC::Noncopy,
2279 BoundShare => TC::Nonsharable,
2280 };
2281 });
2282 return tc;
2283
2284 // Iterates over all builtin bounds on the type parameter def, including
2285 // those inherited from traits with builtin-kind-supertraits.
2286 fn each_inherited_builtin_bound(cx: &ctxt,
2287 bounds: BuiltinBounds,
2288 traits: &[Rc<TraitRef>],
2289 f: |BuiltinBound|) {
2290 for bound in bounds.iter() {
2291 f(bound);
2292 }
2293
2294 each_bound_trait_and_supertraits(cx, traits, |trait_ref| {
2295 let trait_def = lookup_trait_def(cx, trait_ref.def_id);
2296 for bound in trait_def.bounds.iter() {
2297 f(bound);
2298 }
2299 true
2300 });
2301 }
2302 }
2303 }
2304
2305 pub fn type_moves_by_default(cx: &ctxt, ty: t) -> bool {
2306 type_contents(cx, ty).moves_by_default(cx)
2307 }
2308
2309 // True if instantiating an instance of `r_ty` requires an instance of `r_ty`.
2310 pub fn is_instantiable(cx: &ctxt, r_ty: t) -> bool {
2311 fn type_requires(cx: &ctxt, seen: &mut Vec<DefId>,
2312 r_ty: t, ty: t) -> bool {
2313 debug!("type_requires({}, {})?",
2314 ::util::ppaux::ty_to_str(cx, r_ty),
2315 ::util::ppaux::ty_to_str(cx, ty));
2316
2317 let r = {
2318 get(r_ty).sty == get(ty).sty ||
2319 subtypes_require(cx, seen, r_ty, ty)
2320 };
2321
2322 debug!("type_requires({}, {})? {}",
2323 ::util::ppaux::ty_to_str(cx, r_ty),
2324 ::util::ppaux::ty_to_str(cx, ty),
2325 r);
2326 return r;
2327 }
2328
2329 fn subtypes_require(cx: &ctxt, seen: &mut Vec<DefId>,
2330 r_ty: t, ty: t) -> bool {
2331 debug!("subtypes_require({}, {})?",
2332 ::util::ppaux::ty_to_str(cx, r_ty),
2333 ::util::ppaux::ty_to_str(cx, ty));
2334
2335 let r = match get(ty).sty {
2336 // fixed length vectors need special treatment compared to
2337 // normal vectors, since they don't necessarily have the
2338 // possibility to have length zero.
2339 ty_vec(_, Some(0)) => false, // don't need no contents
2340 ty_vec(mt, Some(_)) => type_requires(cx, seen, r_ty, mt.ty),
2341
2342 ty_nil |
2343 ty_bot |
2344 ty_bool |
2345 ty_char |
2346 ty_int(_) |
2347 ty_uint(_) |
2348 ty_float(_) |
2349 ty_str |
2350 ty_bare_fn(_) |
2351 ty_closure(_) |
2352 ty_infer(_) |
2353 ty_err |
2354 ty_param(_) |
2355 ty_self(_) |
2356 ty_vec(_, None) => {
2357 false
2358 }
2359 ty_box(typ) | ty_uniq(typ) => {
2360 type_requires(cx, seen, r_ty, typ)
2361 }
2362 ty_rptr(_, ref mt) => {
2363 type_requires(cx, seen, r_ty, mt.ty)
2364 }
2365
2366 ty_ptr(..) => {
2367 false // unsafe ptrs can always be NULL
2368 }
2369
2370 ty_trait(..) => {
2371 false
2372 }
2373
2374 ty_struct(ref did, _) if seen.contains(did) => {
2375 false
2376 }
2377
2378 ty_struct(did, ref substs) => {
2379 seen.push(did);
2380 let fields = struct_fields(cx, did, substs);
2381 let r = fields.iter().any(|f| type_requires(cx, seen, r_ty, f.mt.ty));
2382 seen.pop().unwrap();
2383 r
2384 }
2385
2386 ty_tup(ref ts) => {
2387 ts.iter().any(|t| type_requires(cx, seen, r_ty, *t))
2388 }
2389
2390 ty_enum(ref did, _) if seen.contains(did) => {
2391 false
2392 }
2393
2394 ty_enum(did, ref substs) => {
2395 seen.push(did);
2396 let vs = enum_variants(cx, did);
2397 let r = !vs.is_empty() && vs.iter().all(|variant| {
2398 variant.args.iter().any(|aty| {
2399 let sty = subst(cx, substs, *aty);
2400 type_requires(cx, seen, r_ty, sty)
2401 })
2402 });
2403 seen.pop().unwrap();
2404 r
2405 }
2406 };
2407
2408 debug!("subtypes_require({}, {})? {}",
2409 ::util::ppaux::ty_to_str(cx, r_ty),
2410 ::util::ppaux::ty_to_str(cx, ty),
2411 r);
2412
2413 return r;
2414 }
2415
2416 let mut seen = Vec::new();
2417 !subtypes_require(cx, &mut seen, r_ty, r_ty)
2418 }
2419
2420 /// Describes whether a type is representable. For types that are not
2421 /// representable, 'SelfRecursive' and 'ContainsRecursive' are used to
2422 /// distinguish between types that are recursive with themselves and types that
2423 /// contain a different recursive type. These cases can therefore be treated
2424 /// differently when reporting errors.
2425 #[deriving(Eq)]
2426 pub enum Representability {
2427 Representable,
2428 SelfRecursive,
2429 ContainsRecursive,
2430 }
2431
2432 /// Check whether a type is representable. This means it cannot contain unboxed
2433 /// structural recursion. This check is needed for structs and enums.
2434 pub fn is_type_representable(cx: &ctxt, sp: Span, ty: t) -> Representability {
2435
2436 // Iterate until something non-representable is found
2437 fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
2438 mut iter: It) -> Representability {
2439 for ty in iter {
2440 let r = type_structurally_recursive(cx, sp, seen, ty);
2441 if r != Representable {
2442 return r
2443 }
2444 }
2445 Representable
2446 }
2447
2448 // Does the type `ty` directly (without indirection through a pointer)
2449 // contain any types on stack `seen`?
2450 fn type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
2451 ty: t) -> Representability {
2452 debug!("type_structurally_recursive: {}",
2453 ::util::ppaux::ty_to_str(cx, ty));
2454
2455 // Compare current type to previously seen types
2456 match get(ty).sty {
2457 ty_struct(did, _) |
2458 ty_enum(did, _) => {
2459 for (i, &seen_did) in seen.iter().enumerate() {
2460 if did == seen_did {
2461 return if i == 0 { SelfRecursive }
2462 else { ContainsRecursive }
2463 }
2464 }
2465 }
2466 _ => (),
2467 }
2468
2469 // Check inner types
2470 match get(ty).sty {
2471 // Tuples
2472 ty_tup(ref ts) => {
2473 find_nonrepresentable(cx, sp, seen, ts.iter().map(|t| *t))
2474 }
2475 // Fixed-length vectors.
2476 // FIXME(#11924) Behavior undecided for zero-length vectors.
2477 ty_vec(mt, Some(_)) => {
2478 type_structurally_recursive(cx, sp, seen, mt.ty)
2479 }
2480
2481 // Push struct and enum def-ids onto `seen` before recursing.
2482 ty_struct(did, ref substs) => {
2483 seen.push(did);
2484 let fields = struct_fields(cx, did, substs);
2485 let r = find_nonrepresentable(cx, sp, seen,
2486 fields.iter().map(|f| f.mt.ty));
2487 seen.pop();
2488 r
2489 }
2490 ty_enum(did, ref substs) => {
2491 seen.push(did);
2492 let vs = enum_variants(cx, did);
2493
2494 let mut r = Representable;
2495 for variant in vs.iter() {
2496 let iter = variant.args.iter().map(|aty| {
2497 aty.subst_spanned(cx, substs, Some(sp))
2498 });
2499 r = find_nonrepresentable(cx, sp, seen, iter);
2500
2501 if r != Representable { break }
2502 }
2503
2504 seen.pop();
2505 r
2506 }
2507
2508 _ => Representable,
2509 }
2510 }
2511
2512 debug!("is_type_representable: {}",
2513 ::util::ppaux::ty_to_str(cx, ty));
2514
2515 // To avoid a stack overflow when checking an enum variant or struct that
2516 // contains a different, structurally recursive type, maintain a stack
2517 // of seen types and check recursion for each of them (issues #3008, #3779).
2518 let mut seen: Vec<DefId> = Vec::new();
2519 type_structurally_recursive(cx, sp, &mut seen, ty)
2520 }
2521
2522 pub fn type_is_trait(ty: t) -> bool {
2523 match get(ty).sty {
2524 ty_trait(..) => true,
2525 _ => false
2526 }
2527 }
2528
2529 pub fn type_is_integral(ty: t) -> bool {
2530 match get(ty).sty {
2531 ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true,
2532 _ => false
2533 }
2534 }
2535
2536 pub fn type_is_uint(ty: t) -> bool {
2537 match get(ty).sty {
2538 ty_infer(IntVar(_)) | ty_uint(ast::TyU) => true,
2539 _ => false
2540 }
2541 }
2542
2543 pub fn type_is_char(ty: t) -> bool {
2544 match get(ty).sty {
2545 ty_char => true,
2546 _ => false
2547 }
2548 }
2549
2550 pub fn type_is_bare_fn(ty: t) -> bool {
2551 match get(ty).sty {
2552 ty_bare_fn(..) => true,
2553 _ => false
2554 }
2555 }
2556
2557 pub fn type_is_fp(ty: t) -> bool {
2558 match get(ty).sty {
2559 ty_infer(FloatVar(_)) | ty_float(_) => true,
2560 _ => false
2561 }
2562 }
2563
2564 pub fn type_is_numeric(ty: t) -> bool {
2565 return type_is_integral(ty) || type_is_fp(ty);
2566 }
2567
2568 pub fn type_is_signed(ty: t) -> bool {
2569 match get(ty).sty {
2570 ty_int(_) => true,
2571 _ => false
2572 }
2573 }
2574
2575 pub fn type_is_machine(ty: t) -> bool {
2576 match get(ty).sty {
2577 ty_int(ast::TyI) | ty_uint(ast::TyU) => false,
2578 ty_int(..) | ty_uint(..) | ty_float(..) => true,
2579 _ => false
2580 }
2581 }
2582
2583 // Is the type's representation size known at compile time?
2584 #[allow(dead_code)] // leaving in for DST
2585 pub fn type_is_sized(cx: &ctxt, ty: ty::t) -> bool {
2586 type_contents(cx, ty).is_sized(cx)
2587 }
2588
2589 // Whether a type is enum like, that is an enum type with only nullary
2590 // constructors
2591 pub fn type_is_c_like_enum(cx: &ctxt, ty: t) -> bool {
2592 match get(ty).sty {
2593 ty_enum(did, _) => {
2594 let variants = enum_variants(cx, did);
2595 if variants.len() == 0 {
2596 false
2597 } else {
2598 variants.iter().all(|v| v.args.len() == 0)
2599 }
2600 }
2601 _ => false
2602 }
2603 }
2604
2605 // Returns the type and mutability of *t.
2606 //
2607 // The parameter `explicit` indicates if this is an *explicit* dereference.
2608 // Some types---notably unsafe ptrs---can only be dereferenced explicitly.
2609 pub fn deref(t: t, explicit: bool) -> Option<mt> {
2610 match get(t).sty {
2611 ty_box(typ) | ty_uniq(typ) => match get(typ).sty {
2612 // Don't deref ~[] etc., might need to generalise this to all DST.
2613 ty_vec(_, None) | ty_str => None,
2614 _ => Some(mt {
2615 ty: typ,
2616 mutbl: ast::MutImmutable,
2617 }),
2618 },
2619 ty_rptr(_, mt) => match get(mt.ty).sty {
2620 // Don't deref &[], might need to generalise this to all DST.
2621 ty_vec(_, None) | ty_str => None,
2622 _ => Some(mt),
2623 },
2624 ty_ptr(mt) if explicit => Some(mt),
2625 _ => None
2626 }
2627 }
2628
2629 // Returns the type of t[i]
2630 pub fn index(t: t) -> Option<mt> {
2631 match get(t).sty {
2632 ty_vec(mt, Some(_)) => Some(mt),
2633 ty_ptr(mt{ty: t, ..}) | ty_rptr(_, mt{ty: t, ..}) |
2634 ty_box(t) | ty_uniq(t) => match get(t).sty {
2635 ty_vec(mt, None) => Some(mt),
2636 ty_str => Some(mt {ty: mk_u8(), mutbl: ast::MutImmutable}),
2637 _ => None,
2638 },
2639 _ => None
2640 }
2641 }
2642
2643 pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc<ty::TraitRef> {
2644 match cx.trait_refs.borrow().find(&id) {
2645 Some(t) => t.clone(),
2646 None => cx.sess.bug(
2647 format!("node_id_to_trait_ref: no trait ref for node `{}`",
2648 cx.map.node_to_str(id)))
2649 }
2650 }
2651
2652 pub fn try_node_id_to_type(cx: &ctxt, id: ast::NodeId) -> Option<t> {
2653 cx.node_types.borrow().find_copy(&(id as uint))
2654 }
2655
2656 pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
2657 match try_node_id_to_type(cx, id) {
2658 Some(t) => t,
2659 None => cx.sess.bug(
2660 format!("node_id_to_type: no type for node `{}`",
2661 cx.map.node_to_str(id)))
2662 }
2663 }
2664
2665 pub fn node_id_to_type_opt(cx: &ctxt, id: ast::NodeId) -> Option<t> {
2666 match cx.node_types.borrow().find(&(id as uint)) {
2667 Some(&t) => Some(t),
2668 None => None
2669 }
2670 }
2671
2672 // FIXME(pcwalton): Makes a copy, bleh. Probably better to not do that.
2673 pub fn node_id_to_type_params(cx: &ctxt, id: ast::NodeId) -> Vec<t> {
2674 match cx.node_type_substs.borrow().find(&id) {
2675 None => return Vec::new(),
2676 Some(ts) => return (*ts).clone(),
2677 }
2678 }
2679
2680 pub fn fn_is_variadic(fty: t) -> bool {
2681 match get(fty).sty {
2682 ty_bare_fn(ref f) => f.sig.variadic,
2683 ty_closure(ref f) => f.sig.variadic,
2684 ref s => {
2685 fail!("fn_is_variadic() called on non-fn type: {:?}", s)
2686 }
2687 }
2688 }
2689
2690 pub fn ty_fn_sig(fty: t) -> FnSig {
2691 match get(fty).sty {
2692 ty_bare_fn(ref f) => f.sig.clone(),
2693 ty_closure(ref f) => f.sig.clone(),
2694 ref s => {
2695 fail!("ty_fn_sig() called on non-fn type: {:?}", s)
2696 }
2697 }
2698 }
2699
2700 // Type accessors for substructures of types
2701 pub fn ty_fn_args(fty: t) -> Vec<t> {
2702 match get(fty).sty {
2703 ty_bare_fn(ref f) => f.sig.inputs.clone(),
2704 ty_closure(ref f) => f.sig.inputs.clone(),
2705 ref s => {
2706 fail!("ty_fn_args() called on non-fn type: {:?}", s)
2707 }
2708 }
2709 }
2710
2711 pub fn ty_closure_store(fty: t) -> TraitStore {
2712 match get(fty).sty {
2713 ty_closure(ref f) => f.store,
2714 ref s => {
2715 fail!("ty_closure_store() called on non-closure type: {:?}", s)
2716 }
2717 }
2718 }
2719
2720 pub fn ty_fn_ret(fty: t) -> t {
2721 match get(fty).sty {
2722 ty_bare_fn(ref f) => f.sig.output,
2723 ty_closure(ref f) => f.sig.output,
2724 ref s => {
2725 fail!("ty_fn_ret() called on non-fn type: {:?}", s)
2726 }
2727 }
2728 }
2729
2730 pub fn is_fn_ty(fty: t) -> bool {
2731 match get(fty).sty {
2732 ty_bare_fn(_) => true,
2733 ty_closure(_) => true,
2734 _ => false
2735 }
2736 }
2737
2738 pub fn ty_region(tcx: &ctxt,
2739 span: Span,
2740 ty: t) -> Region {
2741 match get(ty).sty {
2742 ty_rptr(r, _) => r,
2743 ref s => {
2744 tcx.sess.span_bug(
2745 span,
2746 format!("ty_region() invoked on in appropriate ty: {:?}", s));
2747 }
2748 }
2749 }
2750
2751 // Returns the type of a pattern as a monotype. Like @expr_ty, this function
2752 // doesn't provide type parameter substitutions.
2753 pub fn pat_ty(cx: &ctxt, pat: &ast::Pat) -> t {
2754 return node_id_to_type(cx, pat.id);
2755 }
2756
2757
2758 // Returns the type of an expression as a monotype.
2759 //
2760 // NB (1): This is the PRE-ADJUSTMENT TYPE for the expression. That is, in
2761 // some cases, we insert `AutoAdjustment` annotations such as auto-deref or
2762 // auto-ref. The type returned by this function does not consider such
2763 // adjustments. See `expr_ty_adjusted()` instead.
2764 //
2765 // NB (2): This type doesn't provide type parameter substitutions; e.g. if you
2766 // ask for the type of "id" in "id(3)", it will return "fn(&int) -> int"
2767 // instead of "fn(t) -> T with T = int". If this isn't what you want, see
2768 // expr_ty_params_and_ty() below.
2769 pub fn expr_ty(cx: &ctxt, expr: &ast::Expr) -> t {
2770 return node_id_to_type(cx, expr.id);
2771 }
2772
2773 pub fn expr_ty_opt(cx: &ctxt, expr: &ast::Expr) -> Option<t> {
2774 return node_id_to_type_opt(cx, expr.id);
2775 }
2776
2777 pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t {
2778 /*!
2779 *
2780 * Returns the type of `expr`, considering any `AutoAdjustment`
2781 * entry recorded for that expression.
2782 *
2783 * It would almost certainly be better to store the adjusted ty in with
2784 * the `AutoAdjustment`, but I opted not to do this because it would
2785 * require serializing and deserializing the type and, although that's not
2786 * hard to do, I just hate that code so much I didn't want to touch it
2787 * unless it was to fix it properly, which seemed a distraction from the
2788 * task at hand! -nmatsakis
2789 */
2790
2791 adjust_ty(cx, expr.span, expr.id, expr_ty(cx, expr),
2792 cx.adjustments.borrow().find(&expr.id),
2793 |method_call| cx.method_map.borrow().find(&method_call).map(|method| method.ty))
2794 }
2795
2796 pub fn expr_span(cx: &ctxt, id: NodeId) -> Span {
2797 match cx.map.find(id) {
2798 Some(ast_map::NodeExpr(e)) => {
2799 e.span
2800 }
2801 Some(f) => {
2802 cx.sess.bug(format!("Node id {} is not an expr: {:?}",
2803 id, f));
2804 }
2805 None => {
2806 cx.sess.bug(format!("Node id {} is not present \
2807 in the node map", id));
2808 }
2809 }
2810 }
2811
2812 pub fn local_var_name_str(cx: &ctxt, id: NodeId) -> InternedString {
2813 match cx.map.find(id) {
2814 Some(ast_map::NodeLocal(pat)) => {
2815 match pat.node {
2816 ast::PatIdent(_, ref path, _) => {
2817 token::get_ident(ast_util::path_to_ident(path))
2818 }
2819 _ => {
2820 cx.sess.bug(
2821 format!("Variable id {} maps to {:?}, not local",
2822 id, pat));
2823 }
2824 }
2825 }
2826 r => {
2827 cx.sess.bug(
2828 format!("Variable id {} maps to {:?}, not local",
2829 id, r));
2830 }
2831 }
2832 }
2833
2834 pub fn adjust_ty(cx: &ctxt,
2835 span: Span,
2836 expr_id: ast::NodeId,
2837 unadjusted_ty: ty::t,
2838 adjustment: Option<&AutoAdjustment>,
2839 method_type: |typeck::MethodCall| -> Option<ty::t>)
2840 -> ty::t {
2841 /*! See `expr_ty_adjusted` */
2842
2843 return match adjustment {
2844 Some(adjustment) => {
2845 match *adjustment {
2846 AutoAddEnv(store) => {
2847 match ty::get(unadjusted_ty).sty {
2848 ty::ty_bare_fn(ref b) => {
2849 ty::mk_closure(
2850 cx,
2851 ty::ClosureTy {fn_style: b.fn_style,
2852 onceness: ast::Many,
2853 store: store,
2854 bounds: ty::AllBuiltinBounds(),
2855 sig: b.sig.clone()})
2856 }
2857 ref b => {
2858 cx.sess.bug(
2859 format!("add_env adjustment on non-bare-fn: \
2860 {:?}",
2861 b));
2862 }
2863 }
2864 }
2865
2866 AutoDerefRef(ref adj) => {
2867 let mut adjusted_ty = unadjusted_ty;
2868
2869 if !ty::type_is_error(adjusted_ty) {
2870 for i in range(0, adj.autoderefs) {
2871 let method_call = typeck::MethodCall::autoderef(expr_id, i as u32);
2872 match method_type(method_call) {
2873 Some(method_ty) => {
2874 adjusted_ty = ty_fn_ret(method_ty);
2875 }
2876 None => {}
2877 }
2878 match deref(adjusted_ty, true) {
2879 Some(mt) => { adjusted_ty = mt.ty; }
2880 None => {
2881 cx.sess.span_bug(
2882 span,
2883 format!("the {}th autoderef failed: \
2884 {}",
2885 i,
2886 ty_to_str(cx, adjusted_ty)));
2887 }
2888 }
2889 }
2890 }
2891
2892 match adj.autoref {
2893 None => adjusted_ty,
2894 Some(ref autoref) => {
2895 match *autoref {
2896 AutoPtr(r, m) => {
2897 mk_rptr(cx, r, mt {
2898 ty: adjusted_ty,
2899 mutbl: m
2900 })
2901 }
2902
2903 AutoBorrowVec(r, m) => {
2904 borrow_vec(cx, span, r, m, adjusted_ty)
2905 }
2906
2907 AutoBorrowVecRef(r, m) => {
2908 adjusted_ty = borrow_vec(cx,
2909 span,
2910 r,
2911 m,
2912 adjusted_ty);
2913 mk_rptr(cx, r, mt {
2914 ty: adjusted_ty,
2915 mutbl: ast::MutImmutable
2916 })
2917 }
2918
2919 AutoUnsafe(m) => {
2920 mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
2921 }
2922
2923 AutoBorrowObj(r, m) => {
2924 borrow_obj(cx, span, r, m, adjusted_ty)
2925 }
2926 }
2927 }
2928 }
2929 }
2930
2931 AutoObject(store, bounds, def_id, ref substs) => {
2932 mk_trait(cx, def_id, substs.clone(), store, bounds)
2933 }
2934 }
2935 }
2936 None => unadjusted_ty
2937 };
2938
2939 fn borrow_vec(cx: &ctxt,
2940 span: Span,
2941 r: Region,
2942 m: ast::Mutability,
2943 ty: ty::t) -> ty::t {
2944 match get(ty).sty {
2945 ty_uniq(t) | ty_ptr(mt{ty: t, ..}) |
2946 ty_rptr(_, mt{ty: t, ..}) => match get(t).sty {
2947 ty::ty_vec(mt, None) => ty::mk_slice(cx, r, ty::mt {ty: mt.ty, mutbl: m}),
2948 ty::ty_str => ty::mk_str_slice(cx, r, m),
2949 _ => {
2950 cx.sess.span_bug(
2951 span,
2952 format!("borrow-vec associated with bad sty: {:?}", get(ty).sty));
2953 }
2954 },
2955 ty_vec(mt, Some(_)) => ty::mk_slice(cx, r, ty::mt {ty: mt.ty, mutbl: m}),
2956
2957 ref s => {
2958 cx.sess.span_bug(
2959 span,
2960 format!("borrow-vec associated with bad sty: {:?}", s));
2961 }
2962 }
2963 }
2964
2965 fn borrow_obj(cx: &ctxt, span: Span, r: Region,
2966 m: ast::Mutability, ty: ty::t) -> ty::t {
2967 match get(ty).sty {
2968 ty_trait(box ty::TyTrait {def_id, ref substs, bounds, .. }) => {
2969 ty::mk_trait(cx, def_id, substs.clone(),
2970 RegionTraitStore(r, m), bounds)
2971 }
2972 ref s => {
2973 cx.sess.span_bug(
2974 span,
2975 format!("borrow-trait-obj associated with bad sty: {:?}",
2976 s));
2977 }
2978 }
2979 }
2980 }
2981
2982 impl AutoRef {
2983 pub fn map_region(&self, f: |Region| -> Region) -> AutoRef {
2984 match *self {
2985 ty::AutoPtr(r, m) => ty::AutoPtr(f(r), m),
2986 ty::AutoBorrowVec(r, m) => ty::AutoBorrowVec(f(r), m),
2987 ty::AutoBorrowVecRef(r, m) => ty::AutoBorrowVecRef(f(r), m),
2988 ty::AutoUnsafe(m) => ty::AutoUnsafe(m),
2989 ty::AutoBorrowObj(r, m) => ty::AutoBorrowObj(f(r), m),
2990 }
2991 }
2992 }
2993
2994 pub struct ParamsTy {
2995 pub params: Vec<t>,
2996 pub ty: t
2997 }
2998
2999 #[allow(dead_code)] // this may be useful?
3000 pub fn expr_ty_params_and_ty(cx: &ctxt,
3001 expr: &ast::Expr)
3002 -> ParamsTy {
3003 ParamsTy {
3004 params: node_id_to_type_params(cx, expr.id),
3005 ty: node_id_to_type(cx, expr.id)
3006 }
3007 }
3008
3009 pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
3010 -> Rc<Vec<TypeParameterDef>> {
3011 match origin {
3012 typeck::MethodStatic(did) => {
3013 // n.b.: When we encode impl methods, the bounds
3014 // that we encode include both the impl bounds
3015 // and then the method bounds themselves...
3016 ty::lookup_item_type(tcx, did).generics.type_param_defs
3017 }
3018 typeck::MethodParam(typeck::MethodParam {
3019 trait_id: trt_id,
3020 method_num: n_mth, ..}) |
3021 typeck::MethodObject(typeck::MethodObject {
3022 trait_id: trt_id,
3023 method_num: n_mth, ..}) => {
3024 // ...trait methods bounds, in contrast, include only the
3025 // method bounds, so we must preprend the tps from the
3026 // trait itself. This ought to be harmonized.
3027 let trait_type_param_defs =
3028 Vec::from_slice(lookup_trait_def(tcx, trt_id).generics.type_param_defs());
3029 Rc::new(trait_type_param_defs.append(
3030 ty::trait_method(tcx, trt_id, n_mth).generics.type_param_defs()))
3031 }
3032 }
3033 }
3034
3035 pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def {
3036 match tcx.def_map.borrow().find(&expr.id) {
3037 Some(&def) => def,
3038 None => {
3039 tcx.sess.span_bug(expr.span, format!(
3040 "no def-map entry for expr {:?}", expr.id));
3041 }
3042 }
3043 }
3044
3045 pub fn expr_is_lval(tcx: &ctxt, e: &ast::Expr) -> bool {
3046 match expr_kind(tcx, e) {
3047 LvalueExpr => true,
3048 RvalueDpsExpr | RvalueDatumExpr | RvalueStmtExpr => false
3049 }
3050 }
3051
3052 /// We categorize expressions into three kinds. The distinction between
3053 /// lvalue/rvalue is fundamental to the language. The distinction between the
3054 /// two kinds of rvalues is an artifact of trans which reflects how we will
3055 /// generate code for that kind of expression. See trans/expr.rs for more
3056 /// information.
3057 pub enum ExprKind {
3058 LvalueExpr,
3059 RvalueDpsExpr,
3060 RvalueDatumExpr,
3061 RvalueStmtExpr
3062 }
3063
3064 pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
3065 if tcx.method_map.borrow().contains_key(&typeck::MethodCall::expr(expr.id)) {
3066 // Overloaded operations are generally calls, and hence they are
3067 // generated via DPS, but there are two exceptions:
3068 return match expr.node {
3069 // `a += b` has a unit result.
3070 ast::ExprAssignOp(..) => RvalueStmtExpr,
3071
3072 // the deref method invoked for `*a` always yields an `&T`
3073 ast::ExprUnary(ast::UnDeref, _) => LvalueExpr,
3074
3075 // in the general case, result could be any type, use DPS
3076 _ => RvalueDpsExpr
3077 };
3078 }
3079
3080 match expr.node {
3081 ast::ExprPath(..) => {
3082 match resolve_expr(tcx, expr) {
3083 ast::DefVariant(tid, vid, _) => {
3084 let variant_info = enum_variant_with_id(tcx, tid, vid);
3085 if variant_info.args.len() > 0u {
3086 // N-ary variant.
3087 RvalueDatumExpr
3088 } else {
3089 // Nullary variant.
3090 RvalueDpsExpr
3091 }
3092 }
3093
3094 ast::DefStruct(_) => {
3095 match get(expr_ty(tcx, expr)).sty {
3096 ty_bare_fn(..) => RvalueDatumExpr,
3097 _ => RvalueDpsExpr
3098 }
3099 }
3100
3101 // Fn pointers are just scalar values.
3102 ast::DefFn(..) | ast::DefStaticMethod(..) => RvalueDatumExpr,
3103
3104 // Note: there is actually a good case to be made that
3105 // DefArg's, particularly those of immediate type, ought to
3106 // considered rvalues.
3107 ast::DefStatic(..) |
3108 ast::DefBinding(..) |
3109 ast::DefUpvar(..) |
3110 ast::DefArg(..) |
3111 ast::DefLocal(..) => LvalueExpr,
3112
3113 def => {
3114 tcx.sess.span_bug(expr.span, format!(
3115 "uncategorized def for expr {:?}: {:?}",
3116 expr.id, def));
3117 }
3118 }
3119 }
3120
3121 ast::ExprUnary(ast::UnDeref, _) |
3122 ast::ExprField(..) |
3123 ast::ExprIndex(..) => {
3124 LvalueExpr
3125 }
3126
3127 ast::ExprCall(..) |
3128 ast::ExprMethodCall(..) |
3129 ast::ExprStruct(..) |
3130 ast::ExprTup(..) |
3131 ast::ExprIf(..) |
3132 ast::ExprMatch(..) |
3133 ast::ExprFnBlock(..) |
3134 ast::ExprProc(..) |
3135 ast::ExprBlock(..) |
3136 ast::ExprRepeat(..) |
3137 ast::ExprVstore(_, ast::ExprVstoreSlice) |
3138 ast::ExprVstore(_, ast::ExprVstoreMutSlice) |
3139 ast::ExprVec(..) => {
3140 RvalueDpsExpr
3141 }
3142
3143 ast::ExprLit(lit) if lit_is_str(lit) => {
3144 RvalueDpsExpr
3145 }
3146
3147 ast::ExprCast(..) => {
3148 match tcx.node_types.borrow().find(&(expr.id as uint)) {
3149 Some(&t) => {
3150 if type_is_trait(t) {
3151 RvalueDpsExpr
3152 } else {
3153 RvalueDatumExpr
3154 }
3155 }
3156 None => {
3157 // Technically, it should not happen that the expr is not
3158 // present within the table. However, it DOES happen
3159 // during type check, because the final types from the
3160 // expressions are not yet recorded in the tcx. At that
3161 // time, though, we are only interested in knowing lvalue
3162 // vs rvalue. It would be better to base this decision on
3163 // the AST type in cast node---but (at the time of this
3164 // writing) it's not easy to distinguish casts to traits
3165 // from other casts based on the AST. This should be
3166 // easier in the future, when casts to traits
3167 // would like @Foo, Box<Foo>, or &Foo.
3168 RvalueDatumExpr
3169 }
3170 }
3171 }
3172
3173 ast::ExprBreak(..) |
3174 ast::ExprAgain(..) |
3175 ast::ExprRet(..) |
3176 ast::ExprWhile(..) |
3177 ast::ExprLoop(..) |
3178 ast::ExprAssign(..) |
3179 ast::ExprInlineAsm(..) |
3180 ast::ExprAssignOp(..) => {
3181 RvalueStmtExpr
3182 }
3183
3184 ast::ExprForLoop(..) => fail!("non-desugared expr_for_loop"),
3185
3186 ast::ExprLit(_) | // Note: LitStr is carved out above
3187 ast::ExprUnary(..) |
3188 ast::ExprAddrOf(..) |
3189 ast::ExprBinary(..) |
3190 ast::ExprVstore(_, ast::ExprVstoreUniq) => {
3191 RvalueDatumExpr
3192 }
3193
3194 ast::ExprBox(place, _) => {
3195 // Special case `Box<T>` for now:
3196 let definition = match tcx.def_map.borrow().find(&place.id) {
3197 Some(&def) => def,
3198 None => fail!("no def for place"),
3199 };
3200 let def_id = ast_util::def_id_of_def(definition);
3201 match tcx.lang_items.items.get(ExchangeHeapLangItem as uint) {
3202 &Some(item_def_id) if def_id == item_def_id => {
3203 RvalueDatumExpr
3204 }
3205 &Some(_) | &None => RvalueDpsExpr,
3206 }
3207 }
3208
3209 ast::ExprParen(e) => expr_kind(tcx, e),
3210
3211 ast::ExprMac(..) => {
3212 tcx.sess.span_bug(
3213 expr.span,
3214 "macro expression remains after expansion");
3215 }
3216 }
3217 }
3218
3219 pub fn stmt_node_id(s: &ast::Stmt) -> ast::NodeId {
3220 match s.node {
3221 ast::StmtDecl(_, id) | StmtExpr(_, id) | StmtSemi(_, id) => {
3222 return id;
3223 }
3224 ast::StmtMac(..) => fail!("unexpanded macro in trans")
3225 }
3226 }
3227
3228 pub fn field_idx_strict(tcx: &ctxt, name: ast::Name, fields: &[field])
3229 -> uint {
3230 let mut i = 0u;
3231 for f in fields.iter() { if f.ident.name == name { return i; } i += 1u; }
3232 tcx.sess.bug(format!(
3233 "no field named `{}` found in the list of fields `{:?}`",
3234 token::get_name(name),
3235 fields.iter().map(|f| token::get_ident(f.ident).get().to_str()).collect::<Vec<~str>>()));
3236 }
3237
3238 pub fn method_idx(id: ast::Ident, meths: &[Rc<Method>]) -> Option<uint> {
3239 meths.iter().position(|m| m.ident == id)
3240 }
3241
3242 /// Returns a vector containing the indices of all type parameters that appear
3243 /// in `ty`. The vector may contain duplicates. Probably should be converted
3244 /// to a bitset or some other representation.
3245 pub fn param_tys_in_type(ty: t) -> Vec<param_ty> {
3246 let mut rslt = Vec::new();
3247 walk_ty(ty, |ty| {
3248 match get(ty).sty {
3249 ty_param(p) => {
3250 rslt.push(p);
3251 }
3252 _ => ()
3253 }
3254 });
3255 rslt
3256 }
3257
3258 pub fn ty_sort_str(cx: &ctxt, t: t) -> ~str {
3259 match get(t).sty {
3260 ty_nil | ty_bot | ty_bool | ty_char | ty_int(_) |
3261 ty_uint(_) | ty_float(_) | ty_str => {
3262 ::util::ppaux::ty_to_str(cx, t)
3263 }
3264
3265 ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
3266 ty_box(_) => "@-ptr".to_owned(),
3267 ty_uniq(_) => "box".to_owned(),
3268 ty_vec(_, _) => "vector".to_owned(),
3269 ty_ptr(_) => "*-ptr".to_owned(),
3270 ty_rptr(_, _) => "&-ptr".to_owned(),
3271 ty_bare_fn(_) => "extern fn".to_owned(),
3272 ty_closure(_) => "fn".to_owned(),
3273 ty_trait(ref inner) => format!("trait {}", item_path_str(cx, inner.def_id)),
3274 ty_struct(id, _) => format!("struct {}", item_path_str(cx, id)),
3275 ty_tup(_) => "tuple".to_owned(),
3276 ty_infer(TyVar(_)) => "inferred type".to_owned(),
3277 ty_infer(IntVar(_)) => "integral variable".to_owned(),
3278 ty_infer(FloatVar(_)) => "floating-point variable".to_owned(),
3279 ty_param(_) => "type parameter".to_owned(),
3280 ty_self(_) => "self".to_owned(),
3281 ty_err => "type error".to_owned()
3282 }
3283 }
3284
3285 pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
3286 /*!
3287 *
3288 * Explains the source of a type err in a short,
3289 * human readable way. This is meant to be placed in
3290 * parentheses after some larger message. You should
3291 * also invoke `note_and_explain_type_err()` afterwards
3292 * to present additional details, particularly when
3293 * it comes to lifetime-related errors. */
3294
3295 fn tstore_to_closure(s: &TraitStore) -> ~str {
3296 match s {
3297 &UniqTraitStore => "proc".to_owned(),
3298 &RegionTraitStore(..) => "closure".to_owned()
3299 }
3300 }
3301
3302 match *err {
3303 terr_mismatch => "types differ".to_owned(),
3304 terr_fn_style_mismatch(values) => {
3305 format!("expected {} fn but found {} fn",
3306 values.expected.to_str(), values.found.to_str())
3307 }
3308 terr_abi_mismatch(values) => {
3309 format!("expected {} fn but found {} fn",
3310 values.expected.to_str(), values.found.to_str())
3311 }
3312 terr_onceness_mismatch(values) => {
3313 format!("expected {} fn but found {} fn",
3314 values.expected.to_str(), values.found.to_str())
3315 }
3316 terr_sigil_mismatch(values) => {
3317 format!("expected {}, found {}",
3318 tstore_to_closure(&values.expected),
3319 tstore_to_closure(&values.found))
3320 }
3321 terr_mutability => "values differ in mutability".to_owned(),
3322 terr_box_mutability => "boxed values differ in mutability".to_owned(),
3323 terr_vec_mutability => "vectors differ in mutability".to_owned(),
3324 terr_ptr_mutability => "pointers differ in mutability".to_owned(),
3325 terr_ref_mutability => "references differ in mutability".to_owned(),
3326 terr_ty_param_size(values) => {
3327 format!("expected a type with {} type params \
3328 but found one with {} type params",
3329 values.expected, values.found)
3330 }
3331 terr_tuple_size(values) => {
3332 format!("expected a tuple with {} elements \
3333 but found one with {} elements",
3334 values.expected, values.found)
3335 }
3336 terr_record_size(values) => {
3337 format!("expected a record with {} fields \
3338 but found one with {} fields",
3339 values.expected, values.found)
3340 }
3341 terr_record_mutability => {
3342 "record elements differ in mutability".to_owned()
3343 }
3344 terr_record_fields(values) => {
3345 format!("expected a record with field `{}` but found one with field \
3346 `{}`",
3347 token::get_ident(values.expected),
3348 token::get_ident(values.found))
3349 }
3350 terr_arg_count => "incorrect number of function parameters".to_owned(),
3351 terr_regions_does_not_outlive(..) => {
3352 format!("lifetime mismatch")
3353 }
3354 terr_regions_not_same(..) => {
3355 format!("lifetimes are not the same")
3356 }
3357 terr_regions_no_overlap(..) => {
3358 format!("lifetimes do not intersect")
3359 }
3360 terr_regions_insufficiently_polymorphic(br, _) => {
3361 format!("expected bound lifetime parameter {}, \
3362 but found concrete lifetime",
3363 bound_region_ptr_to_str(cx, br))
3364 }
3365 terr_regions_overly_polymorphic(br, _) => {
3366 format!("expected concrete lifetime, \
3367 but found bound lifetime parameter {}",
3368 bound_region_ptr_to_str(cx, br))
3369 }
3370 terr_trait_stores_differ(_, ref values) => {
3371 format!("trait storage differs: expected `{}` but found `{}`",
3372 trait_store_to_str(cx, (*values).expected),
3373 trait_store_to_str(cx, (*values).found))
3374 }
3375 terr_sorts(values) => {
3376 format!("expected {} but found {}",
3377 ty_sort_str(cx, values.expected),
3378 ty_sort_str(cx, values.found))
3379 }
3380 terr_traits(values) => {
3381 format!("expected trait `{}` but found trait `{}`",
3382 item_path_str(cx, values.expected),
3383 item_path_str(cx, values.found))
3384 }
3385 terr_builtin_bounds(values) => {
3386 if values.expected.is_empty() {
3387 format!("expected no bounds but found `{}`",
3388 values.found.user_string(cx))
3389 } else if values.found.is_empty() {
3390 format!("expected bounds `{}` but found no bounds",
3391 values.expected.user_string(cx))
3392 } else {
3393 format!("expected bounds `{}` but found bounds `{}`",
3394 values.expected.user_string(cx),
3395 values.found.user_string(cx))
3396 }
3397 }
3398 terr_integer_as_char => {
3399 format!("expected an integral type but found `char`")
3400 }
3401 terr_int_mismatch(ref values) => {
3402 format!("expected `{}` but found `{}`",
3403 values.expected.to_str(),
3404 values.found.to_str())
3405 }
3406 terr_float_mismatch(ref values) => {
3407 format!("expected `{}` but found `{}`",
3408 values.expected.to_str(),
3409 values.found.to_str())
3410 }
3411 terr_variadic_mismatch(ref values) => {
3412 format!("expected {} fn but found {} function",
3413 if values.expected { "variadic" } else { "non-variadic" },
3414 if values.found { "variadic" } else { "non-variadic" })
3415 }
3416 }
3417 }
3418
3419 pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
3420 match *err {
3421 terr_regions_does_not_outlive(subregion, superregion) => {
3422 note_and_explain_region(cx, "", subregion, "...");
3423 note_and_explain_region(cx, "...does not necessarily outlive ",
3424 superregion, "");
3425 }
3426 terr_regions_not_same(region1, region2) => {
3427 note_and_explain_region(cx, "", region1, "...");
3428 note_and_explain_region(cx, "...is not the same lifetime as ",
3429 region2, "");
3430 }
3431 terr_regions_no_overlap(region1, region2) => {
3432 note_and_explain_region(cx, "", region1, "...");
3433 note_and_explain_region(cx, "...does not overlap ",
3434 region2, "");
3435 }
3436 terr_regions_insufficiently_polymorphic(_, conc_region) => {
3437 note_and_explain_region(cx,
3438 "concrete lifetime that was found is ",
3439 conc_region, "");
3440 }
3441 terr_regions_overly_polymorphic(_, conc_region) => {
3442 note_and_explain_region(cx,
3443 "expected concrete lifetime is ",
3444 conc_region, "");
3445 }
3446 _ => {}
3447 }
3448 }
3449
3450 pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
3451 cx.provided_method_sources.borrow().find(&id).map(|x| *x)
3452 }
3453
3454 pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<Rc<Method>> {
3455 if is_local(id) {
3456 match cx.map.find(id.node) {
3457 Some(ast_map::NodeItem(item)) => {
3458 match item.node {
3459 ItemTrait(_, _, _, ref ms) => {
3460 let (_, p) = ast_util::split_trait_methods(ms.as_slice());
3461 p.iter().map(|m| method(cx, ast_util::local_def(m.id))).collect()
3462 }
3463 _ => cx.sess.bug(format!("provided_trait_methods: `{}` is not a trait", id))
3464 }
3465 }
3466 _ => cx.sess.bug(format!("provided_trait_methods: `{}` is not a trait", id))
3467 }
3468 } else {
3469 csearch::get_provided_trait_methods(cx, id)
3470 }
3471 }
3472
3473 pub fn trait_supertraits(cx: &ctxt, id: ast::DefId) -> Rc<Vec<Rc<TraitRef>>> {
3474 // Check the cache.
3475 match cx.supertraits.borrow().find(&id) {
3476 Some(trait_refs) => { return trait_refs.clone(); }
3477 None => {} // Continue.
3478 }
3479
3480 // Not in the cache. It had better be in the metadata, which means it
3481 // shouldn't be local.
3482 assert!(!is_local(id));
3483
3484 // Get the supertraits out of the metadata and create the
3485 // TraitRef for each.
3486 let result = Rc::new(csearch::get_supertraits(cx, id));
3487 cx.supertraits.borrow_mut().insert(id, result.clone());
3488 result
3489 }
3490
3491 pub fn trait_ref_supertraits(cx: &ctxt, trait_ref: &ty::TraitRef) -> Vec<Rc<TraitRef>> {
3492 let supertrait_refs = trait_supertraits(cx, trait_ref.def_id);
3493 supertrait_refs.iter().map(
3494 |supertrait_ref| supertrait_ref.subst(cx, &trait_ref.substs)).collect()
3495 }
3496
3497 fn lookup_locally_or_in_crate_store<V:Clone>(
3498 descr: &str,
3499 def_id: ast::DefId,
3500 map: &mut DefIdMap<V>,
3501 load_external: || -> V) -> V {
3502 /*!
3503 * Helper for looking things up in the various maps
3504 * that are populated during typeck::collect (e.g.,
3505 * `cx.methods`, `cx.tcache`, etc). All of these share
3506 * the pattern that if the id is local, it should have
3507 * been loaded into the map by the `typeck::collect` phase.
3508 * If the def-id is external, then we have to go consult
3509 * the crate loading code (and cache the result for the future).
3510 */
3511
3512 match map.find_copy(&def_id) {
3513 Some(v) => { return v; }
3514 None => { }
3515 }
3516
3517 if def_id.krate == ast::LOCAL_CRATE {
3518 fail!("No def'n found for {:?} in tcx.{}", def_id, descr);
3519 }
3520 let v = load_external();
3521 map.insert(def_id, v.clone());
3522 v
3523 }
3524
3525 pub fn trait_method(cx: &ctxt, trait_did: ast::DefId, idx: uint) -> Rc<Method> {
3526 let method_def_id = *ty::trait_method_def_ids(cx, trait_did).get(idx);
3527 ty::method(cx, method_def_id)
3528 }
3529
3530
3531 pub fn trait_methods(cx: &ctxt, trait_did: ast::DefId) -> Rc<Vec<Rc<Method>>> {
3532 let mut trait_methods = cx.trait_methods_cache.borrow_mut();
3533 match trait_methods.find_copy(&trait_did) {
3534 Some(methods) => methods,
3535 None => {
3536 let def_ids = ty::trait_method_def_ids(cx, trait_did);
3537 let methods: Rc<Vec<Rc<Method>>> = Rc::new(def_ids.iter().map(|d| {
3538 ty::method(cx, *d)
3539 }).collect());
3540 trait_methods.insert(trait_did, methods.clone());
3541 methods
3542 }
3543 }
3544 }
3545
3546 pub fn method(cx: &ctxt, id: ast::DefId) -> Rc<Method> {
3547 lookup_locally_or_in_crate_store("methods", id,
3548 &mut *cx.methods.borrow_mut(), || {
3549 Rc::new(csearch::get_method(cx, id))
3550 })
3551 }
3552
3553 pub fn trait_method_def_ids(cx: &ctxt, id: ast::DefId) -> Rc<Vec<DefId>> {
3554 lookup_locally_or_in_crate_store("trait_method_def_ids",
3555 id,
3556 &mut *cx.trait_method_def_ids.borrow_mut(),
3557 || {
3558 Rc::new(csearch::get_trait_method_def_ids(&cx.sess.cstore, id))
3559 })
3560 }
3561
3562 pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<Rc<TraitRef>> {
3563 match cx.impl_trait_cache.borrow().find(&id) {
3564 Some(ret) => { return ret.clone(); }
3565 None => {}
3566 }
3567
3568 let ret = if id.krate == ast::LOCAL_CRATE {
3569 debug!("(impl_trait_ref) searching for trait impl {:?}", id);
3570 match cx.map.find(id.node) {
3571 Some(ast_map::NodeItem(item)) => {
3572 match item.node {
3573 ast::ItemImpl(_, ref opt_trait, _, _) => {
3574 match opt_trait {
3575 &Some(ref t) => {
3576 Some(ty::node_id_to_trait_ref(cx, t.ref_id))
3577 }
3578 &None => None
3579 }
3580 }
3581 _ => None
3582 }
3583 }
3584 _ => None
3585 }
3586 } else {
3587 csearch::get_impl_trait(cx, id)
3588 };
3589
3590 cx.impl_trait_cache.borrow_mut().insert(id, ret.clone());
3591 ret
3592 }
3593
3594 pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
3595 let def = *tcx.def_map.borrow()
3596 .find(&tr.ref_id)
3597 .expect("no def-map entry for trait");
3598 ast_util::def_id_of_def(def)
3599 }
3600
3601 pub fn try_add_builtin_trait(tcx: &ctxt,
3602 trait_def_id: ast::DefId,
3603 builtin_bounds: &mut BuiltinBounds) -> bool {
3604 //! Checks whether `trait_ref` refers to one of the builtin
3605 //! traits, like `Send`, and adds the corresponding
3606 //! bound to the set `builtin_bounds` if so. Returns true if `trait_ref`
3607 //! is a builtin trait.
3608
3609 match tcx.lang_items.to_builtin_kind(trait_def_id) {
3610 Some(bound) => { builtin_bounds.add(bound); true }
3611 None => false
3612 }
3613 }
3614
3615 pub fn ty_to_def_id(ty: t) -> Option<ast::DefId> {
3616 match get(ty).sty {
3617 ty_trait(box TyTrait { def_id: id, .. }) |
3618 ty_struct(id, _) |
3619 ty_enum(id, _) => Some(id),
3620 _ => None
3621 }
3622 }
3623
3624 // Enum information
3625 #[deriving(Clone)]
3626 pub struct VariantInfo {
3627 pub args: Vec<t>,
3628 pub arg_names: Option<Vec<ast::Ident> >,
3629 pub ctor_ty: t,
3630 pub name: ast::Ident,
3631 pub id: ast::DefId,
3632 pub disr_val: Disr,
3633 pub vis: Visibility
3634 }
3635
3636 impl VariantInfo {
3637
3638 /// Creates a new VariantInfo from the corresponding ast representation.
3639 ///
3640 /// Does not do any caching of the value in the type context.
3641 pub fn from_ast_variant(cx: &ctxt,
3642 ast_variant: &ast::Variant,
3643 discriminant: Disr) -> VariantInfo {
3644 let ctor_ty = node_id_to_type(cx, ast_variant.node.id);
3645
3646 match ast_variant.node.kind {
3647 ast::TupleVariantKind(ref args) => {
3648 let arg_tys = if args.len() > 0 {
3649 ty_fn_args(ctor_ty).iter().map(|a| *a).collect()
3650 } else {
3651 Vec::new()
3652 };
3653
3654 return VariantInfo {
3655 args: arg_tys,
3656 arg_names: None,
3657 ctor_ty: ctor_ty,
3658 name: ast_variant.node.name,
3659 id: ast_util::local_def(ast_variant.node.id),
3660 disr_val: discriminant,
3661 vis: ast_variant.node.vis
3662 };
3663 },
3664 ast::StructVariantKind(ref struct_def) => {
3665
3666 let fields: &[StructField] = struct_def.fields.as_slice();
3667
3668 assert!(fields.len() > 0);
3669
3670 let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
3671 let arg_names = fields.iter().map(|field| {
3672 match field.node.kind {
3673 NamedField(ident, _) => ident,
3674 UnnamedField(..) => cx.sess.bug(
3675 "enum_variants: all fields in struct must have a name")
3676 }
3677 }).collect();
3678
3679 return VariantInfo {
3680 args: arg_tys,
3681 arg_names: Some(arg_names),
3682 ctor_ty: ctor_ty,
3683 name: ast_variant.node.name,
3684 id: ast_util::local_def(ast_variant.node.id),
3685 disr_val: discriminant,
3686 vis: ast_variant.node.vis
3687 };
3688 }
3689 }
3690 }
3691 }
3692
3693 pub fn substd_enum_variants(cx: &ctxt,
3694 id: ast::DefId,
3695 substs: &substs)
3696 -> Vec<Rc<VariantInfo>> {
3697 enum_variants(cx, id).iter().map(|variant_info| {
3698 let substd_args = variant_info.args.iter()
3699 .map(|aty| subst(cx, substs, *aty)).collect();
3700
3701 let substd_ctor_ty = subst(cx, substs, variant_info.ctor_ty);
3702
3703 Rc::new(VariantInfo {
3704 args: substd_args,
3705 ctor_ty: substd_ctor_ty,
3706 ..(**variant_info).clone()
3707 })
3708 }).collect()
3709 }
3710
3711 pub fn item_path_str(cx: &ctxt, id: ast::DefId) -> ~str {
3712 with_path(cx, id, |path| ast_map::path_to_str(path)).to_owned()
3713 }
3714
3715 pub enum DtorKind {
3716 NoDtor,
3717 TraitDtor(DefId, bool)
3718 }
3719
3720 impl DtorKind {
3721 pub fn is_not_present(&self) -> bool {
3722 match *self {
3723 NoDtor => true,
3724 _ => false
3725 }
3726 }
3727
3728 pub fn is_present(&self) -> bool {
3729 !self.is_not_present()
3730 }
3731
3732 pub fn has_drop_flag(&self) -> bool {
3733 match self {
3734 &NoDtor => false,
3735 &TraitDtor(_, flag) => flag
3736 }
3737 }
3738 }
3739
3740 /* If struct_id names a struct with a dtor, return Some(the dtor's id).
3741 Otherwise return none. */
3742 pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
3743 match cx.destructor_for_type.borrow().find(&struct_id) {
3744 Some(&method_def_id) => {
3745 let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag");
3746
3747 TraitDtor(method_def_id, flag)
3748 }
3749 None => NoDtor,
3750 }
3751 }
3752
3753 pub fn has_dtor(cx: &ctxt, struct_id: DefId) -> bool {
3754 ty_dtor(cx, struct_id).is_present()
3755 }
3756
3757 pub fn with_path<T>(cx: &ctxt, id: ast::DefId, f: |ast_map::PathElems| -> T) -> T {
3758 if id.krate == ast::LOCAL_CRATE {
3759 cx.map.with_path(id.node, f)
3760 } else {
3761 f(ast_map::Values(csearch::get_item_path(cx, id).iter()).chain(None))
3762 }
3763 }
3764
3765 pub fn enum_is_univariant(cx: &ctxt, id: ast::DefId) -> bool {
3766 enum_variants(cx, id).len() == 1
3767 }
3768
3769 pub fn type_is_empty(cx: &ctxt, t: t) -> bool {
3770 match ty::get(t).sty {
3771 ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(),
3772 _ => false
3773 }
3774 }
3775
3776 pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> Rc<Vec<Rc<VariantInfo>>> {
3777 match cx.enum_var_cache.borrow().find(&id) {
3778 Some(variants) => return variants.clone(),
3779 _ => { /* fallthrough */ }
3780 }
3781
3782 let result = if ast::LOCAL_CRATE != id.krate {
3783 Rc::new(csearch::get_enum_variants(cx, id))
3784 } else {
3785 /*
3786 Although both this code and check_enum_variants in typeck/check
3787 call eval_const_expr, it should never get called twice for the same
3788 expr, since check_enum_variants also updates the enum_var_cache
3789 */
3790 match cx.map.get(id.node) {
3791 ast_map::NodeItem(item) => {
3792 match item.node {
3793 ast::ItemEnum(ref enum_definition, _) => {
3794 let mut last_discriminant: Option<Disr> = None;
3795 Rc::new(enum_definition.variants.iter().map(|&variant| {
3796
3797 let mut discriminant = match last_discriminant {
3798 Some(val) => val + 1,
3799 None => INITIAL_DISCRIMINANT_VALUE
3800 };
3801
3802 match variant.node.disr_expr {
3803 Some(e) => match const_eval::eval_const_expr_partial(cx, e) {
3804 Ok(const_eval::const_int(val)) => {
3805 discriminant = val as Disr
3806 }
3807 Ok(const_eval::const_uint(val)) => {
3808 discriminant = val as Disr
3809 }
3810 Ok(_) => {
3811 cx.sess
3812 .span_err(e.span,
3813 "expected signed integer constant");
3814 }
3815 Err(ref err) => {
3816 cx.sess
3817 .span_err(e.span,
3818 format!("expected constant: {}",
3819 *err));
3820 }
3821 },
3822 None => {}
3823 };
3824
3825 last_discriminant = Some(discriminant);
3826 Rc::new(VariantInfo::from_ast_variant(cx, variant,
3827 discriminant))
3828 }).collect())
3829 }
3830 _ => {
3831 cx.sess.bug("enum_variants: id not bound to an enum")
3832 }
3833 }
3834 }
3835 _ => cx.sess.bug("enum_variants: id not bound to an enum")
3836 }
3837 };
3838
3839 cx.enum_var_cache.borrow_mut().insert(id, result.clone());
3840 result
3841 }
3842
3843
3844 // Returns information about the enum variant with the given ID:
3845 pub fn enum_variant_with_id(cx: &ctxt,
3846 enum_id: ast::DefId,
3847 variant_id: ast::DefId)
3848 -> Rc<VariantInfo> {
3849 enum_variants(cx, enum_id).iter()
3850 .find(|variant| variant.id == variant_id)
3851 .expect("enum_variant_with_id(): no variant exists with that ID")
3852 .clone()
3853 }
3854
3855
3856 // If the given item is in an external crate, looks up its type and adds it to
3857 // the type cache. Returns the type parameters and type.
3858 pub fn lookup_item_type(cx: &ctxt,
3859 did: ast::DefId)
3860 -> ty_param_bounds_and_ty {
3861 lookup_locally_or_in_crate_store(
3862 "tcache", did, &mut *cx.tcache.borrow_mut(),
3863 || csearch::get_type(cx, did))
3864 }
3865
3866 pub fn lookup_impl_vtables(cx: &ctxt,
3867 did: ast::DefId)
3868 -> typeck::impl_res {
3869 lookup_locally_or_in_crate_store(
3870 "impl_vtables", did, &mut *cx.impl_vtables.borrow_mut(),
3871 || csearch::get_impl_vtables(cx, did) )
3872 }
3873
3874 /// Given the did of a trait, returns its canonical trait ref.
3875 pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> Rc<ty::TraitDef> {
3876 let mut trait_defs = cx.trait_defs.borrow_mut();
3877 match trait_defs.find_copy(&did) {
3878 Some(trait_def) => {
3879 // The item is in this crate. The caller should have added it to the
3880 // type cache already
3881 trait_def
3882 }
3883 None => {
3884 assert!(did.krate != ast::LOCAL_CRATE);
3885 let trait_def = Rc::new(csearch::get_trait_def(cx, did));
3886 trait_defs.insert(did, trait_def.clone());
3887 trait_def
3888 }
3889 }
3890 }
3891
3892 /// Iterate over meta_items of a definition.
3893 // (This should really be an iterator, but that would require csearch and
3894 // decoder to use iterators instead of higher-order functions.)
3895 pub fn each_attr(tcx: &ctxt, did: DefId, f: |@ast::MetaItem| -> bool) -> bool {
3896 if is_local(did) {
3897 let item = tcx.map.expect_item(did.node);
3898 item.attrs.iter().advance(|attr| f(attr.node.value))
3899 } else {
3900 let mut cont = true;
3901 csearch::get_item_attrs(&tcx.sess.cstore, did, |meta_items| {
3902 if cont {
3903 cont = meta_items.iter().advance(|ptrptr| f(*ptrptr));
3904 }
3905 });
3906 cont
3907 }
3908 }
3909
3910 /// Determine whether an item is annotated with an attribute
3911 pub fn has_attr(tcx: &ctxt, did: DefId, attr: &str) -> bool {
3912 let mut found = false;
3913 each_attr(tcx, did, |item| {
3914 if item.name().equiv(&attr) {
3915 found = true;
3916 false
3917 } else {
3918 true
3919 }
3920 });
3921 found
3922 }
3923
3924 /// Determine whether an item is annotated with `#[packed]`
3925 pub fn lookup_packed(tcx: &ctxt, did: DefId) -> bool {
3926 has_attr(tcx, did, "packed")
3927 }
3928
3929 /// Determine whether an item is annotated with `#[simd]`
3930 pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
3931 has_attr(tcx, did, "simd")
3932 }
3933
3934 // Obtain the representation annotation for a definition.
3935 pub fn lookup_repr_hint(tcx: &ctxt, did: DefId) -> attr::ReprAttr {
3936 let mut acc = attr::ReprAny;
3937 ty::each_attr(tcx, did, |meta| {
3938 acc = attr::find_repr_attr(tcx.sess.diagnostic(), meta, acc);
3939 true
3940 });
3941 return acc;
3942 }
3943
3944 // Look up a field ID, whether or not it's local
3945 // Takes a list of type substs in case the struct is generic
3946 pub fn lookup_field_type(tcx: &ctxt,
3947 struct_id: DefId,
3948 id: DefId,
3949 substs: &substs)
3950 -> ty::t {
3951 let t = if id.krate == ast::LOCAL_CRATE {
3952 node_id_to_type(tcx, id.node)
3953 } else {
3954 let mut tcache = tcx.tcache.borrow_mut();
3955 match tcache.find(&id) {
3956 Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
3957 None => {
3958 let tpt = csearch::get_field_type(tcx, struct_id, id);
3959 tcache.insert(id, tpt.clone());
3960 tpt.ty
3961 }
3962 }
3963 };
3964 subst(tcx, substs, t)
3965 }
3966
3967 // Lookup all ancestor structs of a struct indicated by did. That is the reflexive,
3968 // transitive closure of doing a single lookup in cx.superstructs.
3969 fn each_super_struct(cx: &ctxt, mut did: ast::DefId, f: |ast::DefId|) {
3970 let superstructs = cx.superstructs.borrow();
3971
3972 loop {
3973 f(did);
3974 match superstructs.find(&did) {
3975 Some(&Some(def_id)) => {
3976 did = def_id;
3977 },
3978 Some(&None) => break,
3979 None => {
3980 cx.sess.bug(
3981 format!("ID not mapped to super-struct: {}",
3982 cx.map.node_to_str(did.node)));
3983 }
3984 }
3985 }
3986 }
3987
3988 // Look up the list of field names and IDs for a given struct.
3989 // Fails if the id is not bound to a struct.
3990 pub fn lookup_struct_fields(cx: &ctxt, did: ast::DefId) -> Vec<field_ty> {
3991 if did.krate == ast::LOCAL_CRATE {
3992 // We store the fields which are syntactically in each struct in cx. So
3993 // we have to walk the inheritance chain of the struct to get all the
3994 // structs (explicit and inherited) for a struct. If this is expensive
3995 // we could cache the whole list of fields here.
3996 let struct_fields = cx.struct_fields.borrow();
3997 let mut results: SmallVector<&[field_ty]> = SmallVector::zero();
3998 each_super_struct(cx, did, |s| {
3999 match struct_fields.find(&s) {
4000 Some(fields) => results.push(fields.as_slice()),
4001 _ => {
4002 cx.sess.bug(
4003 format!("ID not mapped to struct fields: {}",
4004 cx.map.node_to_str(did.node)));
4005 }
4006 }
4007 });
4008
4009 let len = results.as_slice().iter().map(|x| x.len()).sum();
4010 let mut result: Vec<field_ty> = Vec::with_capacity(len);
4011 result.extend(results.as_slice().iter().flat_map(|rs| rs.iter().map(|&f| f)));
4012 assert!(result.len() == len);
4013 result
4014 } else {
4015 csearch::get_struct_fields(&cx.sess.cstore, did)
4016 }
4017 }
4018
4019 pub fn lookup_struct_field(cx: &ctxt,
4020 parent: ast::DefId,
4021 field_id: ast::DefId)
4022 -> field_ty {
4023 let r = lookup_struct_fields(cx, parent);
4024 match r.iter().find(|f| f.id.node == field_id.node) {
4025 Some(t) => *t,
4026 None => cx.sess.bug("struct ID not found in parent's fields")
4027 }
4028 }
4029
4030 // Returns a list of fields corresponding to the struct's items. trans uses
4031 // this. Takes a list of substs with which to instantiate field types.
4032 pub fn struct_fields(cx: &ctxt, did: ast::DefId, substs: &substs)
4033 -> Vec<field> {
4034 lookup_struct_fields(cx, did).iter().map(|f| {
4035 field {
4036 // FIXME #6993: change type of field to Name and get rid of new()
4037 ident: ast::Ident::new(f.name),
4038 mt: mt {
4039 ty: lookup_field_type(cx, did, f.id, substs),
4040 mutbl: MutImmutable
4041 }
4042 }
4043 }).collect()
4044 }
4045
4046 pub fn is_binopable(cx: &ctxt, ty: t, op: ast::BinOp) -> bool {
4047 static tycat_other: int = 0;
4048 static tycat_bool: int = 1;
4049 static tycat_char: int = 2;
4050 static tycat_int: int = 3;
4051 static tycat_float: int = 4;
4052 static tycat_bot: int = 5;
4053 static tycat_raw_ptr: int = 6;
4054
4055 static opcat_add: int = 0;
4056 static opcat_sub: int = 1;
4057 static opcat_mult: int = 2;
4058 static opcat_shift: int = 3;
4059 static opcat_rel: int = 4;
4060 static opcat_eq: int = 5;
4061 static opcat_bit: int = 6;
4062 static opcat_logic: int = 7;
4063 static opcat_mod: int = 8;
4064
4065 fn opcat(op: ast::BinOp) -> int {
4066 match op {
4067 ast::BiAdd => opcat_add,
4068 ast::BiSub => opcat_sub,
4069 ast::BiMul => opcat_mult,
4070 ast::BiDiv => opcat_mult,
4071 ast::BiRem => opcat_mod,
4072 ast::BiAnd => opcat_logic,
4073 ast::BiOr => opcat_logic,
4074 ast::BiBitXor => opcat_bit,
4075 ast::BiBitAnd => opcat_bit,
4076 ast::BiBitOr => opcat_bit,
4077 ast::BiShl => opcat_shift,
4078 ast::BiShr => opcat_shift,
4079 ast::BiEq => opcat_eq,
4080 ast::BiNe => opcat_eq,
4081 ast::BiLt => opcat_rel,
4082 ast::BiLe => opcat_rel,
4083 ast::BiGe => opcat_rel,
4084 ast::BiGt => opcat_rel
4085 }
4086 }
4087
4088 fn tycat(cx: &ctxt, ty: t) -> int {
4089 if type_is_simd(cx, ty) {
4090 return tycat(cx, simd_type(cx, ty))
4091 }
4092 match get(ty).sty {
4093 ty_char => tycat_char,
4094 ty_bool => tycat_bool,
4095 ty_int(_) | ty_uint(_) | ty_infer(IntVar(_)) => tycat_int,
4096 ty_float(_) | ty_infer(FloatVar(_)) => tycat_float,
4097 ty_bot => tycat_bot,
4098 ty_ptr(_) => tycat_raw_ptr,
4099 _ => tycat_other
4100 }
4101 }
4102
4103 static t: bool = true;
4104 static f: bool = false;
4105
4106 let tbl = [
4107 // +, -, *, shift, rel, ==, bit, logic, mod
4108 /*other*/ [f, f, f, f, f, f, f, f, f],
4109 /*bool*/ [f, f, f, f, t, t, t, t, f],
4110 /*char*/ [f, f, f, f, t, t, f, f, f],
4111 /*int*/ [t, t, t, t, t, t, t, f, t],
4112 /*float*/ [t, t, t, f, t, t, f, f, f],
4113 /*bot*/ [t, t, t, t, t, t, t, t, t],
4114 /*raw ptr*/ [f, f, f, f, t, t, f, f, f]];
4115
4116 return tbl[tycat(cx, ty) as uint ][opcat(op) as uint];
4117 }
4118
4119 /// Returns an equivalent type with all the typedefs and self regions removed.
4120 pub fn normalize_ty(cx: &ctxt, t: t) -> t {
4121 let u = TypeNormalizer(cx).fold_ty(t);
4122 return u;
4123
4124 struct TypeNormalizer<'a>(&'a ctxt);
4125
4126 impl<'a> TypeFolder for TypeNormalizer<'a> {
4127 fn tcx<'a>(&'a self) -> &'a ctxt { let TypeNormalizer(c) = *self; c }
4128
4129 fn fold_ty(&mut self, t: ty::t) -> ty::t {
4130 match self.tcx().normalized_cache.borrow().find_copy(&t) {
4131 None => {}
4132 Some(u) => return u
4133 }
4134
4135 let t_norm = ty_fold::super_fold_ty(self, t);
4136 self.tcx().normalized_cache.borrow_mut().insert(t, t_norm);
4137 return t_norm;
4138 }
4139
4140 fn fold_region(&mut self, _: ty::Region) -> ty::Region {
4141 ty::ReStatic
4142 }
4143
4144 fn fold_substs(&mut self,
4145 substs: &substs)
4146 -> substs {
4147 substs { regions: ErasedRegions,
4148 self_ty: ty_fold::fold_opt_ty(self, substs.self_ty),
4149 tps: ty_fold::fold_ty_vec(self, substs.tps.as_slice()) }
4150 }
4151
4152 fn fold_sig(&mut self,
4153 sig: &ty::FnSig)
4154 -> ty::FnSig {
4155 // The binder-id is only relevant to bound regions, which
4156 // are erased at trans time.
4157 ty::FnSig {
4158 binder_id: ast::DUMMY_NODE_ID,
4159 inputs: ty_fold::fold_ty_vec(self, sig.inputs.as_slice()),
4160 output: self.fold_ty(sig.output),
4161 variadic: sig.variadic,
4162 }
4163 }
4164 }
4165 }
4166
4167 pub trait ExprTyProvider {
4168 fn expr_ty(&self, ex: &ast::Expr) -> t;
4169 fn ty_ctxt<'a>(&'a self) -> &'a ctxt;
4170 }
4171
4172 impl ExprTyProvider for ctxt {
4173 fn expr_ty(&self, ex: &ast::Expr) -> t {
4174 expr_ty(self, ex)
4175 }
4176
4177 fn ty_ctxt<'a>(&'a self) -> &'a ctxt {
4178 self
4179 }
4180 }
4181
4182 // Returns the repeat count for a repeating vector expression.
4183 pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) -> uint {
4184 match const_eval::eval_const_expr_partial(tcx, count_expr) {
4185 Ok(ref const_val) => match *const_val {
4186 const_eval::const_int(count) => if count < 0 {
4187 tcx.ty_ctxt().sess.span_err(count_expr.span,
4188 "expected positive integer for \
4189 repeat count but found negative integer");
4190 return 0;
4191 } else {
4192 return count as uint
4193 },
4194 const_eval::const_uint(count) => return count as uint,
4195 const_eval::const_float(count) => {
4196 tcx.ty_ctxt().sess.span_err(count_expr.span,
4197 "expected positive integer for \
4198 repeat count but found float");
4199 return count as uint;
4200 }
4201 const_eval::const_str(_) => {
4202 tcx.ty_ctxt().sess.span_err(count_expr.span,
4203 "expected positive integer for \
4204 repeat count but found string");
4205 return 0;
4206 }
4207 const_eval::const_bool(_) => {
4208 tcx.ty_ctxt().sess.span_err(count_expr.span,
4209 "expected positive integer for \
4210 repeat count but found boolean");
4211 return 0;
4212 }
4213 const_eval::const_binary(_) => {
4214 tcx.ty_ctxt().sess.span_err(count_expr.span,
4215 "expected positive integer for \
4216 repeat count but found binary array");
4217 return 0;
4218 }
4219 },
4220 Err(..) => {
4221 tcx.ty_ctxt().sess.span_err(count_expr.span,
4222 "expected constant integer for repeat count \
4223 but found variable");
4224 return 0;
4225 }
4226 }
4227 }
4228
4229 // Iterate over a type parameter's bounded traits and any supertraits
4230 // of those traits, ignoring kinds.
4231 // Here, the supertraits are the transitive closure of the supertrait
4232 // relation on the supertraits from each bounded trait's constraint
4233 // list.
4234 pub fn each_bound_trait_and_supertraits(tcx: &ctxt,
4235 bounds: &[Rc<TraitRef>],
4236 f: |Rc<TraitRef>| -> bool)
4237 -> bool {
4238 for bound_trait_ref in bounds.iter() {
4239 let mut supertrait_set = HashMap::new();
4240 let mut trait_refs = Vec::new();
4241 let mut i = 0;
4242
4243 // Seed the worklist with the trait from the bound
4244 supertrait_set.insert(bound_trait_ref.def_id, ());
4245 trait_refs.push(bound_trait_ref.clone());
4246
4247 // Add the given trait ty to the hash map
4248 while i < trait_refs.len() {
4249 debug!("each_bound_trait_and_supertraits(i={:?}, trait_ref={})",
4250 i, trait_refs.get(i).repr(tcx));
4251
4252 if !f(trait_refs.get(i).clone()) {
4253 return false;
4254 }
4255
4256 // Add supertraits to supertrait_set
4257 let supertrait_refs = trait_ref_supertraits(tcx,
4258 &**trait_refs.get(i));
4259 for supertrait_ref in supertrait_refs.iter() {
4260 debug!("each_bound_trait_and_supertraits(supertrait_ref={})",
4261 supertrait_ref.repr(tcx));
4262
4263 let d_id = supertrait_ref.def_id;
4264 if !supertrait_set.contains_key(&d_id) {
4265 // FIXME(#5527) Could have same trait multiple times
4266 supertrait_set.insert(d_id, ());
4267 trait_refs.push(supertrait_ref.clone());
4268 }
4269 }
4270
4271 i += 1;
4272 }
4273 }
4274 return true;
4275 }
4276
4277 pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> {
4278 tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
4279 tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item)
4280 .expect("Failed to resolve TyDesc")
4281 })
4282 }
4283
4284 pub fn get_opaque_ty(tcx: &ctxt) -> Result<t, ~str> {
4285 tcx.lang_items.require(OpaqueStructLangItem).map(|opaque_lang_item| {
4286 tcx.intrinsic_defs.borrow().find_copy(&opaque_lang_item)
4287 .expect("Failed to resolve Opaque")
4288 })
4289 }
4290
4291 pub fn visitor_object_ty(tcx: &ctxt,
4292 region: ty::Region) -> Result<(Rc<TraitRef>, t), ~str> {
4293 let trait_lang_item = match tcx.lang_items.require(TyVisitorTraitLangItem) {
4294 Ok(id) => id,
4295 Err(s) => { return Err(s); }
4296 };
4297 let substs = substs {
4298 regions: ty::NonerasedRegions(OwnedSlice::empty()),
4299 self_ty: None,
4300 tps: Vec::new()
4301 };
4302 let trait_ref = Rc::new(TraitRef { def_id: trait_lang_item, substs: substs });
4303 Ok((trait_ref.clone(),
4304 mk_trait(tcx,
4305 trait_ref.def_id,
4306 trait_ref.substs.clone(),
4307 RegionTraitStore(region, ast::MutMutable),
4308 EmptyBuiltinBounds())))
4309 }
4310
4311 pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
4312 lookup_locally_or_in_crate_store(
4313 "item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),
4314 || Rc::new(csearch::get_item_variances(&tcx.sess.cstore, item_id)))
4315 }
4316
4317 /// Records a trait-to-implementation mapping.
4318 pub fn record_trait_implementation(tcx: &ctxt,
4319 trait_def_id: DefId,
4320 impl_def_id: DefId) {
4321 match tcx.trait_impls.borrow().find(&trait_def_id) {
4322 Some(impls_for_trait) => {
4323 impls_for_trait.borrow_mut().push(impl_def_id);
4324 return;
4325 }
4326 None => {}
4327 }
4328 tcx.trait_impls.borrow_mut().insert(trait_def_id, Rc::new(RefCell::new(vec!(impl_def_id))));
4329 }
4330
4331 /// Populates the type context with all the implementations for the given type
4332 /// if necessary.
4333 pub fn populate_implementations_for_type_if_necessary(tcx: &ctxt,
4334 type_id: ast::DefId) {
4335 if type_id.krate == LOCAL_CRATE {
4336 return
4337 }
4338 if tcx.populated_external_types.borrow().contains(&type_id) {
4339 return
4340 }
4341
4342 csearch::each_implementation_for_type(&tcx.sess.cstore, type_id,
4343 |impl_def_id| {
4344 let methods = csearch::get_impl_methods(&tcx.sess.cstore, impl_def_id);
4345
4346 // Record the trait->implementation mappings, if applicable.
4347 let associated_traits = csearch::get_impl_trait(tcx, impl_def_id);
4348 for trait_ref in associated_traits.iter() {
4349 record_trait_implementation(tcx, trait_ref.def_id, impl_def_id);
4350 }
4351
4352 // For any methods that use a default implementation, add them to
4353 // the map. This is a bit unfortunate.
4354 for &method_def_id in methods.iter() {
4355 for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4356 tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
4357 }
4358 }
4359
4360 // Store the implementation info.
4361 tcx.impl_methods.borrow_mut().insert(impl_def_id, methods);
4362
4363 // If this is an inherent implementation, record it.
4364 if associated_traits.is_none() {
4365 match tcx.inherent_impls.borrow().find(&type_id) {
4366 Some(implementation_list) => {
4367 implementation_list.borrow_mut().push(impl_def_id);
4368 return;
4369 }
4370 None => {}
4371 }
4372 tcx.inherent_impls.borrow_mut().insert(type_id,
4373 Rc::new(RefCell::new(vec!(impl_def_id))));
4374 }
4375 });
4376
4377 tcx.populated_external_types.borrow_mut().insert(type_id);
4378 }
4379
4380 /// Populates the type context with all the implementations for the given
4381 /// trait if necessary.
4382 pub fn populate_implementations_for_trait_if_necessary(
4383 tcx: &ctxt,
4384 trait_id: ast::DefId) {
4385 if trait_id.krate == LOCAL_CRATE {
4386 return
4387 }
4388 if tcx.populated_external_traits.borrow().contains(&trait_id) {
4389 return
4390 }
4391
4392 csearch::each_implementation_for_trait(&tcx.sess.cstore, trait_id,
4393 |implementation_def_id| {
4394 let methods = csearch::get_impl_methods(&tcx.sess.cstore, implementation_def_id);
4395
4396 // Record the trait->implementation mapping.
4397 record_trait_implementation(tcx, trait_id, implementation_def_id);
4398
4399 // For any methods that use a default implementation, add them to
4400 // the map. This is a bit unfortunate.
4401 for &method_def_id in methods.iter() {
4402 for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4403 tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
4404 }
4405 }
4406
4407 // Store the implementation info.
4408 tcx.impl_methods.borrow_mut().insert(implementation_def_id, methods);
4409 });
4410
4411 tcx.populated_external_traits.borrow_mut().insert(trait_id);
4412 }
4413
4414 /// Given the def_id of an impl, return the def_id of the trait it implements.
4415 /// If it implements no trait, return `None`.
4416 pub fn trait_id_of_impl(tcx: &ctxt,
4417 def_id: ast::DefId) -> Option<ast::DefId> {
4418 let node = match tcx.map.find(def_id.node) {
4419 Some(node) => node,
4420 None => return None
4421 };
4422 match node {
4423 ast_map::NodeItem(item) => {
4424 match item.node {
4425 ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
4426 Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id)
4427 }
4428 _ => None
4429 }
4430 }
4431 _ => None
4432 }
4433 }
4434
4435 /// If the given def ID describes a method belonging to a trait (either a
4436 /// default method or an implementation of a trait method), return the ID of
4437 /// the trait that the method belongs to. Otherwise, return `None`.
4438 pub fn trait_of_method(tcx: &ctxt, def_id: ast::DefId)
4439 -> Option<ast::DefId> {
4440 if def_id.krate != LOCAL_CRATE {
4441 return csearch::get_trait_of_method(&tcx.sess.cstore, def_id, tcx);
4442 }
4443 match tcx.methods.borrow().find_copy(&def_id) {
4444 Some(method) => {
4445 match method.container {
4446 TraitContainer(def_id) => Some(def_id),
4447 ImplContainer(def_id) => trait_id_of_impl(tcx, def_id),
4448 }
4449 }
4450 None => None
4451 }
4452 }
4453
4454 /// If the given def ID describes a method belonging to a trait, (either a
4455 /// default method or an implementation of a trait method), return the ID of
4456 /// the method inside trait definition (this means that if the given def ID
4457 /// is already that of the original trait method, then the return value is
4458 /// the same).
4459 /// Otherwise, return `None`.
4460 pub fn trait_method_of_method(tcx: &ctxt,
4461 def_id: ast::DefId) -> Option<ast::DefId> {
4462 let method = match tcx.methods.borrow().find(&def_id) {
4463 Some(m) => m.clone(),
4464 None => return None,
4465 };
4466 let name = method.ident.name;
4467 match trait_of_method(tcx, def_id) {
4468 Some(trait_did) => {
4469 let trait_methods = ty::trait_methods(tcx, trait_did);
4470 trait_methods.iter()
4471 .position(|m| m.ident.name == name)
4472 .map(|idx| ty::trait_method(tcx, trait_did, idx).def_id)
4473 }
4474 None => None
4475 }
4476 }
4477
4478 /// Creates a hash of the type `t` which will be the same no matter what crate
4479 /// context it's calculated within. This is used by the `type_id` intrinsic.
4480 pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 {
4481 let mut state = sip::SipState::new();
4482 macro_rules! byte( ($b:expr) => { ($b as u8).hash(&mut state) } );
4483 macro_rules! hash( ($e:expr) => { $e.hash(&mut state) } );
4484
4485 let region = |_state: &mut sip::SipState, r: Region| {
4486 match r {
4487 ReStatic => {}
4488
4489 ReEmpty |
4490 ReEarlyBound(..) |
4491 ReLateBound(..) |
4492 ReFree(..) |
4493 ReScope(..) |
4494 ReInfer(..) => {
4495 tcx.sess.bug("non-static region found when hashing a type")
4496 }
4497 }
4498 };
4499 let did = |state: &mut sip::SipState, did: DefId| {
4500 let h = if ast_util::is_local(did) {
4501 svh.clone()
4502 } else {
4503 tcx.sess.cstore.get_crate_hash(did.krate)
4504 };
4505 h.as_str().hash(state);
4506 did.node.hash(state);
4507 };
4508 let mt = |state: &mut sip::SipState, mt: mt| {
4509 mt.mutbl.hash(state);
4510 };
4511 ty::walk_ty(t, |t| {
4512 match ty::get(t).sty {
4513 ty_nil => byte!(0),
4514 ty_bot => byte!(1),
4515 ty_bool => byte!(2),
4516 ty_char => byte!(3),
4517 ty_int(i) => {
4518 byte!(4);
4519 hash!(i);
4520 }
4521 ty_uint(u) => {
4522 byte!(5);
4523 hash!(u);
4524 }
4525 ty_float(f) => {
4526 byte!(6);
4527 hash!(f);
4528 }
4529 ty_str => {
4530 byte!(7);
4531 }
4532 ty_enum(d, _) => {
4533 byte!(8);
4534 did(&mut state, d);
4535 }
4536 ty_box(_) => {
4537 byte!(9);
4538 }
4539 ty_uniq(_) => {
4540 byte!(10);
4541 }
4542 ty_vec(m, Some(_)) => {
4543 byte!(11);
4544 mt(&mut state, m);
4545 1u8.hash(&mut state);
4546 }
4547 ty_vec(m, None) => {
4548 byte!(11);
4549 mt(&mut state, m);
4550 0u8.hash(&mut state);
4551 }
4552 ty_ptr(m) => {
4553 byte!(12);
4554 mt(&mut state, m);
4555 }
4556 ty_rptr(r, m) => {
4557 byte!(13);
4558 region(&mut state, r);
4559 mt(&mut state, m);
4560 }
4561 ty_bare_fn(ref b) => {
4562 byte!(14);
4563 hash!(b.fn_style);
4564 hash!(b.abi);
4565 }
4566 ty_closure(ref c) => {
4567 byte!(15);
4568 hash!(c.fn_style);
4569 hash!(c.onceness);
4570 hash!(c.bounds);
4571 match c.store {
4572 UniqTraitStore => byte!(0),
4573 RegionTraitStore(r, m) => {
4574 byte!(1)
4575 region(&mut state, r);
4576 assert_eq!(m, ast::MutMutable);
4577 }
4578 }
4579 }
4580 ty_trait(box ty::TyTrait { def_id: d, store, bounds, .. }) => {
4581 byte!(17);
4582 did(&mut state, d);
4583 match store {
4584 UniqTraitStore => byte!(0),
4585 RegionTraitStore(r, m) => {
4586 byte!(1)
4587 region(&mut state, r);
4588 hash!(m);
4589 }
4590 }
4591 hash!(bounds);
4592 }
4593 ty_struct(d, _) => {
4594 byte!(18);
4595 did(&mut state, d);
4596 }
4597 ty_tup(ref inner) => {
4598 byte!(19);
4599 hash!(inner.len());
4600 }
4601 ty_param(p) => {
4602 byte!(20);
4603 hash!(p.idx);
4604 did(&mut state, p.def_id);
4605 }
4606 ty_self(d) => {
4607 byte!(21);
4608 did(&mut state, d);
4609 }
4610 ty_infer(_) => unreachable!(),
4611 ty_err => byte!(23),
4612 }
4613 });
4614
4615 state.result()
4616 }
4617
4618 impl Variance {
4619 pub fn to_str(self) -> &'static str {
4620 match self {
4621 Covariant => "+",
4622 Contravariant => "-",
4623 Invariant => "o",
4624 Bivariant => "*",
4625 }
4626 }
4627 }
4628
4629 pub fn construct_parameter_environment(
4630 tcx: &ctxt,
4631 self_bound: Option<Rc<TraitRef>>,
4632 item_type_params: &[TypeParameterDef],
4633 method_type_params: &[TypeParameterDef],
4634 item_region_params: &[RegionParameterDef],
4635 method_region_params: &[RegionParameterDef],
4636 free_id: ast::NodeId)
4637 -> ParameterEnvironment
4638 {
4639 /*! See `ParameterEnvironment` struct def'n for details */
4640
4641 //
4642 // Construct the free substs.
4643 //
4644
4645 // map Self => Self
4646 let self_ty = self_bound.as_ref().map(|t| ty::mk_self(tcx, t.def_id));
4647
4648 // map A => A
4649 let num_item_type_params = item_type_params.len();
4650 let num_method_type_params = method_type_params.len();
4651 let num_type_params = num_item_type_params + num_method_type_params;
4652 let type_params = Vec::from_fn(num_type_params, |i| {
4653 let def_id = if i < num_item_type_params {
4654 item_type_params[i].def_id
4655 } else {
4656 method_type_params[i - num_item_type_params].def_id
4657 };
4658
4659 ty::mk_param(tcx, i, def_id)
4660 });
4661
4662 // map bound 'a => free 'a
4663 let region_params = {
4664 fn push_region_params(mut accum: Vec<ty::Region>,
4665 free_id: ast::NodeId,
4666 region_params: &[RegionParameterDef])
4667 -> Vec<ty::Region> {
4668 for r in region_params.iter() {
4669 accum.push(
4670 ty::ReFree(ty::FreeRegion {
4671 scope_id: free_id,
4672 bound_region: ty::BrNamed(r.def_id, r.name)}));
4673 }
4674 accum
4675 }
4676
4677 let t = push_region_params(vec!(), free_id, item_region_params);
4678 push_region_params(t, free_id, method_region_params)
4679 };
4680
4681 let free_substs = substs {
4682 self_ty: self_ty,
4683 tps: type_params,
4684 regions: ty::NonerasedRegions(OwnedSlice::from_vec(region_params))
4685 };
4686
4687 //
4688 // Compute the bounds on Self and the type parameters.
4689 //
4690
4691 let self_bound_substd = self_bound.map(|b| b.subst(tcx, &free_substs));
4692 let type_param_bounds_substd = Vec::from_fn(num_type_params, |i| {
4693 if i < num_item_type_params {
4694 (*item_type_params[i].bounds).subst(tcx, &free_substs)
4695 } else {
4696 let j = i - num_item_type_params;
4697 (*method_type_params[j].bounds).subst(tcx, &free_substs)
4698 }
4699 });
4700
4701 debug!("construct_parameter_environment: free_id={} \
4702 free_subst={} \
4703 self_param_bound={} \
4704 type_param_bound={}",
4705 free_id,
4706 free_substs.repr(tcx),
4707 self_bound_substd.repr(tcx),
4708 type_param_bounds_substd.repr(tcx));
4709
4710 ty::ParameterEnvironment {
4711 free_substs: free_substs,
4712 self_param_bound: self_bound_substd,
4713 type_param_bounds: type_param_bounds_substd,
4714 }
4715 }
4716
4717 impl substs {
4718 pub fn empty() -> substs {
4719 substs {
4720 self_ty: None,
4721 tps: Vec::new(),
4722 regions: NonerasedRegions(OwnedSlice::empty())
4723 }
4724 }
4725 }
4726
4727 impl BorrowKind {
4728 pub fn from_mutbl(m: ast::Mutability) -> BorrowKind {
4729 match m {
4730 ast::MutMutable => MutBorrow,
4731 ast::MutImmutable => ImmBorrow,
4732 }
4733 }
4734
4735 pub fn to_user_str(&self) -> &'static str {
4736 match *self {
4737 MutBorrow => "mutable",
4738 ImmBorrow => "immutable",
4739 UniqueImmBorrow => "uniquely immutable",
4740 }
4741 }
4742 }
4743
4744 impl mc::Typer for ty::ctxt {
4745 fn tcx<'a>(&'a self) -> &'a ty::ctxt {
4746 self
4747 }
4748
4749 fn node_ty(&self, id: ast::NodeId) -> mc::McResult<ty::t> {
4750 Ok(ty::node_id_to_type(self, id))
4751 }
4752
4753 fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t> {
4754 self.method_map.borrow().find(&method_call).map(|method| method.ty)
4755 }
4756
4757 fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>> {
4758 &self.adjustments
4759 }
4760
4761 fn is_method_call(&self, id: ast::NodeId) -> bool {
4762 self.method_map.borrow().contains_key(&typeck::MethodCall::expr(id))
4763 }
4764
4765 fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<ast::NodeId> {
4766 self.region_maps.temporary_scope(rvalue_id)
4767 }
4768
4769 fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow {
4770 self.upvar_borrow_map.borrow().get_copy(&upvar_id)
4771 }
4772 }
librustc/middle/ty.rs:1311:10-1311:10 -fn- definition:
pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) }
pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
pub fn mk_mach_int(tm: ast::IntTy) -> t {
references:- 121331: ast::TyU16 => mk_u16(),
1332: ast::TyU32 => mk_u32(),
1333: ast::TyU64 => mk_u64(),
librustc/middle/typeck/check/mod.rs:
4371: "u32_add_with_overflow" | "u32_sub_with_overflow" | "u32_mul_with_overflow"=>
4372: (0, vec!(ty::mk_u32(), ty::mk_u32()),
4373: ty::mk_tup(tcx, vec!(ty::mk_u32(), ty::mk_bool()))),
librustc/middle/ty.rs:2608:75-2608:75 -fn- definition:
// Some types---notably unsafe ptrs---can only be dereferenced explicitly.
pub fn deref(t: t, explicit: bool) -> Option<mt> {
match get(t).sty {
references:- 72877: }
2878: match deref(adjusted_ty, true) {
2879: Some(mt) => { adjusted_ty = mt.ty; }
librustc/middle/typeck/check/mod.rs:
2804: oprnd_t = structurally_resolved_type(fcx, expr.span, oprnd_t);
2805: oprnd_t = match ty::deref(oprnd_t, true) {
2806: Some(mt) => mt.ty,
librustc/middle/typeck/check/regionck.rs:
912: match ty::deref(derefd_ty, true) {
913: Some(mt) => derefd_ty = mt.ty,
librustc/middle/trans/consts.rs:
137: -> (ValueRef, ty::t) {
138: match ty::deref(t, explicit) {
139: Some(ref mt) => {
librustc/middle/mem_categorization.rs:
723: };
724: match ty::deref(base_cmt.ty, true) {
725: Some(mt) => self.cat_deref_common(node, base_cmt, deref_cnt, mt.ty),
librustc/middle/ty.rs:3741:29-3741:29 -fn- definition:
Otherwise return none. */
pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
match cx.destructor_for_type.borrow().find(&struct_id) {
references:- 33753: pub fn has_dtor(cx: &ctxt, struct_id: DefId) -> bool {
3754: ty_dtor(cx, struct_id).is_present()
3755: }
librustc/middle/trans/adt.rs:
148: let packed = ty::lookup_packed(cx.tcx(), def_id);
149: let dtor = ty::ty_dtor(cx.tcx(), def_id).has_drop_flag();
150: if dtor { ftys.push(ty::mk_bool()); }
librustc/middle/trans/glue.rs:
307: let tcx = bcx.tcx();
308: match ty::ty_dtor(tcx, did) {
309: ty::TraitDtor(dtor, true) => {
librustc/middle/ty.rs:1308:10-1308:10 -fn- definition:
pub fn mk_u16() -> t { mk_prim_t(&primitives::TY_U16) }
pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) }
pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
references:- 121330: ast::TyU8 => mk_u8(),
1331: ast::TyU16 => mk_u16(),
1332: ast::TyU32 => mk_u32(),
librustc/middle/typeck/check/mod.rs:
4337: "cttz64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()),
4338: "bswap16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()),
4339: "bswap32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()),
--
4368: (0, vec!(ty::mk_u16(), ty::mk_u16()),
4369: ty::mk_tup(tcx, vec!(ty::mk_u16(), ty::mk_bool()))),
librustc/middle/ty.rs:457:66-457:66 -enum- definition:
pub enum Region {
// Region bound in a type or fn declaration which will be
// substituted 'early' -- that is, at the same time when type
references:- 265librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/rscope.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/borrowck/gather_loans/mod.rs:
librustc/middle/borrowck/gather_loans/lifetime.rs:
librustc/middle/borrowck/gather_loans/restrictions.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/kind.rs:
librustc/middle/region.rs:
librustc/middle/astencode.rs:
librustc/middle/expr_use_visitor.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/subst.rs:
librustc/middle/ty.rs:838:1-838:1 -fn- definition:
pub fn EmptyBuiltinBounds() -> BuiltinBounds {
EnumSet::empty()
}
references:- 174307: RegionTraitStore(region, ast::MutMutable),
4308: EmptyBuiltinBounds())))
4309: }
librustc/middle/typeck/check/mod.rs:
2302: // Not an error! Means we're inferring the closure type
2303: let mut bounds = ty::EmptyBuiltinBounds();
2304: let onceness = match expr.node {
librustc/middle/typeck/check/vtable.rs:
473: ty::RegionTraitStore(ty::ReStatic, ast::MutImmutable),
474: ty::EmptyBuiltinBounds());
475: fixup_ty(vcx, span, t, is_early).map(|t_f| {
--
762: let param_bounds = ty::ParamBounds {
763: builtin_bounds: ty::EmptyBuiltinBounds(),
764: trait_bounds: vec!(Rc::new(impl_trait_ref))
librustc/middle/typeck/check/method.rs:
276: RegionTraitStore(r, mt.mutbl),
277: ty::EmptyBuiltinBounds())
278: }
--
281: UniqTraitStore,
282: ty::EmptyBuiltinBounds())
283: }
librustc/middle/typeck/astconv.rs:
883: (&Some(ref bound_vec), _) => {
884: let mut builtin_bounds = ty::EmptyBuiltinBounds();
885: for ast_bound in bound_vec.iter() {
--
922: (&None, ty::RegionTraitStore(..)) |
923: (&None, ty::UniqTraitStore) => ty::EmptyBuiltinBounds(),
924: }
librustc/middle/typeck/infer/mod.rs:
682: ty::UniqTraitStore,
683: ty::EmptyBuiltinBounds());
684: let dummy1 = self.resolve_type_vars_if_possible(dummy0);
librustc/middle/typeck/collect.rs:
1089: let mut param_bounds = ty::ParamBounds {
1090: builtin_bounds: ty::EmptyBuiltinBounds(),
1091: trait_bounds: Vec::new()
librustc/middle/kind.rs:
366: let kind = ty::type_contents(cx.tcx, ty);
367: let mut missing = ty::EmptyBuiltinBounds();
368: for bound in bounds.iter() {
librustc/metadata/tydecode.rs:
555: let mut param_bounds = ty::ParamBounds {
556: builtin_bounds: ty::EmptyBuiltinBounds(),
557: trait_bounds: Vec::new()
librustc/metadata/decoder.rs:
384: let sized = item_sized(item_doc);
385: let mut bounds = ty::EmptyBuiltinBounds();
386: // Collect the builtin bounds from the encoded supertraits.
librustc/middle/typeck/astconv.rs:
918: (&None, ty::RegionTraitStore(ty::ReStatic, _)) => {
919: let mut set = ty::EmptyBuiltinBounds(); set.add(ty::BoundStatic); set
920: }
librustc/middle/ty.rs:1281:10-1281:10 -fn- definition:
pub fn mk_i8() -> t { mk_prim_t(&primitives::TY_I8) }
pub fn mk_i16() -> t { mk_prim_t(&primitives::TY_I16) }
pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) }
references:- 111319: ast::TyI => mk_int(),
1320: ast::TyI8 => mk_i8(),
1321: ast::TyI16 => mk_i16(),
librustc/middle/typeck/check/mod.rs:
4347: "i8_add_with_overflow" | "i8_sub_with_overflow" | "i8_mul_with_overflow" =>
4348: (0, vec!(ty::mk_i8(), ty::mk_i8()),
4349: ty::mk_tup(tcx, vec!(ty::mk_i8(), ty::mk_bool()))),
librustc/middle/trans/glue.rs:
95: } else {
96: ty::mk_uniq(tcx, ty::mk_i8())
97: }
librustc/middle/trans/closure.rs:
131: fn tuplify_box_ty(tcx: &ty::ctxt, t: ty::t) -> ty::t {
132: let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8());
133: ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t))
librustc/middle/trans/debuginfo.rs:
2214: ty::ty_str => {
2215: let i8_t = ty::mk_i8();
2216: vec_slice_metadata(cx, t, i8_t, usage_site_span)
librustc/middle/typeck/check/mod.rs:
4348: (0, vec!(ty::mk_i8(), ty::mk_i8()),
4349: ty::mk_tup(tcx, vec!(ty::mk_i8(), ty::mk_bool()))),
librustc/middle/ty.rs:4628:1-4628:1 -fn- definition:
pub fn construct_parameter_environment(
tcx: &ctxt,
self_bound: Option<Rc<TraitRef>>,
references:- 4librustc/middle/typeck/check/mod.rs:
659: let param_env = ty::construct_parameter_environment(
660: ccx.tcx,
librustc/middle/typeck/check/vtable.rs:
795: infcx: &infer::new_infer_ctxt(tcx),
796: param_env: &ty::construct_parameter_environment(tcx, None, [], [], [], [], id)
797: };
librustc/middle/typeck/check/mod.rs:
768: let param_env =
769: ty::construct_parameter_environment(
770: ccx.tcx,
librustc/middle/ty.rs:1513:79-1513:79 -fn- definition:
// Substitute *only* type parameters. Used in trans where regions are erased.
pub fn subst_tps(tcx: &ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
let mut subst = TpsSubst { tcx: tcx, self_ty_opt: self_ty_opt, tps: tps };
references:- 12librustc/middle/trans/monomorphize.rs:
141: let mono_ty = match is_static_provided {
142: None => ty::subst_tps(ccx.tcx(), real_substs.tps.as_slice(),
143: real_substs.self_ty, llitem_ty),
--
166: ty::subst_tps(ccx.tcx(), substs.as_slice(), None, llitem_ty)
167: }
librustc/middle/trans/common.rs:
733: params.iter().map(|t| {
734: ty::subst_tps(tcx, substs.tys.as_slice(), substs.self_ty, *t)
735: }).collect()
--
791: tys.iter().map(|t| {
792: ty::subst_tps(tcx,
793: substs.tys.as_slice(),
librustc/middle/trans/base.rs:
682: adt::trans_field_ptr(cx, repr, av, variant.disr_val, i),
683: ty::subst_tps(tcx, tps, None, arg));
684: }
--
1158: Some(substs) => {
1159: ty::subst_tps(ccx.tcx(),
1160: substs.tys.as_slice(),
--
1218: Some(substs) => {
1219: ty::subst_tps(fcx.ccx.tcx(),
1220: substs.tys.as_slice(),
librustc/middle/trans/debuginfo.rs:
816: Some(substs) => {
817: ty::subst_tps(cx.tcx(),
818: substs.tys.as_slice(),
librustc/middle/trans/base.rs:
1518: ty::subst_tps(ccx.tcx(),
1519: ty_param_substs,
librustc/middle/ty.rs:1305:10-1305:10 -fn- definition:
pub fn mk_u8() -> t { mk_prim_t(&primitives::TY_U8) }
pub fn mk_u16() -> t { mk_prim_t(&primitives::TY_U16) }
pub fn mk_u32() -> t { mk_prim_t(&primitives::TY_U32) }
references:- 141329: ast::TyU => mk_uint(),
1330: ast::TyU8 => mk_u8(),
1331: ast::TyU16 => mk_u16(),
--
2635: ty_vec(mt, None) => Some(mt),
2636: ty_str => Some(mt {ty: mk_u8(), mutbl: ast::MutImmutable}),
2637: _ => None,
librustc/middle/typeck/mod.rs:
390: ty::mk_int(),
391: ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
392: ),
librustc/middle/typeck/check/mod.rs:
4333: "ctlz64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()),
4334: "cttz8" => (0, vec!( ty::mk_u8() ), ty::mk_u8()),
4335: "cttz16" => (0, vec!( ty::mk_u16() ), ty::mk_u16()),
--
4364: (0, vec!(ty::mk_u8(), ty::mk_u8()),
4365: ty::mk_tup(tcx, vec!(ty::mk_u8(), ty::mk_bool()))),
librustc/middle/ty.rs:4381:24-4381:24 -fn- definition:
/// trait if necessary.
pub fn populate_implementations_for_trait_if_necessary(
tcx: &ctxt,
references:- 7librustc/middle/typeck/check/vtable.rs:
136: ty::populate_implementations_for_trait_if_necessary(tcx,
137: trait_ref.def_id);
--
318: // Load the implementations from external metadata if necessary.
319: ty::populate_implementations_for_trait_if_necessary(tcx,
320: trait_ref.def_id);
librustc/middle/trans/callee.rs:
288: Some(trait_id) => {
289: ty::populate_implementations_for_trait_if_necessary(tcx, trait_id)
290: }
librustc/middle/trans/meth.rs:
500: ty::populate_implementations_for_trait_if_necessary(bcx.tcx(), trt_id);
librustc/middle/typeck/check/method.rs:
476: fn push_extension_candidate(&mut self, trait_did: DefId) {
477: ty::populate_implementations_for_trait_if_necessary(self.tcx(), trait_did);
librustc/middle/ty.rs:1296:10-1296:10 -fn- definition:
pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
pub fn mk_f128() -> t { mk_prim_t(&primitives::TY_F128) }
pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) }
references:- 44librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:1556:1-1556:1 -fn- definition:
pub fn substs_is_noop(substs: &substs) -> bool {
let regions_is_noop = match substs.regions {
ErasedRegions => false, // may be used to canonicalize
references:- 2librustc/middle/typeck/check/mod.rs:
1114: pub fn write_substs(&self, node_id: ast::NodeId, substs: ty::substs) {
1115: if !ty::substs_is_noop(&substs) {
1116: debug!("write_substs({}, {}) in fcx {}",
librustc/middle/subst.rs:
50: span: Option<Span>) -> ty::t {
51: if ty::substs_is_noop(substs) && !ty::type_has_params(*self) {
52: *self
librustc/middle/ty.rs:3857:57-3857:57 -fn- definition:
// the type cache. Returns the type parameters and type.
pub fn lookup_item_type(cx: &ctxt,
did: ast::DefId)
references:- 47librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/lint.rs:
librustc/middle/kind.rs:
librustc/middle/privacy.rs:
librustc/metadata/encoder.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/inline.rs:
librustc/middle/trans/monomorphize.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/adt.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:3284:1-3284:1 -fn- definition:
pub fn type_err_to_str(cx: &ctxt, err: &type_err) -> ~str {
/*!
*
references:- 5librustc/middle/typeck/mod.rs:
308: tcx.sess.span_err(span, msg() + ": " +
309: ty::type_err_to_str(tcx, terr));
310: ty::note_and_explain_type_err(tcx, terr);
librustc/middle/typeck/check/vtable.rs:
209: ppaux::trait_ref_to_str(tcx, &r_act_trait_ref),
210: ty::type_err_to_str(tcx, err)));
211: }
librustc/middle/typeck/infer/mod.rs:
731: let error_str = err.map_or("".to_owned(), |t_err| {
732: format!(" ({})", ty::type_err_to_str(self.tcx, t_err))
733: });
librustc/middle/typeck/infer/error_reporting.rs:
357: expected_found_str,
358: ty::type_err_to_str(self.tcx, terr)));
359: }
librustc/middle/typeck/check/mod.rs:
1042: token::get_ident(trait_m.ident),
1043: ty::type_err_to_str(tcx, terr)));
1044: ty::note_and_explain_type_err(tcx, terr);
librustc/middle/ty.rs:2584:42-2584:42 -fn- definition:
pub fn type_is_sized(cx: &ctxt, ty: ty::t) -> bool {
type_contents(cx, ty).is_sized(cx)
}
references:- 3librustc/middle/typeck/check/mod.rs:
592: let t = ty::node_id_to_type(tcx, f.node.id);
593: if !ty::type_is_sized(tcx, t) {
594: match f.node.kind {
librustc/middle/kind.rs:
561: fn check_sized(tcx: &ty::ctxt, ty: ty::t, name: ~str, sp: Span) {
562: if !ty::type_is_sized(tcx, ty) {
563: tcx.sess.span_err(sp, format!("variable `{}` has dynamically sized type `{}`",
librustc/middle/typeck/check/mod.rs:
3605: // unsized and we must track this in the type system.
3606: if !ty::type_is_sized(ccx.tcx, *t) {
3607: ccx.tcx.sess.span_err(args.get(i).ty.span,
librustc/middle/ty.rs:1287:10-1287:10 -fn- definition:
pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) }
pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) }
pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
references:- 6librustc/middle/typeck/check/mod.rs:
4356: (0, vec!(ty::mk_i32(), ty::mk_i32()),
4357: ty::mk_tup(tcx, vec!(ty::mk_i32(), ty::mk_bool()))),
librustc/middle/ty.rs:
1321: ast::TyI16 => mk_i16(),
1322: ast::TyI32 => mk_i32(),
1323: ast::TyI64 => mk_i64(),
librustc/middle/ty.rs:2030:1-2030:1 -fn- definition:
pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
let ty_id = type_id(ty);
match cx.tc_cache.borrow().find(&ty_id) {
references:- 102027: pub fn type_interior_is_unsafe(cx: &ctxt, t: ty::t) -> bool {
2028: type_contents(cx, t).interior_unsafe()
2029: }
--
2585: pub fn type_is_sized(cx: &ctxt, ty: ty::t) -> bool {
2586: type_contents(cx, ty).is_sized(cx)
2587: }
librustc/middle/check_static.rs:
37: let node_ty = ty::node_id_to_type(cx, e.id);
38: let tcontents = ty::type_contents(cx, node_ty);
39: debug!("safe_type_for_static_mut(dtor={}, managed={}, owned={})",
librustc/middle/kind.rs:
431: ty_to_str(cx.tcx, ty),
432: ty::type_contents(cx.tcx, ty).to_str());
433: if ty::type_moves_by_default(cx.tcx, ty) {
librustc/middle/trans/intrinsic.rs:
451: let tp_ty = *substs.tys.get(0);
452: Ret(bcx, C_bool(ccx, ty::type_contents(ccx.tcx(), tp_ty).owns_managed()));
453: }
librustc/middle/ty.rs:
2305: pub fn type_moves_by_default(cx: &ctxt, ty: t) -> bool {
2306: type_contents(cx, ty).moves_by_default(cx)
2307: }
librustc/middle/ty.rs:2833:1-2833:1 -fn- definition:
pub fn adjust_ty(cx: &ctxt,
span: Span,
expr_id: ast::NodeId,
references:- 42791: adjust_ty(cx, expr.span, expr.id, expr_ty(cx, expr),
2792: cx.adjustments.borrow().find(&expr.id),
librustc/middle/typeck/check/regionck.rs:
256: let tcx = self.fcx.tcx();
257: ty::adjust_ty(tcx, expr.span, expr.id, ty_unadjusted,
258: self.fcx.inh.adjustments.borrow().find(&expr.id),
librustc/middle/mem_categorization.rs:
369: let unadjusted_ty = if_ok!(self.expr_ty(expr));
370: Ok(ty::adjust_ty(self.tcx(), expr.span, expr.id, unadjusted_ty,
371: self.typer.adjustments().borrow().find(&expr.id),
librustc/middle/typeck/check/regionck.rs:
971: let ty0 = rcx.resolve_node_type(id);
972: let ty = ty::adjust_ty(tcx, origin.span(), id, ty0,
973: rcx.fcx.inh.adjustments.borrow().find(&id),
librustc/middle/ty.rs:870:60-870:60 -struct- definition:
pub struct RegionVid {
pub id: uint
}
references:- 55librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/util/ppaux.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/ty.rs:2250:4-2250:4 -fn- definition:
fn object_contents(cx: &ctxt,
store: TraitStore,
bounds: BuiltinBounds)
references:- 22103: ty_trait(box ty::TyTrait { store, bounds, .. }) => {
2104: object_contents(cx, store, bounds)
2105: }
--
2237: // even more stuff.
2238: let st = object_contents(cx, cty.store, cty.bounds);
librustc/middle/ty.rs:2811:1-2811:1 -fn- definition:
pub fn local_var_name_str(cx: &ctxt, id: NodeId) -> InternedString {
match cx.map.find(id) {
Some(ast_map::NodeLocal(pat)) => {
references:- 9librustc/middle/typeck/check/writeback.rs:
448: captured variable `{}`: {}",
449: ty::local_var_name_str(
450: self.tcx(),
librustc/middle/typeck/infer/error_reporting.rs:
1307: format!("...so that closure can access `{}`",
1308: ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str()))
1309: }
--
1330: does not outlive the enclosing closure",
1331: ty::local_var_name_str(self.tcx, id).get().to_str()));
1332: }
librustc/middle/borrowck/mod.rs:
720: LpVar(id) => {
721: out.push_str(ty::local_var_name_str(self.tcx, id).get());
722: }
librustc/util/ppaux.rs:
938: self.var_id,
939: ty::local_var_name_str(tcx, self.var_id),
940: self.closure_expr_id)
librustc/middle/typeck/infer/error_reporting.rs:
441: format!("...but `{}` is only valid for ",
442: ty::local_var_name_str(self.tcx, upvar_id.var_id).get().to_str()),
443: sup,
librustc/middle/ty.rs:3910:61-3910:61 -fn- definition:
/// Determine whether an item is annotated with an attribute
pub fn has_attr(tcx: &ctxt, did: DefId, attr: &str) -> bool {
let mut found = false;
references:- 43744: Some(&method_def_id) => {
3745: let flag = !has_attr(cx, struct_id, "unsafe_no_drop_flag");
--
3925: pub fn lookup_packed(tcx: &ctxt, did: DefId) -> bool {
3926: has_attr(tcx, did, "packed")
3927: }
librustc/middle/typeck/variance.rs:
1001: // attribute and report an error with various results if found.
1002: if ty::has_attr(tcx, item_def_id, "rustc_variance") {
1003: let found = item_variances.repr(tcx);
librustc/middle/ty.rs:
3930: pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
3931: has_attr(tcx, did, "simd")
3932: }
librustc/middle/ty.rs:1461:1-1461:1 -fn- definition:
pub fn mk_self(cx: &ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }
pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
references:- 74645: // map Self => Self
4646: let self_ty = self_bound.as_ref().map(|t| ty::mk_self(tcx, t.def_id));
librustc/middle/typeck/astconv.rs:
671: let did = ast_util::local_def(id);
672: ty::mk_self(tcx, did)
673: }
librustc/middle/typeck/collect.rs:
867: ast::ItemTrait(ref generics, sized, ref supertraits, _) => {
868: let self_ty = ty::mk_self(tcx, def_id);
869: let ty_generics = ty_generics_for_type(ccx, generics);
librustc/metadata/tydecode.rs:
330: let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
331: return ty::mk_self(st.tcx, did);
332: }
librustc/middle/typeck/collect.rs:
643: split_trait_methods(trait_methods.as_slice());
644: let untransformed_rcvr_ty = ty::mk_self(tcx, local_def(it.id));
645: convert_methods(ccx,
librustc/middle/ty.rs:194:51-194:51 -enum- definition:
pub enum Variance {
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
references:- 24195: pub enum Variance {
--
4618: impl Variance {
4619: pub fn to_str(self) -> &'static str {
librustc/middle/typeck/variance.rs:
1040: impl Xform for ty::Variance {
1041: fn xform(self, v: ty::Variance) -> ty::Variance {
--
1065: fn glb(v1: ty::Variance, v2: ty::Variance) -> ty::Variance {
1066: // Greatest lower bound of the variance lattice as
librustc/util/ppaux.rs:
732: impl Repr for ty::Variance {
733: fn repr(&self, _: &ctxt) -> ~str {
librustc/middle/ty.rs:
195: pub enum Variance {
librustc/middle/ty.rs:4276:1-4276:1 -fn- definition:
pub fn get_tydesc_ty(tcx: &ctxt) -> Result<t, ~str> {
tcx.lang_items.require(TyDescStructLangItem).map(|tydesc_lang_item| {
tcx.intrinsic_defs.borrow().find_copy(&tydesc_lang_item)
references:- 3librustc/middle/typeck/check/mod.rs:
4205: "visit_tydesc" => {
4206: let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
4207: Ok(t) => t,
librustc/middle/trans/reflect.rs:
386: let final = fcx.new_temp_block("final");
387: let tydesc_ty = ty::get_tydesc_ty(bcx.tcx()).unwrap();
388: let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
librustc/middle/ty.rs:2689:1-2689:1 -fn- definition:
pub fn ty_fn_sig(fty: t) -> FnSig {
match get(fty).sty {
ty_bare_fn(ref f) => f.sig.clone(),
references:- 2librustc/middle/typeck/check/regionck.rs:
812: }
813: let fn_sig = ty::ty_fn_sig(callee_ty);
--
876: // was applied on the base type, as that is always the case.
877: let fn_sig = ty::ty_fn_sig(method.ty);
878: let self_ty = *fn_sig.inputs.get(0);
librustc/middle/ty.rs:394:1-394:1 -fn- definition:
pub fn get(t: t) -> t_box {
unsafe {
let t2: t_box = cast::transmute(t);
references:- 294librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/check_match.rs:
librustc/middle/check_static.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/borrowck/gather_loans/gather_moves.rs:
librustc/middle/borrowck/gather_loans/move_error.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/liveness.rs:
librustc/middle/kind.rs:
librustc/middle/const_eval.rs:
librustc/middle/privacy.rs:
librustc/middle/effect.rs:
librustc/middle/expr_use_visitor.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/decoder.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/monomorphize.rs:
librustc/middle/trans/glue.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/common.rs:
librustc/middle/trans/consts.rs:
librustc/middle/trans/type_of.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/closure.rs:
librustc/middle/trans/tvec.rs:
librustc/middle/trans/meth.rs:
librustc/middle/trans/foreign.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/trans/adt.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:3034:1-3034:1 -fn- definition:
pub fn resolve_expr(tcx: &ctxt, expr: &ast::Expr) -> ast::Def {
match tcx.def_map.borrow().find(&expr.id) {
Some(&def) => def,
references:- 4librustc/middle/effect.rs:
183: ast::ExprPath(..) => {
184: match ty::resolve_expr(self.tcx, expr) {
185: ast::DefStatic(_, true) => {
librustc/middle/trans/expr.rs:
261: let fn_ptr = datum.to_llscalarish(bcx);
262: let def = ty::resolve_expr(bcx.tcx(), expr);
263: closure::make_closure_from_bare_fn(bcx, closure_ty, def, fn_ptr)
librustc/middle/trans/consts.rs:
196: ty::AutoAddEnv(ty::RegionTraitStore(ty::ReStatic, _)) => {
197: let def = ty::resolve_expr(cx.tcx(), e);
198: let wrapper = closure::get_wrapper_for_bare_fn(cx,
librustc/middle/ty.rs:
3081: ast::ExprPath(..) => {
3082: match resolve_expr(tcx, expr) {
3083: ast::DefVariant(tid, vid, _) => {
librustc/middle/ty.rs:2939:4-2939:4 -fn- definition:
fn borrow_vec(cx: &ctxt,
span: Span,
r: Region,
references:- 22907: AutoBorrowVecRef(r, m) => {
2908: adjusted_ty = borrow_vec(cx,
2909: span,
librustc/middle/ty.rs:1272:10-1272:10 -fn- definition:
pub fn mk_bot() -> t { mk_prim_t(&primitives::TY_BOT) }
pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) }
pub fn mk_int() -> t { mk_prim_t(&primitives::TY_INT) }
references:- 13librustc/middle/typeck/check/mod.rs:
1156: pub fn write_bot(&self, node_id: ast::NodeId) {
1157: self.write_ty(node_id, ty::mk_bot());
1158: }
--
2038: } else if ty::type_is_bot(cond_ty) {
2039: ty::mk_bot()
2040: } else {
--
2647: } else if ty::type_is_bot(arg_t) {
2648: ty::mk_bot()
2649: } else {
--
2890: } else if ty::type_is_bot(tm.ty) {
2891: ty::mk_bot()
2892: }
--
4163: match name.get() {
4164: "abort" => (0, Vec::new(), ty::mk_bot()),
4165: "breakpoint" => (0, Vec::new(), ty::mk_nil()),
librustc/middle/typeck/check/_match.rs:
98: } else if ty::type_is_bot(discrim_ty) {
99: result_ty = ty::mk_bot();
100: }
librustc/middle/typeck/astconv.rs:
554: ast::TyNil => ty::mk_nil(),
555: ast::TyBot => ty::mk_bot(),
556: ast::TyBox(ty) => {
librustc/middle/typeck/infer/lattice.rs:
362: fn ty_bot(&self, _t: ty::t) -> cres<ty::t> {
363: Ok(ty::mk_bot())
364: }
librustc/metadata/tydecode.rs:
286: 'n' => return ty::mk_nil(),
287: 'z' => return ty::mk_bot(),
288: 'b' => return ty::mk_bool(),
librustc/middle/ty.rs:
1146: ty_char => return mk_char(),
1147: ty_bot => return mk_bot(),
1148: _ => {}
librustc/middle/ty.rs:1606:1-1606:1 -fn- definition:
pub fn type_is_bool(ty: t) -> bool { get(ty).sty == ty_bool }
pub fn type_is_self(ty: t) -> bool {
match get(ty).sty {
references:- 3librustc/middle/trans/datum.rs:
537: C_undef(type_of::type_of(bcx.ccx(), ty))
538: } else if ty::type_is_bool(ty) {
539: LoadRangeAssert(bcx, llptr, 0, 2, lib::llvm::False)
--
659: pub fn to_llbool<'a>(self, bcx: &'a Block<'a>) -> ValueRef {
660: assert!(ty::type_is_bool(self.ty) || ty::type_is_bot(self.ty))
661: let cond_val = self.to_llscalarish(bcx);
librustc/middle/trans/expr.rs:
1125: let datum = unpack_datum!(bcx, trans(bcx, sub_expr));
1126: let llresult = if ty::type_is_bool(un_ty) {
1127: let val = datum.to_llscalarish(bcx);
librustc/middle/ty.rs:1453:1-1453:1 -fn- definition:
pub fn mk_var(cx: &ctxt, v: TyVid) -> t { mk_infer(cx, TyVar(v)) }
pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) }
pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
references:- 5librustc/middle/typeck/check/mod.rs:
379: let var_id = self.fcx.infcx().next_ty_var_id();
380: let var_ty = ty::mk_var(self.fcx.tcx(), var_id);
381: self.fcx.inh.locals.borrow_mut().insert(nid, var_ty);
librustc/middle/typeck/infer/mod.rs:
604: pub fn next_ty_var(&self) -> ty::t {
605: ty::mk_var(self.tcx, self.next_ty_var_id())
606: }
librustc/middle/typeck/infer/resolve.rs:
230: }
231: ty::mk_var(tcx, vid)
232: }
librustc/middle/typeck/infer/lattice.rs:
388: return match r {
389: VarResult(v) => Ok(ty::mk_var(tcx, v)),
390: ValueResult(t) => Ok(t)
librustc/middle/ty.rs:1359:1-1359:1 -fn- definition:
pub fn mk_enum(cx: &ctxt, did: ast::DefId, substs: substs) -> t {
// take a copy of substs so that we own the vectors inside
mk_t(cx, ty_enum(did, substs))
references:- 3librustc/middle/typeck/infer/combine.rs:
469: b_substs));
470: Ok(ty::mk_enum(tcx, a_id, substs))
471: }
librustc/metadata/tydecode.rs:
312: assert_eq!(next(st), ']');
313: return ty::mk_enum(st.tcx, def, substs);
314: }
librustc/middle/typeck/collect.rs:
950: let substs = mk_item_substs(ccx, &ty_generics, None);
951: let t = ty::mk_enum(tcx, local_def(it.id), substs);
952: let tpt = ty_param_bounds_and_ty {
librustc/middle/ty.rs:369:1-369:1 -NK_AS_STR_TODO- definition:
pub type t_box = &'static t_box_;
pub struct t_box_ {
pub sty: sty,
references:- 3402: pub fn tbox_has_flag(tb: t_box, flag: tbox_flag) -> bool {
403: (tb.flags & (flag as uint)) != 0u
librustc/middle/ty.rs:1368:1-1368:1 -fn- definition:
pub fn mk_ptr(cx: &ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t {
references:- 182919: AutoUnsafe(m) => {
2920: mk_ptr(cx, mt {ty: adjusted_ty, mutbl: m})
2921: }
librustc/middle/typeck/check/mod.rs:
4230: ),
4231: ty::mk_ptr(tcx, ty::mt {
4232: ty: param(ccx, 0),
--
4243: }),
4244: ty::mk_ptr(tcx, ty::mt {
4245: ty: param(ccx, 0),
librustc/middle/typeck/astconv.rs:
571: ast::TyPtr(ref mt) => {
572: ty::mk_ptr(tcx, ty::mt {
573: ty: ast_ty_to_ty(this, rscope, mt.ty),
librustc/middle/typeck/infer/combine.rs:
503: let mt = if_ok!(this.mts(a_mt, b_mt));
504: check_ptr_to_vec(this, a, b, a_mt.ty, b_mt.ty, ty::mk_ptr(tcx, mt))
505: }
librustc/middle/typeck/infer/coercion.rs:
428: // check that the types which they point at are compatible
429: let a_unsafe = ty::mk_ptr(self.get_ref().infcx.tcx, mt_a);
430: if_ok!(self.subtype(a_unsafe, b));
librustc/metadata/tydecode.rs:
334: '~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
335: '*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
336: '&' => {
librustc/middle/trans/closure.rs:
184: let cbox_ty = tuplify_box_ty(tcx, cdata_ty);
185: let cboxptr_ty = ty::mk_ptr(tcx, ty::mt {ty:cbox_ty, mutbl:ast::MutImmutable});
186: let llboxptr_ty = type_of(ccx, cboxptr_ty);
librustc/middle/trans/reflect.rs:
283: let opaquety = ty::get_opaque_ty(ccx.tcx()).unwrap();
284: let opaqueptrty = ty::mk_ptr(ccx.tcx(), ty::mt { ty: opaquety,
285: mutbl: ast::MutImmutable });
librustc/middle/trans/debuginfo.rs:
2035: let data_ptr_type = ty::mk_ptr(cx.tcx(), ty::mt {
2036: ty: element_type,
librustc/middle/typeck/check/mod.rs:
4254: vec!(
4255: ty::mk_ptr(tcx, ty::mt {
4256: ty: param(ccx, 0),
librustc/middle/ty.rs:1463:1-1463:1 -fn- definition:
pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
}
references:- 124659: ty::mk_param(tcx, i, def_id)
4660: });
librustc/middle/typeck/check/mod.rs:
989: impl_m.generics.type_param_defs().iter().enumerate().
990: map(|(i,t)| ty::mk_param(tcx, i + impl_tps, t.def_id)).
991: collect();
--
4125: fn param(ccx: &CrateCtxt, n: uint) -> ty::t {
4126: ty::mk_param(ccx.tcx, n, local_def(0))
4127: }
librustc/middle/typeck/astconv.rs:
663: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
664: ty::mk_param(tcx, n, id)
665: }
librustc/middle/typeck/collect.rs:
1095: TraitTyParamBound(ref b) => {
1096: let ty = ty::mk_param(ccx.tcx, param_ty.idx, param_ty.def_id);
1097: let trait_ref = instantiate_trait_ref(ccx, b, ty);
--
1210: ty_generics.type_param_defs().iter().enumerate().map(
1211: |(i, t)| ty::mk_param(ccx.tcx, i, t.def_id)).collect();
librustc/middle/typeck/coherence.rs:
724: method.generics.type_param_defs().iter().enumerate()
725: .map(|(i, t)| ty::mk_param(tcx, i + num_impl_tps, t.def_id))
726: .collect();
librustc/metadata/tydecode.rs:
326: debug!("parsed ty_param: did={:?}", did);
327: return ty::mk_param(st.tcx, parse_uint(st), did);
328: }
librustc/middle/typeck/collect.rs:
301: let shifted_method_tps = Vec::from_fn(num_method_bounds, |i| {
302: ty::mk_param(tcx, i + num_trait_bounds + 1,
303: m.generics.type_param_defs()[i].def_id)
librustc/middle/ty.rs:2776:1-2776:1 -fn- definition:
pub fn expr_ty_adjusted(cx: &ctxt, expr: &ast::Expr) -> t {
/*!
*
references:- 10librustc/middle/borrowck/mod.rs:
489: Some(ast_map::NodeExpr(expr)) => {
490: (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
491: }
--
515: Some(ast_map::NodeExpr(expr)) => {
516: (ty::expr_ty_adjusted(self.tcx, expr), expr.span)
517: }
librustc/middle/kind.rs:
317: let source_ty = ty::expr_ty(cx.tcx, e);
318: let target_ty = ty::expr_ty_adjusted(cx.tcx, e);
319: check_trait_cast(cx, source_ty, target_ty, e.span);
librustc/middle/expr_use_visitor.rs:
400: fn walk_callee(&mut self, call: &ast::Expr, callee: &ast::Expr) {
401: let callee_ty = ty::expr_ty_adjusted(self.tcx(), callee);
402: debug!("walk_callee: callee={} callee_ty={}",
librustc/middle/trans/expr.rs:
206: AutoObject(..) => {
207: let adjusted_ty = ty::expr_ty_adjusted(bcx.tcx(), expr);
208: let scratch = rvalue_scratch_datum(bcx, adjusted_ty, "__adjust");
librustc/middle/trans/common.rs:
699: pub fn expr_ty_adjusted(bcx: &Block, ex: &ast::Expr) -> ty::t {
700: monomorphize_type(bcx, ty::expr_ty_adjusted(bcx.tcx(), ex))
701: }
librustc/middle/trans/consts.rs:
415: ast::ExprField(base, field, _) => {
416: let bt = ty::expr_ty_adjusted(cx.tcx(), base);
417: let brepr = adt::represent_type(cx, bt);
--
425: ast::ExprIndex(base, index) => {
426: let bt = ty::expr_ty_adjusted(cx.tcx(), base);
427: let (bv, inlineable) = const_expr(cx, base, is_local);
librustc/middle/privacy.rs:
776: ast::ExprField(base, ident, _) => {
777: match ty::get(ty::expr_ty_adjusted(self.tcx, base)).sty {
778: ty::ty_struct(id, _) => {
librustc/middle/ty.rs:1594:1-1594:1 -fn- definition:
pub fn trait_ref_contains_error(tref: &ty::TraitRef) -> bool {
tref.substs.self_ty.iter().any(|&t| type_is_error(t)) ||
tref.substs.tps.iter().any(|&t| type_is_error(t))
references:- 3librustc/middle/typeck/check/vtable.rs:
201: // inside the types.
202: if !ty::trait_ref_contains_error(&r_act_trait_ref) &&
203: !ty::trait_ref_contains_error(&r_exp_trait_ref)
librustc/middle/typeck/infer/error_reporting.rs:
1404: fn contains_error(&self) -> bool {
1405: ty::trait_ref_contains_error(&**self)
1406: }
librustc/middle/typeck/check/vtable.rs:
202: if !ty::trait_ref_contains_error(&r_act_trait_ref) &&
203: !ty::trait_ref_contains_error(&r_exp_trait_ref)
204: {
librustc/middle/ty.rs:1290:10-1290:10 -fn- definition:
pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) }
pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
references:- 4librustc/middle/typeck/check/mod.rs:
4359: "i64_add_with_overflow" | "i64_sub_with_overflow" | "i64_mul_with_overflow" =>
4360: (0, vec!(ty::mk_i64(), ty::mk_i64()),
4361: ty::mk_tup(tcx, vec!(ty::mk_i64(), ty::mk_bool()))),
librustc/middle/ty.rs:
1322: ast::TyI32 => mk_i32(),
1323: ast::TyI64 => mk_i64(),
1324: }
librustc/middle/ty.rs:2768:34-2768:34 -fn- definition:
// expr_ty_params_and_ty() below.
pub fn expr_ty(cx: &ctxt, expr: &ast::Expr) -> t {
return node_id_to_type(cx, expr.id);
references:- 37librustc/middle/check_const.rs:
librustc/middle/lint.rs:
librustc/middle/liveness.rs:
librustc/middle/kind.rs:
librustc/middle/const_eval.rs:
librustc/middle/privacy.rs:
librustc/middle/expr_use_visitor.rs:
librustc/driver/driver.rs:
librustc/middle/trans/consts.rs:
librustc/middle/lint.rs:
librustc/middle/ty.rs:3894:64-3894:64 -fn- definition:
// decoder to use iterators instead of higher-order functions.)
pub fn each_attr(tcx: &ctxt, did: DefId, f: |@ast::MetaItem| -> bool) -> bool {
if is_local(did) {
references:- 23936: let mut acc = attr::ReprAny;
3937: ty::each_attr(tcx, did, |meta| {
3938: acc = attr::find_repr_attr(tcx.sess.diagnostic(), meta, acc);
librustc/middle/ty.rs:975:19-975:19 -struct- definition:
pub struct TypeParameterDef {
pub ident: ast::Ident,
pub def_id: ast::DefId,
references:- 30librustc/middle/subst.rs:
librustc/middle/typeck/collect.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/kind.rs:
librustc/middle/astencode.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/util/ppaux.rs:
librustc/middle/ty.rs:1159:4-1159:4 -fn- definition:
fn rflags(r: Region) -> uint {
(has_regions as uint) | {
match r {
references:- 41213: &ty_rptr(r, ref m) => {
1214: flags |= rflags(r);
1215: flags |= get(m.ty).flags;
--
1226: RegionTraitStore(r, _) => {
1227: flags |= rflags(r);
1228: }
librustc/middle/ty.rs:1302:10-1302:10 -fn- definition:
pub fn mk_uint() -> t { mk_prim_t(&primitives::TY_UINT) }
pub fn mk_u8() -> t { mk_prim_t(&primitives::TY_U8) }
pub fn mk_u16() -> t { mk_prim_t(&primitives::TY_U16) }
references:- 101328: match tm {
1329: ast::TyU => mk_uint(),
1330: ast::TyU8 => mk_u8(),
librustc/middle/typeck/check/mod.rs:
4259: ty::mk_u8(),
4260: ty::mk_uint()
4261: ),
librustc/metadata/tydecode.rs:
289: 'i' => return ty::mk_int(),
290: 'u' => return ty::mk_uint(),
291: 'M' => {
librustc/middle/trans/closure.rs:
132: let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8());
133: ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t))
134: }
librustc/middle/trans/debuginfo.rs:
2049: llvm_type: *member_llvm_types.get(1),
2050: type_metadata: type_metadata(cx, ty::mk_uint(), span),
2051: offset: ComputedMemberOffset,
librustc/middle/typeck/check/mod.rs:
4166: "size_of" |
4167: "pref_align_of" | "min_align_of" => (1u, Vec::new(), ty::mk_uint()),
4168: "init" => (1u, Vec::new(), param(ccx, 0u)),
librustc/middle/ty.rs:1633:1-1633:1 -fn- definition:
pub fn type_is_simd(cx: &ctxt, ty: t) -> bool {
match get(ty).sty {
ty_struct(did, _) => lookup_simd(cx, did),
references:- 84088: fn tycat(cx: &ctxt, ty: t) -> int {
4089: if type_is_simd(cx, ty) {
4090: return tycat(cx, simd_type(cx, ty))
librustc/middle/typeck/check/mod.rs:
2121: ast::BiGt => {
2122: if ty::type_is_simd(tcx, lhs_t) {
2123: if ty::type_is_fp(ty::simd_type(tcx, lhs_t)) {
librustc/middle/trans/expr.rs:
1263: let tcx = bcx.tcx();
1264: let is_simd = ty::type_is_simd(tcx, lhs_t);
1265: let intype = {
librustc/middle/trans/common.rs:
66: type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
67: ty::type_is_simd(tcx, ty);
68: if simple {
librustc/middle/trans/type_of.rs:
287: match ty::get(t).sty {
288: ty::ty_enum(..) | ty::ty_struct(..) if !ty::type_is_simd(cx.tcx(), t) => {
289: let repr = adt::represent_type(cx, t);
librustc/middle/trans/debuginfo.rs:
2238: ty::ty_struct(def_id, ref substs) => {
2239: if ty::type_is_simd(cx.tcx(), t) {
2240: let element_type = ty::simd_type(cx.tcx(), t);
librustc/middle/ty.rs:1326:1-1326:1 -fn- definition:
pub fn mk_mach_uint(tm: ast::UintTy) -> t {
match tm {
ast::TyU => mk_uint(),
references:- 111143: ty_int(i) => return mk_mach_int(i),
1144: ty_uint(u) => return mk_mach_uint(u),
1145: ty_float(f) => return mk_mach_float(f),
librustc/middle/typeck/check/mod.rs:
1409: ast::LitInt(_, t) => ty::mk_mach_int(t),
1410: ast::LitUint(_, t) => ty::mk_mach_uint(t),
1411: ast::LitIntUnsuffixed(_) => {
librustc/middle/typeck/astconv.rs:
340: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
341: Some(ty::mk_mach_uint(uit))
342: }
librustc/middle/typeck/infer/combine.rs:
561: IntType(v) => Ok(ty::mk_mach_int(v)),
562: UintType(v) => Ok(ty::mk_mach_uint(v))
563: }
librustc/middle/typeck/infer/resolve.rs:
246: Some(IntType(t)) => ty::mk_mach_int(t),
247: Some(UintType(t)) => ty::mk_mach_uint(t),
248: None => {
librustc/metadata/tydecode.rs:
293: 'b' => return ty::mk_mach_uint(ast::TyU8),
294: 'w' => return ty::mk_mach_uint(ast::TyU16),
295: 'l' => return ty::mk_mach_uint(ast::TyU32),
296: 'd' => return ty::mk_mach_uint(ast::TyU64),
297: 'B' => return ty::mk_mach_int(ast::TyI8),
librustc/middle/trans/adt.rs:
389: attr::SignedInt(t) => ty::mk_mach_int(t),
390: attr::UnsignedInt(t) => ty::mk_mach_uint(t)
391: }
librustc/middle/ty.rs:
1646: ty_vec(mt, None) => mt.ty,
1647: ty_str => mk_mach_uint(ast::TyU8),
1648: _ => cx.sess.bug("sequence_element_type called on non-sequence value"),
librustc/middle/ty.rs:1471:1-1471:1 -fn- definition:
pub fn maybe_walk_ty(ty: t, f: |t| -> bool) {
if !f(ty) {
return;
references:- 101752: let mut needs_unwind_cleanup = false;
1753: maybe_walk_ty(ty, |ty| {
1754: let old_encountered_box = encountered_box;
librustc/middle/ty.rs:2191:4-2191:4 -fn- definition:
fn tc_mt(cx: &ctxt,
mt: mt,
cache: &mut HashMap<uint, TypeContents>) -> TypeContents
references:- 22125: TypeContents::union(flds.as_slice(),
2126: |f| tc_mt(cx, f.mt, cache));
2127: if ty::has_dtor(cx, did) {
librustc/middle/ty.rs:3561:1-3561:1 -fn- definition:
pub fn impl_trait_ref(cx: &ctxt, id: ast::DefId) -> Option<Rc<TraitRef>> {
match cx.impl_trait_cache.borrow().find(&id) {
Some(ret) => { return ret.clone(); }
references:- 9librustc/middle/typeck/check/vtable.rs:
342: // get all the ty vars sorted out.
343: let r = ty::impl_trait_ref(tcx, impl_did);
344: let of_trait_ref = r.expect("trait_ref missing on trait impl");
librustc/middle/typeck/check/method.rs:
674: // we only want to report each base trait once
675: match ty::impl_trait_ref(self.tcx(), impl_did) {
676: Some(trait_ref) => trait_ref.def_id,
librustc/middle/lint.rs:
1514: ty::ImplContainer(cid) => {
1515: match ty::impl_trait_ref(cx.tcx, cid) {
1516: Some(..) => return, // impl for trait: don't doc
librustc/middle/privacy.rs:
255: };
256: let tr = ty::impl_trait_ref(self.tcx, local_def(item.id));
257: let public_trait = tr.clone().map_or(false, |tr| {
--
381: ty::ImplContainer(id) => {
382: match ty::impl_trait_ref(self.tcx, id) {
383: Some(t) => {
--
438: let imp = self.tcx.map.get_parent_did(closest_private_id);
439: match ty::impl_trait_ref(self.tcx, imp) {
440: Some(..) => return Allowable,
librustc/middle/trans/callee.rs:
314: let method = ty::method(tcx, source_id);
315: let trait_ref = ty::impl_trait_ref(tcx, impl_id)
316: .expect("could not find trait_ref for impl with \
librustc/middle/trans/meth.rs:
494: let trt_id = match ty::impl_trait_ref(tcx, impl_id) {
495: Some(t_id) => t_id.def_id,
librustc/middle/typeck/check/vtable.rs:
510: let impl_trait_ref = match ty::impl_trait_ref(tcx, impl_did) {
511: Some(t) => t,
librustc/middle/ty.rs:238:14-238:14 -struct- definition:
/// later on.
pub struct ctxt {
// Specifically use a speedy hash algorithm for this hash map, it's used
references:- 480librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/check_match.rs:
librustc/middle/check_const.rs:
librustc/middle/check_static.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/borrowck/check_loans.rs:
librustc/middle/borrowck/gather_loans/mod.rs:
librustc/middle/borrowck/move_data.rs:
librustc/middle/dataflow.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/liveness.rs:
librustc/middle/kind.rs:
librustc/middle/freevars.rs:
librustc/middle/const_eval.rs:
librustc/middle/astencode.rs:
librustc/middle/privacy.rs:
librustc/middle/effect.rs:
librustc/middle/reachable.rs:
librustc/middle/cfg/mod.rs:
librustc/middle/cfg/construct.rs:
librustc/middle/dead.rs:
librustc/middle/expr_use_visitor.rs:
librustc/middle/dependency_format.rs:
librustc/back/link.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/metadata/csearch.rs:
librustc/driver/driver.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/common.rs:
librustc/middle/trans/context.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/closure.rs:
librustc/middle/trans/adt.rs:
librustc/middle/trans/cleanup.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:498:38-498:38 -struct- definition:
pub struct UpvarId {
pub var_id: ast::NodeId,
pub closure_expr_id: ast::NodeId,
references:- 35librustc/middle/typeck/check/regionck.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/expr_use_visitor.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/borrowck/gather_loans/restrictions.rs:
librustc/middle/mem_categorization.rs:
librustc/util/ppaux.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/ty.rs:1275:10-1275:10 -fn- definition:
pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) }
pub fn mk_int() -> t { mk_prim_t(&primitives::TY_INT) }
pub fn mk_i8() -> t { mk_prim_t(&primitives::TY_I8) }
references:- 19librustc/middle/typeck/check/mod.rs:
4356: (0, vec!(ty::mk_i32(), ty::mk_i32()),
4357: ty::mk_tup(tcx, vec!(ty::mk_i32(), ty::mk_bool()))),
--
4368: (0, vec!(ty::mk_u16(), ty::mk_u16()),
4369: ty::mk_tup(tcx, vec!(ty::mk_u16(), ty::mk_bool()))),
--
4372: (0, vec!(ty::mk_u32(), ty::mk_u32()),
4373: ty::mk_tup(tcx, vec!(ty::mk_u32(), ty::mk_bool()))),
--
4376: (0, vec!(ty::mk_u64(), ty::mk_u64()),
4377: ty::mk_tup(tcx, vec!(ty::mk_u64(), ty::mk_bool()))),
librustc/middle/typeck/check/_match.rs:
64: Some(e) => {
65: check_expr_has_type(fcx, e, ty::mk_bool());
66: let e_ty = fcx.expr_ty(e);
librustc/middle/typeck/astconv.rs:
328: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
329: Some(ty::mk_bool())
330: }
librustc/metadata/tydecode.rs:
287: 'z' => return ty::mk_bot(),
288: 'b' => return ty::mk_bool(),
289: 'i' => return ty::mk_int(),
librustc/middle/trans/adt.rs:
149: let dtor = ty::ty_dtor(cx.tcx(), def_id).has_drop_flag();
150: if dtor { ftys.push(ty::mk_bool()); }
librustc/middle/ty.rs:
1141: ty_err => return mk_err(),
1142: ty_bool => return mk_bool(),
1143: ty_int(i) => return mk_mach_int(i),
librustc/middle/ty.rs:1347:1-1347:1 -fn- definition:
pub fn mk_str(cx: &ctxt) -> t {
mk_t(cx, ty_str)
}
references:- 5librustc/middle/typeck/astconv.rs:
357: // return /something/ so they can at least get more errors
358: Some(ty::mk_uniq(tcx, ty::mk_str(tcx)))
359: }
librustc/middle/typeck/infer/combine.rs:
523: (&ty::ty_str, &ty::ty_str) => {
524: Ok(ty::mk_str(tcx))
525: }
librustc/metadata/tydecode.rs:
346: 'v' => {
347: return ty::mk_str(st.tcx);
348: }
librustc/middle/trans/tvec.rs:
246: let llsizeval = C_uint(ccx, s.get().len());
247: let typ = ty::mk_uniq(bcx.tcx(), ty::mk_str(bcx.tcx()));
248: let lldestval = rvalue_scratch_datum(bcx,
librustc/middle/typeck/astconv.rs:
489: Uniq => {
490: return constr(ty::mk_str(tcx));
491: }
librustc/middle/ty.rs:1314:10-1314:10 -fn- definition:
pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
pub fn mk_mach_int(tm: ast::IntTy) -> t {
match tm {
references:- 15librustc/middle/typeck/check/mod.rs:
4332: "ctlz32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()),
4333: "ctlz64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()),
4334: "cttz8" => (0, vec!( ty::mk_u8() ), ty::mk_u8()),
--
4339: "bswap32" => (0, vec!( ty::mk_u32() ), ty::mk_u32()),
4340: "bswap64" => (0, vec!( ty::mk_u64() ), ty::mk_u64()),
--
4376: (0, vec!(ty::mk_u64(), ty::mk_u64()),
4377: ty::mk_tup(tcx, vec!(ty::mk_u64(), ty::mk_bool()))),
librustc/middle/trans/reflect.rs:
294: ty::mk_u64(), None, None, &arena);
295: init_function(&fcx, false, ty::mk_u64());
librustc/middle/ty.rs:
1332: ast::TyU32 => mk_u32(),
1333: ast::TyU64 => mk_u64(),
1334: }
librustc/middle/ty.rs:1711:3-1711:3 -fn- definition:
*/
pub fn type_is_scalar(ty: t) -> bool {
match get(ty).sty {
references:- 4librustc/middle/typeck/check/mod.rs:
4007: let typ_s = structurally_resolved_type(fcx, sp, typ);
4008: return ty::type_is_scalar(typ_s);
4009: }
librustc/middle/trans/common.rs:
63: let tcx = ccx.tcx();
64: let simple = ty::type_is_scalar(ty) || ty::type_is_boxed(ty) ||
65: ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
librustc/middle/trans/_match.rs:
1242: let _icx = push_ctxt("compare_values");
1243: if ty::type_is_scalar(rhs_t) {
1244: let rs = compare_scalar_types(cx, lhs, rhs, rhs_t, ast::BiEq);
librustc/middle/trans/expr.rs:
1328: C_bool(bcx.ccx(), false)
1329: } else if ty::type_is_scalar(rhs_t) {
1330: let cmpr = base::compare_scalar_types(bcx, lhs, rhs, rhs_t, op);
librustc/middle/ty.rs:1345:10-1345:10 -fn- definition:
pub fn mk_char() -> t { mk_prim_t(&primitives::TY_CHAR) }
pub fn mk_str(cx: &ctxt) -> t {
mk_t(cx, ty_str)
references:- 41145: ty_float(f) => return mk_mach_float(f),
1146: ty_char => return mk_char(),
1147: ty_bot => return mk_bot(),
librustc/middle/typeck/astconv.rs:
332: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
333: Some(ty::mk_char())
334: }
librustc/metadata/tydecode.rs:
306: }
307: 'c' => return ty::mk_char(),
308: 't' => {
librustc/middle/typeck/check/mod.rs:
1407: }
1408: ast::LitChar(_) => ty::mk_char(),
1409: ast::LitInt(_, t) => ty::mk_mach_int(t),
librustc/middle/ty.rs:1062:1-1062:1 -struct- definition:
pub struct ty_param_substs_and_ty {
pub substs: ty::substs,
pub ty: ty::t
references:- 9librustc/middle/typeck/check/mod.rs:
1503: ty_param_substs_and_ty { substs: substs, ty: substd_ty }
1504: }
librustc/middle/typeck/astconv.rs:
289: } = ast_path_to_substs_and_ty(this, rscope, did, path);
290: ty_param_substs_and_ty { substs: substs, ty: ty }
291: }
librustc/middle/typeck/check/mod.rs:
1483: did: ast::DefId)
1484: -> ty_param_substs_and_ty {
1485: let tcx = vcx.tcx();
librustc/middle/typeck/check/method.rs:
702: let vcx = self.fcx.vtable_context();
703: let ty::ty_param_substs_and_ty {
704: substs: impl_substs,
librustc/middle/typeck/astconv.rs:
285: // for any type/region parameters.
286: let ty::ty_param_substs_and_ty {
287: substs: substs,
librustc/middle/typeck/check/vtable.rs:
362: // FIXME(#5781) this should be mk_eqty not mk_subty
363: let ty::ty_param_substs_and_ty {
364: substs: substs,
librustc/middle/ty.rs:1316:1-1316:1 -fn- definition:
pub fn mk_mach_int(tm: ast::IntTy) -> t {
match tm {
ast::TyI => mk_int(),
references:- 101142: ty_bool => return mk_bool(),
1143: ty_int(i) => return mk_mach_int(i),
1144: ty_uint(u) => return mk_mach_uint(u),
librustc/middle/typeck/check/mod.rs:
1408: ast::LitChar(_) => ty::mk_char(),
1409: ast::LitInt(_, t) => ty::mk_mach_int(t),
1410: ast::LitUint(_, t) => ty::mk_mach_uint(t),
librustc/middle/typeck/astconv.rs:
336: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
337: Some(ty::mk_mach_int(it))
338: }
librustc/middle/typeck/infer/combine.rs:
560: match val {
561: IntType(v) => Ok(ty::mk_mach_int(v)),
562: UintType(v) => Ok(ty::mk_mach_uint(v))
librustc/middle/typeck/infer/resolve.rs:
245: match node.possible_types {
246: Some(IntType(t)) => ty::mk_mach_int(t),
247: Some(UintType(t)) => ty::mk_mach_uint(t),
librustc/metadata/tydecode.rs:
296: 'd' => return ty::mk_mach_uint(ast::TyU64),
297: 'B' => return ty::mk_mach_int(ast::TyI8),
298: 'W' => return ty::mk_mach_int(ast::TyI16),
299: 'L' => return ty::mk_mach_int(ast::TyI32),
300: 'D' => return ty::mk_mach_int(ast::TyI64),
301: 'f' => return ty::mk_mach_float(ast::TyF32),
librustc/middle/trans/adt.rs:
388: match ity {
389: attr::SignedInt(t) => ty::mk_mach_int(t),
390: attr::UnsignedInt(t) => ty::mk_mach_uint(t)
librustc/metadata/tydecode.rs:
298: 'W' => return ty::mk_mach_int(ast::TyI16),
299: 'L' => return ty::mk_mach_int(ast::TyI32),
300: 'D' => return ty::mk_mach_int(ast::TyI64),
librustc/middle/ty.rs:3989:45-3989:45 -fn- definition:
// Fails if the id is not bound to a struct.
pub fn lookup_struct_fields(cx: &ctxt, did: ast::DefId) -> Vec<field_ty> {
if did.krate == ast::LOCAL_CRATE {
references:- 221656: ty_struct(did, ref substs) => {
1657: let fields = lookup_struct_fields(cx, did);
1658: lookup_field_type(cx, did, fields.get(0).id, substs)
--
4033: -> Vec<field> {
4034: lookup_struct_fields(cx, did).iter().map(|f| {
4035: field {
librustc/middle/typeck/check/mod.rs:
3568: ty::ty_struct(did, ref substs) => {
3569: let fields = ty::lookup_struct_fields(tcx, did);
3570: if fields.is_empty() {
librustc/middle/typeck/check/_match.rs:
364: let class_fields = ty::lookup_struct_fields(tcx, struct_id);
--
404: // Get the struct fields from this struct-like enum variant.
405: let class_fields = ty::lookup_struct_fields(tcx, variant_id);
librustc/middle/typeck/variance.rs:
494: ast::ItemStruct(..) => {
495: let struct_fields = ty::lookup_struct_fields(tcx, did);
496: for field_info in struct_fields.iter() {
librustc/middle/check_match.rs:
702: if variant(variant_id) == *ctor_id {
703: let struct_fields = ty::lookup_struct_fields(cx.tcx, variant_id);
704: let args = struct_fields.iter().map(|sf| {
librustc/middle/privacy.rs:
827: let guard = |did: ast::DefId| {
828: let fields = ty::lookup_struct_fields(self.tcx, did);
829: let any_priv = fields.iter().any(|f| {
librustc/metadata/encoder.rs:
980: ItemStruct(struct_def, _) => {
981: let fields = ty::lookup_struct_fields(tcx, def_id);
librustc/middle/trans/_match.rs:
658: let mut reordered_patterns = Vec::new();
659: let r = ty::lookup_struct_fields(tcx, struct_id);
660: for field in r.iter() {
--
1553: struct_element_count =
1554: ty::lookup_struct_fields(tcx, struct_id).len();
1555: }
librustc/middle/trans/adt.rs:
143: ty::ty_struct(def_id, ref substs) => {
144: let fields = ty::lookup_struct_fields(cx.tcx(), def_id);
145: let mut ftys = fields.iter().map(|field| {
librustc/middle/check_match.rs:
722: class_fields =
723: ty::lookup_struct_fields(cx.tcx,
724: class_id);
librustc/middle/ty.rs:2700:45-2700:45 -fn- definition:
// Type accessors for substructures of types
pub fn ty_fn_args(fty: t) -> Vec<t> {
match get(fty).sty {
references:- 93648: let arg_tys = if args.len() > 0 {
3649: ty_fn_args(ctor_ty).iter().map(|a| *a).collect()
3650: } else {
--
3670: let arg_tys = ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
3671: let arg_names = fields.iter().map(|field| {
librustc/middle/typeck/check/mod.rs:
3595: let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id);
3596: let arg_tys: Vec<ty::t> = ty::ty_fn_args(ctor_ty).iter().map(|a| *a).collect();
3597: let len = arg_tys.len();
librustc/middle/trans/callee.rs:
775: let _icx = push_ctxt("trans_args");
776: let arg_tys = ty::ty_fn_args(fn_ty);
777: let variadic = ty::fn_is_variadic(fn_ty);
librustc/middle/trans/base.rs:
1401: // Set up arguments to the function.
1402: let arg_tys = ty::ty_fn_args(node_id_type(bcx, id));
1403: let arg_datums = create_datums_for_fn_args(&fcx, arg_tys.as_slice());
--
1537: let arg_tys = ty::ty_fn_args(ctor_ty);
librustc/middle/trans/closure.rs:
440: let args = create_datums_for_fn_args(&fcx,
441: ty::ty_fn_args(closure_ty)
442: .as_slice());
librustc/middle/expr_use_visitor.rs:
598: let cmt = return_if_err!(self.mc.cat_expr_autoderefd(expr, i));
599: let self_ty = *ty::ty_fn_args(method_ty).get(0);
600: let (m, r) = match ty::get(self_ty).sty {
librustc/middle/ty.rs:123:38-123:38 -struct- definition:
pub struct mt {
pub ty: t,
pub mutbl: ast::Mutability,
references:- 133librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/metadata/tydecode.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/closure.rs:
librustc/middle/trans/tvec.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/check_match.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/effect.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/consts.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:450:38-450:38 -struct- definition:
pub struct param_ty {
pub idx: uint,
pub def_id: DefId
references:- 261464: pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
1465: mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
1466: }
librustc/middle/typeck/collect.rs:
1034: existing_def_opt.unwrap_or_else(|| {
1035: let param_ty = ty::param_ty {idx: base_index + offset,
1036: def_id: local_def(param.id)};
librustc/middle/ty.rs:
451: pub struct param_ty {
--
3244: /// to a bitset or some other representation.
3245: pub fn param_tys_in_type(ty: t) -> Vec<param_ty> {
3246: let mut rslt = Vec::new();
librustc/middle/typeck/check/mod.rs:
4106: match ty::get(t).sty {
4107: ty::ty_param(param_ty {idx, ..}) => {
4108: debug!("Found use of ty param \\#{}", idx);
librustc/middle/typeck/check/vtable.rs:
242: let vtable_opt = match ty::get(ty).sty {
243: ty::ty_param(param_ty {idx: n, ..}) => {
244: let env_bounds = &vcx.param_env.type_param_bounds;
librustc/middle/typeck/check/method.rs:
554: restrict_to: Option<DefId>,
555: param_ty: param_ty) {
556: debug!("push_inherent_candidates_from_param(param_ty={:?})",
librustc/middle/typeck/collect.rs:
1075: ccx: &CrateCtxt,
1076: param_ty: ty::param_ty,
1077: ast_bounds: &OwnedSlice<ast::TyParamBound>,
librustc/middle/typeck/variance.rs:
750: ty::ty_param(ty::param_ty { def_id: ref def_id, .. }) => {
751: assert_eq!(def_id.krate, ast::LOCAL_CRATE);
librustc/metadata/tyencode.rs:
281: }
282: ty::ty_param(param_ty {idx: id, def_id: did}) => {
283: mywrite!(w, "p{}|{}", (cx.ds)(did), id);
librustc/util/ppaux.rs:
364: ty_err => "[type error]".to_owned(),
365: ty_param(param_ty {idx: id, def_id: did}) => {
366: let ident = match cx.ty_param_defs.borrow().find(&did.node) {
librustc/middle/ty.rs:
451: pub struct param_ty {
librustc/middle/ty.rs:4437:68-4437:68 -fn- definition:
/// the trait that the method belongs to. Otherwise, return `None`.
pub fn trait_of_method(tcx: &ctxt, def_id: ast::DefId)
-> Option<ast::DefId> {
references:- 2librustc/middle/trans/callee.rs:
285: // Load the info for the appropriate trait if necessary.
286: match ty::trait_of_method(tcx, def_id) {
287: None => {}
librustc/middle/ty.rs:
4466: let name = method.ident.name;
4467: match trait_of_method(tcx, def_id) {
4468: Some(trait_did) => {
librustc/middle/ty.rs:3929:58-3929:58 -fn- definition:
/// Determine whether an item is annotated with `#[simd]`
pub fn lookup_simd(tcx: &ctxt, did: DefId) -> bool {
has_attr(tcx, did, "simd")
references:- 2librustc/middle/typeck/check/mod.rs:
619: if ty::lookup_simd(tcx, local_def(id)) {
620: check_simd(tcx, span, id);
librustc/middle/ty.rs:
1635: match get(ty).sty {
1636: ty_struct(did, _) => lookup_simd(cx, did),
1637: _ => false
librustc/middle/ty.rs:3768:1-3768:1 -fn- definition:
pub fn type_is_empty(cx: &ctxt, t: t) -> bool {
match ty::get(t).sty {
ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(),
references:- 4librustc/middle/trans/common.rs:
101: ty::type_is_nil(ty) || ty::type_is_bot(ty) || ty::type_is_empty(ccx.tcx(), ty)
102: }
librustc/middle/trans/_match.rs:
1890: let chk = {
1891: if ty::type_is_empty(tcx, t) {
1892: // Special case for empty types
librustc/middle/trans/debuginfo.rs:
1539: // appropriate type name
1540: if ty::type_is_empty(cx.tcx(), enum_type) {
1541: let empty_type_metadata = composite_type_metadata(cx,
librustc/middle/check_match.rs:
72: if (*arms).is_empty() {
73: if !type_is_empty(cx.tcx, pat_ty) {
74: // We know the type is inhabited, so this must be wrong
librustc/middle/ty.rs:821:31-821:31 -struct- definition:
pub struct ParamBounds {
pub builtin_bounds: BuiltinBounds,
pub trait_bounds: Vec<Rc<TraitRef>>
references:- 29librustc/middle/subst.rs:
230: span: Option<Span>) -> ty::ParamBounds {
231: ty::ParamBounds {
232: builtin_bounds: self.builtin_bounds,
librustc/middle/typeck/check/vtable.rs:
574: let param_bounds = ty::ParamBounds {
575: builtin_bounds: ty::EmptyBuiltinBounds(),
--
761: // but that falls out of doing this.
762: let param_bounds = ty::ParamBounds {
763: builtin_bounds: ty::EmptyBuiltinBounds(),
librustc/middle/typeck/collect.rs:
1089: let mut param_bounds = ty::ParamBounds {
1090: builtin_bounds: ty::EmptyBuiltinBounds(),
librustc/metadata/tyencode.rs:
326: enc_trait_store(w, cx, ft.store);
327: let bounds = ty::ParamBounds {builtin_bounds: ft.bounds,
328: trait_bounds: Vec::new()};
librustc/metadata/tydecode.rs:
554: fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
555: let mut param_bounds = ty::ParamBounds {
556: builtin_bounds: ty::EmptyBuiltinBounds(),
librustc/middle/ty.rs:
822: pub struct ParamBounds {
--
978: pub def_id: ast::DefId,
979: pub bounds: Rc<ParamBounds>,
980: pub default: Option<ty::t>
--
1036: /// Bounds on each numbered type parameter
1037: pub type_param_bounds: Vec<ParamBounds> ,
1038: }
librustc/middle/subst.rs:
229: substs: &ty::substs,
230: span: Option<Span>) -> ty::ParamBounds {
231: ty::ParamBounds {
librustc/middle/typeck/check/vtable.rs:
120: substs: Option<&ty::substs>,
121: type_param_bounds: &ty::ParamBounds,
122: ty: ty::t,
librustc/middle/typeck/collect.rs:
1136: fn check_bounds_compatible(tcx: &ty::ctxt,
1137: param_bounds: &ty::ParamBounds,
1138: ident: ast::Ident,
librustc/metadata/tyencode.rs:
347: fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {
348: for bound in bs.builtin_bounds.iter() {
librustc/metadata/tydecode.rs:
554: fn parse_bounds(st: &mut PState, conv: conv_did) -> ty::ParamBounds {
555: let mut param_bounds = ty::ParamBounds {
librustc/util/ppaux.rs:
573: impl Repr for ty::ParamBounds {
574: fn repr(&self, tcx: &ctxt) -> ~str {
librustc/middle/subst.rs:
227: impl Subst for ty::ParamBounds {
228: fn subst_spanned(&self, tcx: &ty::ctxt,
librustc/middle/ty.rs:1293:10-1293:10 -fn- definition:
pub fn mk_f32() -> t { mk_prim_t(&primitives::TY_F32) }
pub fn mk_f64() -> t { mk_prim_t(&primitives::TY_F64) }
pub fn mk_f128() -> t { mk_prim_t(&primitives::TY_F128) }
references:- 43librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:407:2-407:2 -fn- definition:
}
pub fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), has_self) }
pub fn type_needs_infer(t: t) -> bool {
references:- 3librustc/middle/typeck/check/method.rs:
1290: let check_for_self_ty = |ty| {
1291: if ty::type_has_self(ty) {
1292: self.tcx().sess.span_err(
librustc/middle/trans/meth.rs:
512: if m.generics.has_type_params() ||
513: ty::type_has_self(ty::mk_bare_fn(tcx, m.fty.clone())) {
514: debug!("(making impl vtable) method has self or type params: {}",
librustc/middle/trans/common.rs:
682: assert!(!ty::type_has_params(t));
683: assert!(!ty::type_has_self(t));
684: t
librustc/middle/ty.rs:411:2-411:2 -fn- definition:
}
pub fn type_id(t: t) -> uint { get(t).id }
pub struct BareFnTy {
references:- 32031: pub fn type_contents(cx: &ctxt, ty: t) -> TypeContents {
2032: let ty_id = type_id(ty);
librustc/middle/trans/debuginfo.rs:
2311: fn cache_id_for_type(t: ty::t) -> uint {
2312: ty::type_id(t)
2313: }
librustc/middle/ty.rs:
2069: // TC::OwnsOwned. This manifested as issue #4821.
2070: let ty_id = type_id(ty);
2071: match cache.find(&ty_id) {
librustc/middle/ty.rs:1625:1-1625:1 -fn- definition:
pub fn type_is_structural(ty: t) -> bool {
match get(ty).sty {
ty_struct(..) | ty_tup(_) | ty_enum(..) | ty_closure(_) | ty_trait(..) |
references:- 3librustc/middle/trans/glue.rs:
347: if ty::type_needs_drop(bcx.tcx(), t) &&
348: ty::type_is_structural(t) {
349: iter_structural_ty(bcx, v0, t, drop_ty)
librustc/middle/trans/base.rs:
1029: let ccx = bcx.ccx();
1030: if ty::type_is_structural(t) {
1031: let llty = type_of::type_of(ccx, t);
librustc/middle/trans/glue.rs:
67: ty::ty_box(_) => incr_refcnt_of_boxed(bcx, v),
68: _ if ty::type_is_structural(t)
69: && ty::type_needs_drop(bcx.tcx(), t) => {
librustc/middle/ty.rs:1455:1-1455:1 -fn- definition:
pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) }
pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
references:- 4librustc/middle/typeck/check/mod.rs:
1413: // so we create an integral type variable for it.
1414: ty::mk_int_var(tcx, fcx.infcx().next_int_var_id())
1415: }
--
3678: let fcx = blank_fn_ctxt(ccx, &inh, rty, e.id);
3679: let declty = ty::mk_int_var(ccx.tcx, fcx.infcx().next_int_var_id());
3680: check_const_with_ty(&fcx, e.span, e, declty);
librustc/middle/typeck/infer/resolve.rs:
254: } else {
255: ty::mk_int_var(self.infcx.tcx, vid)
256: }
librustc/middle/ty.rs:761:31-761:31 -struct- definition:
pub struct TraitRef {
pub def_id: DefId,
pub substs: substs
references:- 92librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/collect.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/metadata/csearch.rs:
librustc/util/ppaux.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:3945:61-3945:61 -fn- definition:
// Takes a list of type substs in case the struct is generic
pub fn lookup_field_type(tcx: &ctxt,
struct_id: DefId,
references:- 84038: mt: mt {
4039: ty: lookup_field_type(cx, did, f.id, substs),
4040: mutbl: MutImmutable
librustc/middle/typeck/check/mod.rs:
2458: expected_field_type =
2459: ty::lookup_field_type(
2460: tcx, class_id, field_id, &substitutions);
--
3575: if !fields.iter().all(
3576: |f| ty::lookup_field_type(tcx, did, f.id, substs) == e) {
3577: tcx.sess.span_err(sp, "SIMD vector should be homogeneous");
librustc/middle/typeck/check/_match.rs:
321: let class_field = *class_fields.get(index);
322: let field_type = ty::lookup_field_type(tcx,
323: class_id,
librustc/middle/trans/adt.rs:
145: let mut ftys = fields.iter().map(|field| {
146: ty::lookup_field_type(cx.tcx(), def_id, field.id, substs)
147: }).collect::<Vec<_>>();
librustc/middle/ty.rs:
1657: let fields = lookup_struct_fields(cx, did);
1658: lookup_field_type(cx, did, fields.get(0).id, substs)
1659: }
librustc/middle/ty.rs:2220:4-2220:4 -fn- definition:
fn borrowed_contents(region: ty::Region,
mutbl: ast::Mutability)
-> TypeContents {
references:- 32113: ty_str => borrowed_contents(r, ast::MutImmutable),
2114: _ => tc_ty(cx, mt.ty, cache).reference(borrowed_contents(r, mt.mutbl)),
2115: }
--
2261: RegionTraitStore(r, mutbl) => {
2262: contents.reference(borrowed_contents(r, mutbl))
2263: }
librustc/middle/ty.rs:3524:1-3524:1 -fn- definition:
pub fn trait_method(cx: &ctxt, trait_did: ast::DefId, idx: uint) -> Rc<Method> {
let method_def_id = *ty::trait_method_def_ids(cx, trait_did).get(idx);
ty::method(cx, method_def_id)
references:- 53029: Rc::new(trait_type_param_defs.append(
3030: ty::trait_method(tcx, trt_id, n_mth).generics.type_param_defs()))
3031: }
librustc/middle/lint.rs:
1589: ..
1590: }) => ty::trait_method(cx.tcx, trait_id, index).def_id
1591: }
librustc/middle/dead.rs:
111: }) => {
112: let def_id = ty::trait_method(self.tcx,
113: trait_id, index).def_id;
librustc/middle/trans/meth.rs:
251: let ccx = bcx.ccx();
252: let mname = ty::trait_method(ccx.tcx(), trait_id, n_method).ident;
253: let mth_id = method_with_name(bcx.ccx(), impl_did, mname.name);
librustc/middle/ty.rs:
4471: .position(|m| m.ident.name == name)
4472: .map(|idx| ty::trait_method(tcx, trait_did, idx).def_id)
4473: }
librustc/middle/ty.rs:2655:1-2655:1 -fn- definition:
pub fn node_id_to_type(cx: &ctxt, id: ast::NodeId) -> t {
match try_node_id_to_type(cx, id) {
Some(t) => t,
references:- 70librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/check_match.rs:
librustc/middle/check_static.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/dataflow.rs:
librustc/middle/liveness.rs:
librustc/middle/kind.rs:
librustc/middle/freevars.rs:
librustc/middle/effect.rs:
librustc/middle/expr_use_visitor.rs:
librustc/metadata/encoder.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/common.rs:
librustc/middle/trans/consts.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/foreign.rs:
librustc/middle/trans/intrinsic.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:404:2-404:2 -fn- definition:
}
pub fn type_has_params(t: t) -> bool {
tbox_has_flag(get(t), has_params)
references:- 4librustc/middle/trans/monomorphize.rs:
49: assert!(real_substs.tps.iter().all(|t| {
50: !ty::type_needs_infer(*t) && !ty::type_has_params(*t)
51: }));
librustc/middle/trans/common.rs:
681: _ => {
682: assert!(!ty::type_has_params(t));
683: assert!(!ty::type_has_self(t));
librustc/middle/trans/base.rs:
1075: let ty = type_of::type_of(ccx, t);
1076: assert!(!ty::type_has_params(t));
1077: let val = alloca(bcx, ty, name);
librustc/middle/subst.rs:
50: span: Option<Span>) -> ty::t {
51: if ty::substs_is_noop(substs) && !ty::type_has_params(*self) {
52: *self
librustc/middle/ty.rs:1582:1-1582:1 -fn- definition:
pub fn type_is_bot(ty: t) -> bool {
(get(ty).flags & (has_ty_bot as uint)) != 0
}
references:- 49librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/dataflow.rs:
librustc/middle/liveness.rs:
librustc/middle/expr_use_visitor.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/datum.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/common.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:1518:4-1518:4 -struct- definition:
struct TpsSubst<'a> {
tcx: &'a ctxt,
self_ty_opt: Option<t>,
references:- 21514: pub fn subst_tps(tcx: &ctxt, tps: &[t], self_ty_opt: Option<t>, typ: t) -> t {
1515: let mut subst = TpsSubst { tcx: tcx, self_ty_opt: self_ty_opt, tps: tps };
1516: return subst.fold_ty(typ);
--
1524: impl<'a> TypeFolder for TpsSubst<'a> {
1525: fn tcx<'a>(&'a self) -> &'a ctxt { self.tcx }
librustc/middle/ty.rs:1467:1-1467:1 -fn- definition:
pub fn walk_ty(ty: t, f: |t|) {
maybe_walk_ty(ty, |t| { f(t); true });
}
references:- 54510: };
4511: ty::walk_ty(t, |t| {
4512: match ty::get(t).sty {
librustc/middle/typeck/collect.rs:
1047: ty::walk_ty(ty, |t| {
1048: match ty::get(t).sty {
librustc/middle/typeck/coherence.rs:
102: let mut found_nominal = false;
103: ty::walk_ty(original_type, |t| {
104: match get(t).sty {
librustc/middle/typeck/check/mod.rs:
4105: ty::walk_ty(ty, |t| {
4106: match ty::get(t).sty {
librustc/middle/ty.rs:3044:1-3044:1 -fn- definition:
pub fn expr_is_lval(tcx: &ctxt, e: &ast::Expr) -> bool {
match expr_kind(tcx, e) {
LvalueExpr => true,
references:- 2librustc/middle/typeck/check/mod.rs:
2942: let tcx = fcx.tcx();
2943: if !ty::expr_is_lval(tcx, lhs) {
2944: tcx.sess.span_err(lhs.span, "illegal left-hand side expression");
librustc/middle/ty.rs:1379:1-1379:1 -fn- definition:
pub fn mk_mut_ptr(cx: &ctxt, ty: t) -> t {
mk_ptr(cx, mt {ty: ty, mutbl: ast::MutMutable})
}
references:- 6librustc/middle/typeck/check/mod.rs:
4142: param(ccx, 0)),
4143: "store" => (1, vec!(ty::mk_mut_ptr(tcx, param(ccx, 0)), param(ccx, 0)),
4144: ty::mk_nil()),
--
4147: "min" | "umax" | "umin" => {
4148: (1, vec!(ty::mk_mut_ptr(tcx, param(ccx, 0)), param(ccx, 0)),
4149: param(ccx, 0))
librustc/middle/trans/closure.rs:
269: let env_pointer_alloca = if bcx.sess().opts.debuginfo == FullDebugInfo {
270: let alloc = alloc_ty(bcx, ty::mk_mut_ptr(bcx.tcx(), cdata_ty), "__debuginfo_env_ptr");
271: Store(bcx, llcdata, alloc);
librustc/middle/typeck/check/mod.rs:
4344: "volatile_store" =>
4345: (1, vec!( ty::mk_mut_ptr(tcx, param(ccx, 0)), param(ccx, 0) ), ty::mk_nil()),
librustc/middle/ty.rs:3496:1-3496:1 -fn- definition:
fn lookup_locally_or_in_crate_store<V:Clone>(
descr: &str,
def_id: ast::DefId,
references:- 53868: -> typeck::impl_res {
3869: lookup_locally_or_in_crate_store(
3870: "impl_vtables", did, &mut *cx.impl_vtables.borrow_mut(),
--
4311: pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
4312: lookup_locally_or_in_crate_store(
4313: "item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),
librustc/middle/ty.rs:2311:4-2311:4 -fn- definition:
fn type_requires(cx: &ctxt, seen: &mut Vec<DefId>,
r_ty: t, ty: t) -> bool {
debug!("type_requires({}, {})?",
references:- 62362: ty_rptr(_, ref mt) => {
2363: type_requires(cx, seen, r_ty, mt.ty)
2364: }
--
2399: let sty = subst(cx, substs, *aty);
2400: type_requires(cx, seen, r_ty, sty)
2401: })
librustc/middle/ty.rs:1259:10-1259:10 -fn- definition:
pub fn mk_prim_t(primitive: &'static t_box_) -> t {
unsafe {
cast::transmute::<&'static t_box_, t>(primitive)
references:- 181276: pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) }
--
1315: pub fn mk_u64() -> t { mk_prim_t(&primitives::TY_U64) }
--
1346: pub fn mk_char() -> t { mk_prim_t(&primitives::TY_CHAR) }
librustc/middle/ty.rs:2567:1-2567:1 -fn- definition:
pub fn type_is_signed(ty: t) -> bool {
match get(ty).sty {
ty_int(_) => true,
references:- 9librustc/middle/trans/expr.rs:
470: if ix_size < int_size {
471: if ty::type_is_signed(expr_ty(bcx, idx)) {
472: SExt(bcx, ix_val, ccx.int_type)
--
1557: let llexpr = datum.to_llscalarish(bcx);
1558: if ty::type_is_signed(t_out) {
1559: FPToSI(bcx, llexpr, ll_t_out)
librustc/middle/trans/consts.rs:
315: let is_float = ty::type_is_fp(ty);
316: let signed = ty::type_is_signed(ty);
317: return (match b {
--
500: expr::cast_integral => {
501: let s = ty::type_is_signed(ety) as Bool;
502: llvm::LLVMConstIntCast(iv, llty.to_ref(), s)
librustc/middle/trans/expr.rs:
1270: let is_float = ty::type_is_fp(intype);
1271: let is_signed = ty::type_is_signed(intype);
librustc/middle/ty.rs:861:38-861:38 -struct- definition:
pub struct TyVid(pub uint);
pub struct IntVid(pub uint);
pub struct FloatVid(pub uint);
references:- 19913: impl fmt::Show for TyVid {
914: fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result{
--
1454: pub fn mk_var(cx: &ctxt, v: TyVid) -> t { mk_infer(cx, TyVar(v)) }
librustc/middle/typeck/infer/mod.rs:
242: unresolved_int_ty(IntVid),
243: unresolved_ty(TyVid),
244: cyclic_ty(TyVid),
--
592: impl<'a> InferCtxt<'a> {
593: pub fn next_ty_var_id(&self) -> TyVid {
594: let id = self.ty_var_counter.get();
librustc/middle/typeck/infer/resolve.rs:
205: pub fn resolve_ty_var(&mut self, vid: TyVid) -> ty::t {
206: if self.v_seen.contains(&vid) {
librustc/middle/typeck/infer/unify.rs:
279: fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt)
280: -> &'v RefCell<ValsAndBindings<ty::TyVid, Bounds<ty::t>>> {
281: return &infcx.ty_var_bindings;
librustc/middle/typeck/infer/mod.rs:
82: // order, represented by its upper and lower bounds.
83: pub ty_var_bindings: RefCell<ValsAndBindings<ty::TyVid, Bounds<ty::t>>>,
84: pub ty_var_counter: Cell<uint>,
librustc/middle/ty.rs:1413:1-1413:1 -fn- definition:
pub fn mk_ctor_fn(cx: &ctxt,
binder_id: ast::NodeId,
input_tys: &[ty::t],
references:- 3librustc/middle/typeck/collect.rs:
156: let input_tys: Vec<_> = args.iter().map(|va| ccx.to_ty(&rs, va.ty)).collect();
157: ty::mk_ctor_fn(tcx, scope, input_tys.as_slice(), enum_ty)
158: }
--
173: |f| ty::node_id_to_type(ccx.tcx, f.node.id)).collect();
174: ty::mk_ctor_fn(tcx, scope, input_tys.as_slice(), enum_ty)
175: }
--
782: &local_def(field.node.id)).ty).collect();
783: let ctor_fn_ty = ty::mk_ctor_fn(tcx,
784: ctor_id,
librustc/middle/ty.rs:2629:28-2629:28 -fn- definition:
// Returns the type of t[i]
pub fn index(t: t) -> Option<mt> {
match get(t).sty {
references:- 2librustc/middle/typeck/check/mod.rs:
3252: autoderef(fcx, expr.span, raw_base_t, Some(base.id),
3253: lvalue_pref, |base_t, _| ty::index(base_t));
3254: match field_ty {
librustc/middle/mem_categorization.rs:
797: let element_ty = match ty::index(base_cmt.ty) {
798: Some(ref mt) => mt.ty,
librustc/middle/ty.rs:3008:1-3008:1 -fn- definition:
pub fn method_call_type_param_defs(tcx: &ctxt, origin: typeck::MethodOrigin)
-> Rc<Vec<TypeParameterDef>> {
match origin {
references:- 3librustc/middle/typeck/check/vtable.rs:
694: let type_param_defs =
695: ty::method_call_type_param_defs(cx.tcx, method.origin);
696: if has_trait_bounds(type_param_defs.deref().as_slice()) {
librustc/middle/kind.rs:
267: Some(method) => {
268: ty::method_call_type_param_defs(cx.tcx, method.origin)
269: }
librustc/middle/typeck/check/vtable.rs:
659: ex.repr(fcx.tcx()));
660: let type_param_defs = ty::method_call_type_param_defs(cx.tcx, method.origin);
661: if has_trait_bounds(type_param_defs.as_slice()) {
librustc/middle/ty.rs:1459:1-1459:1 -fn- definition:
pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
pub fn mk_self(cx: &ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }
pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
references:- 31456: pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) }
1458: pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
librustc/middle/ty.rs:1809:4-1809:4 -struct- definition:
*/
pub struct TypeContents {
pub bits: u64
references:- 85librustc/middle/ty.rs:2542:1-2542:1 -fn- definition:
pub fn type_is_char(ty: t) -> bool {
match get(ty).sty {
ty_char => true,
references:- 3librustc/middle/typeck/check/mod.rs:
4012: let typ_s = structurally_resolved_type(fcx, sp, typ);
4013: return ty::type_is_char(typ_s);
4014: }
librustc/middle/trans/datum.rs:
539: LoadRangeAssert(bcx, llptr, 0, 2, lib::llvm::False)
540: } else if ty::type_is_char(ty) {
541: // a char is a unicode codepoint, and so takes values from 0
librustc/middle/typeck/check/_match.rs:
451: // no-op
452: } else if !ty::type_is_numeric(b_ty) && !ty::type_is_char(b_ty) {
453: tcx.sess.span_err(pat.span, "non-numeric type used in range");
librustc/middle/ty.rs:1728:13-1728:13 -fn- definition:
// cleanups.
pub fn type_needs_unwind_cleanup(cx: &ctxt, ty: t) -> bool {
match cx.needs_unwind_cleanup_cache.borrow().find(&ty) {
references:- 2librustc/middle/trans/cleanup.rs:
265: is_immediate: true,
266: on_unwind: ty::type_needs_unwind_cleanup(self.ccx.tcx(), ty),
267: val: val,
librustc/middle/ty.rs:3449:1-3449:1 -fn- definition:
pub fn provided_source(cx: &ctxt, id: ast::DefId) -> Option<ast::DefId> {
cx.provided_method_sources.borrow().find(&id).map(|x| *x)
}
references:- 3librustc/middle/dead.rs:
96: typeck::MethodStatic(def_id) => {
97: match ty::provided_source(self.tcx, def_id) {
98: Some(p_did) => self.check_def_id(p_did),
librustc/middle/trans/callee.rs:
296: let (is_default, def_id, substs, self_vtables, vtables) =
297: match ty::provided_source(tcx, def_id) {
298: None => (false, def_id, substs, None, vtables),
librustc/middle/typeck/check/method.rs:
1446: // default method for error reporting.
1447: match provided_source(self.tcx(), impl_did) {
1448: None => impl_did,
librustc/middle/ty.rs:1640:1-1640:1 -fn- definition:
pub fn sequence_element_type(cx: &ctxt, ty: t) -> t {
match get(ty).sty {
ty_vec(mt, Some(_)) => mt.ty,
references:- 11librustc/middle/typeck/check/mod.rs:
3119: } else {
3120: let el = ty::sequence_element_type(fcx.tcx(),
3121: t1);
librustc/middle/trans/glue.rs:
292: with_cond(bcx, not_null, |bcx| {
293: let unit_ty = ty::sequence_element_type(bcx.tcx(), t);
294: let bcx = tvec::make_drop_glue_unboxed(bcx, llbox, unit_ty);
librustc/middle/trans/expr.rs:
229: let tcx = bcx.tcx();
230: let unit_ty = ty::sequence_element_type(tcx, datum.ty);
--
481: let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), base_datum.ty));
482: base::maybe_name_value(bcx.ccx(), vt.llunit_size, "unit_sz");
librustc/middle/trans/consts.rs:
94: let vec_ty = ty::expr_ty(cx.tcx(), e);
95: let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
96: let llunitty = type_of::type_of(cx, unit_ty);
librustc/middle/trans/base.rs:
699: ty::ty_vec(_, Some(n)) => {
700: let unit_ty = ty::sequence_element_type(cx.tcx(), t);
701: let (base, len) = tvec::get_fixed_base_and_byte_len(cx, av, unit_ty, n);
librustc/middle/trans/_match.rs:
1012: let vec_ty = node_id_type(bcx, pat_id);
1013: let vt = tvec::vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty));
librustc/middle/trans/tvec.rs:
408: let vec_ty = node_id_type(bcx, vec_expr.id);
409: vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty))
410: }
--
496: assert!(type_is_immediate(bcx.ccx(), vec_ty));
497: let vt = vec_types(bcx, ty::sequence_element_type(bcx.tcx(), vec_ty));
498: let body = Load(bcx, llval);
librustc/middle/trans/consts.rs:
597: let vec_ty = ty::expr_ty(cx.tcx(), e);
598: let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
599: let llunitty = type_of::type_of(cx, unit_ty);
librustc/middle/ty.rs:1448:1-1448:1 -fn- definition:
pub fn mk_struct(cx: &ctxt, struct_id: ast::DefId, substs: substs) -> t {
// take a copy of substs so that we own the vectors inside
mk_t(cx, ty_struct(struct_id, substs))
references:- 8librustc/middle/typeck/check/mod.rs:
2498: if !error_happened {
2499: fcx.write_ty(node_id, ty::mk_struct(fcx.ccx.tcx,
2500: class_id, substitutions));
--
2712: ty::NonerasedRegions(OwnedSlice::empty());
2713: let sty = ty::mk_struct(tcx,
2714: gc_struct_id,
--
4196: match langid {
4197: Ok(did) => (1u, Vec::new(), ty::mk_struct(ccx.tcx, did, substs {
4198: self_ty: None,
librustc/middle/typeck/collect.rs:
765: let substs = mk_item_substs(ccx, &tpt.generics, None);
766: let selfty = ty::mk_struct(tcx, local_def(id), substs);
--
967: let substs = mk_item_substs(ccx, &ty_generics, None);
968: let t = ty::mk_struct(tcx, local_def(it.id), substs);
969: let tpt = ty_param_bounds_and_ty {
librustc/middle/kind.rs:
89: if !struct_tpt.generics.has_type_params() {
90: let struct_ty = ty::mk_struct(cx.tcx, struct_did, ty::substs {
91: regions: ty::NonerasedRegions(OwnedSlice::empty()),
librustc/metadata/tydecode.rs:
392: assert_eq!(next(st), ']');
393: return ty::mk_struct(st.tcx, did, substs);
394: }
librustc/middle/typeck/infer/combine.rs:
489: let substs = if_ok!(this.substs(a_id, a_substs, b_substs));
490: Ok(ty::mk_struct(tcx, a_id, substs))
491: }
librustc/middle/ty.rs:421:38-421:38 -struct- definition:
pub struct ClosureTy {
pub fn_style: ast::FnStyle,
pub onceness: ast::Onceness,
references:- 45librustc/middle/ty_fold.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/kind.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:155:1-155:1 -struct- definition:
pub struct intern_key {
sty: *sty,
}
references:- 81151: let key = intern_key { sty: &st };
--
1246: let key = intern_key {
1247: sty: sty_ptr,
librustc/middle/ty.rs:4031:71-4031:71 -fn- definition:
// this. Takes a list of substs with which to instantiate field types.
pub fn struct_fields(cx: &ctxt, did: ast::DefId, substs: &substs)
-> Vec<field> {
references:- 122122: ty_struct(did, ref substs) => {
2123: let flds = struct_fields(cx, did, substs);
2124: let mut res =
--
2483: seen.push(did);
2484: let fields = struct_fields(cx, did, substs);
2485: let r = find_nonrepresentable(cx, sp, seen,
librustc/middle/typeck/check/mod.rs:
2813: ty::ty_struct(did, ref substs) => {
2814: let fields = ty::struct_fields(fcx.tcx(), did, substs);
2815: fields.len() == 1
librustc/middle/typeck/check/_match.rs:
209: // Get the expected types of the arguments.
210: let class_fields = ty::struct_fields(
211: tcx, struct_def_id, expected_substs);
librustc/middle/expr_use_visitor.rs:
515: ty::ty_struct(did, ref substs) => {
516: ty::struct_fields(self.tcx(), did, substs)
517: }
librustc/middle/trans/glue.rs:
260: // this scope.
261: let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
262: for (i, fld) in field_tys.iter().enumerate() {
librustc/middle/trans/expr.rs:
933: op(variant_info.disr_val,
934: struct_fields(tcx,
935: variant_id,
librustc/middle/trans/reflect.rs:
248: ty::ty_struct(did, ref substs) => {
249: let fields = ty::struct_fields(tcx, did, substs);
250: let mut named_fields = false;
librustc/middle/trans/debuginfo.rs:
1289: let fields = ty::struct_fields(cx.tcx(), def_id, substs);
librustc/middle/trans/common.rs:
49: ty::ty_struct(def_id, ref substs) => {
50: let fields = ty::struct_fields(ccx.tcx(), def_id, substs);
51: fields.len() == 1 &&
librustc/middle/ty.rs:4233:9-4233:9 -fn- definition:
// list.
pub fn each_bound_trait_and_supertraits(tcx: &ctxt,
bounds: &[Rc<TraitRef>],
references:- 62294: each_bound_trait_and_supertraits(cx, traits, |trait_ref| {
2295: let trait_def = lookup_trait_def(cx, trait_ref.def_id);
librustc/middle/typeck/check/vtable.rs:
287: let mut ret = None;
288: ty::each_bound_trait_and_supertraits(tcx, bounds, |bound_trait_ref| {
289: debug!("checking bounds trait {}",
librustc/middle/typeck/check/method.rs:
624: ty::each_bound_trait_and_supertraits(tcx, bounds, |bound_trait_ref| {
625: let this_bound_idx = next_bound_idx;
librustc/middle/typeck/collect.rs:
1142: if !param_bounds.builtin_bounds.contains_elem(ty::BoundSized) {
1143: ty::each_bound_trait_and_supertraits(tcx,
1144: param_bounds.trait_bounds.as_slice(),
librustc/middle/typeck/check/vtable.rs:
129: ty::each_bound_trait_and_supertraits(tcx,
130: type_param_bounds.trait_bounds
librustc/middle/ty.rs:2556:1-2556:1 -fn- definition:
pub fn type_is_fp(ty: t) -> bool {
match get(ty).sty {
ty_infer(FloatVar(_)) | ty_float(_) => true,
references:- 82564: pub fn type_is_numeric(ty: t) -> bool {
2565: return type_is_integral(ty) || type_is_fp(ty);
2566: }
librustc/middle/typeck/check/mod.rs:
2122: if ty::type_is_simd(tcx, lhs_t) {
2123: if ty::type_is_fp(ty::simd_type(tcx, lhs_t)) {
2124: fcx.type_error_message(expr.span,
librustc/middle/const_eval.rs:
223: join(integral_const, base)
224: } else if ty::type_is_fp(ty) {
225: join(general_const, base)
librustc/middle/trans/expr.rs:
1142: let llneg = {
1143: if ty::type_is_fp(un_ty) {
1144: FNeg(bcx, val)
--
1269: };
1270: let is_float = ty::type_is_fp(intype);
1271: let is_signed = ty::type_is_signed(intype);
librustc/middle/trans/consts.rs:
314: let ty = ty::expr_ty(cx.tcx(), e1);
315: let is_float = ty::type_is_fp(ty);
316: let signed = ty::type_is_signed(ty);
--
390: let ty = ty::expr_ty(cx.tcx(), e);
391: let is_float = ty::type_is_fp(ty);
392: return (match u {
librustc/middle/typeck/check/mod.rs:
2849: if !(ty::type_is_integral(oprnd_t) ||
2850: ty::type_is_fp(oprnd_t)) {
2851: oprnd_t = check_user_unop(fcx, "-", "neg",
librustc/middle/ty.rs:2329:4-2329:4 -fn- definition:
fn subtypes_require(cx: &ctxt, seen: &mut Vec<DefId>,
r_ty: t, ty: t) -> bool {
debug!("subtypes_require({}, {})?",
references:- 22318: get(r_ty).sty == get(ty).sty ||
2319: subtypes_require(cx, seen, r_ty, ty)
2320: };
--
2416: let mut seen = Vec::new();
2417: !subtypes_require(cx, &mut seen, r_ty, r_ty)
2418: }
librustc/middle/ty.rs:1372:1-1372:1 -fn- definition:
pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t {
mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutMutable})
}
references:- 2librustc/middle/kind.rs:
186: // mutable. Currently we assume all upvars are referenced mutably.
187: let implicit_borrowed_type = ty::mk_mut_rptr(cx.tcx, region, var_t);
188: check_freevar_bounds(cx, fv.span, implicit_borrowed_type,
librustc/middle/typeck/check/mod.rs:
4174: vec!(
4175: ty::mk_mut_rptr(tcx, ty::ReLateBound(it.id, ty::BrAnon(0)), param(ccx, 0)),
4176: param(ccx, 0u)
librustc/middle/ty.rs:1336:1-1336:1 -fn- definition:
pub fn mk_mach_float(tm: ast::FloatTy) -> t {
match tm {
ast::TyF32 => mk_f32(),
references:- 81144: ty_uint(u) => return mk_mach_uint(u),
1145: ty_float(f) => return mk_mach_float(f),
1146: ty_char => return mk_char(),
librustc/middle/typeck/check/mod.rs:
1415: }
1416: ast::LitFloat(_, t) => ty::mk_mach_float(t),
1417: ast::LitFloatUnsuffixed(_) => {
librustc/middle/typeck/astconv.rs:
351: check_path_args(tcx, path, NO_TPS | NO_REGIONS);
352: Some(ty::mk_mach_float(ft))
353: }
librustc/middle/typeck/infer/combine.rs:
572: if_ok!(this.infcx().simple_var_t(vid_is_expected, vid, val));
573: Ok(ty::mk_mach_float(val))
574: }
librustc/middle/typeck/infer/resolve.rs:
267: match node.possible_types {
268: Some(t) => ty::mk_mach_float(t),
269: None => {
librustc/metadata/tydecode.rs:
301: 'f' => return ty::mk_mach_float(ast::TyF32),
302: 'F' => return ty::mk_mach_float(ast::TyF64),
303: 'Q' => return ty::mk_mach_float(ast::TyF128),
304: _ => fail!("parse_ty: bad numeric type")
librustc/middle/ty.rs:1409:1-1409:1 -fn- definition:
pub fn mk_bare_fn(cx: &ctxt, fty: BareFnTy) -> t {
mk_t(cx, ty_bare_fn(fty))
}
references:- 171418: let input_args = input_tys.iter().map(|t| *t).collect();
1419: mk_bare_fn(cx,
1420: BareFnTy {
librustc/middle/typeck/mod.rs:
384: let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
385: fn_style: ast::NormalFn,
librustc/middle/typeck/check/mod.rs:
4386: };
4387: let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
4388: fn_style: ast::UnsafeFn,
librustc/middle/typeck/check/method.rs:
1224: let transformed_self_ty = *fn_sig.inputs.get(0);
1225: let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {
1226: sig: fn_sig,
librustc/middle/typeck/astconv.rs:
593: }
594: ty::mk_bare_fn(tcx, ty_of_bare_fn(this, ast_ty.id, bf.fn_style,
595: bf.abi, bf.decl))
librustc/middle/typeck/infer/combine.rs:
539: this.bare_fn_tys(a_fty, b_fty).and_then(|fty| {
540: Ok(ty::mk_bare_fn(tcx, fty))
541: })
librustc/middle/typeck/collect.rs:
1186: let t_fn = ty::mk_bare_fn(
1187: ccx.tcx,
librustc/middle/typeck/coherence.rs:
354: generics: new_generics,
355: ty: ty::mk_bare_fn(tcx, new_method_ty.fty.clone())
356: };
librustc/metadata/tydecode.rs:
359: 'F' => {
360: return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
361: }
librustc/middle/trans/reflect.rs:
93: let mth_ty =
94: ty::mk_bare_fn(tcx,
95: self.visitor_methods[mth_idx].fty.clone());
librustc/middle/trans/meth.rs:
512: if m.generics.has_type_params() ||
513: ty::type_has_self(ty::mk_bare_fn(tcx, m.fty.clone())) {
514: debug!("(making impl vtable) method has self or type params: {}",
librustc/middle/ty.rs:3752:1-3752:1 -fn- definition:
pub fn has_dtor(cx: &ctxt, struct_id: DefId) -> bool {
ty_dtor(cx, struct_id).is_present()
}
references:- 52126: |f| tc_mt(cx, f.mt, cache));
2127: if ty::has_dtor(cx, did) {
2128: res = res | TC::OwnsDtor;
librustc/middle/borrowck/gather_loans/gather_moves.rs:
152: ty::ty_struct(did, _) | ty::ty_enum(did, _) => {
153: if ty::has_dtor(bccx.tcx, did) {
154: Some(cmt.clone())
librustc/middle/borrowck/gather_loans/move_error.rs:
140: ty::ty_struct(did, _)
141: | ty::ty_enum(did, _) if ty::has_dtor(bccx.tcx, did) => {
142: bccx.span_err(
librustc/middle/trans/expr.rs:
806: match ty::get(ty).sty {
807: ty::ty_struct(did, _) if ty::has_dtor(bcx.tcx(), did) => {
808: let repr = adt::represent_type(bcx.ccx(), ty);
librustc/middle/check_static.rs:
132: ty::ty_enum(did, _) => {
133: if ty::has_dtor(self.tcx, did) {
134: self.report_error(e.span,
librustc/middle/ty.rs:4290:1-4290:1 -fn- definition:
pub fn visitor_object_ty(tcx: &ctxt,
region: ty::Region) -> Result<(Rc<TraitRef>, t), ~str> {
let trait_lang_item = match tcx.lang_items.require(TyVisitorTraitLangItem) {
references:- 2librustc/middle/typeck/check/mod.rs:
4210: let region = ty::ReLateBound(it.id, ty::BrAnon(0));
4211: let visitor_object_ty = match ty::visitor_object_ty(tcx, region) {
4212: Ok((_, vot)) => vot,
librustc/middle/trans/glue.rs:
201: let mut bcx = bcx;
202: let (visitor_trait, object_ty) = match ty::visitor_object_ty(bcx.tcx(),
203: ty::ReStatic) {
librustc/middle/ty.rs:1580:1-1580:1 -fn- definition:
pub fn type_is_nil(ty: t) -> bool { get(ty).sty == ty_nil }
pub fn type_is_bot(ty: t) -> bool {
(get(ty).flags & (has_ty_bot as uint)) != 0
references:- 5librustc/middle/typeck/check/mod.rs:
3066: _ => {
3067: if ty::type_is_nil(t_e) {
3068: fcx.type_error_message(expr.span, |actual| {
--
3071: }, t_e, None);
3072: } else if ty::type_is_nil(t_1) {
3073: fcx.type_error_message(expr.span, |actual| {
librustc/middle/liveness.rs:
1465: let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.ir.tcx, id));
1466: if ty::type_is_nil(t_ret) {
1467: // for nil return types, it is ok to not return a value expl.
librustc/middle/trans/common.rs:
101: ty::type_is_nil(ty) || ty::type_is_bot(ty) || ty::type_is_empty(ccx.tcx(), ty)
102: }
librustc/middle/trans/intrinsic.rs:
360: Some(ptr) => { Store(bcx, C_null(lltp_ty), ptr); RetVoid(bcx); }
361: None if ty::type_is_nil(tp_ty) => RetVoid(bcx),
362: None => Ret(bcx, C_null(lltp_ty)),
librustc/middle/ty.rs:1663:1-1663:1 -fn- definition:
pub fn simd_size(cx: &ctxt, ty: t) -> uint {
match get(ty).sty {
ty_struct(did, _) => {
references:- 4librustc/middle/trans/expr.rs:
1333: } else if is_simd {
1334: base::compare_simd_types(bcx, lhs, rhs, intype, ty::simd_size(tcx, lhs_t), op)
1335: } else {
librustc/middle/trans/type_of.rs:
255: let et = ty::simd_type(cx.tcx(), t);
256: let n = ty::simd_size(cx.tcx(), t);
257: Type::vector(&type_of(cx, et), n as u64)
librustc/middle/trans/debuginfo.rs:
2240: let element_type = ty::simd_type(cx.tcx(), t);
2241: let len = ty::simd_size(cx.tcx(), t);
2242: fixed_vec_metadata(cx, element_type, len, usage_site_span)
librustc/middle/trans/type_of.rs:
146: let et = ty::simd_type(cx.tcx(), t);
147: let n = ty::simd_size(cx.tcx(), t);
148: Type::vector(&type_of(cx, et), n as u64)
librustc/middle/ty.rs:4317:47-4317:47 -fn- definition:
/// Records a trait-to-implementation mapping.
pub fn record_trait_implementation(tcx: &ctxt,
trait_def_id: DefId,
references:- 34348: for trait_ref in associated_traits.iter() {
4349: record_trait_implementation(tcx, trait_ref.def_id, impl_def_id);
4350: }
librustc/middle/typeck/coherence.rs:
383: fn add_trait_impl(&self, base_def_id: DefId, impl_def_id: DefId) {
384: ty::record_trait_implementation(self.crate_context.tcx,
385: base_def_id,
librustc/middle/ty.rs:
4396: // Record the trait->implementation mapping.
4397: record_trait_implementation(tcx, trait_id, implementation_def_id);
librustc/middle/ty.rs:4166:1-4166:1 -trait- definition:
pub trait ExprTyProvider {
fn expr_ty(&self, ex: &ast::Expr) -> t;
fn ty_ctxt<'a>(&'a self) -> &'a ctxt;
references:- 44182: // Returns the repeat count for a repeating vector expression.
4183: pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) -> uint {
4184: match const_eval::eval_const_expr_partial(tcx, count_expr) {
librustc/middle/typeck/check/mod.rs:
307: impl<'a> ExprTyProvider for FnCtxt<'a> {
308: fn expr_ty(&self, ex: &ast::Expr) -> ty::t {
librustc/middle/const_eval.rs:
302: pub fn eval_const_expr_partial<T: ty::ExprTyProvider>(tcx: &T, e: &Expr)
303: -> Result<const_val, ~str> {
librustc/middle/ty.rs:
4172: impl ExprTyProvider for ctxt {
4173: fn expr_ty(&self, ex: &ast::Expr) -> t {
librustc/middle/ty.rs:875:38-875:38 -enum- definition:
pub enum InferTy {
TyVar(TyVid),
IntVar(IntVid),
references:- 10876: pub enum InferTy {
--
1460: pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
librustc/middle/ty.rs:1741:1-1741:1 -fn- definition:
fn type_needs_unwind_cleanup_(cx: &ctxt, ty: t,
tycache: &mut HashSet<t>,
encountered_box: bool) -> bool {
references:- 21736: let needs_unwind_cleanup =
1737: type_needs_unwind_cleanup_(cx, ty, &mut tycache, false);
1738: cx.needs_unwind_cleanup_cache.borrow_mut().insert(ty, needs_unwind_cleanup);
--
1768: needs_unwind_cleanup |=
1769: type_needs_unwind_cleanup_(cx, t, tycache,
1770: encountered_box);
librustc/middle/ty.rs:1024:31-1024:31 -struct- definition:
/// more distinctions clearer.
pub struct ParameterEnvironment {
/// A substitution that can be applied to move from
references:- 74710: ty::ParameterEnvironment {
4711: free_substs: free_substs,
librustc/middle/typeck/check/mod.rs:
300: // and statement context, but we might as well do write the code only once
301: let param_env = ty::ParameterEnvironment { free_substs: substs::empty(),
302: self_param_bound: None,
librustc/middle/ty.rs:
4636: free_id: ast::NodeId)
4637: -> ParameterEnvironment
4638: {
librustc/middle/typeck/check/mod.rs:
159: locals: RefCell<NodeMap<ty::t>>,
160: param_env: ty::ParameterEnvironment,
--
263: fn new(tcx: &'a ty::ctxt,
264: param_env: ty::ParameterEnvironment)
265: -> Inherited<'a> {
librustc/middle/typeck/check/vtable.rs:
67: pub infcx: &'a infer::InferCtxt<'a>,
68: pub param_env: &'a ty::ParameterEnvironment,
69: }
librustc/middle/typeck/check/mod.rs:
349: fty: ty::t,
350: param_env: ty::ParameterEnvironment) {
351: // Compute the fty from point of view of inside fn
librustc/middle/ty.rs:1278:10-1278:10 -fn- definition:
pub fn mk_int() -> t { mk_prim_t(&primitives::TY_INT) }
pub fn mk_i8() -> t { mk_prim_t(&primitives::TY_I8) }
pub fn mk_i16() -> t { mk_prim_t(&primitives::TY_I16) }
references:- 91318: match tm {
1319: ast::TyI => mk_int(),
1320: ast::TyI8 => mk_i8(),
librustc/middle/typeck/mod.rs:
392: ),
393: output: ty::mk_int(),
394: variadic: false
librustc/middle/typeck/check/mod.rs:
4228: }),
4229: ty::mk_int()
4230: ),
librustc/middle/typeck/infer/resolve.rs:
250: // As a last resort, default to int.
251: let ty = ty::mk_int();
252: self.infcx.set(vid, Root(Some(IntType(ast::TyI)), node.rank));
librustc/metadata/tydecode.rs:
288: 'b' => return ty::mk_bool(),
289: 'i' => return ty::mk_int(),
290: 'u' => return ty::mk_uint(),
librustc/middle/trans/base.rs:
727: (_match::switch, Some(lldiscrim_a)) => {
728: cx = f(cx, lldiscrim_a, ty::mk_int());
729: let unr_cx = fcx.new_temp_block("enum-iter-unr");
librustc/middle/trans/debuginfo.rs:
1973: let int_type_metadata = type_metadata(cx, ty::mk_int(), span);
1974: let array_type_metadata = unsafe {
librustc/middle/typeck/mod.rs:
389: inputs: vec!(
390: ty::mk_int(),
391: ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
librustc/middle/ty.rs:1680:1-1680:1 -fn- definition:
pub fn type_is_region_ptr(ty: t) -> bool {
match get(ty).sty {
ty_rptr(_, mt) => match get(mt.ty).sty {
references:- 2librustc/middle/typeck/check/mod.rs:
4027: let typ_s = structurally_resolved_type(fcx, sp, typ);
4028: return ty::type_is_region_ptr(typ_s);
4029: }
librustc/middle/trans/common.rs:
64: let simple = ty::type_is_scalar(ty) || ty::type_is_boxed(ty) ||
65: ty::type_is_unique(ty) || ty::type_is_region_ptr(ty) ||
66: type_is_newtype_immediate(ccx, ty) || ty::type_is_bot(ty) ||
librustc/middle/ty.rs:3063:1-3063:1 -fn- definition:
pub fn expr_kind(tcx: &ctxt, expr: &ast::Expr) -> ExprKind {
if tcx.method_map.borrow().contains_key(&typeck::MethodCall::expr(expr.id)) {
// Overloaded operations are generally calls, and hence they are
references:- 43045: pub fn expr_is_lval(tcx: &ctxt, e: &ast::Expr) -> bool {
3046: match expr_kind(tcx, e) {
3047: LvalueExpr => true,
librustc/middle/trans/expr.rs:
324: return match ty::expr_kind(bcx.tcx(), expr) {
325: ty::LvalueExpr | ty::RvalueDatumExpr => {
librustc/middle/ty.rs:
3209: ast::ExprParen(e) => expr_kind(tcx, e),
librustc/middle/ty.rs:1364:1-1364:1 -fn- definition:
pub fn mk_box(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_box(ty)) }
pub fn mk_uniq(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_uniq(ty)) }
pub fn mk_ptr(cx: &ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
references:- 7librustc/middle/typeck/check/mod.rs:
2797: ast::UnBox => {
2798: oprnd_t = ty::mk_box(tcx, oprnd_t)
2799: }
librustc/middle/typeck/astconv.rs:
557: let mt = ast::MutTy { ty: ty, mutbl: ast::MutImmutable };
558: mk_pointer(this, rscope, &mt, Box, |ty| ty::mk_box(tcx, ty))
559: }
librustc/middle/typeck/infer/combine.rs:
493: (&ty::ty_box(a_inner), &ty::ty_box(b_inner)) => {
494: this.tys(a_inner, b_inner).and_then(|typ| Ok(ty::mk_box(tcx, typ)))
495: }
librustc/middle/trans/glue.rs:
82: ty::ty_box(typ) if !ty::type_needs_drop(tcx, typ) =>
83: ty::mk_box(tcx, ty::mk_i8()),
librustc/middle/trans/expr.rs:
1229: let contents_ty = expr_ty(bcx, contents);
1230: let box_ty = ty::mk_box(bcx.tcx(), contents_ty);
librustc/middle/trans/base.rs:
374: // Grab the TypeRef type of box_ptr_ty.
375: let box_ptr_ty = ty::mk_box(bcx.tcx(), t);
376: let llty = type_of(ccx, box_ptr_ty);
librustc/metadata/tydecode.rs:
332: }
333: '@' => return ty::mk_box(st.tcx, parse_ty(st, |x,y| conv(x,y))),
334: '~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
librustc/middle/ty.rs:3692:1-3692:1 -fn- definition:
pub fn substd_enum_variants(cx: &ctxt,
id: ast::DefId,
substs: &substs)
references:- 2librustc/middle/trans/reflect.rs:
280: let repr = adt::represent_type(bcx.ccx(), t);
281: let variants = ty::substd_enum_variants(ccx.tcx(), did, substs);
282: let llptrty = type_of(ccx, t).ptr_to();
librustc/middle/ty.rs:
2138: ty_enum(did, ref substs) => {
2139: let variants = substd_enum_variants(cx, did, substs);
2140: let res =
librustc/middle/ty.rs:2450:4-2450:4 -fn- definition:
fn type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
ty: t) -> Representability {
debug!("type_structurally_recursive: {}",
references:- 32477: ty_vec(mt, Some(_)) => {
2478: type_structurally_recursive(cx, sp, seen, mt.ty)
2479: }
--
2518: let mut seen: Vec<DefId> = Vec::new();
2519: type_structurally_recursive(cx, sp, &mut seen, ty)
2520: }
librustc/middle/ty.rs:753:38-753:38 -struct- definition:
pub struct TyTrait {
pub def_id: DefId,
pub substs: substs,
references:- 47librustc/middle/ty_fold.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/lint.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/kind.rs:
librustc/metadata/tyencode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/glue.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/ty.rs:2710:1-2710:1 -fn- definition:
pub fn ty_closure_store(fty: t) -> TraitStore {
match get(fty).sty {
ty_closure(ref f) => f.store,
references:- 3librustc/middle/freevars.rs:
149: let fn_ty = ty::node_id_to_type(tcx, closure_expr_id);
150: match ty::ty_closure_store(fn_ty) {
151: ty::RegionTraitStore(..) => CaptureByRef,
librustc/middle/trans/expr.rs:
708: let expr_ty = expr_ty(bcx, expr);
709: let store = ty::ty_closure_store(expr_ty);
710: debug!("translating block function {} with type {}",
librustc/middle/typeck/check/regionck.rs:
178: DefUpvar(_, subdef, closure_id, body_id) => {
179: match ty::ty_closure_store(fcx.node_ty(closure_id)) {
180: ty::RegionTraitStore(..) => region_of_def(fcx, *subdef),
librustc/middle/ty.rs:3874:63-3874:63 -fn- definition:
/// Given the did of a trait, returns its canonical trait ref.
pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> Rc<ty::TraitDef> {
let mut trait_defs = cx.trait_defs.borrow_mut();
references:- 143027: let trait_type_param_defs =
3028: Vec::from_slice(lookup_trait_def(tcx, trt_id).generics.type_param_defs());
3029: Rc::new(trait_type_param_defs.append(
librustc/middle/typeck/check/mod.rs:
1056: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef> {
1057: ty::lookup_trait_def(self.tcx(), id)
1058: }
--
1531: ast::FromTrait(trait_def_id) => {
1532: ty::lookup_trait_def(type_context, trait_def_id).generics.clone()
1533: }
librustc/middle/typeck/check/vtable.rs:
752: // on the trait.
753: let trait_def = ty::lookup_trait_def(tcx, impl_trait_ref.def_id);
754: let vtbls = lookup_vtables(&vcx, impl_item.span,
librustc/middle/typeck/collect.rs:
847: if trait_id.krate != ast::LOCAL_CRATE {
848: return ty::lookup_trait_def(ccx.tcx, trait_id)
849: }
--
1145: |trait_ref| {
1146: let trait_def = ty::lookup_trait_def(tcx, trait_ref.def_id);
1147: if trait_def.bounds.contains_elem(ty::BoundSized) {
librustc/middle/typeck/variance.rs:
744: ty::ty_trait(box ty::TyTrait { def_id, ref substs, .. }) => {
745: let trait_def = ty::lookup_trait_def(self.tcx(), def_id);
746: self.add_constraints_from_substs(def_id, &trait_def.generics,
librustc/middle/lint.rs:
690: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef> {
691: ty::lookup_trait_def(self.tcx, id)
692: }
librustc/metadata/encoder.rs:
1095: encode_item_variances(ebml_w, ecx, item.id);
1096: let trait_def = ty::lookup_trait_def(tcx, def_id);
1097: encode_ty_type_param_defs(ebml_w, ecx,
librustc/util/ppaux.rs:
425: let generics = if is_trait {
426: ty::lookup_trait_def(cx, did).generics.clone()
427: } else {
librustc/middle/trans/meth.rs:
174: // bound to.
175: let bound_index = ty::lookup_trait_def(bcx.tcx(), trait_id).
176: generics.type_param_defs().len();
librustc/middle/typeck/check/mod.rs:
694: ast::ItemTrait(_, _, _, ref trait_methods) => {
695: let trait_def = ty::lookup_trait_def(ccx.tcx, local_def(it.id));
696: for trait_method in (*trait_methods).iter() {
librustc/middle/ty.rs:826:1-826:1 -NK_AS_STR_TODO- definition:
pub type BuiltinBounds = EnumSet<BuiltinBound>;
pub enum BuiltinBound {
BoundStatic,
references:- 39librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/kind.rs:
librustc/middle/astencode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/ty.rs:1266:10-1266:10 -fn- definition:
pub fn mk_nil() -> t { mk_prim_t(&primitives::TY_NIL) }
pub fn mk_err() -> t { mk_prim_t(&primitives::TY_ERR) }
pub fn mk_bot() -> t { mk_prim_t(&primitives::TY_BOT) }
references:- 121librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/check_match.rs:
librustc/middle/mem_categorization.rs:
librustc/metadata/tydecode.rs:
librustc/middle/trans/glue.rs:
librustc/middle/trans/context.rs:
librustc/middle/trans/base.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:3227:1-3227:1 -fn- definition:
pub fn field_idx_strict(tcx: &ctxt, name: ast::Name, fields: &[field])
-> uint {
let mut i = 0u;
references:- 4librustc/middle/trans/expr.rs:
441: with_field_tys(bcx.tcx(), base_datum.ty, None, |discr, field_tys| {
442: let ix = ty::field_idx_strict(bcx.tcx(), field.name, field_tys);
443: let d = base_datum.get_element(
librustc/middle/trans/_match.rs:
1506: let rec_vals = rec_fields.iter().map(|field_name| {
1507: let ix = ty::field_idx_strict(tcx, field_name.name, field_tys);
1508: adt::trans_field_ptr(bcx, &*pat_repr, val, discr, ix)
--
2246: for f in fields.iter() {
2247: let ix = ty::field_idx_strict(tcx, f.ident.name, field_tys);
2248: let fldptr = adt::trans_field_ptr(bcx, &*pat_repr, val,
librustc/middle/trans/consts.rs:
419: expr::with_field_tys(cx.tcx(), bt, None, |discr, field_tys| {
420: let ix = ty::field_idx_strict(cx.tcx(), field.name, field_tys);
421: (adt::const_get_field(cx, &*brepr, bv, discr, ix), inlineable)
librustc/middle/ty.rs:767:23-767:23 -enum- definition:
pub enum IntVarValue {
IntType(ast::IntTy),
UintType(ast::UintTy),
references:- 14768: pub enum IntVarValue {
--
813: terr_integer_as_char,
814: terr_int_mismatch(expected_found<IntVarValue>),
815: terr_float_mismatch(expected_found<ast::FloatTy>),
--
966: impl fmt::Show for IntVarValue {
967: fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
librustc/middle/typeck/infer/mod.rs:
87: pub int_var_bindings: RefCell<ValsAndBindings<ty::IntVid,
88: Option<IntVarValue>>>,
89: pub int_var_counter: Cell<uint>,
librustc/middle/typeck/infer/combine.rs:
556: vid: ty::IntVid,
557: val: ty::IntVarValue) -> cres<ty::t>
558: {
librustc/middle/typeck/infer/to_str.rs:
78: impl InferStr for IntVarValue {
79: fn inf_str(&self, _cx: &InferCtxt) -> ~str {
librustc/middle/typeck/infer/unify.rs:
286: fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt)
287: -> &'v RefCell<ValsAndBindings<ty::IntVid, Option<IntVarValue>>> {
288: return &infcx.int_var_bindings;
--
292: impl SimplyUnifiable for IntVarValue {
293: fn to_type_err(err: expected_found<IntVarValue>) -> ty::type_err {
294: return ty::terr_int_mismatch(err);
librustc/middle/ty.rs:
768: pub enum IntVarValue {
librustc/middle/ty.rs:788:25-788:25 -enum- definition:
pub enum type_err {
terr_mismatch,
terr_fn_style_mismatch(expected_found<FnStyle>),
references:- 34librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/demand.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:983:41-983:41 -struct- definition:
pub struct RegionParameterDef {
pub name: ast::Name,
pub def_id: ast::DefId,
references:- 22984: pub struct RegionParameterDef {
librustc/middle/typeck/collect.rs:
1025: region_param_defs: Rc::new(lifetimes.iter().map(|l| {
1026: ty::RegionParameterDef { name: l.name,
1027: def_id: local_def(l.id) }
librustc/metadata/decoder.rs:
280: let def_id = translate_def_id(cdata, def_id);
281: v.push(ty::RegionParameterDef { name: ident.name,
282: def_id: def_id });
librustc/middle/ty.rs:
984: pub struct RegionParameterDef {
--
1007: }
1008: pub fn region_param_defs<'a>(&'a self) -> &'a [RegionParameterDef] {
1009: self.region_param_defs.as_slice()
--
4665: free_id: ast::NodeId,
4666: region_params: &[RegionParameterDef])
4667: -> Vec<ty::Region> {
librustc/middle/subst.rs:
264: _: &ty::substs,
265: _: Option<Span>) -> ty::RegionParameterDef {
266: *self
librustc/middle/typeck/infer/mod.rs:
635: span: Span,
636: defs: &[ty::RegionParameterDef])
637: -> OwnedSlice<ty::Region> {
librustc/metadata/encoder.rs:
163: fn encode_region_param_defs(ebml_w: &mut Encoder,
164: params: &[ty::RegionParameterDef]) {
165: for param in params.iter() {
librustc/metadata/decoder.rs:
270: fn item_region_param_defs(item_doc: ebml::Doc, cdata: Cmd)
271: -> Rc<Vec<ty::RegionParameterDef> > {
272: let mut v = Vec::new();
librustc/util/ppaux.rs:
541: impl Repr for ty::RegionParameterDef {
542: fn repr(&self, _tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:
4633: method_type_params: &[TypeParameterDef],
4634: item_region_params: &[RegionParameterDef],
4635: method_region_params: &[RegionParameterDef],
librustc/middle/ty.rs:3453:1-3453:1 -fn- definition:
pub fn provided_trait_methods(cx: &ctxt, id: ast::DefId) -> Vec<Rc<Method>> {
if is_local(id) {
match cx.map.find(id.node) {
references:- 2librustc/middle/typeck/check/mod.rs:
824: // Check for missing methods from trait
825: let provided_methods = ty::provided_trait_methods(tcx,
826: impl_trait_ref.def_id);
librustc/middle/typeck/coherence.rs:
323: let prov = ty::provided_trait_methods(tcx, trait_ref.def_id);
324: for trait_method in prov.iter() {
librustc/middle/ty.rs:2425:16-2425:16 -enum- definition:
pub enum Representability {
Representable,
SelfRecursive,
references:- 62424: /// differently when reporting errors.
2426: pub enum Representability {
--
2450: fn type_structurally_recursive(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
2451: ty: t) -> Representability {
2452: debug!("type_structurally_recursive: {}",
librustc/middle/ty.rs:4088:4-4088:4 -fn- definition:
fn tycat(cx: &ctxt, ty: t) -> int {
if type_is_simd(cx, ty) {
return tycat(cx, simd_type(cx, ty))
references:- 24116: return tbl[tycat(cx, ty) as uint ][opcat(op) as uint];
4117: }
librustc/middle/ty.rs:3600:1-3600:1 -fn- definition:
pub fn try_add_builtin_trait(tcx: &ctxt,
trait_def_id: ast::DefId,
builtin_bounds: &mut BuiltinBounds) -> bool {
references:- 5librustc/middle/typeck/astconv.rs:
889: ast::DefTrait(trait_did) => {
890: if ty::try_add_builtin_trait(tcx, trait_did,
891: &mut builtin_bounds) {
librustc/middle/typeck/collect.rs:
440: match tcx.lang_items.require(SizedTraitLangItem) {
441: Ok(def_id) => { ty::try_add_builtin_trait(tcx, def_id, &mut bounds); },
442: Err(s) => tcx.sess.err(s),
--
1122: match ccx.tcx.lang_items.require(SizedTraitLangItem) {
1123: Ok(def_id) => { ty::try_add_builtin_trait(ccx.tcx,
1124: def_id,
librustc/middle/ty.rs:2672:72-2672:72 -fn- definition:
// FIXME(pcwalton): Makes a copy, bleh. Probably better to not do that.
pub fn node_id_to_type_params(cx: &ctxt, id: ast::NodeId) -> Vec<t> {
match cx.node_type_substs.borrow().find(&id) {
references:- 23003: ParamsTy {
3004: params: node_id_to_type_params(cx, expr.id),
3005: ty: node_id_to_type(cx, expr.id)
librustc/middle/trans/common.rs:
715: let params = match node {
716: ExprId(id) => ty::node_id_to_type_params(tcx, id),
717: MethodCall(method_call) => {
librustc/middle/ty.rs:4310:1-4310:1 -fn- definition:
pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
lookup_locally_or_in_crate_store(
"item_variance_map", item_id, &mut *tcx.item_variance_map.borrow_mut(),
references:- 3librustc/middle/typeck/variance.rs:
638: // variance already inferred, just look it up.
639: let variances = ty::item_variances(self.tcx(), item_def_id);
640: let variance = match kind {
librustc/metadata/encoder.rs:
181: id: ast::NodeId) {
182: let v = ty::item_variances(ecx.tcx, ast_util::local_def(id));
183: ebml_w.start_tag(tag_item_variances);
librustc/middle/typeck/infer/combine.rs:
146: &ty::NonerasedRegions(ref b_rs)) => {
147: let variances = ty::item_variances(tcx, item_def_id);
148: let region_params = &variances.region_params;
librustc/middle/ty.rs:1050:19-1050:19 -struct- definition:
pub struct ty_param_bounds_and_ty {
pub generics: Generics,
pub ty: t
references:- 56librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/astencode.rs:
librustc/metadata/decoder.rs:
librustc/middle/ty.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/lint.rs:
librustc/middle/astencode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/metadata/csearch.rs:
librustc/util/ppaux.rs:
librustc/metadata/csearch.rs:
librustc/middle/ty.rs:864:38-864:38 -struct- definition:
pub struct IntVid(pub uint);
pub struct FloatVid(pub uint);
pub struct RegionVid {
references:- 18919: impl Vid for IntVid {
920: fn to_uint(&self) -> uint { let IntVid(v) = *self; v }
--
1456: pub fn mk_int_var(cx: &ctxt, v: IntVid) -> t { mk_infer(cx, IntVar(v)) }
librustc/middle/typeck/infer/mod.rs:
612: pub fn next_int_var_id(&self) -> IntVid {
613: let mut int_var_counter = self.int_var_counter.get();
librustc/middle/typeck/infer/combine.rs:
555: vid_is_expected: bool,
556: vid: ty::IntVid,
557: val: ty::IntVarValue) -> cres<ty::t>
librustc/middle/typeck/infer/resolve.rs:
239: pub fn resolve_int_var(&mut self, vid: IntVid) -> ty::t {
240: if !self.should(resolve_ivar) {
librustc/middle/typeck/infer/unify.rs:
285: impl UnifyVid<Option<IntVarValue>> for ty::IntVid {
286: fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt)
287: -> &'v RefCell<ValsAndBindings<ty::IntVid, Option<IntVarValue>>> {
288: return &infcx.int_var_bindings;
librustc/middle/typeck/infer/mod.rs:
241: pub enum fixup_err {
242: unresolved_int_ty(IntVid),
243: unresolved_ty(TyVid),
librustc/middle/ty.rs:1403:1-1403:1 -fn- definition:
pub fn mk_tup(cx: &ctxt, ts: Vec<t>) -> t { mk_t(cx, ty_tup(ts)) }
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
mk_t(cx, ty_closure(box fty))
references:- 14librustc/middle/typeck/check/mod.rs:
4372: (0, vec!(ty::mk_u32(), ty::mk_u32()),
4373: ty::mk_tup(tcx, vec!(ty::mk_u32(), ty::mk_bool()))),
--
4376: (0, vec!(ty::mk_u64(), ty::mk_u64()),
4377: ty::mk_tup(tcx, vec!(ty::mk_u64(), ty::mk_bool()))),
librustc/middle/typeck/infer/combine.rs:
530: .map(|(a, b)| this.tys(*a, *b)))
531: .and_then(|ts| Ok(ty::mk_tup(tcx, ts)) )
532: } else {
librustc/metadata/tydecode.rs:
353: st.pos = st.pos + 1u;
354: return ty::mk_tup(st.tcx, params);
355: }
librustc/middle/trans/closure.rs:
132: let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8());
133: ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t))
134: }
librustc/middle/typeck/astconv.rs:
586: .collect();
587: ty::mk_tup(tcx, flds)
588: }
librustc/middle/ty.rs:3295:4-3295:4 -fn- definition:
fn tstore_to_closure(s: &TraitStore) -> ~str {
match s {
&UniqTraitStore => "proc".to_owned(),
references:- 23318: tstore_to_closure(&values.expected),
3319: tstore_to_closure(&values.found))
3320: }
librustc/middle/ty.rs:3934:58-3934:58 -fn- definition:
// Obtain the representation annotation for a definition.
pub fn lookup_repr_hint(tcx: &ctxt, did: DefId) -> attr::ReprAttr {
let mut acc = attr::ReprAny;
references:- 3librustc/middle/trans/adt.rs:
245: }
246: let hint = ty::lookup_repr_hint(tcx, def_id);
247: // Appropriate representation explicitly selected?
librustc/middle/typeck/check/mod.rs:
3726: let hint = ty::lookup_repr_hint(ccx.tcx, ast::DefId { krate: ast::LOCAL_CRATE, node: id });
3727: if hint != attr::ReprAny && vs.len() <= 1 {
librustc/middle/ty.rs:137:19-137:19 -struct- definition:
pub struct field_ty {
pub name: Name,
pub id: DefId,
references:- 22138: pub struct field_ty {
librustc/middle/typeck/collect.rs:
472: ast::UnnamedField(visibility) => {
473: ty::field_ty {
474: name: special_idents::unnamed_field.name,
librustc/metadata/decoder.rs:
991: let origin_id = translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
992: result.push(ty::field_ty {
993: name: name.name,
--
1005: let origin_id = translate_def_id(cdata, reader::with_doc_data(tagdoc, parse_def_id));
1006: result.push(ty::field_ty {
1007: name: special_idents::unnamed_field.name,
librustc/middle/ty.rs:
4021: field_id: ast::DefId)
4022: -> field_ty {
4023: let r = lookup_struct_fields(cx, parent);
librustc/middle/typeck/check/mod.rs:
534: fn span_for_field(tcx: &ty::ctxt, field: &ty::field_ty, struct_id: ast::DefId) -> Span {
535: assert!(field.id.krate == ast::LOCAL_CRATE);
--
1509: class_id: ast::DefId,
1510: items: &[ty::field_ty],
1511: fieldname: ast::Name,
--
2421: substitutions: ty::substs,
2422: field_types: &[ty::field_ty],
2423: ast_fields: &[ast::Field],
librustc/middle/typeck/check/_match.rs:
296: fields: &[ast::FieldPat],
297: class_fields: Vec<ty::field_ty> ,
298: class_id: ast::DefId,
librustc/metadata/encoder.rs:
273: fn encode_struct_fields(ebml_w: &mut Encoder,
274: fields: &[ty::field_ty],
275: origin: DefId) {
--
650: ebml_w: &mut Encoder,
651: fields: &[ty::field_ty],
652: global_index: &mut Vec<entry<i64>>)
librustc/metadata/decoder.rs:
979: pub fn get_struct_fields(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId)
980: -> Vec<ty::field_ty> {
981: let data = cdata.data();
librustc/metadata/csearch.rs:
183: def: ast::DefId)
184: -> Vec<ty::field_ty> {
185: let cdata = cstore.get_crate_data(def.krate);
librustc/middle/typeck/collect.rs:
452: v: &ast::StructField,
453: origin: ast::DefId) -> ty::field_ty {
454: let tt = ccx.to_ty(&ExplicitRscope, v.node.ty);
librustc/middle/ty.rs:623:81-623:81 -enum- definition:
pub enum BoundRegion {
/// An anonymous region parameter for a given fn (&T)
BrAnon(uint),
references:- 43librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/astencode.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:1366:1-1366:1 -fn- definition:
pub fn mk_uniq(cx: &ctxt, ty: t) -> t { mk_t(cx, ty_uniq(ty)) }
pub fn mk_ptr(cx: &ctxt, tm: mt) -> t { mk_t(cx, ty_ptr(tm)) }
pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
references:- 13librustc/middle/typeck/check/mod.rs:
2686: &Some(item_def_id) if def_id == item_def_id => {
2687: fcx.write_ty(id, ty::mk_uniq(tcx,
2688: fcx.expr_ty(subexpr)));
--
2800: ast::UnUniq => {
2801: oprnd_t = ty::mk_uniq(tcx, oprnd_t);
2802: }
librustc/middle/typeck/astconv.rs:
562: mk_pointer(this, rscope, &mt, Uniq,
563: |ty| ty::mk_uniq(tcx, ty))
564: }
--
786: ast::SelfUniq => {
787: Some(ty::mk_uniq(this.tcx(), self_info.untransformed_self_ty))
788: }
librustc/middle/typeck/infer/combine.rs:
498: let typ = if_ok!(this.tys(a_inner, b_inner));
499: check_ptr_to_vec(this, a, b, a_inner, b_inner, ty::mk_uniq(tcx, typ))
500: }
librustc/metadata/tydecode.rs:
333: '@' => return ty::mk_box(st.tcx, parse_ty(st, |x,y| conv(x,y))),
334: '~' => return ty::mk_uniq(st.tcx, parse_ty(st, |x,y| conv(x,y))),
335: '*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
librustc/middle/trans/glue.rs:
95: } else {
96: ty::mk_uniq(tcx, ty::mk_i8())
97: }
librustc/middle/trans/expr.rs:
1174: // if content_ty is, e.g. box fail!().
1175: let real_box_ty = ty::mk_uniq(bcx.tcx(), contents_ty);
1176: let Result { bcx, val } = malloc_raw_dyn(bcx, real_box_ty, size);
librustc/middle/trans/tvec.rs:
246: let llsizeval = C_uint(ccx, s.get().len());
247: let typ = ty::mk_uniq(bcx.tcx(), ty::mk_str(bcx.tcx()));
248: let lldestval = rvalue_scratch_datum(bcx,
librustc/middle/typeck/check/mod.rs:
4041: match v {
4042: ast::ExprVstoreUniq => ty::mk_uniq(fcx.ccx.tcx, mk_inner().ty),
4043: ast::ExprVstoreSlice | ast::ExprVstoreMutSlice => {
librustc/middle/ty.rs:2642:1-2642:1 -fn- definition:
pub fn node_id_to_trait_ref(cx: &ctxt, id: ast::NodeId) -> Rc<ty::TraitRef> {
match cx.trait_refs.borrow().find(&id) {
Some(t) => t.clone(),
references:- 74425: ast::ItemImpl(_, Some(ref trait_ref), _, _) => {
4426: Some(node_id_to_trait_ref(tcx, trait_ref.ref_id).def_id)
4427: }
librustc/middle/typeck/check/mod.rs:
680: let impl_trait_ref =
681: ty::node_id_to_trait_ref(ccx.tcx, ast_trait_ref.ref_id);
682: check_impl_methods_against_trait(ccx,
librustc/middle/typeck/coherence.rs:
573: for trait_ref in trait_refs.iter() {
574: let ty_trait_ref = ty::node_id_to_trait_ref(
575: self.crate_context.tcx,
librustc/metadata/encoder.rs:
1057: for ast_trait_ref in opt_trait.iter() {
1058: let trait_ref = ty::node_id_to_trait_ref(
1059: tcx, ast_trait_ref.ref_id);
--
1121: for ast_trait_ref in super_traits.iter() {
1122: let trait_ref = ty::node_id_to_trait_ref(ecx.tcx, ast_trait_ref.ref_id);
1123: encode_trait_ref(ebml_w, ecx, &*trait_ref, tag_item_super_trait_ref);
librustc/middle/ty.rs:3865:1-3865:1 -fn- definition:
pub fn lookup_impl_vtables(cx: &ctxt,
did: ast::DefId)
-> typeck::impl_res {
references:- 2librustc/metadata/encoder.rs:
1060: encode_trait_ref(ebml_w, ecx, &*trait_ref, tag_item_trait_ref);
1061: let impl_vtables = ty::lookup_impl_vtables(tcx, def_id);
1062: encode_impl_vtables(ebml_w, ecx, &impl_vtables);
librustc/middle/trans/callee.rs:
201: // Get the vtables that the impl implements the trait at
202: let impl_res = ty::lookup_impl_vtables(bcx.tcx(), impl_id);
librustc/middle/ty.rs:904:1-904:1 -trait- definition:
pub trait Vid {
fn to_uint(&self) -> uint;
}
references:- 27929: impl Vid for FloatVid {
930: fn to_uint(&self) -> uint { let FloatVid(v) = *self; v }
--
939: impl Vid for RegionVid {
940: fn to_uint(&self) -> uint { self.id }
librustc/middle/typeck/infer/mod.rs:
484: fn rollback_to<V:Clone + Vid,T:Clone>(vb: &mut ValsAndBindings<V, T>,
485: len: uint) {
librustc/middle/typeck/infer/lattice.rs:
480: T:Clone + InferStr + LatticeValue,
481: V:Clone + Eq + ToStr + Vid + UnifyVid<Bounds<T>>>(
482: this: &L,
librustc/middle/typeck/infer/to_str.rs:
69: impl<V:Vid + ToStr,T:InferStr> InferStr for VarValue<V, T> {
70: fn inf_str(&self, cx: &InferCtxt) -> ~str {
librustc/middle/typeck/infer/unify.rs:
185: fn simple_vars<T:Clone + Eq + InferStr + SimplyUnifiable,
186: V:Clone + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
187: &self,
--
202: fn simple_vars<T:Clone + Eq + InferStr + SimplyUnifiable,
203: V:Clone + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
204: &self,
--
242: fn simple_var_t<T:Clone + Eq + InferStr + SimplyUnifiable,
243: V:Clone + Eq + Vid + ToStr + UnifyVid<Option<T>>>(
244: &self,
librustc/middle/ty.rs:1432:1-1432:1 -fn- definition:
pub fn mk_trait(cx: &ctxt,
did: ast::DefId,
substs: substs,
references:- 144303: Ok((trait_ref.clone(),
4304: mk_trait(tcx,
4305: trait_ref.def_id,
librustc/middle/typeck/check/vtable.rs:
470: // use a dummy type just to package up the substs that need fixing up
471: let t = ty::mk_trait(tcx,
472: id, substs,
--
721: let object_ty = ty::mk_trait(cx.tcx, def_id,
722: substs.clone(),
librustc/middle/typeck/check/method.rs:
915: |m, r| {
916: ty::mk_trait(tcx, trt_did, trt_substs.clone(),
917: RegionTraitStore(r, m), b)
librustc/middle/typeck/astconv.rs:
515: let bounds = conv_builtin_bounds(this.tcx(), bounds, trait_store);
516: return ty::mk_trait(tcx,
517: result.def_id,
librustc/middle/typeck/infer/mod.rs:
678: // make up a dummy type just to reuse/abuse the resolve machinery
679: let dummy0 = ty::mk_trait(self.tcx,
680: trait_ref.def_id,
librustc/middle/typeck/infer/combine.rs:
479: let bounds = if_ok!(this.bounds(a_.bounds, b_.bounds));
480: Ok(ty::mk_trait(tcx,
481: a_.def_id,
librustc/middle/typeck/infer/coercion.rs:
343: }) => {
344: ty::mk_trait(tcx, def_id, substs.clone(),
345: ty::RegionTraitStore(r_a, b_mutbl), bounds)
librustc/metadata/tydecode.rs:
321: assert_eq!(next(st), ']');
322: return ty::mk_trait(st.tcx, def, substs, store, bounds.builtin_bounds);
323: }
librustc/middle/ty.rs:1567:1-1567:1 -fn- definition:
pub fn substs_to_str(cx: &ctxt, substs: &substs) -> ~str {
substs.repr(cx)
}
references:- 2librustc/middle/typeck/check/method.rs:
1194: bare_fn_ty.repr(tcx),
1195: ty::substs_to_str(tcx, &all_substs));
librustc/middle/typeck/check/mod.rs:
1117: node_id,
1118: ty::substs_to_str(self.tcx(), &substs),
1119: self.tag());
librustc/middle/ty.rs:408:71-408:71 -fn- definition:
pub fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), has_self) }
pub fn type_needs_infer(t: t) -> bool {
tbox_has_flag(get(t), needs_infer)
references:- 10librustc/middle/typeck/mod.rs:
259: substs.iter().map(|t| ppaux::ty_to_str(tcx, *t)).collect::<Vec<~str>>());
260: assert!(substs.iter().all(|t| !ty::type_needs_infer(*t)));
librustc/middle/typeck/check/writeback.rs:
464: fn fold_ty(&mut self, t: ty::t) -> ty::t {
465: if !ty::type_needs_infer(t) {
466: return t;
librustc/middle/trans/monomorphize.rs:
49: assert!(real_substs.tps.iter().all(|t| {
50: !ty::type_needs_infer(*t) && !ty::type_has_params(*t)
51: }));
librustc/middle/trans/callee.rs:
274: assert!(type_params.iter().all(|t| !ty::type_needs_infer(*t)));
librustc/middle/trans/common.rs:
722: if !params.iter().all(|t| !ty::type_needs_infer(*t)) {
723: bcx.sess().bug(
librustc/middle/trans/meth.rs:
200: typeck::vtable_static(impl_did, rcvr_substs, rcvr_origins) => {
201: assert!(rcvr_substs.iter().all(|t| !ty::type_needs_infer(*t)));
librustc/middle/typeck/infer/resolve.rs:
156: if !ty::type_needs_infer(typ) {
157: return typ;
librustc/middle/ty.rs:1405:1-1405:1 -fn- definition:
pub fn mk_closure(cx: &ctxt, fty: ClosureTy) -> t {
mk_t(cx, ty_closure(box fty))
}
references:- 72848: ty::ty_bare_fn(ref b) => {
2849: ty::mk_closure(
2850: cx,
librustc/middle/typeck/check/mod.rs:
2325: let fty_sig = fn_ty.sig.clone();
2326: let fty = ty::mk_closure(tcx, fn_ty);
2327: debug!("check_expr_fn fty={}", fcx.infcx().ty_to_str(fty));
librustc/middle/typeck/astconv.rs:
617: None);
618: ty::mk_closure(tcx, fn_decl)
619: }
librustc/middle/typeck/infer/combine.rs:
545: this.closure_tys(*a_fty, *b_fty).and_then(|fty| {
546: Ok(ty::mk_closure(tcx, fty))
547: })
librustc/middle/typeck/infer/coercion.rs:
400: let adj = ty::AutoAddEnv(fn_ty_b.store);
401: let a_closure = ty::mk_closure(self.get_ref().infcx.tcx,
402: ty::ClosureTy {
librustc/metadata/tydecode.rs:
356: 'f' => {
357: return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
358: }
librustc/middle/typeck/astconv.rs:
632: None);
633: ty::mk_closure(tcx, fn_decl)
634: }
librustc/middle/ty.rs:2528:1-2528:1 -fn- definition:
pub fn type_is_integral(ty: t) -> bool {
match get(ty).sty {
ty_infer(IntVar(_)) | ty_int(_) | ty_uint(_) => true,
references:- 82564: pub fn type_is_numeric(ty: t) -> bool {
2565: return type_is_integral(ty) || type_is_fp(ty);
2566: }
librustc/middle/typeck/check/mod.rs:
2838: oprnd_t);
2839: if !(ty::type_is_integral(oprnd_t) ||
2840: ty::get(oprnd_t).sty == ty::ty_bool) {
--
3997: let typ_s = structurally_resolved_type(fcx, sp, typ);
3998: return ty::type_is_integral(typ_s);
3999: }
librustc/middle/const_eval.rs:
221: let base = self.classify(base);
222: if ty::type_is_integral(ty) {
223: join(integral_const, base)
--
253: let ty = ty::expr_ty(self.tcx, rhs);
254: if ty::type_is_integral(ty) {
255: integral_const
librustc/middle/trans/_match.rs:
1606: test_val = load_if_immediate(bcx, val, pty);
1607: kind = if ty::type_is_integral(pty) { switch }
1608: else { compare };
librustc/middle/ty.rs:642:38-642:38 -enum- definition:
pub enum RegionSubsts {
ErasedRegions,
NonerasedRegions(OwnedSlice<ty::Region>)
references:- 17641: * trans, and all region parameters will be replaced with `ty::ReStatic`. */
643: pub enum RegionSubsts {
--
668: pub tps: Vec<t>,
669: pub regions: RegionSubsts,
670: }
librustc/middle/subst.rs:
198: impl Subst for ty::RegionSubsts {
199: fn subst_spanned(&self, tcx: &ty::ctxt,
200: substs: &ty::substs,
201: span: Option<Span>) -> ty::RegionSubsts {
202: match *self {
librustc/middle/typeck/infer/combine.rs:
135: item_def_id: ast::DefId,
136: a: &ty::RegionSubsts,
137: b: &ty::RegionSubsts)
138: -> cres<ty::RegionSubsts> {
139: let tcx = this.infcx().tcx;
librustc/metadata/tyencode.rs:
115: fn enc_region_substs(w: &mut MemWriter, cx: &ctxt, substs: &ty::RegionSubsts) {
116: match *substs {
librustc/metadata/tydecode.rs:
179: fn parse_region_substs(st: &mut PState, conv: conv_did) -> ty::RegionSubsts {
180: match next(st) {
librustc/util/ppaux.rs:
564: impl Repr for ty::RegionSubsts {
565: fn repr(&self, tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:
641: * trans, and all region parameters will be replaced with `ty::ReStatic`. */
643: pub enum RegionSubsts {
librustc/middle/ty.rs:73:19-73:19 -enum- definition:
pub enum MethodContainer {
TraitContainer(ast::DefId),
ImplContainer(ast::DefId),
references:- 686: pub def_id: ast::DefId,
87: pub container: MethodContainer,
--
99: def_id: ast::DefId,
100: container: MethodContainer,
101: provided_source: Option<ast::DefId>)
librustc/middle/typeck/collect.rs:
483: fn convert_methods(ccx: &CrateCtxt,
484: container: MethodContainer,
485: ms: &[@ast::Method],
--
533: fn ty_of_method(ccx: &CrateCtxt,
534: container: MethodContainer,
535: m: &ast::Method,
librustc/middle/ty.rs:1056:53-1056:53 -struct- definition:
/// As `ty_param_bounds_and_ty` but for a trait ref.
pub struct TraitDef {
pub generics: Generics,
references:- 12librustc/middle/typeck/collect.rs:
875: sized);
876: let trait_def = Rc::new(ty::TraitDef {
877: generics: ty_generics,
librustc/metadata/decoder.rs:
403: ty::TraitDef {
404: generics: ty::Generics {type_param_defs: tp_defs,
librustc/middle/ty.rs:
3874: /// Given the did of a trait, returns its canonical trait ref.
3875: pub fn lookup_trait_def(cx: &ctxt, did: ast::DefId) -> Rc<ty::TraitDef> {
3876: let mut trait_defs = cx.trait_defs.borrow_mut();
librustc/middle/typeck/check/mod.rs:
1056: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef> {
1057: ty::lookup_trait_def(self.tcx(), id)
librustc/middle/typeck/astconv.rs:
72: fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty;
73: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef>;
librustc/middle/typeck/collect.rs:
846: fn get_trait_def(ccx: &CrateCtxt, trait_id: ast::DefId) -> Rc<ty::TraitDef> {
847: if trait_id.krate != ast::LOCAL_CRATE {
--
858: pub fn trait_def_of_item(ccx: &CrateCtxt, it: &ast::Item) -> Rc<ty::TraitDef> {
859: let def_id = local_def(it.id);
librustc/middle/lint.rs:
690: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef> {
691: ty::lookup_trait_def(self.tcx, id)
librustc/metadata/decoder.rs:
377: item_id: ast::NodeId,
378: tcx: &ty::ctxt) -> ty::TraitDef
379: {
librustc/metadata/csearch.rs:
197: pub fn get_trait_def(tcx: &ty::ctxt, def: ast::DefId) -> ty::TraitDef {
198: let cstore = &tcx.sess.cstore;
librustc/middle/typeck/collect.rs:
131: fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef> {
132: get_trait_def(self, id)
librustc/middle/ty.rs:4459:30-4459:30 -fn- definition:
/// Otherwise, return `None`.
pub fn trait_method_of_method(tcx: &ctxt,
def_id: ast::DefId) -> Option<ast::DefId> {
references:- 2librustc/middle/typeck/check/method.rs:
1439: // definition if possible, rather than an impl
1440: match ty::trait_method_of_method(self.tcx(), impl_did) {
1441: None => {debug!("(report candidate) No trait method found"); impl_did},
librustc/middle/lint.rs:
1577: // to the method inside impl).
1578: ty::trait_method_of_method(
1579: cx.tcx, def_id).unwrap_or(def_id)
librustc/middle/ty.rs:386:38-386:38 -struct- definition:
pub struct t { inner: *t_opaque }
impl fmt::Show for t {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
references:- 825librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/demand.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lattice.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/resolve.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/check_match.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/kind.rs:
librustc/middle/astencode.rs:
librustc/middle/effect.rs:
librustc/middle/expr_use_visitor.rs:
librustc/back/link.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/monomorphize.rs:
librustc/middle/trans/glue.rs:
librustc/middle/trans/datum.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/common.rs:
librustc/middle/trans/context.rs:
librustc/middle/trans/consts.rs:
librustc/middle/trans/type_of.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/closure.rs:
librustc/middle/trans/tvec.rs:
librustc/middle/trans/meth.rs:
librustc/middle/trans/foreign.rs:
librustc/middle/trans/intrinsic.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/trans/adt.rs:
librustc/middle/trans/cleanup.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:60:1-60:1 -NK_AS_STR_TODO- definition:
pub type Disr = u64;
pub static INITIAL_DISCRIMINANT_VALUE: Disr = 0;
// Data types
references:- 56librustc/middle/typeck/check/mod.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/middle/trans/expr.rs:
librustc/middle/trans/base.rs:
librustc/middle/trans/_match.rs:
librustc/middle/trans/adt.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:1505:1-1505:1 -fn- definition:
pub fn walk_regions_and_ty(cx: &ctxt, ty: t, fldr: |r: Region|, fldt: |t: t|)
-> t {
ty_fold::RegionFolder::general(cx,
references:- 2librustc/middle/kind.rs:
520: let target_params = ty::param_tys_in_type(target_ty);
521: ty::walk_regions_and_ty(
522: cx.tcx,
librustc/middle/ty.rs:1370:1-1370:1 -fn- definition:
pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t {
mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutMutable})
references:- 211373: pub fn mk_mut_rptr(cx: &ctxt, r: Region, ty: t) -> t {
1374: mk_rptr(cx, r, mt {ty: ty, mutbl: ast::MutMutable})
1375: }
--
2896: AutoPtr(r, m) => {
2897: mk_rptr(cx, r, mt {
2898: ty: adjusted_ty,
--
2912: adjusted_ty);
2913: mk_rptr(cx, r, mt {
2914: ty: adjusted_ty,
librustc/middle/typeck/check/mod.rs:
4057: Some(scope) => ty::mk_rptr(fcx.ccx.tcx, ty::ReScope(scope), mk_inner()),
4058: None => ty::mk_rptr(fcx.ccx.tcx, ty::ReStatic, mk_inner()),
4059: }
librustc/middle/typeck/check/_match.rs:
489: let mt = ty::mt {ty: expected, mutbl: mutbl};
490: let region_ty = ty::mk_rptr(tcx, region_var, mt);
491: demand::eqtype(fcx, pat.span, region_ty, typ);
librustc/middle/typeck/check/method.rs:
854: // it can't be observed.
855: ty::mk_rptr(tcx, r, ty::mt {ty:slice_ty, mutbl:MutImmutable})
856: })
--
875: let slice_ty = ty::mk_str_slice(tcx, r, m);
876: ty::mk_rptr(tcx, r, ty::mt {ty:slice_ty, mutbl:m})
877: })
--
949: AutoPtr, autoderefs, [MutImmutable, MutMutable],
950: |m,r| ty::mk_rptr(tcx, r, ty::mt {ty:self_ty, mutbl:m}))
951: }
librustc/middle/typeck/astconv.rs:
781: lifetime);
782: Some(ty::mk_rptr(this.tcx(), region,
783: ty::mt {ty: self_info.untransformed_self_ty,
librustc/middle/typeck/infer/combine.rs:
509: let mt = if_ok!(this.mts(a_mt, b_mt));
510: check_ptr_to_vec(this, a, b, a_mt.ty, b_mt.ty, ty::mk_rptr(tcx, r, mt))
511: }
librustc/metadata/tydecode.rs:
338: let mt = parse_mt(st, |x,y| conv(x,y));
339: return ty::mk_rptr(st.tcx, r, mt);
340: }
librustc/middle/typeck/infer/coercion.rs:
248: let a_borrowed = ty::mk_rptr(self.get_ref().infcx.tcx,
249: r_borrow,
librustc/middle/ty.rs:3545:1-3545:1 -fn- definition:
pub fn method(cx: &ctxt, id: ast::DefId) -> Rc<Method> {
lookup_locally_or_in_crate_store("methods", id,
&mut *cx.methods.borrow_mut(), || {
references:- 203526: let method_def_id = *ty::trait_method_def_ids(cx, trait_did).get(idx);
3527: ty::method(cx, method_def_id)
3528: }
--
4354: for &method_def_id in methods.iter() {
4355: for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4356: tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
--
4401: for &method_def_id in methods.iter() {
4402: for &source in ty::method(tcx, method_def_id).provided_source.iter() {
4403: tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
librustc/middle/typeck/check/mod.rs:
796: let impl_method_def_id = local_def(impl_method.id);
797: let impl_method_ty = ty::method(ccx.tcx, impl_method_def_id);
librustc/middle/typeck/check/method.rs:
688: token::get_name(self.m_name),
689: impl_methods.iter().map(|&did| ty::method(self.tcx(), did).ident)
690: .collect::<Vec<ast::Ident>>()
--
693: let method = match impl_methods.iter().map(|&did| ty::method(self.tcx(), did))
694: .find(|m| m.ident.name == self.m_name) {
librustc/middle/typeck/coherence.rs:
625: for &method_def_id in methods.iter() {
626: for &source in ty::method(tcx, method_def_id).provided_source.iter() {
627: tcx.provided_method_sources.borrow_mut().insert(method_def_id, source);
librustc/metadata/encoder.rs:
1082: ebml_w,
1083: &*ty::method(tcx, method_def_id),
1084: path.clone(),
--
1136: let method_ty = ty::method(tcx, method_def_id);
librustc/middle/trans/callee.rs:
313: let impl_id = ty::method(tcx, def_id).container_id();
314: let method = ty::method(tcx, source_id);
315: let trait_ref = ty::impl_trait_ref(tcx, impl_id)
librustc/middle/trans/meth.rs:
234: .expect("could not find impl while translating");
235: let meth_did = methods.iter().find(|&did| ty::method(&ccx.tcx, *did).ident.name == name)
236: .expect("could not find method while translating");
--
507: let m_id = method_with_name(ccx, impl_id, ident.name);
508: let m = ty::method(tcx, m_id);
509: debug!("(making impl vtable) emitting method {} at subst {}",
librustc/middle/privacy.rs:
635: // the default implementation.
636: let method_id = ty::method(self.tcx, method_id).provided_source
637: .unwrap_or(method_id);
librustc/middle/ty.rs:1590:1-1590:1 -fn- definition:
pub fn type_needs_subst(ty: t) -> bool {
tbox_has_flag(get(ty), needs_subst)
}
references:- 2librustc/middle/subst.rs:
83: fn fold_ty(&mut self, t: ty::t) -> ty::t {
84: if !ty::type_needs_subst(t) {
85: return t;
librustc/middle/typeck/check/mod.rs:
3562: let t = ty::node_id_to_type(tcx, id);
3563: if ty::type_needs_subst(t) {
3564: tcx.sess.span_err(sp, "SIMD vector cannot be generic");
librustc/middle/ty.rs:3418:1-3418:1 -fn- definition:
pub fn note_and_explain_type_err(cx: &ctxt, err: &type_err) {
match *err {
terr_regions_does_not_outlive(subregion, superregion) => {
references:- 4librustc/middle/typeck/mod.rs:
309: ty::type_err_to_str(tcx, terr));
310: ty::note_and_explain_type_err(tcx, terr);
311: false
librustc/middle/typeck/infer/mod.rs:
746: for err in err.iter() {
747: ty::note_and_explain_type_err(self.tcx, *err)
748: }
librustc/middle/typeck/infer/error_reporting.rs:
364: self.report_type_error(trace, terr);
365: ty::note_and_explain_type_err(self.tcx, terr);
366: }
librustc/middle/typeck/check/mod.rs:
1043: ty::type_err_to_str(tcx, terr)));
1044: ty::note_and_explain_type_err(tcx, terr);
1045: }
librustc/middle/ty.rs:2267:4-2267:4 -fn- definition:
fn kind_bounds_to_contents(cx: &ctxt,
bounds: BuiltinBounds,
traits: &[Rc<TraitRef>])
references:- 32160: let tp_def = ty_param_defs.get(&p.def_id.node);
2161: kind_bounds_to_contents(cx,
2162: tp_def.bounds.builtin_bounds,
--
2254: // These are the type contents of the (opaque) interior
2255: let contents = kind_bounds_to_contents(cx, bounds, []);
librustc/middle/ty.rs:3775:1-3775:1 -fn- definition:
pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> Rc<Vec<Rc<VariantInfo>>> {
match cx.enum_var_cache.borrow().find(&id) {
Some(variants) => return variants.clone(),
references:- 241764: ty_enum(did, ref substs) => {
1765: for v in (*enum_variants(cx, did)).iter() {
1766: for aty in v.args.iter() {
--
2593: ty_enum(did, _) => {
2594: let variants = enum_variants(cx, did);
2595: if variants.len() == 0 {
--
3770: match ty::get(t).sty {
3771: ty_enum(did, _) => (*enum_variants(cx, did)).is_empty(),
3772: _ => false
--
3848: -> Rc<VariantInfo> {
3849: enum_variants(cx, enum_id).iter()
3850: .find(|variant| variant.id == variant_id)
librustc/middle/check_match.rs:
264: ty::ty_enum(eid, _) => {
265: for va in (*ty::enum_variants(cx.tcx, eid)).iter() {
266: match is_useful_specialized(cx, m, v, variant(va.id),
--
546: };
547: match ty::enum_variants(cx.tcx, eid).iter().find(|v| v.id == id ) {
548: Some(v) => v.args.len(),
--
888: Some(DefVariant(enum_id, _, _)) => {
889: if ty::enum_variants(cx.tcx, enum_id).len() != 1u {
890: return true;
librustc/metadata/encoder.rs:
302: let mut i = 0;
303: let vi = ty::enum_variants(ecx.tcx,
304: ast::DefId { krate: LOCAL_CRATE, node: id });
librustc/middle/trans/inline.rs:
91: let vs_here = ty::enum_variants(ccx.tcx(), local_def(item.id));
92: let vs_there = ty::enum_variants(ccx.tcx(), parent_id);
93: for (here, there) in vs_here.iter().zip(vs_there.iter()) {
librustc/middle/trans/monomorphize.rs:
247: let parent = ccx.tcx.map.get_parent(fn_id.node);
248: let tvs = ty::enum_variants(ccx.tcx(), local_def(parent));
249: let this_tv = tvs.iter().find(|tv| { tv.id.node == fn_id.node}).unwrap();
librustc/middle/trans/base.rs:
715: let repr = adt::represent_type(ccx, t);
716: let variants = ty::enum_variants(ccx.tcx(), tid);
717: let n_variants = (*variants).len();
--
1623: if !generics.is_type_parameterized() {
1624: let vi = ty::enum_variants(ccx.tcx(), local_def(item.id));
1625: let mut i = 0;
librustc/middle/trans/_match.rs:
339: ast::DefVariant(enum_id, var_id, _) => {
340: let variants = ty::enum_variants(ccx.tcx(), enum_id);
341: for v in (*variants).iter() {
librustc/middle/trans/debuginfo.rs:
1552: let variants = ty::enum_variants(cx.tcx(), enum_def_id);
librustc/middle/trans/adt.rs:
288: fn get_cases(tcx: &ty::ctxt, def_id: ast::DefId, substs: &ty::substs) -> Vec<Case> {
289: ty::enum_variants(tcx, def_id).iter().map(|vi| {
290: let arg_tys = vi.args.iter().map(|&raw_ty| {
librustc/middle/ty.rs:
3696: -> Vec<Rc<VariantInfo>> {
3697: enum_variants(cx, id).iter().map(|variant_info| {
3698: let substd_args = variant_info.args.iter()
librustc/middle/ty.rs:1167:4-1167:4 -fn- definition:
fn sflags(substs: &substs) -> uint {
let mut f = 0u;
for tt in substs.tps.iter() { f |= get(*tt).flags; }
references:- 21198: &ty_trait(box ty::TyTrait { ref substs, store, .. }) => {
1199: flags |= sflags(substs);
1200: match store {
librustc/middle/ty.rs:3530:1-3530:1 -fn- definition:
pub fn trait_methods(cx: &ctxt, trait_did: ast::DefId) -> Rc<Vec<Rc<Method>>> {
let mut trait_methods = cx.trait_methods_cache.borrow_mut();
match trait_methods.find_copy(&trait_did) {
references:- 64468: Some(trait_did) => {
4469: let trait_methods = ty::trait_methods(tcx, trait_did);
4470: trait_methods.iter()
librustc/middle/typeck/check/mod.rs:
790: let tcx = ccx.tcx;
791: let trait_methods = ty::trait_methods(tcx, impl_trait_ref.def_id);
librustc/middle/typeck/check/method.rs:
628: let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id);
629: match trait_methods.iter().position(|m| {
librustc/middle/typeck/variance.rs:
503: ast::ItemTrait(..) => {
504: let methods = ty::trait_methods(tcx, did);
505: for method in methods.iter() {
librustc/middle/trans/reflect.rs:
388: let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
389: let visitor_methods = ty::trait_methods(bcx.tcx(), visitor_trait_id);
390: let mut r = Reflector {
librustc/middle/ty.rs:2045:4-2045:4 -fn- definition:
fn tc_ty(cx: &ctxt,
ty: t,
cache: &mut HashMap<uint, TypeContents>) -> TypeContents
references:- 82039: let mut cache = HashMap::new();
2040: let result = tc_ty(cx, ty, &mut cache);
--
2143: |arg_ty| {
2144: tc_ty(cx, *arg_ty, cache)
2145: })
--
2195: let mc = TC::ReachesMutable.when(mt.mutbl == MutMutable);
2196: mc | tc_ty(cx, mt.ty, cache)
2197: }
librustc/middle/ty.rs:2437:4-2437:4 -fn- definition:
fn find_nonrepresentable<It: Iterator<t>>(cx: &ctxt, sp: Span, seen: &mut Vec<DefId>,
mut iter: It) -> Representability {
for ty in iter {
references:- 32498: });
2499: r = find_nonrepresentable(cx, sp, seen, iter);
librustc/middle/ty.rs:2719:1-2719:1 -fn- definition:
pub fn ty_fn_ret(fty: t) -> t {
match get(fty).sty {
ty_bare_fn(ref f) => f.sig.output,
references:- 112873: Some(method_ty) => {
2874: adjusted_ty = ty_fn_ret(method_ty);
2875: }
librustc/middle/typeck/check/mod.rs:
1385: Some(method) => {
1386: let ref_ty = ty::ty_fn_ret(method.ty);
1387: match method_call {
librustc/middle/typeck/check/_match.rs:
191: let struct_tpt = if ty::is_fn_ty(ctor_tpt.ty) {
192: ty::ty_param_bounds_and_ty {ty: ty::ty_fn_ret(ctor_tpt.ty),
193: ..ctor_tpt}
librustc/middle/typeck/check/regionck.rs:
502: constrain_call(rcx, None, expr, Some(base), [], true);
503: ty::ty_fn_ret(method.ty)
504: }
librustc/middle/liveness.rs:
1140: // will fail, and hence the successors can be ignored
1141: let t_ret = ty::ty_fn_ret(ty::expr_ty(self.ir.tcx, f));
1142: let succ = if ty::type_is_bot(t_ret) {self.s.exit_ln}
--
1465: let t_ret = ty::ty_fn_ret(ty::node_id_to_type(self.ir.tcx, id));
1466: if ty::type_is_nil(t_ret) {
librustc/middle/trans/expr.rs:
1707: datum, None, None));
1708: let ref_ty = ty::ty_fn_ret(monomorphize_type(bcx, method_ty));
1709: Datum(val, ref_ty, RvalueExpr(Rvalue(ByValue)))
librustc/middle/trans/base.rs:
1468: let _icx = push_ctxt("trans_fn");
1469: let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), id));
1470: trans_closure(ccx, decl, body, llfndecl,
librustc/middle/trans/closure.rs:
371: bcx.fcx.param_substs, id,
372: [], ty::ty_fn_ret(fty),
373: |bcx| load_environment(bcx, cdata_ty, &freevars, store));
librustc/middle/trans/intrinsic.rs:
191: let output_type = ty::ty_fn_ret(ty::node_id_to_type(ccx.tcx(), item.id));
librustc/middle/mem_categorization.rs:
718: Some(method_ty) => {
719: let ref_ty = ty::ty_fn_ret(method_ty);
720: self.cat_rvalue_node(node.id(), node.span(), ref_ty)
librustc/middle/ty.rs:867:38-867:38 -struct- definition:
pub struct FloatVid(pub uint);
pub struct RegionVid {
pub id: uint
references:- 17878: IntVar(IntVid),
879: FloatVar(FloatVid)
880: }
--
1458: pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
librustc/middle/typeck/infer/mod.rs:
91: // Map from floating variable to the kind of float it represents
92: pub float_var_bindings: RefCell<ValsAndBindings<ty::FloatVid,
93: Option<ast::FloatTy>>>,
librustc/middle/typeck/infer/combine.rs:
568: vid_is_expected: bool,
569: vid: ty::FloatVid,
570: val: ast::FloatTy) -> cres<ty::t>
librustc/middle/typeck/infer/resolve.rs:
261: pub fn resolve_float_var(&mut self, vid: FloatVid) -> ty::t {
262: if !self.should(resolve_fvar) {
librustc/middle/typeck/infer/unify.rs:
298: impl UnifyVid<Option<ast::FloatTy>> for ty::FloatVid {
299: fn appropriate_vals_and_bindings<'v>(infcx: &'v InferCtxt)
300: -> &'v RefCell<ValsAndBindings<ty::FloatVid, Option<ast::FloatTy>>> {
301: return &infcx.float_var_bindings;
librustc/middle/typeck/infer/mod.rs:
621: pub fn next_float_var_id(&self) -> FloatVid {
622: let mut float_var_counter = self.float_var_counter.get();
librustc/middle/ty.rs:2993:1-2993:1 -struct- definition:
pub struct ParamsTy {
pub params: Vec<t>,
pub ty: t
references:- 23001: expr: &ast::Expr)
3002: -> ParamsTy {
3003: ParamsTy {
3004: params: node_id_to_type_params(cx, expr.id),
librustc/middle/ty.rs:991:19-991:19 -struct- definition:
pub struct Generics {
/// List of type parameters declared on the item.
pub type_param_defs: Rc<Vec<TypeParameterDef>>,
references:- 39librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/astencode.rs:
librustc/metadata/decoder.rs:
librustc/metadata/csearch.rs:
librustc/middle/ty.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/variance.rs:
librustc/util/ppaux.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:1387:1-1387:1 -fn- definition:
pub fn mk_nil_ptr(cx: &ctxt) -> t {
mk_ptr(cx, mt {ty: mk_nil(), mutbl: ast::MutImmutable})
}
references:- 2librustc/middle/trans/debuginfo.rs:
1868: let int_type = ty::mk_int();
1869: let nil_pointer_type = ty::mk_nil_ptr(cx.tcx());
1870: let nil_pointer_type_metadata = type_metadata(cx, nil_pointer_type, codemap::DUMMY_SP);
librustc/middle/trans/closure.rs:
132: let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8());
133: ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t))
134: }
librustc/middle/ty.rs:2737:1-2737:1 -fn- definition:
pub fn ty_region(tcx: &ctxt,
span: Span,
ty: t) -> Region {
references:- 3librustc/middle/expr_use_visitor.rs:
300: if !ty::type_is_bot(expr_ty) {
301: let r = ty::ty_region(self.tcx(), expr.span, expr_ty);
302: let bk = ty::BorrowKind::from_mutbl(m);
--
725: let (r, bk) = {
726: (ty::ty_region(tcx, pat.span, pat_ty),
727: ty::BorrowKind::from_mutbl(m))
librustc/middle/typeck/check/regionck.rs:
1183: debug!("rptr_ty={}", ty_to_str(tcx, rptr_ty));
1184: let r = ty::ty_region(tcx, span, rptr_ty);
1185: link_region(rcx, span, r, ty::BorrowKind::from_mutbl(mutbl),
librustc/middle/ty.rs:1383:1-1383:1 -fn- definition:
pub fn mk_imm_ptr(cx: &ctxt, ty: t) -> t {
mk_ptr(cx, mt {ty: ty, mutbl: ast::MutImmutable})
}
references:- 5librustc/middle/typeck/mod.rs:
390: ty::mk_int(),
391: ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
392: ),
librustc/middle/typeck/check/mod.rs:
4140: param(ccx, 0)),
4141: "load" => (1, vec!(ty::mk_imm_ptr(tcx, param(ccx, 0))),
4142: param(ccx, 0)),
--
4342: "volatile_load" =>
4343: (1, vec!( ty::mk_imm_ptr(tcx, param(ccx, 0)) ), param(ccx, 0)),
4344: "volatile_store" =>
librustc/middle/trans/closure.rs:
131: fn tuplify_box_ty(tcx: &ty::ctxt, t: ty::t) -> ty::t {
132: let ptr = ty::mk_imm_ptr(tcx, ty::mk_i8());
133: ty::mk_tup(tcx, vec!(ty::mk_uint(), ty::mk_nil_ptr(tcx), ptr, ptr, t))
librustc/middle/typeck/mod.rs:
390: ty::mk_int(),
391: ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8()))
392: ),
librustc/middle/ty.rs:3710:1-3710:1 -fn- definition:
pub fn item_path_str(cx: &ctxt, id: ast::DefId) -> ~str {
with_path(cx, id, |path| ast_map::path_to_str(path)).to_owned()
}
references:- 263265: ty_enum(id, _) => format!("enum {}", item_path_str(cx, id)),
3266: ty_box(_) => "@-ptr".to_owned(),
--
3272: ty_closure(_) => "fn".to_owned(),
3273: ty_trait(ref inner) => format!("trait {}", item_path_str(cx, inner.def_id)),
3274: ty_struct(id, _) => format!("struct {}", item_path_str(cx, id)),
3275: ty_tup(_) => "tuple".to_owned(),
--
3382: item_path_str(cx, values.expected),
3383: item_path_str(cx, values.found))
3384: }
librustc/middle/typeck/mod.rs:
205: def_id,
206: ty::item_path_str(tcx, def_id),
207: tys.repr(tcx),
librustc/middle/typeck/check/mod.rs:
644: it.id,
645: ty::item_path_str(ccx.tcx, local_def(it.id)));
646: let _indenter = indenter();
--
928: nimpl = impl_m.fty.sig.inputs.len(),
929: trait = ty::item_path_str(tcx, trait_m.def_id),
930: ntrait = trait_m.fty.sig.inputs.len()));
librustc/middle/typeck/check/method.rs:
1480: idx+1u,
1481: ty::item_path_str(self.tcx(), did)));
1482: }
--
1489: idx+1u,
1490: ty::item_path_str(self.tcx(), did)));
1491: }
--
1505: fn did_to_str(&self, did: DefId) -> ~str {
1506: ty::item_path_str(self.tcx(), did)
1507: }
librustc/middle/typeck/coherence.rs:
414: format!("conflicting implementations for trait `{}`",
415: ty::item_path_str(self.crate_context.tcx,
416: trait_def_id)));
librustc/middle/privacy.rs:
604: let struct_desc = match ty::get(struct_type).sty {
605: ty::ty_struct(_, _) => format!("struct `{}`", ty::item_path_str(self.tcx, id)),
606: ty::ty_bare_fn(ty::BareFnTy { sig: ty::FnSig { output, .. }, .. }) => {
--
617: ty::with_path(self.tcx, id, |mut p| p.last().unwrap()),
618: ty::item_path_str(self.tcx, enum_id))
619: }
librustc/util/ppaux.rs:
897: fn user_string(&self, tcx: &ctxt) -> ~str {
898: let base = ty::item_path_str(tcx, self.def_id);
899: if tcx.sess.verbose() && self.substs.self_ty.is_some() {
librustc/middle/trans/inline.rs:
28: debug!("maybe_instantiate_inline({}): already inline as node id {}",
29: ty::item_path_str(ccx.tcx(), fn_id), node_id);
30: return local_def(node_id);
librustc/middle/trans/monomorphize.rs:
80: debug!("leaving monomorphic fn {}",
81: ty::item_path_str(ccx.tcx(), fn_id));
82: return (val, false);
librustc/middle/trans/type_of.rs:
308: };
309: let tstr = ppaux::parameterized(cx.tcx(), ty::item_path_str(cx.tcx(), did),
310: &ty::NonerasedRegions(OwnedSlice::empty()),
librustc/middle/trans/meth.rs:
155: method_id,
156: ty::item_path_str(bcx.tcx(), trait_id),
157: expr_id);
librustc/middle/trans/adt.rs:
182: discriminants",
183: ty::item_path_str(cx.tcx(), def_id)))
184: }
librustc/middle/trans/monomorphize.rs:
312: debug!("leaving monomorphic fn {}", ty::item_path_str(ccx.tcx(), fn_id));
313: (lldecl, false)
librustc/middle/ty.rs:202:19-202:19 -enum- definition:
pub enum AutoAdjustment {
AutoAddEnv(ty::TraitStore),
AutoDerefRef(AutoDerefRef),
references:- 16203: pub enum AutoAdjustment {
--
2837: unadjusted_ty: ty::t,
2838: adjustment: Option<&AutoAdjustment>,
2839: method_type: |typeck::MethodCall| -> Option<ty::t>)
--
4757: fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>> {
4758: &self.adjustments
librustc/middle/typeck/check/mod.rs:
164: node_type_substs: RefCell<NodeMap<ty::substs>>,
165: adjustments: RefCell<NodeMap<ty::AutoAdjustment>>,
166: method_map: MethodMap,
--
1147: node_id: ast::NodeId,
1148: adj: ty::AutoAdjustment) {
1149: debug!("write_adjustment(node_id={:?}, adj={:?})", node_id, adj);
librustc/middle/typeck/check/regionck.rs:
278: fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>> {
279: &self.fcx.inh.adjustments
librustc/middle/typeck/infer/mod.rs:
74: pub type fres<T> = Result<T, fixup_err>; // "fixup result"
75: pub type CoerceResult = cres<Option<ty::AutoAdjustment>>;
librustc/middle/borrowck/mod.rs:
380: expr: &ast::Expr,
381: adj: &ty::AutoAdjustment)
382: -> mc::cmt {
librustc/middle/mem_categorization.rs:
274: fn node_method_ty(&self, method_call: typeck::MethodCall) -> Option<ty::t>;
275: fn adjustments<'a>(&'a self) -> &'a RefCell<NodeMap<ty::AutoAdjustment>>;
276: fn is_method_call(&self, id: ast::NodeId) -> bool;
librustc/middle/astencode.rs:
1352: c::tag_table_adjustments => {
1353: let adj: ty::AutoAdjustment = val_dsr.read_auto_adjustment(xcx);
1354: dcx.tcx.adjustments.borrow_mut().insert(id, adj);
librustc/middle/ty.rs:
203: pub enum AutoAdjustment {
librustc/middle/ty.rs:129:66-129:66 -enum- definition:
pub enum TraitStore {
/// Box<Trait>
UniqTraitStore,
references:- 49librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/astencode.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/closure.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/trans/closure.rs:
librustc/middle/ty.rs:2563:1-2563:1 -fn- definition:
pub fn type_is_numeric(ty: t) -> bool {
return type_is_integral(ty) || type_is_fp(ty);
}
references:- 2librustc/middle/typeck/check/_match.rs:
451: // no-op
452: } else if !ty::type_is_numeric(b_ty) && !ty::type_is_char(b_ty) {
453: tcx.sess.span_err(pat.span, "non-numeric type used in range");
librustc/middle/check_const.rs:
103: let ety = ty::expr_ty(v.tcx, e);
104: if !ty::type_is_numeric(ety) && !ty::type_is_unsafe_ptr(ety) {
105: v.tcx.sess.span_err(e.span, "can not cast to `".to_owned() +
librustc/middle/ty.rs:1653:1-1653:1 -fn- definition:
pub fn simd_type(cx: &ctxt, ty: t) -> t {
match get(ty).sty {
ty_struct(did, ref substs) => {
references:- 64089: if type_is_simd(cx, ty) {
4090: return tycat(cx, simd_type(cx, ty))
4091: }
librustc/middle/typeck/check/mod.rs:
2122: if ty::type_is_simd(tcx, lhs_t) {
2123: if ty::type_is_fp(ty::simd_type(tcx, lhs_t)) {
2124: fcx.type_error_message(expr.span,
librustc/middle/trans/type_of.rs:
145: if ty::type_is_simd(cx.tcx(), t) {
146: let et = ty::simd_type(cx.tcx(), t);
147: let n = ty::simd_size(cx.tcx(), t);
--
254: if ty::type_is_simd(cx.tcx(), t) {
255: let et = ty::simd_type(cx.tcx(), t);
256: let n = ty::simd_size(cx.tcx(), t);
librustc/middle/trans/debuginfo.rs:
2239: if ty::type_is_simd(cx.tcx(), t) {
2240: let element_type = ty::simd_type(cx.tcx(), t);
2241: let len = ty::simd_size(cx.tcx(), t);
librustc/middle/trans/expr.rs:
1266: if ty::type_is_bot(lhs_t) { rhs_t }
1267: else if is_simd { ty::simd_type(tcx, lhs_t) }
1268: else { lhs_t }
librustc/middle/ty.rs:1284:10-1284:10 -fn- definition:
pub fn mk_i16() -> t { mk_prim_t(&primitives::TY_I16) }
pub fn mk_i32() -> t { mk_prim_t(&primitives::TY_I32) }
pub fn mk_i64() -> t { mk_prim_t(&primitives::TY_I64) }
references:- 4librustc/middle/typeck/check/mod.rs:
4351: "i16_add_with_overflow" | "i16_sub_with_overflow" | "i16_mul_with_overflow" =>
4352: (0, vec!(ty::mk_i16(), ty::mk_i16()),
4353: ty::mk_tup(tcx, vec!(ty::mk_i16(), ty::mk_bool()))),
librustc/middle/ty.rs:
1320: ast::TyI8 => mk_i8(),
1321: ast::TyI16 => mk_i16(),
1322: ast::TyI32 => mk_i32(),
librustc/middle/ty.rs:79:19-79:19 -struct- definition:
pub struct Method {
pub ident: ast::Ident,
pub generics: ty::Generics,
references:- 35librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/metadata/csearch.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/reflect.rs:
librustc/metadata/decoder.rs:
librustc/middle/ty.rs:3593:1-3593:1 -fn- definition:
pub fn trait_ref_to_def_id(tcx: &ctxt, tr: &ast::TraitRef) -> ast::DefId {
let def = *tcx.def_map.borrow()
.find(&tr.ref_id)
references:- 2librustc/middle/privacy.rs:
1267: |tr| {
1268: let did = ty::trait_ref_to_def_id(self.tcx, tr);
librustc/middle/typeck/collect.rs:
420: for ast_trait_ref in ast_trait_refs.iter() {
421: let trait_def_id = ty::trait_ref_to_def_id(ccx.tcx, ast_trait_ref);
422: // FIXME(#8559): Need to instantiate the trait_ref whether or not it's a
librustc/middle/ty.rs:401:1-401:1 -fn- definition:
pub fn tbox_has_flag(tb: t_box, flag: tbox_flag) -> bool {
(tb.flags & (flag as uint)) != 0u
}
references:- 5407: }
408: pub fn type_has_self(t: t) -> bool { tbox_has_flag(get(t), has_self) }
409: pub fn type_needs_infer(t: t) -> bool {
--
1532: let tb = ty::get(t);
1533: if self.self_ty_opt.is_none() && !tbox_has_flag(tb, has_params) {
1534: return t;
--
1591: pub fn type_needs_subst(ty: t) -> bool {
1592: tbox_has_flag(get(ty), needs_subst)
1593: }
librustc/middle/ty.rs:1136:76-1136:76 -fn- definition:
// and returns the box as cast to an unsafe ptr (see comments for t above).
pub fn mk_t(cx: &ctxt, st: sty) -> t {
// Check for primitive types.
references:- 171371: pub fn mk_rptr(cx: &ctxt, r: Region, tm: mt) -> t { mk_t(cx, ty_rptr(r, tm)) }
--
1392: pub fn mk_vec(cx: &ctxt, tm: mt, sz: Option<uint>) -> t {
1393: mk_t(cx, ty_vec(tm, sz))
1394: }
--
1450: // take a copy of substs so that we own the vectors inside
1451: mk_t(cx, ty_struct(struct_id, substs))
1452: }
--
1464: pub fn mk_param(cx: &ctxt, n: uint, k: DefId) -> t {
1465: mk_t(cx, ty_param(param_ty { idx: n, def_id: k }))
1466: }
librustc/middle/ty_fold.rs:
93: let sty = this.fold_sty(&ty::get(t).sty);
94: ty::mk_t(this.tcx(), sty)
95: }
librustc/middle/ty.rs:
1462: pub fn mk_self(cx: &ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }
librustc/middle/ty.rs:3756:1-3756:1 -fn- definition:
pub fn with_path<T>(cx: &ctxt, id: ast::DefId, f: |ast_map::PathElems| -> T) -> T {
if id.krate == ast::LOCAL_CRATE {
cx.map.with_path(id.node, f)
references:- 53711: pub fn item_path_str(cx: &ctxt, id: ast::DefId) -> ~str {
3712: with_path(cx, id, |path| ast_map::path_to_str(path)).to_owned()
3713: }
librustc/middle/privacy.rs:
616: format!("variant `{}` of enum `{}`",
617: ty::with_path(self.tcx, id, |mut p| p.last().unwrap()),
618: ty::item_path_str(self.tcx, enum_id))
librustc/middle/trans/closure.rs:
412: let name = ty::with_path(tcx, def_id, |path| {
413: mangle_internal_name_by_path_and_seq(path, "as_closure")
librustc/middle/trans/debuginfo.rs:
2117: // the trait's methods.
2118: let last = ty::with_path(cx.tcx(), def_id, |mut path| path.last().unwrap());
2119: let ident_string = token::get_name(last.name());
--
2862: fn namespace_for_item(cx: &CrateContext, def_id: ast::DefId) -> Rc<NamespaceTreeNode> {
2863: ty::with_path(cx.tcx(), def_id, |path| {
2864: // prepend crate name if not already present
librustc/middle/ty.rs:721:38-721:38 -enum- definition:
pub enum sty {
ty_nil,
ty_bot,
references:- 27720: // AST structure in libsyntax/ast.rs as well.
722: pub enum sty {
--
1136: // and returns the box as cast to an unsafe ptr (see comments for t above).
1137: pub fn mk_t(cx: &ctxt, st: sty) -> t {
1138: // Check for primitive types.
--
1244: let sty_ptr = &t.sty as *sty;
librustc/middle/ty_fold.rs:
138: pub fn super_fold_sty<T:TypeFolder>(this: &mut T,
139: sty: &ty::sty) -> ty::sty {
140: match *sty {
librustc/middle/typeck/check/mod.rs:
2244: expected: Option<ty::t>,
2245: unpack: |&ty::sty| -> Option<O>)
2246: -> Option<O> {
--
3991: pub fn structure_of<'a>(fcx: &FnCtxt, sp: Span, typ: ty::t)
3992: -> &'a ty::sty {
3993: &ty::get(structurally_resolved_type(fcx, sp, typ)).sty
librustc/middle/typeck/infer/coercion.rs:
288: a: ty::t,
289: sty_a: &ty::sty,
290: b: ty::t,
--
324: a: ty::t,
325: sty_a: &ty::sty,
326: b: ty::t,
--
360: a: ty::t,
361: sty_a: &ty::sty,
362: b: ty::t)
--
442: a: ty::t,
443: sty_a: &ty::sty,
444: b: ty::t,
librustc/metadata/tyencode.rs:
196: fn enc_sty(w: &mut MemWriter, cx: &ctxt, st: &ty::sty) {
197: match *st {
librustc/middle/ty.rs:
1254: unsafe {
1255: cast::transmute::<*sty, t>(sty_ptr)
1256: }
librustc/middle/ty.rs:3257:1-3257:1 -fn- definition:
pub fn ty_sort_str(cx: &ctxt, t: t) -> ~str {
match get(t).sty {
ty_nil | ty_bot | ty_bool | ty_char | ty_int(_) |
references:- 43376: format!("expected {} but found {}",
3377: ty_sort_str(cx, values.expected),
3378: ty_sort_str(cx, values.found))
3379: }
librustc/middle/typeck/check/vtable.rs:
618: to an &-object, not a {}",
619: ty::ty_sort_str(fcx.tcx(), ty)));
620: }
librustc/middle/ty.rs:187:45-187:45 -struct- definition:
pub struct ItemVariances {
pub self_param: Option<Variance>,
pub type_params: OwnedSlice<Variance>,
references:- 24188: pub struct ItemVariances {
librustc/middle/typeck/variance.rs:
289: // no type/region parameters
290: empty_variances: Rc::new(ty::ItemVariances {
291: self_param: None,
--
989: let item_variances = ty::ItemVariances {
990: self_param: self_param,
librustc/middle/ty.rs:
188: pub struct ItemVariances {
--
4311: pub fn item_variances(tcx: &ctxt, item_id: ast::DefId) -> Rc<ItemVariances> {
4312: lookup_locally_or_in_crate_store(
librustc/middle/typeck/variance.rs:
258: empty_variances: Rc<ty::ItemVariances>,
librustc/metadata/decoder.rs:
827: pub fn get_item_variances(cdata: Cmd, id: ast::NodeId) -> ty::ItemVariances {
828: let data = cdata.data();
librustc/metadata/csearch.rs:
142: pub fn get_item_variances(cstore: &cstore::CStore,
143: def: ast::DefId) -> ty::ItemVariances {
144: let cdata = cstore.get_crate_data(def.krate);
librustc/util/ppaux.rs:
723: impl Repr for ty::ItemVariances {
724: fn repr(&self, tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:
188: pub struct ItemVariances {
librustc/middle/ty.rs:665:38-665:38 -struct- definition:
pub struct substs {
pub self_ty: Option<ty::t>,
pub tps: Vec<t>,
references:- 140librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/kind.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/base.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/vtable.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/typeck/coherence.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/astencode.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/monomorphize.rs:
librustc/middle/trans/glue.rs:
librustc/middle/trans/callee.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/trans/adt.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:212:41-212:41 -struct- definition:
pub struct AutoDerefRef {
pub autoderefs: uint,
pub autoref: Option<AutoRef>
references:- 33librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/astencode.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/lint.rs:
librustc/middle/borrowck/mod.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/astencode.rs:
librustc/middle/expr_use_visitor.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/ty.rs:4664:8-4664:8 -fn- definition:
fn push_region_params(mut accum: Vec<ty::Region>,
free_id: ast::NodeId,
region_params: &[RegionParameterDef])
references:- 24677: let t = push_region_params(vec!(), free_id, item_region_params);
4678: push_region_params(t, free_id, method_region_params)
4679: };
librustc/middle/ty.rs:3552:1-3552:1 -fn- definition:
pub fn trait_method_def_ids(cx: &ctxt, id: ast::DefId) -> Rc<Vec<DefId>> {
lookup_locally_or_in_crate_store("trait_method_def_ids",
id,
references:- 53535: None => {
3536: let def_ids = ty::trait_method_def_ids(cx, trait_did);
3537: let methods: Rc<Vec<Rc<Method>>> = Rc::new(def_ids.iter().map(|d| {
librustc/metadata/encoder.rs:
1131: // Now output the method info for each method.
1132: let r = ty::trait_method_def_ids(tcx, def_id);
1133: for (i, &method_def_id) in r.iter().enumerate() {
librustc/middle/trans/meth.rs:
502: let trait_method_def_ids = ty::trait_method_def_ids(tcx, trt_id);
503: trait_method_def_ids.iter().map(|method_def_id| {
librustc/middle/ty.rs:1692:1-1692:1 -fn- definition:
pub fn type_is_unsafe_ptr(ty: t) -> bool {
match get(ty).sty {
ty_ptr(_) => return true,
references:- 2librustc/middle/check_const.rs:
103: let ety = ty::expr_ty(v.tcx, e);
104: if !ty::type_is_numeric(ety) && !ty::type_is_unsafe_ptr(ety) {
105: v.tcx.sess.span_err(e.span, "can not cast to `".to_owned() +
librustc/middle/typeck/check/mod.rs:
4022: let typ_s = structurally_resolved_type(fcx, sp, typ);
4023: return ty::type_is_unsafe_ptr(typ_s);
4024: }
librustc/middle/ty.rs:1571:1-1571:1 -fn- definition:
pub fn subst(cx: &ctxt,
substs: &substs,
typ: t)
references:- 153963: };
3964: subst(tcx, substs, t)
3965: }
librustc/middle/typeck/check/mod.rs:
1128: substs: ty::substs) {
1129: let ty = ty::subst(self.tcx(), &substs, ty);
1130: self.write_ty(node_id, ty);
--
2528: let mut struct_type = ty::subst(tcx, &substitutions, raw_type);
--
2584: let enum_type = ty::subst(tcx, &substitutions, raw_type);
librustc/middle/typeck/check/_match.rs:
153: {
154: ty::subst(tcx, expected_substs, *t)
155: }
librustc/middle/typeck/astconv.rs:
259: let substs = ast_path_substs(this, rscope, &generics, None, path);
260: let ty = ty::subst(tcx, &substs, decl_ty);
261: ty_param_substs_and_ty { substs: substs, ty: ty }
librustc/middle/typeck/collect.rs:
327: // create the type of `foo`, applying the substitution above
328: let ty = ty::subst(tcx,
329: &substs,
librustc/util/ppaux.rs:
441: match def.default {
442: Some(default) => ty::subst(cx, &substs, default) == actual,
443: None => false
librustc/middle/trans/adt.rs:
290: let arg_tys = vi.args.iter().map(|&raw_ty| {
291: ty::subst(tcx, substs, raw_ty)
292: }).collect();
librustc/middle/typeck/coherence.rs:
490: };
491: let monotype = subst(self.crate_context.tcx,
492: &substitutions,
librustc/middle/ty.rs:1457:1-1457:1 -fn- definition:
pub fn mk_float_var(cx: &ctxt, v: FloatVid) -> t { mk_infer(cx, FloatVar(v)) }
pub fn mk_infer(cx: &ctxt, it: InferTy) -> t { mk_t(cx, ty_infer(it)) }
pub fn mk_self(cx: &ctxt, did: ast::DefId) -> t { mk_t(cx, ty_self(did)) }
references:- 3librustc/middle/typeck/infer/resolve.rs:
275: } else {
276: ty::mk_float_var(self.infcx.tcx, vid)
277: }
librustc/middle/typeck/check/mod.rs:
1419: // type, so we create a floating point type variable for it.
1420: ty::mk_float_var(tcx, fcx.infcx().next_float_var_id())
1421: }
librustc/middle/ty.rs:1395:1-1395:1 -fn- definition:
pub fn mk_slice(cx: &ctxt, r: Region, tm: mt) -> t {
mk_rptr(cx, r,
mt {
references:- 92946: ty_rptr(_, mt{ty: t, ..}) => match get(t).sty {
2947: ty::ty_vec(mt, None) => ty::mk_slice(cx, r, ty::mt {ty: mt.ty, mutbl: m}),
2948: ty::ty_str => ty::mk_str_slice(cx, r, m),
--
2954: },
2955: ty_vec(mt, Some(_)) => ty::mk_slice(cx, r, ty::mt {ty: mt.ty, mutbl: m}),
librustc/middle/typeck/check/mod.rs:
1405: ast::LitBinary(..) => {
1406: ty::mk_slice(tcx, ty::ReStatic, ty::mt{ ty: ty::mk_u8(), mutbl: ast::MutImmutable })
1407: }
librustc/middle/typeck/check/method.rs:
836: AutoBorrowVec, autoderefs, [MutImmutable, MutMutable],
837: |m,r| ty::mk_slice(tcx, r,
838: ty::mt {ty:mt.ty, mutbl:m}));
--
847: |m,r| {
848: let slice_ty = ty::mk_slice(tcx, r,
849: ty::mt {ty:mt.ty, mutbl:m});
librustc/middle/typeck/infer/coercion.rs:
314: let a_borrowed = ty::mk_slice(self.get_ref().infcx.tcx, r_borrow,
315: mt {ty: ty_inner, mutbl: mutbl_b});
librustc/middle/trans/expr.rs:
240: // real one, but it will have the same runtime representation
241: let slice_ty = ty::mk_slice(tcx, ty::ReStatic,
242: ty::mt { ty: unit_ty, mutbl: ast::MutImmutable });
librustc/middle/trans/_match.rs:
1032: let slice_len = Sub(bcx, len, slice_len_offset);
1033: let slice_ty = ty::mk_slice(bcx.tcx(),
1034: ty::ReStatic,
librustc/middle/typeck/check/_match.rs:
678: Some(slice_pat) => {
679: let slice_ty = ty::mk_slice(tcx,
680: region_var,
librustc/middle/ty.rs:2304:1-2304:1 -fn- definition:
pub fn type_moves_by_default(cx: &ctxt, ty: t) -> bool {
type_contents(cx, ty).moves_by_default(cx)
}
references:- 8librustc/middle/check_match.rs:
976: let pat_ty = ty::node_id_to_type(tcx, p.id);
977: if ty::type_moves_by_default(tcx, pat_ty) {
978: check_move(p, sub);
librustc/middle/borrowck/mod.rs:
541: e.g. `|x| f(x)`, to override)",
542: _ if ty::type_moves_by_default(tcx, ty) =>
543: "non-copyable (perhaps you meant to use clone()?)",
librustc/middle/kind.rs:
432: ty::type_contents(cx.tcx, ty).to_str());
433: if ty::type_moves_by_default(cx.tcx, ty) {
434: cx.tcx.sess.span_err(
librustc/middle/expr_use_visitor.rs:
856: fn copy_or_move(tcx: &ty::ctxt, ty: ty::t) -> ConsumeMode {
857: if ty::type_moves_by_default(tcx, ty) { Move } else { Copy }
858: }
librustc/middle/trans/datum.rs:
620: assert!(!ty::type_moves_by_default(bcx.tcx(), self.ty));
621: let mut bcx = bcx;
librustc/middle/trans/tvec.rs:
387: let elem = unpack_datum!(bcx, expr::trans(bcx, element));
388: assert!(!ty::type_moves_by_default(bcx.tcx(), elem.ty));
librustc/middle/liveness.rs:
486: freevars::CaptureByValue => {
487: ty::type_moves_by_default(ir.tcx, fv_ty)
488: }
librustc/middle/ty.rs:442:38-442:38 -struct- definition:
pub struct FnSig {
pub binder_id: ast::NodeId,
pub inputs: Vec<t>,
references:- 75librustc/middle/ty_fold.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/collect.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/regionmanip.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/glb.rs:
librustc/middle/typeck/infer/lub.rs:
librustc/middle/typeck/infer/sub.rs:
librustc/middle/typeck/infer/to_str.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/privacy.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/util/ppaux.rs:
librustc/middle/trans/foreign.rs:
librustc/middle/trans/reflect.rs:
librustc/middle/trans/debuginfo.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/ty.rs:599:23-599:23 -struct- definition:
pub struct UpvarBorrow {
pub kind: BorrowKind,
pub region: ty::Region,
references:- 21598: */
600: pub struct UpvarBorrow {
librustc/middle/typeck/check/writeback.rs:
180: let r = r.resolve(self.fcx, ResolvingUpvar(*upvar_id));
181: let new_upvar_borrow = ty::UpvarBorrow { kind: upvar_borrow.kind,
182: region: r };
librustc/middle/typeck/check/regionck.rs:
682: // immutable as dictated by the uses.
683: let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow,
684: region: freevar_region };
librustc/middle/ty.rs:
598: */
600: pub struct UpvarBorrow {
--
4769: fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow {
4770: self.upvar_borrow_map.borrow().get_copy(&upvar_id)
librustc/middle/typeck/check/regionck.rs:
1452: fn adjust_upvar_borrow_kind(upvar_id: ty::UpvarId,
1453: upvar_borrow: &mut ty::UpvarBorrow,
1454: kind: ty::BorrowKind) {
librustc/middle/mem_categorization.rs:
277: fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<ast::NodeId>;
278: fn upvar_borrow(&self, upvar_id: ty::UpvarId) -> ty::UpvarBorrow;
279: }
librustc/util/ppaux.rs:
956: impl Repr for ty::UpvarBorrow {
957: fn repr(&self, tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:
598: */
600: pub struct UpvarBorrow {
librustc/middle/ty.rs:2199:4-2199:4 -fn- definition:
fn apply_lang_items(cx: &ctxt,
did: ast::DefId,
tc: TypeContents)
references:- 22146: });
2147: apply_lang_items(cx, did, res)
2148: }
librustc/middle/ty.rs:3844:65-3844:65 -fn- definition:
// Returns information about the enum variant with the given ID:
pub fn enum_variant_with_id(cx: &ctxt,
enum_id: ast::DefId,
references:- 83083: ast::DefVariant(tid, vid, _) => {
3084: let variant_info = enum_variant_with_id(tcx, tid, vid);
3085: if variant_info.args.len() > 0u {
librustc/middle/typeck/check/_match.rs:
147: let vinfo =
148: ty::enum_variant_with_id(tcx, enm, var);
149: let var_tpt = ty::lookup_item_type(tcx, var);
librustc/middle/trans/expr.rs:
930: ast::DefVariant(enum_id, variant_id, _) => {
931: let variant_info = ty::enum_variant_with_id(
932: tcx, enum_id, variant_id);
librustc/middle/trans/consts.rs:
633: let repr = adt::represent_type(cx, ety);
634: let vinfo = ty::enum_variant_with_id(cx.tcx(),
635: enum_did,
--
661: let repr = adt::represent_type(cx, ety);
662: let vinfo = ty::enum_variant_with_id(cx.tcx(),
663: enum_did,
librustc/middle/trans/_match.rs:
2199: let repr = adt::represent_node(bcx, pat.id);
2200: let vinfo = ty::enum_variant_with_id(ccx.tcx(),
2201: enum_id,
librustc/middle/trans/callee.rs:
130: // nullary variants are not callable
131: assert!(ty::enum_variant_with_id(bcx.tcx(),
132: tid,
librustc/middle/ty.rs:3714:1-3714:1 -enum- definition:
pub enum DtorKind {
NoDtor,
TraitDtor(DefId, bool)
references:- 23720: impl DtorKind {
3721: pub fn is_not_present(&self) -> bool {
--
3741: Otherwise return none. */
3742: pub fn ty_dtor(cx: &ctxt, struct_id: DefId) -> DtorKind {
3743: match cx.destructor_for_type.borrow().find(&struct_id) {
librustc/middle/ty.rs:4182:63-4182:63 -fn- definition:
// Returns the repeat count for a repeating vector expression.
pub fn eval_repeat_count<T: ExprTyProvider>(tcx: &T, count_expr: &ast::Expr) -> uint {
match const_eval::eval_const_expr_partial(tcx, count_expr) {
references:- 5librustc/middle/typeck/check/mod.rs:
2636: check_expr_with_hint(fcx, count_expr, ty::mk_uint());
2637: let _ = ty::eval_repeat_count(fcx, count_expr);
2638: let mutability = match vst {
--
3173: check_expr_with_hint(fcx, count_expr, ty::mk_uint());
3174: let count = ty::eval_repeat_count(fcx, count_expr);
3175: let t: ty::t = fcx.infcx().next_ty_var();
librustc/middle/kind.rs:
301: ExprRepeat(element, count_expr) => {
302: let count = ty::eval_repeat_count(cx.tcx, count_expr);
303: if count > 1 {
librustc/middle/trans/tvec.rs:
376: SaveIn(lldest) => {
377: let count = ty::eval_repeat_count(bcx.tcx(), count_expr);
378: if count == 0 {
--
440: ast::ExprRepeat(_, count_expr) => {
441: ty::eval_repeat_count(bcx.tcx(), count_expr)
442: }
librustc/middle/ty.rs:773:25-773:25 -enum- definition:
pub enum terr_vstore_kind {
terr_vec,
terr_str,
references:- 5774: pub enum terr_vstore_kind {
--
810: terr_regions_overly_polymorphic(BoundRegion, Region),
811: terr_trait_stores_differ(terr_vstore_kind, expected_found<TraitStore>),
812: terr_sorts(expected_found<t>),
librustc/middle/typeck/infer/combine.rs:
258: fn trait_stores(&self,
259: vk: ty::terr_vstore_kind,
260: a: ty::TraitStore,
librustc/middle/ty.rs:504:44-504:44 -enum- definition:
pub enum BorrowKind {
/// Data must be immutable and is aliasable.
ImmBorrow,
references:- 27505: pub enum BorrowKind {
--
600: pub struct UpvarBorrow {
601: pub kind: BorrowKind,
602: pub region: ty::Region,
--
4727: impl BorrowKind {
4728: pub fn from_mutbl(m: ast::Mutability) -> BorrowKind {
4729: match m {
librustc/middle/typeck/check/regionck.rs:
1192: region_min: ty::Region,
1193: kind: ty::BorrowKind,
1194: cmt_borrowed: mc::cmt) {
--
1453: upvar_borrow: &mut ty::UpvarBorrow,
1454: kind: ty::BorrowKind) {
1455: /*!
librustc/middle/borrowck/mod.rs:
189: cmt: mc::cmt,
190: kind: ty::BorrowKind,
191: restrictions: Vec<Restriction>,
librustc/middle/borrowck/gather_loans/mod.rs:
392: fn restriction_set(&self, req_kind: ty::BorrowKind) -> RestrictionSet {
393: match req_kind {
librustc/middle/borrowck/gather_loans/lifetime.rs:
57: loan_region: ty::Region,
58: loan_kind: ty::BorrowKind,
59: cmt_original: mc::cmt
librustc/middle/mem_categorization.rs:
289: pub fn from_borrow_kind(borrow_kind: ty::BorrowKind) -> MutabilityCategory {
290: match borrow_kind {
librustc/middle/expr_use_visitor.rs:
209: r: ty::Region,
210: bk: ty::BorrowKind,
211: cause: LoanCause) {
librustc/util/ppaux.rs:
950: impl Repr for ty::BorrowKind {
951: fn repr(&self, _tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:
505: pub enum BorrowKind {
librustc/middle/ty.rs:830:14-830:14 -enum- definition:
pub enum BuiltinBound {
BoundStatic,
BoundSend,
references:- 19827: pub type BuiltinBounds = EnumSet<BuiltinBound>;
--
852: impl CLike for BuiltinBound {
853: fn to_uint(&self) -> uint {
--
855: }
856: fn from_uint(v: uint) -> BuiltinBound {
857: unsafe { cast::transmute(v) }
--
1888: impl TypeContents {
1889: pub fn meets_bound(&self, cx: &ctxt, bb: BuiltinBound) -> bool {
1890: match bb {
--
2288: traits: &[Rc<TraitRef>],
2289: f: |BuiltinBound|) {
2290: for bound in bounds.iter() {
librustc/middle/lang_items.rs:
84: pub fn to_builtin_kind(&self, id: ast::DefId) -> Option<ty::BuiltinBound> {
85: if Some(id) == self.send_trait() {
librustc/util/ppaux.rs:
847: impl Repr for ty::BuiltinBound {
848: fn repr(&self, _tcx: &ctxt) -> ~str {
--
853: impl UserString for ty::BuiltinBound {
854: fn user_string(&self, _tcx: &ctxt) -> ~str {
librustc/middle/ty.rs:617:81-617:81 -struct- definition:
pub struct FreeRegion {
pub scope_id: NodeId,
pub bound_region: BoundRegion
references:- 64librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/astencode.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/infer/region_inference/mod.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/region.rs:
librustc/middle/ty.rs:218:51-218:51 -enum- definition:
pub enum AutoRef {
/// Convert from T to &T
AutoPtr(Region, ast::Mutability),
references:- 23214: pub autoderefs: uint,
215: pub autoref: Option<AutoRef>
216: }
219: pub enum AutoRef {
--
2982: impl AutoRef {
2983: pub fn map_region(&self, f: |Region| -> Region) -> AutoRef {
2984: match *self {
librustc/middle/ty_fold.rs:
75: fn fold_autoref(&mut self, ar: &ty::AutoRef) -> ty::AutoRef {
76: super_fold_autoref(self, ar)
--
208: autoref: &ty::AutoRef)
209: -> ty::AutoRef
210: {
librustc/middle/typeck/check/writeback.rs:
377: impl Resolve for ty::AutoRef {
378: fn resolve(&self, fcx: &FnCtxt, reason: ResolveReason) -> ty::AutoRef {
379: Resolver::new(fcx, reason).fold_autoref(self)
librustc/middle/typeck/check/method.rs:
963: &self,
964: kind: |Region, ast::Mutability| -> ty::AutoRef,
965: autoderefs: uint,
librustc/middle/astencode.rs:
468: impl tr for ty::AutoRef {
469: fn tr(&self, xcx: &ExtendedDecodeContext) -> ty::AutoRef {
470: self.map_region(|r| r.tr(xcx))
librustc/middle/expr_use_visitor.rs:
615: expr: &ast::Expr,
616: autoref: &ty::AutoRef,
617: autoderefs: uint) {
librustc/middle/typeck/check/regionck.rs:
1117: autoderefs: uint,
1118: autoref: &ty::AutoRef) {
1119: /*!
librustc/middle/ty.rs:371:1-371:1 -struct- definition:
pub struct t_box_ {
pub sty: sty,
pub id: uint,
references:- 41librustc/middle/ty.rs:1720:1-1720:1 -fn- definition:
pub fn type_needs_drop(cx: &ctxt, ty: t) -> bool {
type_contents(cx, ty).needs_drop(cx)
}
references:- 17librustc/middle/trans/controlflow.rs:
77: let ty = expr_ty(cx, e);
78: if ty::type_needs_drop(cx.tcx(), ty) {
79: expr::trans_to_lvalue(cx, e, "stmt").bcx
librustc/middle/trans/glue.rs:
77: let tcx = ccx.tcx();
78: if !ty::type_needs_drop(tcx, t) {
79: return ty::mk_i8();
--
109: let ccx = bcx.ccx();
110: if ty::type_needs_drop(bcx.tcx(), t) {
111: let glue = get_drop_glue(ccx, t);
--
346: _ => {
347: if ty::type_needs_drop(bcx.tcx(), t) &&
348: ty::type_is_structural(t) {
librustc/middle/trans/datum.rs:
245: if ty::type_needs_drop(bcx.tcx(), ty) {
246: if ty::type_moves_by_default(bcx.tcx(), ty) {
--
650: assert!(!ty::type_needs_drop(bcx.tcx(), self.ty));
651: assert!(self.appropriate_rvalue_mode(bcx.ccx()) == ByValue);
librustc/middle/trans/expr.rs:
1740: _ => {
1741: assert!(!ty::type_needs_drop(bcx.tcx(), datum.ty));
librustc/middle/trans/tvec.rs:
60: let tcx = bcx.tcx();
61: if ty::type_needs_drop(tcx, unit_ty) {
62: let fill = get_fill(bcx, vptr);
librustc/middle/trans/intrinsic.rs:
447: let tp_ty = *substs.tys.get(0);
448: Ret(bcx, C_bool(ccx, ty::type_needs_drop(ccx.tcx(), tp_ty)));
449: }
librustc/middle/trans/cleanup.rs:
239: if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
240: let drop = box DropValue {
--
263: if !ty::type_needs_drop(self.ccx.tcx(), ty) { return; }
264: let drop = box DropValue {
librustc/middle/trans/meth.rs:
362: let llval = if ty::type_needs_drop(bcx.tcx(), self_datum.ty) {
363: let self_datum = unpack_datum!(
librustc/middle/ty.rs:781:25-781:25 -struct- definition:
pub struct expected_found<T> {
pub expected: T,
pub found: T
references:- 37librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/ty.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/unify.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/ty.rs:
librustc/middle/ty.rs:1351:1-1351:1 -fn- definition:
pub fn mk_str_slice(cx: &ctxt, r: Region, m: ast::Mutability) -> t {
mk_rptr(cx, r,
mt {
references:- 72947: ty::ty_vec(mt, None) => ty::mk_slice(cx, r, ty::mt {ty: mt.ty, mutbl: m}),
2948: ty::ty_str => ty::mk_str_slice(cx, r, m),
2949: _ => {
librustc/middle/typeck/check/method.rs:
865: AutoBorrowVec, autoderefs, [MutImmutable],
866: |_m,r| ty::mk_str_slice(tcx, r, MutImmutable));
--
874: |m,r| {
875: let slice_ty = ty::mk_str_slice(tcx, r, m);
876: ty::mk_rptr(tcx, r, ty::mt {ty:slice_ty, mutbl:m})
librustc/middle/typeck/astconv.rs:
492: RPtr(r) => {
493: return ty::mk_str_slice(tcx, r, ast::MutImmutable);
494: }
librustc/middle/typeck/infer/coercion.rs:
278: let r_a = self.get_ref().infcx.next_region_var(coercion);
279: let a_borrowed = ty::mk_str_slice(self.get_ref().infcx.tcx, r_a, ast::MutImmutable);
280: if_ok!(self.subtype(a_borrowed, b));
librustc/middle/trans/reflect.rs:
57: let bcx = self.bcx;
58: let str_ty = ty::mk_str_slice(bcx.tcx(), ty::ReStatic, ast::MutImmutable);
59: let scratch = rvalue_scratch_datum(bcx, str_ty, "");
librustc/middle/typeck/check/mod.rs:
1403: match lit.node {
1404: ast::LitStr(..) => ty::mk_str_slice(tcx, ty::ReStatic, ast::MutImmutable),
1405: ast::LitBinary(..) => {
librustc/middle/ty.rs:414:38-414:38 -struct- definition:
pub struct BareFnTy {
pub fn_style: ast::FnStyle,
pub abi: abi::Abi,
references:- 49librustc/middle/ty_fold.rs:
librustc/middle/typeck/mod.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/collect.rs:
librustc/metadata/tydecode.rs:
librustc/middle/ty.rs:
librustc/middle/ty_fold.rs:
librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/typeck/infer/coercion.rs:
librustc/middle/typeck/variance.rs:
librustc/middle/privacy.rs:
librustc/metadata/tyencode.rs:
librustc/metadata/tydecode.rs:
librustc/metadata/encoder.rs:
librustc/metadata/decoder.rs:
librustc/util/ppaux.rs:
librustc/middle/typeck/infer/combine.rs:
librustc/middle/ty.rs:1269:10-1269:10 -fn- definition:
pub fn mk_err() -> t { mk_prim_t(&primitives::TY_ERR) }
pub fn mk_bot() -> t { mk_prim_t(&primitives::TY_BOT) }
pub fn mk_bool() -> t { mk_prim_t(&primitives::TY_BOOL) }
references:- 46librustc/middle/subst.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/writeback.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/check/method.rs:
librustc/middle/typeck/astconv.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/collect.rs:
librustc/middle/mem_categorization.rs:
librustc/middle/typeck/check/mod.rs:
librustc/middle/ty.rs:604:1-604:1 -NK_AS_STR_TODO- definition:
pub type UpvarBorrowMap = HashMap<UpvarId, UpvarBorrow>;
impl Region {
pub fn is_bound(&self) -> bool {
references:- 2343: // Borrows
344: pub upvar_borrow_map: RefCell<UpvarBorrowMap>,
librustc/middle/typeck/check/mod.rs:
167: vtable_map: vtable_map,
168: upvar_borrow_map: RefCell<ty::UpvarBorrowMap>,
169: }
librustc/middle/ty.rs:3625:19-3625:19 -struct- definition:
pub struct VariantInfo {
pub args: Vec<t>,
pub arg_names: Option<Vec<ast::Ident> >,
references:- 223654: return VariantInfo {
3655: args: arg_tys,
--
3703: Rc::new(VariantInfo {
3704: args: substd_args,
librustc/metadata/decoder.rs:
715: disr_val += 1;
716: Rc::new(ty::VariantInfo {
717: args: arg_tys,
librustc/middle/ty.rs:
3776: pub fn enum_variants(cx: &ctxt, id: ast::DefId) -> Rc<Vec<Rc<VariantInfo>>> {
3777: match cx.enum_var_cache.borrow().find(&id) {
--
3847: variant_id: ast::DefId)
3848: -> Rc<VariantInfo> {
3849: enum_variants(cx, enum_id).iter()
librustc/middle/typeck/check/mod.rs:
3656: hint: attr::ReprAttr)
3657: -> Vec<Rc<ty::VariantInfo>> {
--
3659: let rty = ty::node_id_to_type(ccx.tcx, id);
3660: let mut variants: Vec<Rc<ty::VariantInfo>> = Vec::new();
3661: let mut disr_vals: Vec<ty::Disr> = Vec::new();
librustc/metadata/decoder.rs:
695: pub fn get_enum_variants(intr: Rc<IdentInterner>, cdata: Cmd, id: ast::NodeId,
696: tcx: &ty::ctxt) -> Vec<Rc<ty::VariantInfo>> {
697: let data = cdata.data();
librustc/metadata/csearch.rs:
109: pub fn get_enum_variants(tcx: &ty::ctxt, def: ast::DefId)
110: -> Vec<Rc<ty::VariantInfo>> {
111: let cstore = &tcx.sess.cstore;
librustc/middle/trans/base.rs:
671: av: ValueRef,
672: variant: &ty::VariantInfo,
673: tps: &[ty::t],
--
1559: fn trans_enum_def(ccx: &CrateContext, enum_definition: &ast::EnumDef,
1560: id: ast::NodeId, vi: &[Rc<ty::VariantInfo>],
1561: i: &mut uint) {
librustc/middle/trans/debuginfo.rs:
1467: struct_def: &adt::Struct,
1468: variant_info: &ty::VariantInfo,
1469: discriminant_type_metadata: Option<DIType>,
librustc/middle/ty.rs:1586:1-1586:1 -fn- definition:
pub fn type_is_error(ty: t) -> bool {
(get(ty).flags & (has_ty_err as uint)) != 0
}
references:- 45librustc/middle/typeck/check/mod.rs:
librustc/middle/typeck/check/_match.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/typeck/infer/mod.rs:
librustc/middle/typeck/infer/error_reporting.rs:
librustc/middle/typeck/check/regionck.rs:
librustc/middle/ty.rs:1391:1-1391:1 -fn- definition:
pub fn mk_vec(cx: &ctxt, tm: mt, sz: Option<uint>) -> t {
mk_t(cx, ty_vec(tm, sz))
}
references:- 121398: mt {
1399: ty: mk_vec(cx, tm, None),
1400: mutbl: tm.mutbl
librustc/middle/typeck/check/mod.rs:
3167: }
3168: let typ = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: ast::MutImmutable},
3169: Some(args.len()));
--
3184: else {
3185: let t = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: ast::MutImmutable},
3186: Some(count));
librustc/middle/typeck/astconv.rs:
695: const_eval::const_uint(i) =>
696: ty::mk_vec(tcx, ast_ty_to_mt(this, rscope, ty),
697: Some(i as uint)),
librustc/metadata/tydecode.rs:
343: let sz = parse_size(st);
344: return ty::mk_vec(st.tcx, mt, sz);
345: }
librustc/middle/trans/tvec.rs:
164: // Arrange for the backing array to be cleaned up.
165: let fixed_ty = ty::mk_vec(bcx.tcx(),
166: ty::mt {ty: vt.unit_ty,
librustc/middle/typeck/infer/combine.rs:
515: if sz_a == sz_b {
516: Ok(ty::mk_vec(tcx, mt, sz_a))
517: } else {
librustc/middle/ty.rs:882:62-882:62 -enum- definition:
pub enum InferRegion {
ReVar(RegionVid),
ReSkolemized(uint, BoundRegion)
references:- 12888: impl cmp::Eq for InferRegion {
889: fn eq(&self, other: &InferRegion) -> bool {
890: match ((*self), *other) {
--
899: }
900: fn ne(&self, other: &InferRegion) -> bool {
901: !((*self) == (*other))
librustc/middle/ty.rs:147:31-147:31 -struct- definition:
pub struct creader_cache_key {
pub cnum: CrateNum,
pub pos: uint,
references:- 13librustc/metadata/tydecode.rs:
366: assert_eq!(next(st), '#');
367: let key = ty::creader_cache_key {cnum: st.krate,
368: pos: pos,
librustc/middle/ty.rs:
146: // the types of AST nodes.
148: pub struct creader_cache_key {
--
154: pub type creader_cache = RefCell<HashMap<creader_cache_key, t>>;
librustc/middle/ty.rs:2752:49-2752:49 -fn- definition:
// doesn't provide type parameter substitutions.
pub fn pat_ty(cx: &ctxt, pat: &ast::Pat) -> t {
return node_id_to_type(cx, pat.id);
references:- 2librustc/middle/privacy.rs:
909: ast::PatStruct(_, ref fields, _) => {
910: match ty::get(ty::pat_ty(self.tcx, pattern)).sty {
911: ty::ty_struct(id, _) => {
--
940: ast::PatEnum(_, Some(ref fields)) => {
941: match ty::get(ty::pat_ty(self.tcx, pattern)).sty {
942: ty::ty_struct(id, _) => {
librustc/middle/ty.rs:1599:1-1599:1 -fn- definition:
pub fn type_is_ty_var(ty: t) -> bool {
match get(ty).sty {
ty_infer(TyVar(_)) => true,
references:- 2librustc/middle/typeck/coherence.rs:
65: resolve_ivar) {
66: Ok(resulting_type) if !type_is_ty_var(resulting_type) => {
67: resolved_type = resulting_type;
librustc/middle/typeck/check/mod.rs:
3978: match infer::resolve_type(fcx.infcx(), tp, force_tvar) {
3979: Ok(t_s) if !ty::type_is_ty_var(t_s) => t_s,
3980: _ => {
librustc/middle/ty.rs:67:31-67:31 -struct- definition:
pub struct field {
pub ident: ast::Ident,
pub mt: mt
references:- 174034: lookup_struct_fields(cx, did).iter().map(|f| {
4035: field {
4036: // FIXME #6993: change type of field to Name and get rid of new()
librustc/middle/expr_use_visitor.rs:
536: fn contains_field_named(field: &ty::field,
537: fields: &Vec<ast::Field>)
librustc/middle/trans/expr.rs:
903: node_id_opt: Option<ast::NodeId>,
904: op: |ty::Disr, (&[ty::field])| -> R)
905: -> R {
librustc/middle/trans/debuginfo.rs:
1243: struct StructMemberDescriptionFactory {
1244: fields: Vec<ty::field> ,
1245: span: Span,
librustc/middle/ty.rs:
3228: pub fn field_idx_strict(tcx: &ctxt, name: ast::Name, fields: &[field])
3229: -> uint {