Skip to content

Commit 248a139

Browse files
committed
rust: Lower minimum supported Rust version to 1.49
gcc/rust/ChangeLog: * checks/errors/borrowck/ffi-polonius/Cargo.lock: Regenerate. * checks/errors/borrowck/ffi-polonius/Cargo.toml: Update to use source patching instead of vendoring, lower edition to 2018. * checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml: Change edition to 2018. * checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs: Remove uses of unstable feature. * checks/errors/borrowck/ffi-polonius/.cargo/config.toml: Removed. libgrust/ChangeLog: * libformat_parser/Makefile.am: Avoid using --config as it is unsupported by cargo 1.49. * libformat_parser/Makefile.in: Regenerate. * libformat_parser/generic_format_parser/src/lib.rs: Use extension trait for missing features. * libformat_parser/src/lib.rs: Likewise. * libformat_parser/.cargo/config: Moved to... * libformat_parser/.cargo/config.toml: ...here.
1 parent a988708 commit 248a139

File tree

10 files changed

+41
-170
lines changed

10 files changed

+41
-170
lines changed

gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
[package]
22
name = "ffi-polonius"
33
version = "0.1.0"
4-
edition = "2021"
4+
edition = "2018"
55
license = "GPL-3"
66

77
[lib]
88
crate-type = ["staticlib"]
99

1010
[dependencies]
11-
polonius-engine = "0.13.0"
11+
polonius-engine = "0.13.0"
12+
13+
[patch.crates-io]
14+
log = { path = "vendor/log" }
15+
datafrog = { path = "vendor/datafrog" }
16+
polonius-engine = { path = "vendor/polonius-engine" }
17+
rustc-hash = { path = "vendor/rustc-hash" }

gcc/rust/checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
# See Cargo.toml.orig for the original contents.
1111

1212
[package]
13-
edition = "2021"
13+
edition = "2018"
1414
rust-version = "1.60.0"
1515
name = "log"
1616
version = "0.4.22"

gcc/rust/checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs

Lines changed: 0 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -397,20 +397,13 @@ mod serde;
397397
#[cfg(feature = "kv")]
398398
pub mod kv;
399399

400-
#[cfg(target_has_atomic = "ptr")]
401-
use std::sync::atomic::{AtomicUsize, Ordering};
402-
403-
#[cfg(not(target_has_atomic = "ptr"))]
404400
use std::cell::Cell;
405-
#[cfg(not(target_has_atomic = "ptr"))]
406401
use std::sync::atomic::Ordering;
407402

408-
#[cfg(not(target_has_atomic = "ptr"))]
409403
struct AtomicUsize {
410404
v: Cell<usize>,
411405
}
412406

413-
#[cfg(not(target_has_atomic = "ptr"))]
414407
impl AtomicUsize {
415408
const fn new(v: usize) -> AtomicUsize {
416409
AtomicUsize { v: Cell::new(v) }
@@ -423,26 +416,10 @@ impl AtomicUsize {
423416
fn store(&self, val: usize, _order: Ordering) {
424417
self.v.set(val)
425418
}
426-
427-
#[cfg(target_has_atomic = "ptr")]
428-
fn compare_exchange(
429-
&self,
430-
current: usize,
431-
new: usize,
432-
_success: Ordering,
433-
_failure: Ordering,
434-
) -> Result<usize, usize> {
435-
let prev = self.v.get();
436-
if current == prev {
437-
self.v.set(new);
438-
}
439-
Ok(prev)
440-
}
441419
}
442420

443421
// Any platform without atomics is unlikely to have multiple cores, so
444422
// writing via Cell will not be a race condition.
445-
#[cfg(not(target_has_atomic = "ptr"))]
446423
unsafe impl Sync for AtomicUsize {}
447424

448425
// The LOGGER static holds a pointer to the global logger. It is protected by
@@ -1258,17 +1235,6 @@ where
12581235
}
12591236
}
12601237

