From fd7ac6b17ef98f63438f59edca40562c400d4128 Mon Sep 17 00:00:00 2001 From: BO41 Date: Sun, 23 Jun 2019 12:19:46 +0000 Subject: [PATCH 1/3] Deprecate `try!` macro Co-Authored-By: Mazdak Farrokhzad Co-Authored-By: Oliver Middleton --- src/libcore/macros.rs | 1 + src/libstd/lib.rs | 5 ++++- src/test/ui/associated-types/cache/chrono-scan.rs | 2 +- src/test/ui/derived-errors/issue-31997.rs | 2 +- src/test/ui/derived-errors/issue-31997.stderr | 6 +++--- src/test/ui/lint/lint-qualification.rs | 2 +- src/test/ui/macros/macro-comma-support-rpass.rs | 2 ++ src/test/ui/macros/try-macro.rs | 1 + src/test/ui/rust-2018/try-macro.fixed | 1 + src/test/ui/rust-2018/try-macro.rs | 1 + src/test/ui/rust-2018/try-macro.stderr | 2 +- 11 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index 09d2331b60fed..ba641f7dc5c12 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -300,6 +300,7 @@ macro_rules! debug_assert_ne { /// Ok(()) /// } /// ``` +#[rustc_deprecated(since = "1.38.0", reason = "use the `?` operator instead")] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] #[doc(alias = "?")] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index cfee49a7b555c..34956fc839450 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -330,7 +330,10 @@ use prelude::v1::*; #[stable(feature = "rust1", since = "1.0.0")] pub use core::{assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne}; #[stable(feature = "rust1", since = "1.0.0")] -pub use core::{unreachable, unimplemented, write, writeln, r#try, todo}; +pub use core::{unreachable, unimplemented, write, writeln, todo}; +#[allow(deprecated)] +#[stable(feature = "rust1", since = "1.0.0")] +pub use core::r#try; #[allow(unused_imports)] // macros from `alloc` are not used on all platforms #[macro_use] diff --git a/src/test/ui/associated-types/cache/chrono-scan.rs b/src/test/ui/associated-types/cache/chrono-scan.rs index 8ddd347ff3607..5c05240552761 100644 --- a/src/test/ui/associated-types/cache/chrono-scan.rs +++ b/src/test/ui/associated-types/cache/chrono-scan.rs @@ -18,7 +18,7 @@ pub fn timezone_offset_zulu(s: &str, colon: F) -> ParseResult<(&str, i32)> pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()> where I: Iterator> { macro_rules! try_consume { - ($e:expr) => ({ let (s_, v) = try!($e); s = s_; v }) + ($e:expr) => ({ let (s_, v) = $e?; s = s_; v }) } let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space)); let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space)); diff --git a/src/test/ui/derived-errors/issue-31997.rs b/src/test/ui/derived-errors/issue-31997.rs index cfdee26c5599c..6d7d21e367322 100644 --- a/src/test/ui/derived-errors/issue-31997.rs +++ b/src/test/ui/derived-errors/issue-31997.rs @@ -10,7 +10,7 @@ fn closure(x: F) -> Result } fn foo() -> Result<(), ()> { - try!(closure(|| bar(core::ptr::null_mut()))); //~ ERROR cannot find function `bar` in this scope + closure(|| bar(core::ptr::null_mut()))?; //~ ERROR cannot find function `bar` in this scope Ok(()) } diff --git a/src/test/ui/derived-errors/issue-31997.stderr b/src/test/ui/derived-errors/issue-31997.stderr index e9fe0d3971ee6..d9260f79f2742 100644 --- a/src/test/ui/derived-errors/issue-31997.stderr +++ b/src/test/ui/derived-errors/issue-31997.stderr @@ -1,8 +1,8 @@ error[E0425]: cannot find function `bar` in this scope - --> $DIR/issue-31997.rs:13:21 + --> $DIR/issue-31997.rs:13:16 | -LL | try!(closure(|| bar(core::ptr::null_mut()))); - | ^^^ not found in this scope +LL | closure(|| bar(core::ptr::null_mut()))?; + | ^^^ not found in this scope error: aborting due to previous error diff --git a/src/test/ui/lint/lint-qualification.rs b/src/test/ui/lint/lint-qualification.rs index 2aa4526b8169b..d458c31dc4926 100644 --- a/src/test/ui/lint/lint-qualification.rs +++ b/src/test/ui/lint/lint-qualification.rs @@ -9,7 +9,7 @@ fn main() { foo::bar(); //~ ERROR: unnecessary qualification bar(); - let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345 + let _ = || -> Result<(), ()> { Ok(())?; Ok(()) }; // issue #37345 macro_rules! m { () => { $crate::foo::bar(); // issue #37357 diff --git a/src/test/ui/macros/macro-comma-support-rpass.rs b/src/test/ui/macros/macro-comma-support-rpass.rs index 12a612c153ad6..17c27b7cda473 100644 --- a/src/test/ui/macros/macro-comma-support-rpass.rs +++ b/src/test/ui/macros/macro-comma-support-rpass.rs @@ -261,7 +261,9 @@ fn thread_local() { #[test] fn try() { fn inner() -> Result<(), ()> { + #[allow(deprecated)] try!(Ok(())); + #[allow(deprecated)] try!(Ok(()),); Ok(()) } diff --git a/src/test/ui/macros/try-macro.rs b/src/test/ui/macros/try-macro.rs index 83b30a8b7ba11..643312654493a 100644 --- a/src/test/ui/macros/try-macro.rs +++ b/src/test/ui/macros/try-macro.rs @@ -1,4 +1,5 @@ // run-pass +#[allow(deprecated)] use std::num::{ParseFloatError, ParseIntError}; fn main() { diff --git a/src/test/ui/rust-2018/try-macro.fixed b/src/test/ui/rust-2018/try-macro.fixed index 7c1692fd7fb13..a7b7d3faf5ee9 100644 --- a/src/test/ui/rust-2018/try-macro.fixed +++ b/src/test/ui/rust-2018/try-macro.fixed @@ -6,6 +6,7 @@ #![warn(rust_2018_compatibility)] #![allow(unused_variables)] #![allow(dead_code)] +#![allow(deprecated)] fn foo() -> Result { let x: Result = Ok(22); diff --git a/src/test/ui/rust-2018/try-macro.rs b/src/test/ui/rust-2018/try-macro.rs index 2089d367be698..986e158eb644e 100644 --- a/src/test/ui/rust-2018/try-macro.rs +++ b/src/test/ui/rust-2018/try-macro.rs @@ -6,6 +6,7 @@ #![warn(rust_2018_compatibility)] #![allow(unused_variables)] #![allow(dead_code)] +#![allow(deprecated)] fn foo() -> Result { let x: Result = Ok(22); diff --git a/src/test/ui/rust-2018/try-macro.stderr b/src/test/ui/rust-2018/try-macro.stderr index eb65d4150642a..fad1bb9f1b068 100644 --- a/src/test/ui/rust-2018/try-macro.stderr +++ b/src/test/ui/rust-2018/try-macro.stderr @@ -1,5 +1,5 @@ warning: `try` is a keyword in the 2018 edition - --> $DIR/try-macro.rs:12:5 + --> $DIR/try-macro.rs:13:5 | LL | try!(x); | ^^^ help: you can use a raw identifier to stay compatible: `r#try` From 90fa7901b98367d04857cb96366b2eedf70693e2 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Mon, 15 Jul 2019 17:42:08 +0000 Subject: [PATCH 2/3] Postpone deprecating try! until 1.39.0 --- src/libcore/macros.rs | 2 +- src/libstd/lib.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs index ba641f7dc5c12..aa661078e7176 100644 --- a/src/libcore/macros.rs +++ b/src/libcore/macros.rs @@ -300,9 +300,9 @@ macro_rules! debug_assert_ne { /// Ok(()) /// } /// ``` -#[rustc_deprecated(since = "1.38.0", reason = "use the `?` operator instead")] #[macro_export] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_deprecated(since = "1.39.0", reason = "use the `?` operator instead")] #[doc(alias = "?")] macro_rules! r#try { ($expr:expr) => (match $expr { diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 34956fc839450..54abf72d3075a 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -331,7 +331,8 @@ use prelude::v1::*; pub use core::{assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::{unreachable, unimplemented, write, writeln, todo}; -#[allow(deprecated)] +// FIXME: change this to `#[allow(deprecated)]` when we update nightly compiler. +#[allow(deprecated_in_future)] #[stable(feature = "rust1", since = "1.0.0")] pub use core::r#try; From 6842316f6ff4586465e6412edce5e6808cfcd396 Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Sun, 14 Jul 2019 08:16:46 +0000 Subject: [PATCH 3/3] Allow deprecated try macro in test crates --- src/test/ui/associated-types/cache/chrono-scan.rs | 4 +++- src/test/ui/derived-errors/issue-31997.rs | 3 ++- src/test/ui/derived-errors/issue-31997.stderr | 6 +++--- src/test/ui/lint/lint-qualification.rs | 3 ++- src/test/ui/lint/lint-qualification.stderr | 2 +- src/test/ui/macros/macro-comma-support-rpass.rs | 3 +-- src/test/ui/macros/try-macro.rs | 2 +- 7 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/test/ui/associated-types/cache/chrono-scan.rs b/src/test/ui/associated-types/cache/chrono-scan.rs index 5c05240552761..964ddc9b625de 100644 --- a/src/test/ui/associated-types/cache/chrono-scan.rs +++ b/src/test/ui/associated-types/cache/chrono-scan.rs @@ -1,5 +1,7 @@ // check-pass +#![allow(deprecated)] + pub type ParseResult = Result; pub enum Item<'a> { @@ -18,7 +20,7 @@ pub fn timezone_offset_zulu(s: &str, colon: F) -> ParseResult<(&str, i32)> pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()> where I: Iterator> { macro_rules! try_consume { - ($e:expr) => ({ let (s_, v) = $e?; s = s_; v }) + ($e:expr) => ({ let (s_, v) = try!($e); s = s_; v }) } let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space)); let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space)); diff --git a/src/test/ui/derived-errors/issue-31997.rs b/src/test/ui/derived-errors/issue-31997.rs index 6d7d21e367322..ff619313afb5b 100644 --- a/src/test/ui/derived-errors/issue-31997.rs +++ b/src/test/ui/derived-errors/issue-31997.rs @@ -1,5 +1,6 @@ // Test that the resolve failure does not lead to downstream type errors. // See issue #31997. +#![allow(deprecated)] trait TheTrait { } @@ -10,7 +11,7 @@ fn closure(x: F) -> Result } fn foo() -> Result<(), ()> { - closure(|| bar(core::ptr::null_mut()))?; //~ ERROR cannot find function `bar` in this scope + try!(closure(|| bar(core::ptr::null_mut()))); //~ ERROR cannot find function `bar` in this scope Ok(()) } diff --git a/src/test/ui/derived-errors/issue-31997.stderr b/src/test/ui/derived-errors/issue-31997.stderr index d9260f79f2742..b53c0cda8de4d 100644 --- a/src/test/ui/derived-errors/issue-31997.stderr +++ b/src/test/ui/derived-errors/issue-31997.stderr @@ -1,8 +1,8 @@ error[E0425]: cannot find function `bar` in this scope - --> $DIR/issue-31997.rs:13:16 + --> $DIR/issue-31997.rs:14:21 | -LL | closure(|| bar(core::ptr::null_mut()))?; - | ^^^ not found in this scope +LL | try!(closure(|| bar(core::ptr::null_mut()))); + | ^^^ not found in this scope error: aborting due to previous error diff --git a/src/test/ui/lint/lint-qualification.rs b/src/test/ui/lint/lint-qualification.rs index d458c31dc4926..1b24191a111c2 100644 --- a/src/test/ui/lint/lint-qualification.rs +++ b/src/test/ui/lint/lint-qualification.rs @@ -1,4 +1,5 @@ #![deny(unused_qualifications)] +#[allow(deprecated)] mod foo { pub fn bar() {} @@ -9,7 +10,7 @@ fn main() { foo::bar(); //~ ERROR: unnecessary qualification bar(); - let _ = || -> Result<(), ()> { Ok(())?; Ok(()) }; // issue #37345 + let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345 macro_rules! m { () => { $crate::foo::bar(); // issue #37357 diff --git a/src/test/ui/lint/lint-qualification.stderr b/src/test/ui/lint/lint-qualification.stderr index 78f7e32a30cd1..125aeb3db0366 100644 --- a/src/test/ui/lint/lint-qualification.stderr +++ b/src/test/ui/lint/lint-qualification.stderr @@ -1,5 +1,5 @@ error: unnecessary qualification - --> $DIR/lint-qualification.rs:9:5 + --> $DIR/lint-qualification.rs:10:5 | LL | foo::bar(); | ^^^^^^^^ diff --git a/src/test/ui/macros/macro-comma-support-rpass.rs b/src/test/ui/macros/macro-comma-support-rpass.rs index 17c27b7cda473..50c0ef3451d3d 100644 --- a/src/test/ui/macros/macro-comma-support-rpass.rs +++ b/src/test/ui/macros/macro-comma-support-rpass.rs @@ -15,6 +15,7 @@ #![cfg_attr(core, no_std)] +#![allow(deprecated)] // for deprecated `try!()` macro #![feature(concat_idents)] #[cfg(std)] use std::fmt; @@ -261,9 +262,7 @@ fn thread_local() { #[test] fn try() { fn inner() -> Result<(), ()> { - #[allow(deprecated)] try!(Ok(())); - #[allow(deprecated)] try!(Ok(()),); Ok(()) } diff --git a/src/test/ui/macros/try-macro.rs b/src/test/ui/macros/try-macro.rs index 643312654493a..824c77d9de528 100644 --- a/src/test/ui/macros/try-macro.rs +++ b/src/test/ui/macros/try-macro.rs @@ -1,5 +1,5 @@ // run-pass -#[allow(deprecated)] +#![allow(deprecated)] // for deprecated `try!()` macro use std::num::{ParseFloatError, ParseIntError}; fn main() {