]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
rust: Silence a clang warning in borrow-checker-diagnostics
authorMartin Jambor <mjambor@suse.cz>
Mon, 23 Jun 2025 21:52:20 +0000 (23:52 +0200)
committerMartin Jambor <jamborm@gcc.gnu.org>
Thu, 26 Jun 2025 14:35:52 +0000 (16:35 +0200)
When compiling
gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
with clang, it emits the following warning:

  gcc/rust/checks/errors/borrowck/rust-borrow-checker-diagnostics.cc:145:46: warning: non-constant-expression cannot be narrowed from type 'Polonius::Loan' (aka 'unsigned long') to 'uint32_t' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]

I'd hope that for indexing that is never really a problem,
nevertheless if narrowing is taking place, I guess it can be argued it
should be made explicit.

gcc/rust/ChangeLog:

2025-06-23  Martin Jambor  <mjambor@suse.cz>

* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_loan): Type cast loan to uint32_t.

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

index 6c67706780bf5ba0d7763669be4a7fe270a42f69..adf1448791e199cf5245c7bcb8ba4522dd4db892 100644 (file)
@@ -142,7 +142,7 @@ BorrowCheckerDiagnostics::get_statement (Polonius::Point point)
 const BIR::Loan &
 BorrowCheckerDiagnostics::get_loan (Polonius::Loan loan)
 {
-  return bir_function.place_db.get_loans ()[{loan}];
+  return bir_function.place_db.get_loans ()[{(uint32_t) loan}];
 }
 
 const HIR::LifetimeParam *