Snap for 8562061 from 0c2e319ae98e2ee744e5ae16c2156824cf133d43 to mainline-media-release
Change-Id: I6df80550c2ea8ed76d0a2f550eb2ab5aee6b4315
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 1f45e32..6895b5b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,5 +1,5 @@
{
"git": {
- "sha1": "2449cbc9d927411e8c88802b120a002e2e3507aa"
+ "sha1": "ecc07fb53f45a093811484d4ee1ac791144defd7"
}
}
diff --git a/.clippy.toml b/.clippy.toml
new file mode 100644
index 0000000..3d30690
--- /dev/null
+++ b/.clippy.toml
@@ -0,0 +1 @@
+msrv = "1.31.0"
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 9105f94..9ba68d6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -28,3 +28,11 @@
- uses: dtolnay/rust-toolchain@nightly
- run: cargo update -Z minimal-versions
- run: cargo test
+
+ clippy:
+ name: Clippy
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v2
+ - uses: dtolnay/rust-toolchain@clippy
+ - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic
diff --git a/Android.bp b/Android.bp
index dfe1604..ad91d42 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,4 +1,4 @@
-// This file is generated by cargo2android.py --run --device --dependencies.
+// This file is generated by cargo2android.py --config cargo2android.json.
// Do not modify this file as changes will be overridden on upgrade.
package {
@@ -40,6 +40,8 @@
rust_proc_macro {
name: "librustversion",
crate_name: "rustversion",
+ cargo_env_compat: true,
+ cargo_pkg_version: "1.0.5",
srcs: ["src/lib.rs"],
edition: "2018",
}
diff --git a/Cargo.toml b/Cargo.toml
index 56995ff..c72b1b2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
[package]
edition = "2018"
name = "rustversion"
-version = "1.0.4"
+version = "1.0.5"
authors = ["David Tolnay <[email protected]>"]
build = "build/build.rs"
description = "Conditional compilation according to rustc compiler version"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 268b002..75f8ea1 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "rustversion"
-version = "1.0.4"
+version = "1.0.5"
authors = ["David Tolnay <[email protected]>"]
edition = "2018"
license = "MIT OR Apache-2.0"
diff --git a/METADATA b/METADATA
index eb41a97..514a21f 100644
--- a/METADATA
+++ b/METADATA
@@ -7,14 +7,13 @@
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/rustversion/rustversion-1.0.4.crate"
+ value: "https://static.crates.io/crates/rustversion/rustversion-1.0.5.crate"
}
- version: "1.0.4"
- # Dual-licensed, using the least restrictive per go/thirdpartylicenses#same.
+ version: "1.0.5"
license_type: NOTICE
last_upgrade_date {
year: 2021
- month: 2
- day: 19
+ month: 5
+ day: 25
}
}
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..684ef48
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,11 @@
+// Generated by update_crate_tests.py for tests that depend on this crate.
+{
+ "imports": [
+ {
+ "path": "external/rust/crates/bitflags"
+ },
+ {
+ "path": "external/rust/crates/crossbeam-utils"
+ }
+ ]
+}
diff --git a/build/build.rs b/build/build.rs
index 2a8bc4a..1531251 100644
--- a/build/build.rs
+++ b/build/build.rs
@@ -1,3 +1,9 @@
+#![allow(
+ clippy::enum_glob_use,
+ clippy::must_use_candidate,
+ clippy::single_match_else
+)]
+
mod rustc;
use std::env;
diff --git a/build/rustc.rs b/build/rustc.rs
index 723e6bd..dfc6a05 100644
--- a/build/rustc.rs
+++ b/build/rustc.rs
@@ -48,23 +48,21 @@
Some(channel) if channel == "dev" => Dev,
Some(channel) if channel.starts_with("beta") => Beta,
Some(channel) if channel == "nightly" => match words.next() {
- Some(hash) => {
- if !hash.starts_with('(') {
- return None;
+ Some(hash) if hash.starts_with('(') => match words.next() {
+ None if hash.ends_with(')') => Dev,
+ Some(date) if date.ends_with(')') => {
+ let mut date = date[..date.len() - 1].split('-');
+ let year = date.next()?.parse().ok()?;
+ let month = date.next()?.parse().ok()?;
+ let day = date.next()?.parse().ok()?;
+ match date.next() {
+ None => Nightly(Date { year, month, day }),
+ Some(_) => return None,
+ }
}
- let date = words.next()?;
- if !date.ends_with(')') {
- return None;
- }
- let mut date = date[..date.len() - 1].split('-');
- let year = date.next()?.parse().ok()?;
- let month = date.next()?.parse().ok()?;
- let day = date.next()?.parse().ok()?;
- match date.next() {
- None => Nightly(Date { year, month, day }),
- Some(_) => return None,
- }
- }
+ None | Some(_) => return None,
+ },
+ Some(_) => return None,
None => Dev,
},
Some(_) => return None,
diff --git a/cargo2android.json b/cargo2android.json
new file mode 100644
index 0000000..bf78496
--- /dev/null
+++ b/cargo2android.json
@@ -0,0 +1,4 @@
+{
+ "device": true,
+ "run": true
+}
\ No newline at end of file
diff --git a/patches/version.diff b/patches/version.diff
index ea177f8..cd19b04 100644
--- a/patches/version.diff
+++ b/patches/version.diff
@@ -1,16 +1,16 @@
diff --git a/src/lib.rs b/src/lib.rs
-index 2614105..18d170d 100644
+index 172eb89..6c4ef6a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
-@@ -165,7 +165,16 @@ use crate::version::Version;
+@@ -180,7 +180,16 @@ use crate::version::Version;
use proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter::FromIterator;
-const RUSTVERSION: Version = include!(concat!(env!("OUT_DIR"), "/version.rs"));
+// ANDROID: Soong is providing the version of rustc via an env variable.
-+const ANDROID_RUSTVERSION: &str = env!("ANDROID_RUST_VERSION");
++const ANDROID_RUSTVERSION: Option<&str> = option_env!("ANDROID_RUST_VERSION");
+fn rust_version() -> Version {
-+ let v: Vec<&str> = ANDROID_RUSTVERSION.split('.').collect();
++ let v: Vec<&str> = ANDROID_RUSTVERSION.unwrap().split('.').collect();
+ Version {
+ minor: v[1].parse().unwrap(),
+ patch: v[2].parse().unwrap(),
@@ -20,7 +20,7 @@
#[proc_macro_attribute]
pub fn stable(args: TokenStream, input: TokenStream) -> TokenStream {
-@@ -226,7 +235,7 @@ fn try_cfg(introducer: &str, args: TokenStream, input: TokenStream) -> Result<To
+@@ -241,7 +250,7 @@ fn try_cfg(introducer: &str, args: TokenStream, input: TokenStream) -> Result<To
let expr = expr::parse(full_args)?;
token::parse_end(full_args)?;
@@ -29,7 +29,7 @@
Ok(input)
} else {
Ok(TokenStream::new())
-@@ -241,7 +250,7 @@ pub fn attr(args: TokenStream, input: TokenStream) -> TokenStream {
+@@ -256,7 +265,7 @@ pub fn attr(args: TokenStream, input: TokenStream) -> TokenStream {
}
fn try_attr(args: attr::Args, input: TokenStream) -> Result<TokenStream> {
diff --git a/src/lib.rs b/src/lib.rs
index 18d170d..6c4ef6a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -145,6 +145,21 @@
//!
//! <br>
+#![allow(
+ clippy::cast_lossless,
+ clippy::cast_possible_truncation,
+ clippy::doc_markdown,
+ clippy::enum_glob_use,
+ clippy::from_iter_instead_of_collect,
+ clippy::module_name_repetitions,
+ clippy::must_use_candidate,
+ clippy::needless_doctest_main,
+ clippy::needless_pass_by_value,
+ clippy::redundant_else,
+ clippy::toplevel_ref_arg,
+ clippy::unreadable_literal
+)]
+
extern crate proc_macro;
mod attr;
@@ -166,9 +181,9 @@
use std::iter::FromIterator;
// ANDROID: Soong is providing the version of rustc via an env variable.
-const ANDROID_RUSTVERSION: &str = env!("ANDROID_RUST_VERSION");
+const ANDROID_RUSTVERSION: Option<&str> = option_env!("ANDROID_RUST_VERSION");
fn rust_version() -> Version {
- let v: Vec<&str> = ANDROID_RUSTVERSION.split('.').collect();
+ let v: Vec<&str> = ANDROID_RUSTVERSION.unwrap().split('.').collect();
Version {
minor: v[1].parse().unwrap(),
patch: v[2].parse().unwrap(),
diff --git a/src/time.rs b/src/time.rs
index 1e6dd90..3c21463 100644
--- a/src/time.rs
+++ b/src/time.rs
@@ -1,4 +1,5 @@
use crate::date::Date;
+use std::env;
use std::time::{SystemTime, UNIX_EPOCH};
// Timestamp of 2016-03-01 00:00:00 in UTC.
@@ -13,14 +14,20 @@
pub fn today() -> Date {
let default = Date {
- year: 2019,
- month: 1,
- day: 1,
+ year: 2020,
+ month: 2,
+ day: 25,
};
try_today().unwrap_or(default)
}
fn try_today() -> Option<Date> {
+ if let Some(pkg_name) = env::var_os("CARGO_PKG_NAME") {
+ if pkg_name.to_str() == Some("rustversion-tests") {
+ return None; // Stable date for ui testing.
+ }
+ }
+
let now = SystemTime::now();
let since_epoch = now.duration_since(UNIX_EPOCH).ok()?;
let secs = since_epoch.as_secs();
diff --git a/tests/test_parse.rs b/tests/test_parse.rs
index 843bd73..cb39b31 100644
--- a/tests/test_parse.rs
+++ b/tests/test_parse.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::enum_glob_use, clippy::must_use_candidate)]
+
include!("../build/rustc.rs");
#[test]
@@ -76,6 +78,14 @@
}),
},
),
+ (
+ "rustc 1.52.1-nightly (gentoo)",
+ Version {
+ minor: 52,
+ patch: 1,
+ channel: Dev,
+ },
+ ),
];
for (string, expected) in cases {
diff --git a/tests/ui/bad-bound.stderr b/tests/ui/bad-bound.stderr
index f8c498c..2c56acb 100644
--- a/tests/ui/bad-bound.stderr
+++ b/tests/ui/bad-bound.stderr
@@ -1,10 +1,10 @@
-error: expected rustc release number like 1.31, or nightly date like 2020-10-26
+error: expected rustc release number like 1.31, or nightly date like 2020-02-25
--> $DIR/bad-bound.rs:1:22
|
1 | #[rustversion::since(stable)]
| ^^^^^^
-error: expected rustc release number like 1.31, or nightly date like 2020-10-26
+error: expected rustc release number like 1.31, or nightly date like 2020-02-25
--> $DIR/bad-bound.rs:4:26
|
4 | #[rustversion::any(since(stable))]
diff --git a/tests/ui/bad-date.stderr b/tests/ui/bad-date.stderr
index 734d788..c523ccc 100644
--- a/tests/ui/bad-date.stderr
+++ b/tests/ui/bad-date.stderr
@@ -1,10 +1,10 @@
-error: expected nightly date, like 2020-10-26
+error: expected nightly date, like 2020-02-25
--> $DIR/bad-date.rs:1:24
|
1 | #[rustversion::nightly(stable)]
| ^^^^^^
-error: expected nightly date, like 2020-10-26
+error: expected nightly date, like 2020-02-25
--> $DIR/bad-date.rs:4:28
|
4 | #[rustversion::any(nightly(stable))]