Skip to content

Commit fd7ac6b

Browse files
BO41Centrilollie27
authored andcommitted
Deprecate try! macro
Co-Authored-By: Mazdak Farrokhzad <[email protected]> Co-Authored-By: Oliver Middleton <[email protected]>
1 parent 2d1a551 commit fd7ac6b

File tree

11 files changed

+17
-8
lines changed

11 files changed

+17
-8
lines changed

src/libcore/macros.rs

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ macro_rules! debug_assert_ne {
300300
/// Ok(())
301301
/// }
302302
/// ```
303+
#[rustc_deprecated(since = "1.38.0", reason = "use the `?` operator instead")]
303304
#[macro_export]
304305
#[stable(feature = "rust1", since = "1.0.0")]
305306
#[doc(alias = "?")]

src/libstd/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,10 @@ use prelude::v1::*;
330330
#[stable(feature = "rust1", since = "1.0.0")]
331331
pub use core::{assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne};
332332
#[stable(feature = "rust1", since = "1.0.0")]
333-
pub use core::{unreachable, unimplemented, write, writeln, r#try, todo};
333+
pub use core::{unreachable, unimplemented, write, writeln, todo};
334+
#[allow(deprecated)]
335+
#[stable(feature = "rust1", since = "1.0.0")]
336+
pub use core::r#try;
334337

335338
#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
336339
#[macro_use]

src/test/ui/associated-types/cache/chrono-scan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn timezone_offset_zulu<F>(s: &str, colon: F) -> ParseResult<(&str, i32)>
1818
pub fn parse<'a, I>(mut s: &str, items: I) -> ParseResult<()>
1919
where I: Iterator<Item=Item<'a>> {
2020
macro_rules! try_consume {
21-
($e:expr) => ({ let (s_, v) = try!($e); s = s_; v })
21+
($e:expr) => ({ let (s_, v) = $e?; s = s_; v })
2222
}
2323
let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space));
2424
let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space));

src/test/ui/derived-errors/issue-31997.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ fn closure<F, T>(x: F) -> Result<T, ()>
1010
}
1111

1212
fn foo() -> Result<(), ()> {
13-
try!(closure(|| bar(core::ptr::null_mut()))); //~ ERROR cannot find function `bar` in this scope
13+
closure(|| bar(core::ptr::null_mut()))?; //~ ERROR cannot find function `bar` in this scope
1414
Ok(())
1515
}
1616

src/test/ui/derived-errors/issue-31997.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0425]: cannot find function `bar` in this scope
2-
--> $DIR/issue-31997.rs:13:21
2+
--> $DIR/issue-31997.rs:13:16
33
|
4-
LL | try!(closure(|| bar(core::ptr::null_mut())));
5-
| ^^^ not found in this scope
4+
LL | closure(|| bar(core::ptr::null_mut()))?;
5+
| ^^^ not found in this scope
66

77
error: aborting due to previous error
88

src/test/ui/lint/lint-qualification.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ fn main() {
99
foo::bar(); //~ ERROR: unnecessary qualification
1010
bar();
1111

12-
let _ = || -> Result<(), ()> { try!(Ok(())); Ok(()) }; // issue #37345
12+
let _ = || -> Result<(), ()> { Ok(())?; Ok(()) }; // issue #37345
1313

1414
macro_rules! m { () => {
1515
$crate::foo::bar(); // issue #37357

src/test/ui/macros/macro-comma-support-rpass.rs

+2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ fn thread_local() {
261261
#[test]
262262
fn try() {
263263
fn inner() -> Result<(), ()> {
264+
#[allow(deprecated)]
264265
try!(Ok(()));
266+
#[allow(deprecated)]
265267
try!(Ok(()),);
266268
Ok(())
267269
}

src/test/ui/macros/try-macro.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
#[allow(deprecated)]
23
use std::num::{ParseFloatError, ParseIntError};
34

45
fn main() {

src/test/ui/rust-2018/try-macro.fixed

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![warn(rust_2018_compatibility)]
77
#![allow(unused_variables)]
88
#![allow(dead_code)]
9+
#![allow(deprecated)]
910

1011
fn foo() -> Result<usize, ()> {
1112
let x: Result<usize, ()> = Ok(22);

src/test/ui/rust-2018/try-macro.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![warn(rust_2018_compatibility)]
77
#![allow(unused_variables)]
88
#![allow(dead_code)]
9+
#![allow(deprecated)]
910

1011
fn foo() -> Result<usize, ()> {
1112
let x: Result<usize, ()> = Ok(22);

src/test/ui/rust-2018/try-macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: `try` is a keyword in the 2018 edition
2-
--> $DIR/try-macro.rs:12:5
2+
--> $DIR/try-macro.rs:13:5
33
|
44
LL | try!(x);
55
| ^^^ help: you can use a raw identifier to stay compatible: `r#try`

0 commit comments

Comments
 (0)