Line data Source code
1 : // Copyright (C) 2020-2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #ifndef RUST_HIR_PATH_PROBE_TYPE_H
20 : #define RUST_HIR_PATH_PROBE_TYPE_H
21 :
22 : #include "rust-hir-map.h"
23 : #include "rust-hir-path-probe.h"
24 : #include "rust-tyty.h"
25 :
26 : namespace Rust {
27 : namespace Resolver {
28 :
29 207 : struct TypePathProbeResult
30 : {
31 : std::set<PathProbeCandidate> type_candidates;
32 : std::set<PathProbeCandidate> non_type_matches;
33 :
34 : bool has_type_candidates () const { return !type_candidates.empty (); }
35 :
36 : bool has_non_type_matches () const { return !non_type_matches.empty (); }
37 :
38 : bool is_empty () const
39 : {
40 : return type_candidates.empty () && non_type_matches.empty ();
41 : }
42 : };
43 :
44 207 : class TypePathProbe
45 : {
46 : public:
47 : static TypePathProbeResult Probe (TyTy::BaseType *receiver,
48 : const HIR::PathIdentSegment &segment_name);
49 :
50 : private:
51 207 : TypePathProbe (TyTy::BaseType *receiver,
52 : const HIR::PathIdentSegment &segment_name)
53 207 : : mappings (Analysis::Mappings::get ()), receiver (receiver),
54 207 : search (segment_name)
55 207 : {}
56 :
57 : TypePathProbeResult probe ();
58 :
59 : void probe_generic ();
60 : void probe_adt (TyTy::ADTType *adt);
61 : void probe_fallback ();
62 :
63 : bool process_impl_item (HirId id, HIR::ImplItem *item, HIR::ImplBlock *impl);
64 :
65 : void process_trait_impl_item (HIR::ImplBlock *impl);
66 :
67 : PathProbeCandidate
68 : process_predicate_for_candidates (const TyTy::TypeBoundPredicate &predicate);
69 :
70 : void insert_candidate (PathProbeCandidate candidate);
71 :
72 : Analysis::Mappings &mappings;
73 : TyTy::BaseType *receiver;
74 : const HIR::PathIdentSegment &search;
75 : TypePathProbeResult result;
76 : };
77 :
78 : } // namespace Resolver
79 : } // namespace Rust
80 :
81 : #endif // RUST_HIR_PATH_PROBE_TYPE_H
|