Skip to content

Commit

Permalink
Merge pull request rust-lang#5670 from calebcartwright/subtree-sync-2…
Browse files Browse the repository at this point in the history
…023-01-24

Subtree sync 2023-01-24
  • Loading branch information
calebcartwright authored Jan 24, 2023
2 parents aae222c + 18dd075 commit 6eeb4fd
Show file tree
Hide file tree
Showing 36 changed files with 204 additions and 166 deletions.
4 changes: 0 additions & 4 deletions Processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,3 @@ git tag -s v1.2.3 -m "Release 1.2.3"
`cargo publish`

## 5. Create a PR to rust-lang/rust to update the rustfmt submodule

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.

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).
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ completed without error (whether or not changes were made).
* [Emacs](https://github.com/rust-lang/rust-mode)
* [Sublime Text 3](https://packagecontrol.io/packages/RustFmt)
* [Atom](atom.md)
* 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.
* [Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer)
* [IntelliJ or CLion](intellij.md)


Expand Down
4 changes: 2 additions & 2 deletions atom.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Running Rustfmt from Atom

## RLS
## rust-analyzer

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

`apm install ide-rust`

Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2022-08-06"
components = ["rustc-dev"]
channel = "nightly-2023-01-24"
components = ["llvm-tools", "rustc-dev"]
34 changes: 19 additions & 15 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,7 @@ pub(crate) fn get_span_without_attrs(stmt: &ast::Stmt) -> Span {
}

/// Returns attributes that are within `outer_span`.
pub(crate) fn filter_inline_attrs(
attrs: &[ast::Attribute],
outer_span: Span,
) -> Vec<ast::Attribute> {
pub(crate) fn filter_inline_attrs(attrs: &[ast::Attribute], outer_span: Span) -> ast::AttrVec {
attrs
.iter()
.filter(|a| outer_span.lo() <= a.span.lo() && a.span.hi() <= outer_span.hi())
Expand Down Expand Up @@ -263,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::Literal(ref l) => rewrite_literal(context, l, shape),
ast::NestedMetaItem::Lit(ref l) => {
rewrite_literal(context, l.as_token_lit(), l.span, shape)
}
}
}
}
Expand Down Expand Up @@ -291,10 +290,10 @@ impl Rewrite for ast::MetaItem {
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
Some(match self.kind {
ast::MetaItemKind::Word => {
rewrite_path(context, PathContext::Type, None, &self.path, shape)?
rewrite_path(context, PathContext::Type, &None, &self.path, shape)?
}
ast::MetaItemKind::List(ref list) => {
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
let path = rewrite_path(context, PathContext::Type, &None, &self.path, shape)?;
let has_trailing_comma = crate::expr::span_ends_with_comma(context, self.span);
overflow::rewrite_with_parens(
context,
Expand All @@ -311,18 +310,18 @@ impl Rewrite for ast::MetaItem {
}),
)?
}
ast::MetaItemKind::NameValue(ref literal) => {
let path = rewrite_path(context, PathContext::Type, None, &self.path, shape)?;
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, 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)
}
})
Expand Down Expand Up @@ -528,14 +527,19 @@ pub(crate) trait MetaVisitor<'ast> {

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

fn visit_meta_name_value(&mut self, _meta_item: &'ast ast::MetaItem, _lit: &'ast ast::Lit) {}
fn visit_meta_name_value(
&mut self,
_meta_item: &'ast ast::MetaItem,
_lit: &'ast ast::MetaItemLit,
) {
}

fn visit_nested_meta_item(&mut self, nm: &'ast ast::NestedMetaItem) {
match nm {
ast::NestedMetaItem::MetaItem(ref meta_item) => self.visit_meta_item(meta_item),
ast::NestedMetaItem::Literal(ref lit) => self.visit_literal(lit),
ast::NestedMetaItem::Lit(ref lit) => self.visit_meta_item_lit(lit),
}
}

