Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare Tokio v1.8.4 #4237

Merged
merged 16 commits into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .cargo/audit.toml
@@ -0,0 +1,7 @@
# See https://github.com/rustsec/rustsec/blob/59e1d2ad0b9cbc6892c26de233d4925074b4b97b/cargo-audit/audit.toml.example for example.

[advisories]
ignore = [
# https://github.com/tokio-rs/tokio/issues/4177
"RUSTSEC-2020-0159",
]
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Expand Up @@ -20,7 +20,7 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
httparse = "1.0"
time = "0.1"
httpdate = "1.0"
once_cell = "1.5.2"
rand = "0.8.3"

Expand Down
24 changes: 14 additions & 10 deletions examples/tinyhttp.rs
Expand Up @@ -221,8 +221,9 @@ mod date {
use std::cell::RefCell;
use std::fmt::{self, Write};
use std::str;
use std::time::SystemTime;

use time::{self, Duration};
use httpdate::HttpDate;

pub struct Now(());

Expand Down Expand Up @@ -252,22 +253,26 @@ mod date {
struct LastRenderedNow {
bytes: [u8; 128],
amt: usize,
next_update: time::Timespec,
unix_date: u64,
}

thread_local!(static LAST: RefCell<LastRenderedNow> = RefCell::new(LastRenderedNow {
bytes: [0; 128],
amt: 0,
next_update: time::Timespec::new(0, 0),
unix_date: 0,
}));

impl fmt::Display for Now {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
LAST.with(|cache| {
let mut cache = cache.borrow_mut();
let now = time::get_time();
if now >= cache.next_update {
cache.update(now);
let now = SystemTime::now();
let now_unix = now
.duration_since(SystemTime::UNIX_EPOCH)
.map(|since_epoch| since_epoch.as_secs())
.unwrap_or(0);
if cache.unix_date != now_unix {
cache.update(now, now_unix);
}
f.write_str(cache.buffer())
})
Expand All @@ -279,11 +284,10 @@ mod date {
str::from_utf8(&self.bytes[..self.amt]).unwrap()
}

fn update(&mut self, now: time::Timespec) {
fn update(&mut self, now: SystemTime, now_unix: u64) {
self.amt = 0;
write!(LocalBuffer(self), "{}", time::at(now).rfc822()).unwrap();
self.next_update = now + Duration::seconds(1);
self.next_update.nsec = 0;
self.unix_date = now_unix;
write!(LocalBuffer(self), "{}", HttpDate::from(now)).unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests-build/tests/fail/macros_core_no_default.stderr
Expand Up @@ -4,4 +4,4 @@ error: The default runtime flavor is `multi_thread`, but the `rt-multi-thread` f
3 | #[tokio::main]
| ^^^^^^^^^^^^^^
|
= note: this error originates in an attribute macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the attribute macro `tokio::main` (in Nightly builds, run with -Z macro-backtrace for more info)
10 changes: 2 additions & 8 deletions tests-build/tests/fail/macros_type_mismatch.rs
Expand Up @@ -7,12 +7,6 @@ async fn missing_semicolon_or_return_type() {

#[tokio::main]
async fn missing_return_type() {
/* TODO(taiki-e): one of help messages still wrong
help: consider using a semicolon here
|
16 | return Ok(());;
|
*/
return Ok(());
}

Expand All @@ -21,9 +15,9 @@ async fn extra_semicolon() -> Result<(), ()> {
/* TODO(taiki-e): help message still wrong
help: try using a variant of the expected enum
|
29 | Ok(Ok(());)
23 | Ok(Ok(());)
|
29 | Err(Ok(());)
23 | Err(Ok(());)
|
*/
Ok(());
Expand Down
28 changes: 11 additions & 17 deletions tests-build/tests/fail/macros_type_mismatch.stderr
Expand Up @@ -9,43 +9,37 @@ error[E0308]: mismatched types
help: consider using a semicolon here
|
5 | Ok(());
| ^
| +
help: try adding a return type
|
4 | async fn missing_semicolon_or_return_type() -> Result<(), _> {
| ^^^^^^^^^^^^^^^^
| ++++++++++++++++

error[E0308]: mismatched types
--> $DIR/macros_type_mismatch.rs:16:5
--> $DIR/macros_type_mismatch.rs:10:5
|
16 | return Ok(());
9 | async fn missing_return_type() {
| - help: try adding a return type: `-> Result<(), _>`
10 | return Ok(());
| ^^^^^^^^^^^^^^ expected `()`, found enum `Result`
|
= note: expected unit type `()`
found enum `Result<(), _>`
help: consider using a semicolon here
|
16 | return Ok(());;
| ^
help: try adding a return type
|
9 | async fn missing_return_type() -> Result<(), _> {
| ^^^^^^^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/macros_type_mismatch.rs:29:5
--> $DIR/macros_type_mismatch.rs:23:5
|
20 | async fn extra_semicolon() -> Result<(), ()> {
14 | async fn extra_semicolon() -> Result<(), ()> {
| -------------- expected `Result<(), ()>` because of return type
...
29 | Ok(());
23 | Ok(());
| ^^^^^^^ expected enum `Result`, found `()`
|
= note: expected enum `Result<(), ()>`
found unit type `()`
help: try using a variant of the expected enum
|
29 | Ok(Ok(());)
23 | Ok(Ok(());)
|
29 | Err(Ok(());)
23 | Err(Ok(());)
|
6 changes: 6 additions & 0 deletions tests-build/tests/macros.rs
Expand Up @@ -5,6 +5,12 @@ fn compile_fail_full() {
#[cfg(feature = "full")]
t.pass("tests/pass/forward_args_and_output.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main_return.rs");

#[cfg(feature = "full")]
t.pass("tests/pass/macros_main_loop.rs");

#[cfg(feature = "full")]
t.compile_fail("tests/fail/macros_invalid_input.rs");

Expand Down
7 changes: 7 additions & 0 deletions tests-build/tests/macros_clippy.rs
@@ -0,0 +1,7 @@
#[cfg(feature = "full")]
#[tokio::test]
async fn test_with_semicolon_without_return_type() {
#![deny(clippy::semicolon_if_nothing_returned)]

dbg!(0);
}
14 changes: 14 additions & 0 deletions tests-build/tests/pass/macros_main_loop.rs
@@ -0,0 +1,14 @@
use tests_build::tokio;

#[tokio::main]
async fn main() -> Result<(), ()> {
loop {
if !never() {
return Ok(());
}
}
}

fn never() -> bool {
std::time::Instant::now() > std::time::Instant::now()
}
6 changes: 6 additions & 0 deletions tests-build/tests/pass/macros_main_return.rs
@@ -0,0 +1,6 @@
use tests_build::tokio;

#[tokio::main]
async fn main() -> Result<(), ()> {
return Ok(());
}