-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce new class to handle borrow errors
gcc/rust/ChangeLog: * Make-lang.in: Compile new file. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Use new class to report errors. * checks/errors/borrowck/rust-borrow-checker-diagnostics.cc: New file. * checks/errors/borrowck/rust-borrow-checker-diagnostics.h: New file, adds new class. Signed-off-by: Kushal Pal <[email protected]>
- Loading branch information
1 parent
ff59d15
commit c1ba898
Showing
4 changed files
with
142 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright (C) 2020-2024 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#include "rust-borrow-checker-diagnostics.h" | ||
|
||
namespace Rust { | ||
namespace BIR { | ||
|
||
void | ||
BorrowCheckerDiagnostics::report_errors () | ||
{ | ||
report_move_errors (); | ||
report_loan_errors (); | ||
report_subset_errors (); | ||
} | ||
|
||
void | ||
BorrowCheckerDiagnostics::report_move_errors () | ||
{ | ||
if (!move_errors.empty ()) | ||
{ | ||
rust_error_at (hir_function->get_locus (), | ||
"Found move errors in function %s", | ||
hir_function->get_function_name ().as_string ().c_str ()); | ||
} | ||
} | ||
|
||
void | ||
BorrowCheckerDiagnostics::report_loan_errors () | ||
{ | ||
if (!loan_errors.empty ()) | ||
{ | ||
rust_error_at (hir_function->get_locus (), | ||
"Found loan errors in function %s", | ||
hir_function->get_function_name ().as_string ().c_str ()); | ||
} | ||
} | ||
|
||
void | ||
BorrowCheckerDiagnostics::report_subset_errors () | ||
{ | ||
if (!subset_errors.empty ()) | ||
{ | ||
rust_error_at (hir_function->get_locus (), | ||
"Found subset errors in function %s. Some lifetime " | ||
"constraints need to be added.", | ||
hir_function->get_function_name ().as_string ().c_str ()); | ||
} | ||
} | ||
|
||
} // namespace BIR | ||
} // namespace Rust |
70 changes: 70 additions & 0 deletions
70
gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (C) 2020-2024 Free Software Foundation, Inc. | ||
|
||
// This file is part of GCC. | ||
|
||
// GCC is free software; you can redistribute it and/or modify it under | ||
// the terms of the GNU General Public License as published by the Free | ||
// Software Foundation; either version 3, or (at your option) any later | ||
// version. | ||
|
||
// GCC is distributed in the hope that it will be useful, but WITHOUT ANY | ||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
// for more details. | ||
|
||
// You should have received a copy of the GNU General Public License | ||
// along with GCC; see the file COPYING3. If not see | ||
// <http://www.gnu.org/licenses/>. | ||
|
||
#ifndef RUST_BORROW_CHECKER_DIAGNOSTICS_H | ||
#define RUST_BORROW_CHECKER_DIAGNOSTICS_H | ||
|
||
#include "polonius/rust-polonius.h" | ||
#include "rust-bir.h" | ||
#include "rust-hir-item.h" | ||
|
||
namespace Rust { | ||
namespace BIR { | ||
class BorrowCheckerDiagnostics | ||
{ | ||
// HIR representation of Rust function | ||
const HIR::Function *hir_function; | ||
// BIR representation of Rust function | ||
const Function &bir_function; | ||
// Some facts related to this function | ||
const Polonius::Facts &facts; | ||
// Polonius output | ||
// Point - vector<Path> | ||
const std::vector<std::pair<size_t, std::vector<size_t>>> &move_errors; | ||
// Point - vector<Loan> | ||
const std::vector<std::pair<size_t, std::vector<size_t>>> &loan_errors; | ||
// Point - pair<Origin, Origin> | ||
const std::vector<std::pair<size_t, std::pair<size_t, size_t>>> | ||
&subset_errors; | ||
|
||
public: | ||
BorrowCheckerDiagnostics ( | ||
const HIR::Function *hir_function, const Function &bir_function, | ||
const Polonius::Facts &facts, | ||
const std::vector<std::pair<size_t, std::vector<size_t>>> &move_errors, | ||
const std::vector<std::pair<size_t, std::vector<size_t>>> &loan_errors, | ||
const std::vector<std::pair<size_t, std::pair<size_t, size_t>>> | ||
&subset_errors) | ||
|
||
: hir_function (hir_function), bir_function (bir_function), facts (facts), | ||
move_errors (move_errors), loan_errors (loan_errors), | ||
subset_errors (subset_errors) | ||
{} | ||
|
||
void report_errors (); | ||
|
||
private: | ||
void report_move_errors (); | ||
void report_loan_errors (); | ||
void report_subset_errors (); | ||
}; | ||
|
||
} // namespace BIR | ||
} // namespace Rust | ||
|
||
#endif // RUST_BORROW_CHECKER_DIAGNOSTICS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters