@@ -28,13 +28,12 @@ use middle::ty::{ty_param, Polytype, ty_ptr};
2828use middle:: ty:: { ty_rptr, ty_struct, ty_trait, ty_tup} ;
2929use middle:: ty:: { ty_uint, ty_unboxed_closure, ty_uniq, ty_bare_fn} ;
3030use middle:: ty:: { ty_closure} ;
31- use middle:: ty:: type_is_ty_var;
3231use middle:: subst:: Subst ;
3332use middle:: ty;
3433use middle:: typeck:: CrateCtxt ;
3534use middle:: typeck:: infer:: combine:: Combine ;
3635use middle:: typeck:: infer:: InferCtxt ;
37- use middle:: typeck:: infer:: { new_infer_ctxt, resolve_ivar , resolve_type } ;
36+ use middle:: typeck:: infer:: new_infer_ctxt;
3837use std:: collections:: { HashSet } ;
3938use std:: cell:: RefCell ;
4039use std:: rc:: Rc ;
@@ -54,80 +53,35 @@ use util::ppaux::Repr;
5453mod orphan;
5554mod overlap;
5655
57- fn get_base_type < ' a , ' tcx > ( inference_context : & InferCtxt < ' a , ' tcx > ,
58- span : Span ,
59- original_type : Ty < ' tcx > )
60- -> Option < Ty < ' tcx > > {
61- let resolved_type = match resolve_type ( inference_context,
62- Some ( span) ,
63- original_type,
64- resolve_ivar) {
65- Ok ( resulting_type) if !type_is_ty_var ( resulting_type) => resulting_type,
66- _ => {
67- inference_context. tcx . sess . span_fatal ( span,
68- "the type of this value must be known in order \
69- to determine the base type") ;
70- }
71- } ;
72-
73- match resolved_type. sty {
74- ty_enum( ..) | ty_struct( ..) | ty_unboxed_closure( ..) => {
75- debug ! ( "(getting base type) found base type" ) ;
76- Some ( resolved_type)
56+ // Returns the def ID of the base type, if there is one.
57+ fn get_base_type_def_id < ' a , ' tcx > ( inference_context : & InferCtxt < ' a , ' tcx > ,
58+ span : Span ,
59+ ty : Ty < ' tcx > )
60+ -> Option < DefId > {
61+ match ty. sty {
62+ ty_enum( def_id, _) |
63+ ty_struct( def_id, _) => {
64+ Some ( def_id)
7765 }
7866
79- _ if ty:: type_is_trait ( resolved_type) => {
80- debug ! ( "(getting base type) found base type (trait)" ) ;
81- Some ( resolved_type)
67+ ty_trait( ref t) => {
68+ Some ( t. principal . def_id )
8269 }
8370
8471 ty_bool | ty_char | ty_int( ..) | ty_uint( ..) | ty_float( ..) |
8572 ty_str( ..) | ty_vec( ..) | ty_bare_fn( ..) | ty_closure( ..) | ty_tup( ..) |
86- ty_infer ( .. ) | ty_param( ..) | ty_err | ty_open( ..) | ty_uniq( _) |
73+ ty_param( ..) | ty_err | ty_open( ..) | ty_uniq( _) |
8774 ty_ptr( _) | ty_rptr( _, _) => {
88- debug ! ( "(getting base type) no base type; found {}" ,
89- original_type. sty) ;
9075 None
9176 }
92- ty_trait( ..) => panic ! ( "should have been caught" )
93- }
94- }
9577
96- // Returns the def ID of the base type, if there is one.
97- fn get_base_type_def_id < ' a , ' tcx > ( inference_context : & InferCtxt < ' a , ' tcx > ,
98- span : Span ,
99- original_type : Ty < ' tcx > )
100- -> Option < DefId > {
101- match get_base_type ( inference_context, span, original_type) {
102- None => None ,
103- Some ( base_type) => {
104- match base_type. sty {
105- ty_enum( def_id, _) |
106- ty_struct( def_id, _) |
107- ty_unboxed_closure( def_id, _, _) => {
108- Some ( def_id)
109- }
110- ty_ptr( ty:: mt { ty, ..} ) |
111- ty_rptr( _, ty:: mt { ty, ..} ) |
112- ty_uniq( ty) => {
113- match ty. sty {
114- ty_trait( box ty:: TyTrait { ref principal, .. } ) => {
115- Some ( principal. def_id )
116- }
117- _ => {
118- panic ! ( "get_base_type() returned a type that wasn't an \
119- enum, struct, or trait") ;
120- }
121- }
122- }
123- ty_trait( box ty:: TyTrait { ref principal, .. } ) => {
124- Some ( principal. def_id )
125- }
126- _ => {
127- panic ! ( "get_base_type() returned a type that wasn't an \
128- enum, struct, or trait") ;
129- }
130- }
78+ ty_infer( ..) | ty_unboxed_closure( ..) => {
79+ // `ty` comes from a user declaration so we should only expect types
80+ // that the user can type
81+ inference_context. tcx . sess . span_bug (
82+ span,
83+ format ! ( "coherence encountered unexpected type searching for base type: {}" ,
84+ ty. repr( inference_context. tcx) ) [ ] ) ;
13185 }
13286 }
13387}
0 commit comments