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

change default edition to 2018 #3942

Merged
merged 1 commit into from
Nov 27, 2019
Merged
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
2 changes: 1 addition & 1 deletion Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -2352,7 +2352,7 @@ Replace uses of the try! macro by the ? shorthand

```rust
fn main() {
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
}
```

Expand Down
4 changes: 2 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ create_config! {
"Maximum number of blank lines which can be put between items";
blank_lines_lower_bound: usize, 0, false,
"Minimum number of blank lines which must be put between items";
edition: Edition, Edition::Edition2015, true, "The edition of the parser (RFC 2052)";
edition: Edition, Edition::Edition2018, true, "The edition of the parser (RFC 2052)";
version: Version, Version::One, false, "Version of formatting rules";
inline_attribute_width: usize, 0, false,
"Write an item and its attribute on the same line \
Expand Down Expand Up @@ -531,7 +531,7 @@ trailing_comma = "Vertical"
match_block_trailing_comma = false
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
edition = "2015"
edition = "2018"
version = "One"
inline_attribute_width = 0
merge_derives = true
Expand Down
2 changes: 1 addition & 1 deletion src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ pub enum Edition {

impl Default for Edition {
fn default() -> Edition {
Edition::Edition2015
Edition::Edition2018
}
}

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

Expand Down
4 changes: 2 additions & 2 deletions tests/source/configs/indent_style/block_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ fn main() {
}

// nesting macro and function call
try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx));
try!(foo(try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)));
r#try!(foo(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx));
r#try!(foo(r#try!(xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)));
}

// #1521
Expand Down
2 changes: 1 addition & 1 deletion tests/source/configs/use_try_shorthand/false.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Use try! shorthand

fn main() {
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
}
2 changes: 1 addition & 1 deletion tests/source/configs/use_try_shorthand/true.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
// Use try! shorthand

fn main() {
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
let lorem = r#try!(ipsum.map(|dolor| dolor.sit()));
}
7 changes: 7 additions & 0 deletions tests/source/configs/use_try_shorthand/true_2015_edition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// rustfmt-use_try_shorthand: true
// rustfmt-edition: 2015
// Use try! shorthand

fn main() {
let lorem = try!(ipsum.map(|dolor| dolor.sit()));
}
4 changes: 2 additions & 2 deletions tests/source/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use foo::{baz, qux as bar};
use ::foo;
use ::foo::{Bar};
use ::foo::{Bar, Baz};
use ::{Foo};
use ::{qux};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was changed due to an existing bug I discovered during this process that only surfaces when using the 2018 edition (we didn't see it before because the default edition was 2015).

I've opened #3943 to track that separate issue

use ::{Bar, Baz};

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

// #3273
#[rustfmt::skip]
use std::fmt::{self, {Display, Formatter}};
use std::fmt::{self, {Display, Formatter}};
108 changes: 108 additions & 0 deletions tests/source/imports_2015_edition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// rustfmt-normalize_comments: true
// rustfmt-edition: 2015

// Imports.

// Long import.
use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, ItemDefaultImpl};
use exceedingly::looooooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB};
use exceedingly::loooooooooooooooooooooooooooooooooooooooooooooooooooooooong::import::path::{ItemA, ItemB};

use list::{
// Some item
SomeItem /* Comment */, /* Another item */ AnotherItem /* Another Comment */, // Last Item
LastItem
};

use test::{ Other /* C */ , /* A */ self /* B */ };

use syntax::{self};
use {/* Pre-comment! */
Foo, Bar /* comment */};
use Foo::{Bar, Baz};
pub use syntax::ast::{Expr_, Expr, ExprAssign, ExprCall, ExprMethodCall, ExprPath};

use syntax::some::{};

use self;
use std::io::{self};
use std::io::self;

mod Foo {
pub use syntax::ast::{
ItemForeignMod,
ItemImpl,
ItemMac,
ItemMod,
ItemStatic,
ItemDefaultImpl
};

mod Foo2 {
pub use syntax::ast::{ItemForeignMod, ItemImpl, ItemMac, ItemMod, ItemStatic, self, ItemDefaultImpl};
}
}

fn test() {
use Baz::*;
use Qux;
}

// Simple imports
use foo::bar::baz as baz ;
use bar::quux as kaas;
use foo;

// With aliases.
use foo::{self as bar, baz};
use foo::{self as bar};
use foo::{qux as bar};
use foo::{baz, qux as bar};

// With absolute paths
use ::foo;
use ::foo::{Bar};
use ::foo::{Bar, Baz};
use ::{Foo};
use ::{Bar, Baz};

// Root globs
use *;
use ::*;

// spaces used to cause glob imports to disappear (#1356)
use super:: * ;
use foo::issue_1356:: * ;

// We shouldn't remove imports which have attributes attached (#1858)
#[cfg(unix)]
use self::unix::{};

// nested imports
use foo::{a, bar::{baz, qux, xxxxxxxxxxx, yyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, foo::{a, b, cxxxxxxxxxxxxx, yyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz}}, b, boo, c,};

use fooo::{baar::{foobar::{xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz}}, z, bar, bar::*, x, y};

use exonum::{api::{Api, ApiError}, blockchain::{self, BlockProof, Blockchain, Transaction, TransactionSet}, crypto::{Hash, PublicKey}, helpers::Height, node::TransactionSend, storage::{ListProof, MapProof}};

// nested imports with a single sub-tree.
use a::{b::{c::*}};
use a::{b::{c::{}}};
use a::{b::{c::d}};
use a::{b::{c::{xxx, yyy, zzz}}};

// #2645
/// This line is not affected.
// This line is deleted.
use c;

// #2670
#[macro_use]
use imports_with_attr;

// #2888
use std::f64::consts::{SQRT_2, E, PI};

// #3273
#[rustfmt::skip]
use std::fmt::{self, {Display, Formatter}};
4 changes: 2 additions & 2 deletions tests/source/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn increment(& mut self, x: i32 );
}

pub trait WriteMessage {
fn write_message (&mut self, &FrontendMessage) -> io::Result<()>;
fn write_message (&mut self, fm: &FrontendMessage) -> io::Result<()>;
}

trait Runnable {
Expand Down Expand Up @@ -173,4 +173,4 @@ Send
+ DDDDDDD
+ DDDDDDDD
+ DDDDDDDDD
+ EEEEEEE;
+ EEEEEEE;
Loading