summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/rustfmt')
-rw-r--r--src/tools/rustfmt/src/bin/main.rs9
-rw-r--r--src/tools/rustfmt/src/chains.rs4
-rw-r--r--src/tools/rustfmt/src/expr.rs8
-rw-r--r--src/tools/rustfmt/src/types.rs6
-rw-r--r--src/tools/rustfmt/src/utils.rs1
-rw-r--r--src/tools/rustfmt/tests/source/type-ascription.rs10
-rw-r--r--src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs8
-rw-r--r--src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs8
-rw-r--r--src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs8
-rw-r--r--src/tools/rustfmt/tests/target/macros.rs22
-rw-r--r--src/tools/rustfmt/tests/target/negative-bounds.rs11
-rw-r--r--src/tools/rustfmt/tests/target/type-ascription.rs12
-rw-r--r--src/tools/rustfmt/tests/target/type.rs2
13 files changed, 50 insertions, 59 deletions
diff --git a/src/tools/rustfmt/src/bin/main.rs b/src/tools/rustfmt/src/bin/main.rs
index be64559e8..47846424b 100644
--- a/src/tools/rustfmt/src/bin/main.rs
+++ b/src/tools/rustfmt/src/bin/main.rs
@@ -1,3 +1,5 @@
+#![feature(rustc_private)]
+
use anyhow::{format_err, Result};
use io::Error as IoError;
@@ -19,7 +21,14 @@ use crate::rustfmt::{
FormatReportFormatterBuilder, Input, Session, Verbosity,
};
+const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug";
+
+// N.B. these crates are loaded from the sysroot, so they need extern crate.
+extern crate rustc_driver;
+
fn main() {
+ rustc_driver::install_ice_hook(BUG_REPORT_URL, |_| ());
+
env_logger::Builder::from_env("RUSTFMT_LOG").init();
let opts = make_opts();
diff --git a/src/tools/rustfmt/src/chains.rs b/src/tools/rustfmt/src/chains.rs
index cbe523c6c..0afce7cf6 100644
--- a/src/tools/rustfmt/src/chains.rs
+++ b/src/tools/rustfmt/src/chains.rs
@@ -232,7 +232,7 @@ impl ChainItemKind {
let span = mk_sp(nested.span.hi(), field.span.hi());
(kind, span)
}
- ast::ExprKind::Await(ref nested) => {
+ ast::ExprKind::Await(ref nested, _) => {
let span = mk_sp(nested.span.hi(), expr.span.hi());
(ChainItemKind::Await, span)
}
@@ -459,7 +459,7 @@ impl Chain {
ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
ast::ExprKind::Field(ref subexpr, _)
| ast::ExprKind::Try(ref subexpr)
- | ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),
+ | ast::ExprKind::Await(ref subexpr, _) => Some(Self::convert_try(subexpr, context)),
_ => None,
}
}
diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs
index ac96bedf2..5dc628adb 100644
--- a/src/tools/rustfmt/src/expr.rs
+++ b/src/tools/rustfmt/src/expr.rs
@@ -218,7 +218,7 @@ pub(crate) fn format_expr(
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::MethodCall(..)
- | ast::ExprKind::Await(_) => rewrite_chain(expr, context, shape),
+ | ast::ExprKind::Await(_, _) => rewrite_chain(expr, context, shape),
ast::ExprKind::MacCall(ref mac) => {
rewrite_macro(mac, None, context, shape, MacroPosition::Expression).or_else(|| {
wrap_str(
@@ -399,7 +399,9 @@ pub(crate) fn format_expr(
}
}
ast::ExprKind::Underscore => Some("_".to_owned()),
- ast::ExprKind::FormatArgs(..) | ast::ExprKind::IncludedBytes(..) => {
+ ast::ExprKind::FormatArgs(..)
+ | ast::ExprKind::IncludedBytes(..)
+ | ast::ExprKind::OffsetOf(..) => {
// These do not occur in the AST because macros aren't expanded.
unreachable!()
}
@@ -1887,7 +1889,7 @@ impl<'ast> RhsAssignKind<'ast> {
ast::ExprKind::Try(..)
| ast::ExprKind::Field(..)
| ast::ExprKind::MethodCall(..)
- | ast::ExprKind::Await(_)
+ | ast::ExprKind::Await(_, _)
)
}
_ => false,
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs
index 01e2fb6e6..f548388ed 100644
--- a/src/tools/rustfmt/src/types.rs
+++ b/src/tools/rustfmt/src/types.rs
@@ -552,6 +552,12 @@ impl Rewrite for ast::GenericBound {
ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
.rewrite(context, shape.offset_left(8)?)
.map(|s| format!("~const ?{}", s)),
+ ast::TraitBoundModifier::Negative => poly_trait_ref
+ .rewrite(context, shape.offset_left(1)?)
+ .map(|s| format!("!{}", s)),
+ ast::TraitBoundModifier::MaybeConstNegative => poly_trait_ref
+ .rewrite(context, shape.offset_left(8)?)
+ .map(|s| format!("~const !{}", s)),
};
rewrite.map(|s| if has_paren { format!("({})", s) } else { s })
}
diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs
index a26375ee6..ca1716574 100644
--- a/src/tools/rustfmt/src/utils.rs
+++ b/src/tools/rustfmt/src/utils.rs
@@ -499,6 +499,7 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
| ast::ExprKind::Field(..)
| ast::ExprKind::IncludedBytes(..)
| ast::ExprKind::InlineAsm(..)
+ | ast::ExprKind::OffsetOf(..)
| ast::ExprKind::Let(..)
| ast::ExprKind::Path(..)
| ast::ExprKind::Range(..)
diff --git a/src/tools/rustfmt/tests/source/type-ascription.rs b/src/tools/rustfmt/tests/source/type-ascription.rs
deleted file mode 100644
index 4874094cc..000000000
--- a/src/tools/rustfmt/tests/source/type-ascription.rs
+++ /dev/null
@@ -1,10 +0,0 @@
-
-fn main() {
- let xxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy : SomeTrait<AA, BB, CC>;
-
- let xxxxxxxxxxxxxxx = yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
-
- let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww): AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
-
- x : u32 - 1u32 / 10f32 : u32
-}
diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs b/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs
index 9dc2524c3..17ac1498c 100644
--- a/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs
+++ b/src/tools/rustfmt/tests/target/configs/format_macro_bodies/true.rs
@@ -1,10 +1,6 @@
// rustfmt-format_macro_bodies: true
macro_rules! foo {
- ($a: ident : $b: ty) => {
- $a(42): $b;
- };
- ($a: ident $b: ident $c: ident) => {
- $a = $b + $c;
- };
+ ($a: ident : $b: ty) => { $a(42): $b; };
+ ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
}
diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs
index 3966d21be..01ecac987 100644
--- a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs
+++ b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/false.rs
@@ -1,10 +1,6 @@
// rustfmt-format_macro_matchers: false
macro_rules! foo {
- ($a: ident : $b: ty) => {
- $a(42): $b;
- };
- ($a: ident $b: ident $c: ident) => {
- $a = $b + $c;
- };
+ ($a: ident : $b: ty) => { $a(42): $b; };
+ ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
}
diff --git a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs
index e113af96f..fa0442e22 100644
--- a/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs
+++ b/src/tools/rustfmt/tests/target/configs/format_macro_matchers/true.rs
@@ -1,10 +1,6 @@
// rustfmt-format_macro_matchers: true
macro_rules! foo {
- ($a:ident : $b:ty) => {
- $a(42): $b;
- };
- ($a:ident $b:ident $c:ident) => {
- $a = $b + $c;
- };
+ ($a: ident : $b: ty) => { $a(42): $b; };
+ ($a: ident $b: ident $c: ident) => { $a=$b+$c; };
}
diff --git a/src/tools/rustfmt/tests/target/macros.rs b/src/tools/rustfmt/tests/target/macros.rs
index e930b5037..7b4574349 100644
--- a/src/tools/rustfmt/tests/target/macros.rs
+++ b/src/tools/rustfmt/tests/target/macros.rs
@@ -122,7 +122,7 @@ fn main() {
20, 21, 22);
// #1092
- chain!(input, a: take!(max_size), || []);
+ chain!(input, a:take!(max_size), || []);
// #2727
foo!("bar");
@@ -156,17 +156,13 @@ fn issue1178() {
}
fn issue1739() {
- sql_function!(
- add_rss_item,
- add_rss_item_t,
- (
- a: types::Integer,
- b: types::Timestamptz,
- c: types::Text,
- d: types::Text,
- e: types::Text
- )
- );
+ sql_function!(add_rss_item,
+ add_rss_item_t,
+ (a: types::Integer,
+ b: types::Timestamptz,
+ c: types::Text,
+ d: types::Text,
+ e: types::Text));
w.slice_mut(s![
..,
@@ -232,7 +228,7 @@ fn issue_3174() {
"debugMessage": debug.message,
})
} else {
- json!({ "errorKind": format!("{:?}", error.err_kind()) })
+ json!({"errorKind": format!("{:?}", error.err_kind())})
};
}
diff --git a/src/tools/rustfmt/tests/target/negative-bounds.rs b/src/tools/rustfmt/tests/target/negative-bounds.rs
new file mode 100644
index 000000000..4fb35cccf
--- /dev/null
+++ b/src/tools/rustfmt/tests/target/negative-bounds.rs
@@ -0,0 +1,11 @@
+fn negative()
+where
+ i32: !Copy,
+{
+}
+
+fn maybe_const_negative()
+where
+ i32: ~const !Copy,
+{
+}
diff --git a/src/tools/rustfmt/tests/target/type-ascription.rs b/src/tools/rustfmt/tests/target/type-ascription.rs
deleted file mode 100644
index a2f082ba4..000000000
--- a/src/tools/rustfmt/tests/target/type-ascription.rs
+++ /dev/null
@@ -1,12 +0,0 @@
-fn main() {
- let xxxxxxxxxxx =
- yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: SomeTrait<AA, BB, CC>;
-
- let xxxxxxxxxxxxxxx =
- yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
-
- let z = funk(yyyyyyyyyyyyyyy, zzzzzzzzzzzzzzzz, wwwwww):
- AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA;
-
- x: u32 - 1u32 / 10f32: u32
-}
diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs
index 38cf909c2..c789ecb05 100644
--- a/src/tools/rustfmt/tests/target/type.rs
+++ b/src/tools/rustfmt/tests/target/type.rs
@@ -129,7 +129,7 @@ fn issue3117() {
fn issue3139() {
assert_eq!(
to_json_value(&None::<i32>).unwrap(),
- json!({ "test": None::<i32> })
+ json!( { "test": None :: <i32> } )
);
}