1
- // Copyright (C) 2020- 2025 Free Software Foundation, Inc.
1
+ // Copyright (C) 2025 Free Software Foundation, Inc.
2
2
3
3
// This file is part of GCC.
4
4
@@ -39,32 +39,34 @@ class PrimitiveImplCheck : public TypeCheckBase
39
39
40
40
private:
41
41
void scan ()
42
-
43
42
{
44
- std::vector<HIR::ImplBlock *> possible_primitive_impl;
43
+ std::vector<HIR::ImplBlock *> possible_primitive_impls;
44
+
45
45
mappings.iterate_impl_blocks ([&] (HirId id, HIR::ImplBlock *impl) -> bool {
46
46
// filtering trait-impl-blocks
47
47
if (impl->has_trait_ref ())
48
48
return true ;
49
+
49
50
HirId impl_ty_id = impl->get_type ().get_mappings ().get_hirid ();
51
+
50
52
TyTy::BaseType *impl_type = nullptr ;
51
53
if (!query_type (impl_ty_id, &impl_type))
52
54
return true ;
55
+
53
56
DefId defid = impl->get_mappings ().get_defid ();
57
+
54
58
// ignore lang item
55
59
if (mappings.lookup_lang_item (defid))
56
60
return true ;
61
+
57
62
if (is_primitive_type_kind (impl_type->get_kind ()))
58
- {
59
- possible_primitive_impl.push_back (impl);
60
- }
63
+ possible_primitive_impls.push_back (impl);
64
+
61
65
return true ;
62
66
});
63
67
64
- for (auto impl : possible_primitive_impl)
65
- {
66
- report_error (impl);
67
- }
68
+ for (auto impl : possible_primitive_impls)
69
+ report_error (impl);
68
70
}
69
71
70
72
void report_error (HIR::ImplBlock *impl)
@@ -73,8 +75,9 @@ class PrimitiveImplCheck : public TypeCheckBase
73
75
std::string msg = " consider using an extension trait instead" ;
74
76
r.add_fixit_replace (impl->get_locus (), msg.c_str ());
75
77
r.add_range (impl->get_locus ());
76
- std::string err = " impl" ;
77
- err = " cannot define inherent `" + err + " ` for primitive types" ;
78
+
79
+ std::string err = " cannot define inherent impl for primitive types" ;
80
+
78
81
rust_error_at (r, ErrorCode::E0390 , " %s" , err.c_str ());
79
82
}
80
83
};
0 commit comments