]>
git.proxmox.com Git - rustc.git/blob - src/librustc/middle/astconv_util.rs
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.
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.
12 * This module contains a simple utility routine
13 * used by both `typeck` and `const_eval`.
14 * Almost certainly this could (and should) be refactored out of existence.
23 impl<'a
, 'gcx
, 'tcx
> TyCtxt
<'a
, 'gcx
, 'tcx
> {
24 pub fn prohibit_type_params(self, segments
: &[ast
::PathSegment
]) {
25 for segment
in segments
{
26 for typ
in segment
.parameters
.types() {
27 struct_span_err
!(self.sess
, typ
.span
, E0109
,
28 "type parameters are not allowed on this type")
29 .span_label(typ
.span
, &format
!("type parameter not allowed"))
33 for lifetime
in segment
.parameters
.lifetimes() {
34 struct_span_err
!(self.sess
, lifetime
.span
, E0110
,
35 "lifetime parameters are not allowed on this type")
36 .span_label(lifetime
.span
,
37 &format
!("lifetime parameter not allowed on this type"))
41 for binding
in segment
.parameters
.bindings() {
42 self.prohibit_projection(binding
.span
);
48 pub fn prohibit_projection(self, span
: Span
)
50 let mut err
= struct_span_err
!(self.sess
, span
, E0229
,
51 "associated type bindings are not allowed here");
52 err
.span_label(span
, &format
!("associate type not allowed here")).emit();
55 pub fn prim_ty_to_ty(self,
56 segments
: &[ast
::PathSegment
],
59 self.prohibit_type_params(segments
);
61 ast
::TyBool
=> self.types
.bool
,
62 ast
::TyChar
=> self.types
.char,
63 ast
::TyInt(it
) => self.mk_mach_int(it
),
64 ast
::TyUint(uit
) => self.mk_mach_uint(uit
),
65 ast
::TyFloat(ft
) => self.mk_mach_float(ft
),
66 ast
::TyStr
=> self.mk_str()
70 /// If a type in the AST is a primitive type, return the ty::Ty corresponding
72 pub fn ast_ty_to_prim_ty(self, ast_ty
: &ast
::Ty
) -> Option
<Ty
<'tcx
>> {
73 if let ast
::TyPath(None
, ref path
) = ast_ty
.node
{
74 if let Def
::PrimTy(nty
) = self.expect_def(ast_ty
.id
) {
75 Some(self.prim_ty_to_ty(&path
.segments
, nty
))