aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiƩbaud Weksteen <tweek@google.com>2021-05-25 15:57:46 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-05-25 15:57:46 +0000
commit89b96a9d737db00f41fc6042253f00b3b73caeab (patch)
treece0071e97df5b92389a681455c78fa3709cb90b8
parent68e08af36a24ec9d3c3602cbf1f81d1909a8e035 (diff)
parent845aa00b38625edff140376c4ab72aa10760dba5 (diff)
downloadrustversion-89b96a9d737db00f41fc6042253f00b3b73caeab.tar.gz
Update to 1.0.5 am: b8acb8069f am: 7d4df56722 am: 7c127cbf8b am: 845aa00b38
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/rustversion/+/1716719 Change-Id: I5f4b663416de4cbbc361f3a133ea3d71af45dc88
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.clippy.toml1
-rw-r--r--.github/workflows/ci.yml8
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA9
-rw-r--r--build/build.rs6
-rw-r--r--build/rustc.rs30
-rw-r--r--patches/version.diff12
-rw-r--r--src/lib.rs19
-rw-r--r--src/time.rs13
-rw-r--r--tests/test_parse.rs10
-rw-r--r--tests/ui/bad-bound.stderr4
-rw-r--r--tests/ui/bad-date.stderr4
14 files changed, 83 insertions, 39 deletions
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 @@ jobs:
- 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/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 <dtolnay@gmail.com>"]
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 <dtolnay@gmail.com>"]
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 @@ third_party {
}
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/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 @@ pub fn parse(string: &str) -> Option<Version> {
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/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 @@ index 2614105..18d170d 100644
#[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 @@ index 2614105..18d170d 100644
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 proc_macro::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, Tok
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 @@ const DAYS_BY_MONTH: [u8; 12] = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
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 @@ fn test_parse() {
}),
},
),
+ (
+ "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))]