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

Deprecate try! macro #62077

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "?")]
Expand Down
5 changes: 4 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,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]
Expand Down
2 changes: 2 additions & 0 deletions src/test/run-pass/macros/macro-comma-support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ fn thread_local() {
#[test]
fn try() {
fn inner() -> Result<(), ()> {
#[allow(deprecated)]
try!(Ok(()));
#[allow(deprecated)]
try!(Ok(()),);
Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/macros/try-macro.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-pass
#[allow(deprecated)]
use std::num::{ParseFloatError, ParseIntError};

fn main() {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-types/cache/chrono-scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn timezone_offset_zulu<F>(s: &str, colon: F) -> ParseResult<(&str, i32)>
pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()>
where I: Iterator<Item=Item<'a>> {
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));
This conversation was marked as resolved.
Show resolved Hide resolved
let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space));
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/derived-errors/issue-31997.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
}

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(())
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/derived-errors/issue-31997.stderr
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/lint-qualification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/rust-2018/try-macro.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![warn(rust_2018_compatibility)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(deprecated)]

fn foo() -> Result<usize, ()> {
let x: Result<usize, ()> = Ok(22);
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/rust-2018/try-macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#![warn(rust_2018_compatibility)]
#![allow(unused_variables)]
#![allow(dead_code)]
#![allow(deprecated)]

fn foo() -> Result<usize, ()> {
let x: Result<usize, ()> = Ok(22);
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/rust-2018/try-macro.stderr
Original file line number Diff line number Diff line change
@@ -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`
Expand Down