fn visit_literal(&mut self, _lit: &'ast ast::Lit) {}
fn visit_meta_item_lit(&mut self, _lit: &'ast ast::MetaItemLit) {}
}
14 changes: 6 additions & 8 deletions src/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ impl ChainItemKind {

fn from_ast(context: &RewriteContext<'_>, expr: &ast::Expr) -> (ChainItemKind, Span) {
let (kind, span) = match expr.kind {
ast::ExprKind::MethodCall(ref segment, ref expressions, _) => {
let types = if let Some(ref generic_args) = segment.args {
ast::ExprKind::MethodCall(ref call) => {
let types = if let Some(ref generic_args) = call.seg.args {
if let ast::GenericArgs::AngleBracketed(ref data) = **generic_args {
data.args
.iter()
Expand All @@ -217,8 +217,8 @@ impl ChainItemKind {
} else {
vec![]
};
let span = mk_sp(expressions[0].span.hi(), expr.span.hi());
let kind = ChainItemKind::MethodCall(segment.clone(), types, expressions.clone());
let span = mk_sp(call.receiver.span.hi(), expr.span.hi());
let kind = ChainItemKind::MethodCall(call.seg.clone(), types, call.args.clone());
(kind, span)
}
ast::ExprKind::Field(ref nested, field) => {
Expand Down Expand Up @@ -307,7 +307,7 @@ impl ChainItem {
format!("::<{}>", type_list.join(", "))
};
let callee_str = format!(".{}{}", rewrite_ident(context, method_name), type_str);
rewrite_call(context, &callee_str, &args[1..], span, shape)
rewrite_call(context, &callee_str, &args, span, shape)
}
}

Expand Down Expand Up @@ -454,9 +454,7 @@ impl Chain {
// is a try! macro, we'll convert it to shorthand when the option is set.
fn pop_expr_chain(expr: &ast::Expr, context: &RewriteContext<'_>) -> Option<ast::Expr> {
match expr.kind {
ast::ExprKind::MethodCall(_, ref expressions, _) => {
Some(Self::convert_try(&expressions[0], context))
}
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)),
Expand Down
50 changes: 36 additions & 14 deletions src/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)?;
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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 = |
Expand Down Expand Up @@ -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') {
Expand All @@ -326,16 +337,18 @@ pub(crate) fn rewrite_last_closure(
expr: &ast::Expr,
shape: Shape,
) -> Option<String> {
if let ast::ExprKind::Closure(
ref binder,
capture,
ref is_async,
movability,
ref fn_decl,
ref body,
_,
) = expr.kind
{
if let ast::ExprKind::Closure(ref closure) = expr.kind {
let ast::Closure {
ref binder,
constness,
capture_clause,
ref asyncness,
movability,
ref fn_decl,
ref body,
fn_decl_span: _,
fn_arg_span: _,
} = **closure;
let body = match body.kind {
ast::ExprKind::Block(ref block, _)
if !is_unsafe_block(block)
Expand All @@ -347,7 +360,16 @@ pub(crate) fn rewrite_last_closure(
_ => body,
};
let (prefix, extra_offset) = rewrite_closure_fn_decl(
binder, capture, is_async, movability, fn_decl, body, expr.span, context, shape,
binder,
constness,
capture_clause,
asyncness,
movability,
fn_decl,
body,
expr.span,
context,
shape,
)?;
// If the closure goes multi line before its body, do not overflow the closure.
if prefix.contains('\n') {
Expand Down
2 changes: 1 addition & 1 deletion src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::config::options::{IgnoreList, WidthHeuristics};
/// Trait for types that can be used in `Config`.
pub(crate) trait ConfigType: Sized {
/// Returns hint text for use in `Config::print_docs()`. For enum types, this is a
/// pipe-separated list of variants; for other types it returns "<type>".
/// pipe-separated list of variants; for other types it returns `<type>`.
fn doc_hint() -> String;

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

0 comments on commit 6eeb4fd

Please sign in to comment.