1261-
/// Sets the global maximum log level.
1262-
///
1263-
/// Generally, this should only be called by the active logging implementation.
1264-
///
1265-
/// Note that `Trace` is the maximum level, because it provides the maximum amount of detail in the emitted logs.
1266-
#[inline]
1267-
#[cfg(target_has_atomic = "ptr")]
1268-
pub fn set_max_level(level: LevelFilter) {
1269-
MAX_LOG_LEVEL_FILTER.store(level as usize, Ordering::Relaxed);
1270-
}
1271-
12721238
/// A thread-unsafe version of [`set_max_level`].
12731239
///
12741240
/// This function is available on all platforms, even those that do not have
@@ -1320,110 +1286,6 @@ pub fn max_level() -> LevelFilter {
13201286
unsafe { mem::transmute(MAX_LOG_LEVEL_FILTER.load(Ordering::Relaxed)) }
13211287
}
13221288

1323-
/// Sets the global logger to a `Box<Log>`.
1324-
///
1325-
/// This is a simple convenience wrapper over `set_logger`, which takes a
1326-
/// `Box<Log>` rather than a `&'static Log`. See the documentation for
1327-
/// [`set_logger`] for more details.
1328-
///
1329-
/// Requires the `std` feature.
1330-
///
1331-
/// # Errors
1332-
///
1333-
/// An error is returned if a logger has already been set.
1334-
///
1335-
/// [`set_logger`]: fn.set_logger.html
1336-
#[cfg(all(feature = "std", target_has_atomic = "ptr"))]
1337-
pub fn set_boxed_logger(logger: Box<dyn Log>) -> Result<(), SetLoggerError> {
1338-
set_logger_inner(|| Box::leak(logger))
1339-
}
1340-
1341-
/// Sets the global logger to a `&'static Log`.
1342-
///
1343-
/// This function may only be called once in the lifetime of a program. Any log
1344-
/// events that occur before the call to `set_logger` completes will be ignored.
1345-
///
1346-
/// This function does not typically need to be called manually. Logger
1347-
/// implementations should provide an initialization method that installs the
1348-
/// logger internally.
1349-
///
1350-
/// # Availability
1351-
///
1352-
/// This method is available even when the `std` feature is disabled. However,
1353-
/// it is currently unavailable on `thumbv6` targets, which lack support for
1354-
/// some atomic operations which are used by this function. Even on those
1355-
/// targets, [`set_logger_racy`] will be available.
1356-
///
1357-
/// # Errors
1358-
///
1359-
/// An error is returned if a logger has already been set.
1360-
///
1361-
/// # Examples
1362-
///
1363-
/// ```
1364-
/// use log::{error, info, warn, Record, Level, Metadata, LevelFilter};
1365-
///
1366-
/// static MY_LOGGER: MyLogger = MyLogger;
1367-
///
1368-
/// struct MyLogger;
1369-
///
1370-
/// impl log::Log for MyLogger {
1371-
/// fn enabled(&self, metadata: &Metadata) -> bool {
1372-
/// metadata.level() <= Level::Info
1373-
/// }
1374-
///
1375-
/// fn log(&self, record: &Record) {
1376-
/// if self.enabled(record.metadata()) {
1377-
/// println!("{} - {}", record.level(), record.args());
1378-
/// }
1379-
/// }
1380-
/// fn flush(&self) {}
1381-
/// }
1382-
///
1383-
/// # fn main(){
1384-
/// log::set_logger(&MY_LOGGER).unwrap();
1385-
/// log::set_max_level(LevelFilter::Info);
1386-
///
1387-
/// info!("hello log");
1388-
/// warn!("warning");
1389-
/// error!("oops");
1390-
/// # }
1391-
/// ```
1392-
///
1393-
/// [`set_logger_racy`]: fn.set_logger_racy.html
1394-
#[cfg(target_has_atomic = "ptr")]
1395-
pub fn set_logger(logger: &'static dyn Log) -> Result<(), SetLoggerError> {
1396-
set_logger_inner(|| logger)
1397-
}
1398-
1399-
#[cfg(target_has_atomic = "ptr")]
1400-
fn set_logger_inner<F>(make_logger: F) -> Result<(), SetLoggerError>
1401-
where
1402-
F: FnOnce() -> &'static dyn Log,
1403-
{
1404-
match STATE.compare_exchange(
1405-
UNINITIALIZED,
1406-
INITIALIZING,
1407-
Ordering::Acquire,
1408-
Ordering::Relaxed,
1409-
) {
1410-
Ok(UNINITIALIZED) => {
1411-
unsafe {
1412-
LOGGER = make_logger();
1413-
}
1414-
STATE.store(INITIALIZED, Ordering::Release);
1415-
Ok(())
1416-
}
1417-
Err(INITIALIZING) => {
1418-
while STATE.load(Ordering::Relaxed) == INITIALIZING {
1419-
std::hint::spin_loop();
1420-
}
1421-
Err(SetLoggerError(()))
1422-
}
1423-
_ => Err(SetLoggerError(())),
1424-
}
1425-
}
1426-
14271289
/// A thread-unsafe version of [`set_logger`].
14281290
///
14291291
/// This function is available on all platforms, even those that do not have

