summaryrefslogtreecommitdiffstats
path: root/src/tools/rustfmt
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:03 +0000
commit64d98f8ee037282c35007b64c2649055c56af1db (patch)
tree5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /src/tools/rustfmt
parentAdding debian version 1.67.1+dfsg1-1. (diff)
downloadrustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz
rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rustfmt')
-rw-r--r--src/tools/rustfmt/src/attr.rs12
-rw-r--r--src/tools/rustfmt/src/closures.rs19
-rw-r--r--src/tools/rustfmt/src/expr.rs1
-rw-r--r--src/tools/rustfmt/src/lib.rs5
-rw-r--r--src/tools/rustfmt/src/types.rs4
-rw-r--r--src/tools/rustfmt/tests/source/issue-2445.rs4
-rw-r--r--src/tools/rustfmt/tests/target/issue-2445.rs4
-rw-r--r--src/tools/rustfmt/tests/target/issue_4110.rs1
8 files changed, 36 insertions, 14 deletions
diff --git a/src/tools/rustfmt/src/attr.rs b/src/tools/rustfmt/src/attr.rs
index 2ac703b95..c503eeeb9 100644
--- a/src/tools/rustfmt/src/attr.rs
+++ b/src/tools/rustfmt/src/attr.rs
@@ -260,7 +260,9 @@ impl Rewrite for ast::NestedMetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
match self {
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
- ast::NestedMetaItem::Lit(ref l) => rewrite_literal(context, l.token_lit, l.span, shape),
+ ast::NestedMetaItem::Lit(ref l) => {
+ rewrite_literal(context, l.as_token_lit(), l.span, shape)
+ }
}
}
}
@@ -308,18 +310,18 @@ impl Rewrite for ast::MetaItem {
}),
)?
}
- ast::MetaItemKind::NameValue(ref literal) => {
+ ast::MetaItemKind::NameValue(ref lit) => {
let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
// 3 = ` = `
let lit_shape = shape.shrink_left(path.len() + 3)?;
- // `rewrite_literal` returns `None` when `literal` exceeds max
+ // `rewrite_literal` returns `None` when `lit` exceeds max
// width. Since a literal is basically unformattable unless it
// is a string literal (and only if `format_strings` is set),
// we might be better off ignoring the fact that the attribute
// is longer than the max width and continue on formatting.
// See #2479 for example.
- let value = rewrite_literal(context, literal.token_lit, literal.span, lit_shape)
- .unwrap_or_else(|| context.snippet(literal.span).to_owned());
+ let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape)
+ .unwrap_or_else(|| context.snippet(lit.span).to_owned());
format!("{} = {}", path, value)
}
})
diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs
index 244d4427c..8fd0fcf8f 100644
--- a/src/tools/rustfmt/src/closures.rs
+++ b/src/tools/rustfmt/src/closures.rs
@@ -26,6 +26,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
pub(crate) fn rewrite_closure(
binder: &ast::ClosureBinder,
+ constness: ast::Const,
capture: ast::CaptureBy,
is_async: &ast::Async,
movability: ast::Movability,
@@ -38,7 +39,7 @@ pub(crate) fn rewrite_closure(
debug!("rewrite_closure {:?}", body);
let (prefix, extra_offset) = rewrite_closure_fn_decl(
- binder, capture, is_async, movability, fn_decl, body, span, context, shape,
+ binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
)?;
// 1 = space between `|...|` and body.
let body_shape = shape.offset_left(extra_offset)?;
@@ -230,6 +231,7 @@ fn rewrite_closure_block(
// Return type is (prefix, extra_offset)
fn rewrite_closure_fn_decl(
binder: &ast::ClosureBinder,
+ constness: ast::Const,
capture: ast::CaptureBy,
asyncness: &ast::Async,
movability: ast::Movability,
@@ -250,6 +252,12 @@ fn rewrite_closure_fn_decl(
ast::ClosureBinder::NotPresent => "".to_owned(),
};
+ let const_ = if matches!(constness, ast::Const::Yes(_)) {
+ "const "
+ } else {
+ ""
+ };
+
let immovable = if movability == ast::Movability::Static {
"static "
} else {
@@ -264,7 +272,7 @@ fn rewrite_closure_fn_decl(
// 4 = "|| {".len(), which is overconservative when the closure consists of
// a single expression.
let nested_shape = shape
- .shrink_left(binder.len() + immovable.len() + is_async.len() + mover.len())?
+ .shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())?
.sub_width(4)?;
// 1 = |
@@ -302,7 +310,10 @@ fn rewrite_closure_fn_decl(
.tactic(tactic)
.preserve_newline(true);
let list_str = write_list(&item_vec, &fmt)?;
- let mut prefix = format!("{}{}{}{}|{}|", binder, immovable, is_async, mover, list_str);
+ let mut prefix = format!(
+ "{}{}{}{}{}|{}|",
+ binder, const_, immovable, is_async, mover, list_str
+ );
if !ret_str.is_empty() {
if prefix.contains('\n') {
@@ -329,6 +340,7 @@ pub(crate) fn rewrite_last_closure(
if let ast::ExprKind::Closure(ref closure) = expr.kind {
let ast::Closure {
ref binder,
+ constness,
capture_clause,
ref asyncness,
movability,
@@ -349,6 +361,7 @@ pub(crate) fn rewrite_last_closure(
};
let (prefix, extra_offset) = rewrite_closure_fn_decl(
binder,
+ constness,
capture_clause,
asyncness,
movability,
diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs
index 414e76769..868ff045a 100644
--- a/src/tools/rustfmt/src/expr.rs
+++ b/src/tools/rustfmt/src/expr.rs
@@ -205,6 +205,7 @@ pub(crate) fn format_expr(
}
ast::ExprKind::Closure(ref cl) => closures::rewrite_closure(
&cl.binder,
+ cl.constness,
cl.capture_clause,
&cl.asyncness,
cl.movability,
diff --git a/src/tools/rustfmt/src/lib.rs b/src/tools/rustfmt/src/lib.rs
index 1d1ef525f..0c27bcacf 100644
--- a/src/tools/rustfmt/src/lib.rs
+++ b/src/tools/rustfmt/src/lib.rs
@@ -24,6 +24,11 @@ extern crate rustc_parse;
extern crate rustc_session;
extern crate rustc_span;
+// Necessary to pull in object code as the rest of the rustc crates are shipped only as rmeta
+// files.
+#[allow(unused_extern_crates)]
+extern crate rustc_driver;
+
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs
index d5177a205..c1991e8d2 100644
--- a/src/tools/rustfmt/src/types.rs
+++ b/src/tools/rustfmt/src/types.rs
@@ -688,7 +688,7 @@ impl Rewrite for ast::Ty {
rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
}
- ast::TyKind::Rptr(ref lifetime, ref mt) => {
+ ast::TyKind::Ref(ref lifetime, ref mt) => {
let mut_str = format_mutability(mt.mutbl);
let mut_len = mut_str.len();
let mut result = String::with_capacity(128);
@@ -1059,7 +1059,7 @@ pub(crate) fn can_be_overflowed_type(
) -> bool {
match ty.kind {
ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
- ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
+ ast::TyKind::Ref(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
can_be_overflowed_type(context, &*mutty.ty, len)
}
_ => false,
diff --git a/src/tools/rustfmt/tests/source/issue-2445.rs b/src/tools/rustfmt/tests/source/issue-2445.rs
index 84ce6e647..deef429db 100644
--- a/src/tools/rustfmt/tests/source/issue-2445.rs
+++ b/src/tools/rustfmt/tests/source/issue-2445.rs
@@ -1,6 +1,6 @@
test!(RunPassPretty {
// comment
- path: "src/test/run-pass/pretty",
+ path: "tests/run-pass/pretty",
mode: "pretty",
suite: "run-pass",
default: false,
@@ -9,7 +9,7 @@ test!(RunPassPretty {
test!(RunPassPretty {
// comment
- path: "src/test/run-pass/pretty",
+ path: "tests/run-pass/pretty",
mode: "pretty",
suite: "run-pass",
default: false,
diff --git a/src/tools/rustfmt/tests/target/issue-2445.rs b/src/tools/rustfmt/tests/target/issue-2445.rs
index 1bc7752fd..463c5d495 100644
--- a/src/tools/rustfmt/tests/target/issue-2445.rs
+++ b/src/tools/rustfmt/tests/target/issue-2445.rs
@@ -1,6 +1,6 @@
test!(RunPassPretty {
// comment
- path: "src/test/run-pass/pretty",
+ path: "tests/run-pass/pretty",
mode: "pretty",
suite: "run-pass",
default: false,
@@ -9,7 +9,7 @@ test!(RunPassPretty {
test!(RunPassPretty {
// comment
- path: "src/test/run-pass/pretty",
+ path: "tests/run-pass/pretty",
mode: "pretty",
suite: "run-pass",
default: false,
diff --git a/src/tools/rustfmt/tests/target/issue_4110.rs b/src/tools/rustfmt/tests/target/issue_4110.rs
index 4a58c3946..d3734e90b 100644
--- a/src/tools/rustfmt/tests/target/issue_4110.rs
+++ b/src/tools/rustfmt/tests/target/issue_4110.rs
@@ -20,6 +20,7 @@ fn bindings() {
category,
span,
&format!("`{}`", name),
+ "function",
),
(
ref name,