Skip to content

Commit 6eeb4fd

Browse files
Merge pull request #5670 from calebcartwright/subtree-sync-2023-01-24
Subtree sync 2023-01-24
2 parents aae222c + 18dd075 commit 6eeb4fd

36 files changed

+204
-166
lines changed

Processes.md

-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,3 @@ git tag -s v1.2.3 -m "Release 1.2.3"
5151
`cargo publish`
5252

5353
## 5. Create a PR to rust-lang/rust to update the rustfmt submodule
54-
55-
Note that if you are updating `rustc-ap-*` crates, then you need to update **every** submodules in the rust-lang/rust repository that depend on the crates to use the same version of those.
56-
57-
As of 2019/05, there are two such crates: `rls` and `racer` (`racer` depends on `rustc-ap-syntax` and `rls` depends on `racer`, and `rls` is one of submodules of the rust-lang/rust repository).

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ completed without error (whether or not changes were made).
135135
* [Emacs](https://github.com/rust-lang/rust-mode)
136136
* [Sublime Text 3](https://packagecontrol.io/packages/RustFmt)
137137
* [Atom](atom.md)
138-
* Visual Studio Code using [vscode-rust](https://github.com/editor-rs/vscode-rust), [vsc-rustfmt](https://github.com/Connorcpu/vsc-rustfmt) or [rls_vscode](https://github.com/jonathandturner/rls_vscode) through RLS.
138+
* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
139139
* [IntelliJ or CLion](intellij.md)
140140

141141

atom.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Running Rustfmt from Atom
22

3-
## RLS
3+
## rust-analyzer
44

5-
Rustfmt is included with the Rust Language Server, itself provided by [ide-rust](https://atom.io/packages/ide-rust).
5+
Rustfmt can be utilized from [rust-analyzer](https://rust-analyzer.github.io/) which is provided by [ide-rust](https://atom.io/packages/ide-rust).
66

77
`apm install ide-rust`
88

rust-toolchain

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-08-06"
3-
components = ["rustc-dev"]
2+
channel = "nightly-2023-01-24"
3+
components = ["llvm-tools", "rustc-dev"]

src/attr.rs

+19-15
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
4949
}
5050

5151
/// Returns attributes that are within `outer_span`.
52-
pub(crate) fn filter_inline_attrs(
53-
attrs: &[ast::Attribute],
54-
outer_span: Span,
55-
) -> Vec<ast::Attribute> {
52+
pub(crate) fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> ast::AttrVec {
5653
attrs
5754
.iter()
5855
.filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi())
@@ -263,7 +260,9 @@ impl Rewrite for ast::NestedMetaItem {
263260
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
264261
match self {
265262
ast::NestedMetaItem::MetaItem(ref meta_item) => meta_item.rewrite(context, shape),
266-
ast::NestedMetaItem::Literal(ref l) => rewrite_literal(context, l, shape),
263+
ast::NestedMetaItem::Lit(ref l) => {
264+
rewrite_literal(context, l.as_token_lit(), l.span, shape)
265+
}
267266
}
268267
}
269268
}
@@ -291,10 +290,10 @@ impl Rewrite for ast::MetaItem {
291290
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
292291
Some(match self.kind {
293292
ast::MetaItemKind::Word => {
294-
rewrite_path(context, PathContext::Type, None, &self.path, shape)?
293+
rewrite_path(context, PathContext::Type, &None, &self.path, shape)?
295294
}
296295
ast::MetaItemKind::List(ref list) => {
297-
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
296+
let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
298297
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
299298
overflow::rewrite_with_parens(
300299
context,
@@ -311,18 +310,18 @@ impl Rewrite for ast::MetaItem {
311310
}),
312311
)?
313312
}
314-
ast::MetaItemKind::NameValue(ref literal) => {
315-
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
313+
ast::MetaItemKind::NameValue(ref lit) => {
314+
let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
316315
// 3 = ` = `
317316
let lit_shape = shape.shrink_left(path.len() + 3)?;
318-
// `rewrite_literal` returns `None` when `literal` exceeds max
317+
// `rewrite_literal` returns `None` when `lit` exceeds max
319318
// width. Since a literal is basically unformattable unless it
320319
// is a string literal (and only if `format_strings` is set),
321320
// we might be better off ignoring the fact that the attribute
322321
// is longer than the max width and continue on formatting.
323322
// See #2479 for example.
324-
let value = rewrite_literal(context, literal, lit_shape)
325-
.unwrap_or_else(|| context.snippet(literal.span).to_owned());
323+
let value = rewrite_literal(context, lit.as_token_lit(), lit.span, lit_shape)
324+
.unwrap_or_else(|| context.snippet(lit.span).to_owned());
326325
format!("{} = {}", path, value)
327326
}
328327
})
@@ -528,14 +527,19 @@ pub(crate) trait MetaVisitor<'ast> {
528527

529528
fn visit_meta_word(&mut self, _meta_item: &'ast ast::MetaItem) {}
530529

531-
fn visit_meta_name_value(&mut self, _meta_item: &'ast ast::MetaItem, _lit: &'ast ast::Lit) {}
530+
fn visit_meta_name_value(
531+
&mut self,
532+
_meta_item: &'ast ast::MetaItem,
533+
_lit: &'ast ast::MetaItemLit,
534+
) {
535+
}
532536

533537
fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
534538
match nm {
535539
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
536-
ast::NestedMetaItem::Literal(ref lit) => self.visit_literal(lit),
540+
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
537541
}
538542
}
539543

540-
fn visit_literal(&mut self, _lit: &'ast ast::Lit) {}
544+
fn visit_meta_item_lit(&mut self, _lit: &'ast ast::MetaItemLit) {}
541545
}

src/chains.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ impl ChainItemKind {
199199

200200
fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
201201
let (kind, span) = match expr.kind {
202-
ast::ExprKind::MethodCall(ref segment, ref expressions, _) => {
203-
let types = if let Some(ref generic_args) = segment.args {
202+
ast::ExprKind::MethodCall(ref call) => {
203+
let types = if let Some(ref generic_args) = call.seg.args {
204204
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
205205
data.args
206206
.iter()
@@ -217,8 +217,8 @@ impl ChainItemKind {
217217
} else {
218218
vec![]
219219
};
220-
let span = mk_sp(expressions[0].span.hi(), expr.span.hi());
221-
let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
220+
let span = mk_sp(call.receiver.span.hi(), expr.span.hi());
221+
let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone());
222222
(kind, span)
223223
}
224224
ast::ExprKind::Field(ref nested, field) => {
@@ -307,7 +307,7 @@ impl ChainItem {
307307
format!("::<{}>", type_list.join(", "))
308308
};
309309
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
310-
rewrite_call(context, &callee_str, &args[1..], span, shape)
310+
rewrite_call(context, &callee_str, &args, span, shape)
311311
}
312312
}
313313

@@ -454,9 +454,7 @@ impl Chain {
454454
// is a try! macro, we'll convert it to shorthand when the option is set.
455455
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
456456
match expr.kind {
457-
ast::ExprKind::MethodCall(_, ref expressions, _) => {
458-
Some(Self::convert_try(&expressions[0], context))
459-
}
457+
ast::ExprKind::MethodCall(ref call) => Some(Self::convert_try(&call.receiver, context)),
460458
ast::ExprKind::Field(ref subexpr, _)
461459
| ast::ExprKind::Try(ref subexpr)
462460
| ast::ExprKind::Await(ref subexpr) => Some(Self::convert_try(subexpr, context)),

src/closures.rs

+36-14
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use crate::utils::{last_line_width, left_most_sub_expr, stmt_expr, NodeIdExt};
2626

2727
pub(crate) fn rewrite_closure(
2828
binder: &ast::ClosureBinder,
29+
constness: ast::Const,
2930
capture: ast::CaptureBy,
3031
is_async: &ast::Async,
3132
movability: ast::Movability,
@@ -38,7 +39,7 @@ pub(crate) fn rewrite_closure(
3839
debug!("rewrite_closure {:?}", body);
3940

4041
let (prefix, extra_offset) = rewrite_closure_fn_decl(
41-
binder, capture, is_async, movability, fn_decl, body, span, context, shape,
42+
binder, constness, capture, is_async, movability, fn_decl, body, span, context, shape,
4243
)?;
4344
// 1 = space between `|...|` and body.
4445
let body_shape = shape.offset_left(extra_offset)?;
@@ -230,6 +231,7 @@ fn rewrite_closure_block(
230231
// Return type is (prefix, extra_offset)
231232
fn rewrite_closure_fn_decl(
232233
binder: &ast::ClosureBinder,
234+
constness: ast::Const,
233235
capture: ast::CaptureBy,
234236
asyncness: &ast::Async,
235237
movability: ast::Movability,
@@ -250,6 +252,12 @@ fn rewrite_closure_fn_decl(
250252
ast::ClosureBinder::NotPresent => "".to_owned(),
251253
};
252254

255+
let const_ = if matches!(constness, ast::Const::Yes(_)) {
256+
"const "
257+
} else {
258+
""
259+
};
260+
253261
let immovable = if movability == ast::Movability::Static {
254262
"static "
255263
} else {
@@ -264,7 +272,7 @@ fn rewrite_closure_fn_decl(
264272
// 4 = "|| {".len(), which is overconservative when the closure consists of
265273
// a single expression.
266274
let nested_shape = shape
267-
.shrink_left(binder.len() + immovable.len() + is_async.len() + mover.len())?
275+
.shrink_left(binder.len() + const_.len() + immovable.len() + is_async.len() + mover.len())?
268276
.sub_width(4)?;
269277

270278
// 1 = |
@@ -302,7 +310,10 @@ fn rewrite_closure_fn_decl(
302310
.tactic(tactic)
303311
.preserve_newline(true);
304312
let list_str = write_list(&item_vec, &fmt)?;
305-
let mut prefix = format!("{}{}{}{}|{}|", binder, immovable, is_async, mover, list_str);
313+
let mut prefix = format!(
314+
"{}{}{}{}{}|{}|",
315+
binder, const_, immovable, is_async, mover, list_str
316+
);
306317

307318
if !ret_str.is_empty() {
308319
if prefix.contains('\n') {
@@ -326,16 +337,18 @@ pub(crate) fn rewrite_last_closure(
326337
expr: &ast::Expr,
327338
shape: Shape,
328339
) -> Option<String> {
329-
if let ast::ExprKind::Closure(
330-
ref binder,
331-
capture,
332-
ref is_async,
333-
movability,
334-
ref fn_decl,
335-
ref body,
336-
_,
337-
) = expr.kind
338-
{
340+
if let ast::ExprKind::Closure(ref closure) = expr.kind {
341+
let ast::Closure {
342+
ref binder,
343+
constness,
344+
capture_clause,
345+
ref asyncness,
346+
movability,
347+
ref fn_decl,
348+
ref body,
349+
fn_decl_span: _,
350+
fn_arg_span: _,
351+
} = **closure;
339352
let body = match body.kind {
340353
ast::ExprKind::Block(ref block, _)
341354
if !is_unsafe_block(block)
@@ -347,7 +360,16 @@ pub(crate) fn rewrite_last_closure(
347360
_ => body,
348361
};
349362
let (prefix, extra_offset) = rewrite_closure_fn_decl(
350-
binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
363+
binder,
364+
constness,
365+
capture_clause,
366+
asyncness,
367+
movability,
368+
fn_decl,
369+
body,
370+
expr.span,
371+
context,
372+
shape,
351373
)?;
352374
// If the closure goes multi line before its body, do not overflow the closure.
353375
if prefix.contains('\n') {

src/config/config_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::config::options::{IgnoreList, WidthHeuristics};
55
/// Trait for types that can be used in `Config`.
66
pub(crate) trait ConfigType: Sized {
77
/// Returns hint text for use in `Config::print_docs()`. For enum types, this is a
8-
/// pipe-separated list of variants; for other types it returns "<type>".
8+
/// pipe-separated list of variants; for other types it returns `<type>`.
99
fn doc_hint() -> String;
1010

1111
/// Return `true` if the variant (i.e. value of this type) is stable.

0 commit comments

Comments
 (0)