libgrust/libformat_parser/.cargo/config

Lines changed: 0 additions & 5 deletions
This file was deleted.

libgrust/libformat_parser/Makefile.am

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@ LIBFORMAT_PARSER = debug/liblibformat_parser.a
22

33
all-local: $(LIBFORMAT_PARSER)
44

5+
RUST_BUILD_DIR=$(PWD)
6+
57
# TODO: Improve `cargo` invocation with host specific flags, possibly creating a $(CARGO) variable?
68
$(LIBFORMAT_PARSER): $(srcdir)/Cargo.toml $(srcdir)/src/*.rs
7-
cargo \
8-
--config $(srcdir)/.cargo/config \
9-
build \
10-
--offline \
11-
--target-dir . \
12-
--manifest-path $(srcdir)/Cargo.toml \
13-
# FIXME: Not always '--release', right?
9+
cd $(srcdir) && \
10+
cargo build --offline --target-dir $(RUST_BUILD_DIR)

libgrust/libformat_parser/Makefile.in

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ top_build_prefix = @top_build_prefix@
263263
top_builddir = @top_builddir@
264264
top_srcdir = @top_srcdir@
265265
LIBFORMAT_PARSER = debug/liblibformat_parser.a
266+
RUST_BUILD_DIR = $(PWD)
266267
all: all-am
267268

268269
.SUFFIXES:
@@ -428,13 +429,8 @@ all-local: $(LIBFORMAT_PARSER)
428429

429430
# TODO: Improve `cargo` invocation with host specific flags, possibly creating a $(CARGO) variable?
430431
$(LIBFORMAT_PARSER): $(srcdir)/Cargo.toml $(srcdir)/src/*.rs
431-
cargo \
432-
--config $(srcdir)/.cargo/config \
433-
build \
434-
--offline \
435-
--target-dir . \
436-
--manifest-path $(srcdir)/Cargo.toml \
437-
# FIXME: Not always '--release', right?
432+
cd $(srcdir) && \
433+
cargo build --offline --target-dir $(RUST_BUILD_DIR)
438434

439435
# Tell versions [3.59,3.63) of GNU make to not export all variables.
440436
# Otherwise a system limit (for SysV at least) may be exceeded.

libgrust/libformat_parser/generic_format_parser/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ use std::iter;
3232
use std::str;
3333
use std::string;
3434

35+
// Extension trait for `Option<T>::is_some_and()` which was not a feature in Rust 1.49
36+
pub trait OptionIsSomeAndExt<T> {
37+
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool;
38+
}
39+
40+
impl<T> OptionIsSomeAndExt<T> for Option<T> {
41+
fn is_some_and(self, f: impl FnOnce(T) -> bool) -> bool {
42+
match self {
43+
None => false,
44+
Some(x) => f(x),
45+
}
46+
}
47+
}
48+
3549
// Note: copied from rustc_span
3650
/// Range inside of a `Span` used for diagnostics when we only have access to relative positions.
3751
#[derive(Copy, Clone, PartialEq, Eq, Debug)]

libgrust/libformat_parser/src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ where
2121
}
2222
}
2323

24+
// Extension trait to provide `String::leak` which did not exist in Rust 1.49
25+
pub trait StringLeakExt {
26+
fn leak<'a>(self) -> &'a mut str;
27+
}
28+
29+
impl StringLeakExt for String {
30+
fn leak<'a>(self) -> &'a mut str {
31+
Box::leak(self.into_boxed_str())
32+
}
33+
}
34+
2435
// FIXME: Make an ffi module in a separate file
2536
// FIXME: Remember to leak the boxed type somehow
2637
// FIXME: How to encode the Option type? As a pointer? Option<T> -> Option<&T> -> *const T could work maybe?

0 commit comments

Comments
 (0)