@@ -72,7 +72,7 @@ class TypeCheckResolveGenericArguments : public TypeCheckBase
72
72
public:
73
73
static HIR::GenericArgs resolve (HIR::TypePathSegment *segment)
74
74
{
75
- TypeCheckResolveGenericArguments resolver;
75
+ TypeCheckResolveGenericArguments resolver (segment-> get_locus ()) ;
76
76
segment->accept_vis (resolver);
77
77
return resolver.args ;
78
78
};
@@ -83,8 +83,8 @@ class TypeCheckResolveGenericArguments : public TypeCheckBase
83
83
}
84
84
85
85
private:
86
- TypeCheckResolveGenericArguments ()
87
- : TypeCheckBase (), args (HIR::GenericArgs::create_empty ())
86
+ TypeCheckResolveGenericArguments (Location locus )
87
+ : TypeCheckBase (), args (HIR::GenericArgs::create_empty (locus ))
88
88
{}
89
89
90
90
HIR::GenericArgs args;
@@ -165,57 +165,57 @@ class TypeCheckType : public TypeCheckBase
165
165
return ;
166
166
}
167
167
168
- // reverse lookup the hir node from ast node id
169
168
HirId hir_lookup;
170
- if (context->lookup_type_by_node_id (ref, &hir_lookup))
169
+ if (! context->lookup_type_by_node_id (ref, &hir_lookup))
171
170
{
172
- // we got an HIR node
173
- if (context->lookup_type (hir_lookup, &translated))
174
- {
175
- translated = translated->clone ();
176
- auto ref = path.get_mappings ().get_hirid ();
177
- translated->set_ref (ref);
178
-
179
- HIR::TypePathSegment *final_seg = path.get_final_segment ();
180
- HIR::GenericArgs args
181
- = TypeCheckResolveGenericArguments::resolve (final_seg);
182
-
183
- bool path_declared_generic_arguments = !args.is_empty ();
184
- if (path_declared_generic_arguments)
185
- {
186
- if (translated->has_subsititions_defined ())
187
- {
188
- translated
189
- = SubstMapper::Resolve (translated, path.get_locus (),
190
- &args);
191
- if (translated->get_kind () != TyTy::TypeKind::ERROR
192
- && mappings != nullptr )
193
- {
194
- check_for_unconstrained (args.get_type_args ());
195
- }
196
- }
197
- else
198
- {
199
- rust_error_at (
200
- path.get_locus (),
201
- " TypePath %s declares generic argument's but "
202
- " the type %s does not have any" ,
203
- path.as_string ().c_str (),
204
- translated->as_string ().c_str ());
205
- }
206
- }
207
- else if (translated->has_subsititions_defined ())
208
- {
209
- translated
210
- = SubstMapper::InferSubst (translated, path.get_locus ());
211
- }
171
+ rust_error_at (path.get_locus (), " failed to lookup HIR node" );
172
+ return ;
173
+ }
174
+
175
+ TyTy::BaseType *lookup = nullptr ;
176
+ if (!context->lookup_type (hir_lookup, &lookup))
177
+ {
178
+ rust_error_at (path.get_locus (), " failed to lookup HIR TyTy" );
179
+ return ;
180
+ }
181
+
182
+ TyTy::BaseType *path_type = lookup->clone ();
183
+ path_type->set_ref (path.get_mappings ().get_hirid ());
184
+
185
+ HIR::TypePathSegment *final_seg = path.get_final_segment ();
186
+ HIR::GenericArgs args
187
+ = TypeCheckResolveGenericArguments::resolve (final_seg);
188
+
189
+ bool is_big_self = final_seg->is_ident_only ()
190
+ && (final_seg->as_string ().compare (" Self" ) == 0 );
212
191
192
+ if (path_type->needs_generic_substitutions ())
193
+ {
194
+ if (is_big_self)
195
+ {
196
+ translated = path_type;
213
197
return ;
214
198
}
215
- }
216
199
217
- rust_error_at (path.get_locus (), " failed to type-resolve TypePath: %s" ,
218
- path.as_string ().c_str ());
200
+ translated = SubstMapper::Resolve (path_type, path.get_locus (), &args);
201
+ if (translated->get_kind () != TyTy::TypeKind::ERROR
202
+ && mappings != nullptr )
203
+ {
204
+ check_for_unconstrained (args.get_type_args ());
205
+ }
206
+ }
207
+ else if (!args.is_empty ())
208
+ {
209
+ rust_error_at (path.get_locus (),
210
+ " TypePath %s declares generic argument's but "
211
+ " the type %s does not have any" ,
212
+ path.as_string ().c_str (),
213
+ translated->as_string ().c_str ());
214
+ }
215
+ else
216
+ {
217
+ translated = path_type;
218
+ }
219
219
}
220
220
221
221
void visit (HIR::ArrayType &type) override
0 commit comments