Debian Codegraph @

gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h

raw
1 // Copyright (C) 2020-2024 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_BORROW_CHECKER_DIAGNOSTICS_H
20 #define RUST_BORROW_CHECKER_DIAGNOSTICS_H
21
22 #include "polonius/rust-polonius.h"
23 #include "rust-bir.h"
24 #include "rust-hir-item.h"
25 #include "text-range-label.h"
26
27 namespace Rust {
28 namespace BIR {
29 class BorrowCheckerDiagnostics
30 {
31 // HIR representation of Rust function
32 const HIR::Function *hir_function;
33 // BIR representation of Rust function
34 const Function &bir_function;
35 // Some facts related to this function
36 const Polonius::Facts &facts;
37 // Polonius output
38 // Point - vector<Path>
39 const std::vector<std::pair<size_t, std::vector<size_t>>> &move_errors;
40 // Point - vector<Loan>
41 const std::vector<std::pair<size_t, std::vector<size_t>>> &loan_errors;
42 // Point - pair<Origin, Origin>
43 const std::vector<std::pair<size_t, std::pair<size_t, size_t>>>
44 &subset_errors;
45
46 public:
47 BorrowCheckerDiagnostics (
48 const HIR::Function *hir_function, const Function &bir_function,
49 const Polonius::Facts &facts,
50 const std::vector<std::pair<size_t, std::vector<size_t>>> &move_errors,
51 const std::vector<std::pair<size_t, std::vector<size_t>>> &loan_errors,
52 const std::vector<std::pair<size_t, std::pair<size_t, size_t>>>
53 &subset_errors)
54
55 : hir_function (hir_function), bir_function (bir_function), facts (facts),
56 move_errors (move_errors), loan_errors (loan_errors),
57 subset_errors (subset_errors)
58 {}
59
60 void report_errors ();
61
62 private:
63 void report_move_errors ();
64 void report_loan_errors ();
65 void report_subset_errors ();
66
67 const BIR::Statement &get_statement (Polonius::Point point);
68 const BIR::Loan &get_loan (Polonius::Loan loan);
69 const HIR::LifetimeParam *get_lifetime_param (Polonius::Origin origin);
70
71 struct LabelLocationPair
72 {
73 text_range_label label;
74 location_t location;
75 };
76 static void
77 multi_label_error (const char *error_message, location_t error_location,
78 std::vector<LabelLocationPair> location_label_pairs);
79 };
80
81 } // namespace BIR
82 } // namespace Rust
83
84 #endif // RUST_BORROW_CHECKER_DIAGNOSTICS_H