Deprecate try!
macro
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com> Co-Authored-By: Oliver Middleton <olliemail27@gmail.com>
This commit is contained in:
parent
2d1a551e14
commit
fd7ac6b17e
11 changed files with 17 additions and 8 deletions
|
@ -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 = "?")]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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));
|
||||
let offset = try_consume!(timezone_offset_zulu(s.trim_start(), colon_or_space));
|
||||
|
|
|
@ -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(())
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -261,7 +261,9 @@ fn thread_local() {
|
|||
#[test]
|
||||
fn try() {
|
||||
fn inner() -> Result<(), ()> {
|
||||
#[allow(deprecated)]
|
||||
try!(Ok(()));
|
||||
#[allow(deprecated)]
|
||||
try!(Ok(()),);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
// run-pass
|
||||
#[allow(deprecated)]
|
||||
use std::num::{ParseFloatError, ParseIntError};
|
||||
|
||||
fn main() {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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`
|
||||
|
|
Loading…
Add table
Reference in a new issue