Skip to content

Commit 0db9010

Browse files
calebcartwrighttopecongiro
authored andcommitted
feat: change default edition to 2018 (#3942)
1 parent d810c30 commit 0db9010

File tree

21 files changed

+680
-28
lines changed

21 files changed

+680
-28
lines changed

Configurations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2352,7 +2352,7 @@ Replace uses of the try! macro by the ? shorthand
23522352

23532353
```rust
23542354
fn main() {
2355-
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
2355+
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
23562356
}
23572357
```
23582358

src/config/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ create_config! {
107107
"Maximum number of blank lines which can be put between items";
108108
blank_lines_lower_bound: usize, 0, false,
109109
"Minimum number of blank lines which must be put between items";
110-
edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)";
110+
edition: Edition, Edition::Edition2018, true, "The edition of the parser (RFC 2052)";
111111
version: Version, Version::One, false, "Version of formatting rules";
112112
inline_attribute_width: usize, 0, false,
113113
"Write an item and its attribute on the same line \
@@ -531,7 +531,7 @@ trailing_comma = "Vertical"
531531
match_block_trailing_comma = false
532532
blank_lines_upper_bound = 1
533533
blank_lines_lower_bound = 0
534-
edition = "2015"
534+
edition = "2018"
535535
version = "One"
536536
inline_attribute_width = 0
537537
merge_derives = true

src/config/options.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ pub enum Edition {
380380

381381
impl Default for Edition {
382382
fn default() -> Edition {
383-
Edition::Edition2015
383+
Edition::Edition2018
384384
}
385385
}
386386

src/macros.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,12 @@ fn next_space(tok: &TokenKind) -> SpaceState {
11901190
/// when the macro is not an instance of `try!` (or parsing the inner expression
11911191
/// failed).
11921192
pub(crate) fn convert_try_mac(mac: &ast::Mac, context: &RewriteContext<'_>) -> Option<ast::Expr> {
1193-
if &mac.path.to_string() == "try" {
1193+
// The `try!` macro was deprecated in Rust 1.39.0 and `try` is a
1194+
// reserved keyword in the 2018 Edition so the raw identifier
1195+
// `r#try!` must be used in the 2018 Edition.
1196+
// https://doc.rust-lang.org/std/macro.try.html
1197+
// https://github.com/rust-lang/rust/pull/62672
1198+
if &mac.path.to_string() == "try" || &mac.path.to_string() == "r#try" {
11941199
let ts: TokenStream = mac.tts.clone();
11951200
let mut parser = new_parser_from_tts(context.parse_sess.inner(), ts.trees().collect());
11961201

tests/source/configs/indent_style/block_call.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ fn main() {
1818
}
1919

2020
// nesting macro and function call
21-
try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx));
22-
try!(foo(try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)));
21+
r#try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx));
22+
r#try!(foo(r#try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)));
2323
}
2424

2525
// #1521

tests/source/configs/use_try_shorthand/false.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Use try! shorthand
33

44
fn main() {
5-
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
5+
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
66
}

tests/source/configs/use_try_shorthand/true.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Use try! shorthand
33

44
fn main() {
5-
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
5+
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
66
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// rustfmt-use_try_shorthand: true
2+
// rustfmt-edition: 2015
3+
// Use try! shorthand
4+
5+
fn main() {
6+
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
7+
}

tests/source/imports.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ use foo::{baz, qux as bar};
6262
use ::foo;
6363
use ::foo::{Bar};
6464
use ::foo::{Bar, Baz};
65-
use ::{Foo};
65+
use ::{qux};
6666
use ::{Bar, Baz};
6767

6868
// Root globs
@@ -104,4 +104,4 @@ use std::f64::consts::{SQRT_2, E, PI};
104104

105105
// #3273
106106
#[rustfmt::skip]
107-
use std::fmt::{self, {Display, Formatter}};
107+
use std::fmt::{self, {Display, Formatter}};

tests/source/imports_2015_edition.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
// rustfmt-normalize_comments: true
2+
// rustfmt-edition: 2015
3+
4+
// Imports.
5+
6+
// Long import.
7+
use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl};
8+
use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB};
9+
use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB};
10+
11+
use list::{
12+
// Some item
13+
SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item
14+
LastItem
15+
};
16+
17+
use test::{ Other /* C */ , /* A */ self /* B */ };
18+
19+
use syntax::{self};
20+
use {/* Pre-comment! */
21+
Foo, Bar /* comment */};
22+
use Foo::{Bar, Baz};
23+
pub use syntax::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath};
24+
25+
use syntax::some::{};
26+
27+
use self;
28+
use std::io::{self};
29+
use std::io::self;
30+
31+
mod Foo {
32+
pub use syntax::ast::{
33+
ItemForeignMod,
34+
ItemImpl,
35+
ItemMac,
36+
ItemMod,
37+
ItemStatic,
38+
ItemDefaultImpl
39+
};
40+
41+
mod Foo2 {
42+
pub use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, self, ItemDefaultImpl};
43+
}
44+
}
45+
46+
fn test() {
47+
use Baz::*;
48+
use Qux;
49+
}
50+
51+
// Simple imports
52+
use foo::bar::baz as baz ;
53+
use bar::quux as kaas;
54+
use foo;
55+
56+
// With aliases.
57+
use foo::{self as bar, baz};
58+
use foo::{self as bar};
59+
use foo::{qux as bar};
60+
use foo::{baz, qux as bar};
61+
62+
// With absolute paths
63+
use ::foo;
64+
use ::foo::{Bar};
65+
use ::foo::{Bar, Baz};
66+
use ::{Foo};
67+
use ::{Bar, Baz};
68+
69+
// Root globs
70+
use *;
71+
use ::*;
72+
73+
// spaces used to cause glob imports to disappear (#1356)
74+
use super:: * ;
75+
use foo::issue_1356:: * ;
76+
77+
// We shouldn't remove imports which have attributes attached (#1858)
78+
#[cfg(unix)]
79+
use self::unix::{};
80+
81+
// nested imports
82+
use foo::{a, bar::{baz, qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}}, b, boo, c,};
83+
84+
use fooo::{baar::{foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}}, z, bar, bar::*, x, y};
85+
86+
use exonum::{api::{Api, ApiError}, blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, crypto::{Hash, PublicKey}, helpers::Height, node::TransactionSend, storage::{ListProof, MapProof}};
87+
88+
// nested imports with a single sub-tree.
89+
use a::{b::{c::*}};
90+
use a::{b::{c::{}}};
91+
use a::{b::{c::d}};
92+
use a::{b::{c::{xxx, yyy, zzz}}};
93+
94+
// #2645
95+
/// This line is not affected.
96+
// This line is deleted.
97+
use c;
98+
99+
// #2670
100+
#[macro_use]
101+
use imports_with_attr;
102+
103+
// #2888
104+
use std::f64::consts::{SQRT_2, E, PI};
105+
106+
// #3273
107+
#[rustfmt::skip]
108+
use std::fmt::{self, {Display, Formatter}};

0 commit comments

Comments
 (0)