Skip to content

Commit b9178dc

Browse files
Merge pull request rust-lang#5036 from calebcartwright/1.4.38-subtree
sync subtree
2 parents 1ae5c35 + 5f79583 commit b9178dc

File tree

21 files changed

+69
-149
lines changed

21 files changed

+69
-149
lines changed

Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33
name = "rustfmt-nightly"
44
version = "1.4.37"
5-
authors = ["Nicholas Cameron <[email protected]>", "The Rustfmt developers"]
65
description = "Tool to find and fix Rust formatting issues"
76
repository = "https://github.com/rust-lang/rustfmt"
87
readme = "README.md"
98
license = "Apache-2.0/MIT"
109
build = "build.rs"
1110
categories = ["development-tools"]
12-
edition = "2018"
11+
edition = "2021"
1312

1413
[[bin]]
1514
name = "rustfmt"

config_proc_macro/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
[package]
22
name = "rustfmt-config_proc_macro"
33
version = "0.2.0"
4-
authors = ["topecongiro <[email protected]>"]
54
edition = "2018"
65
description = "A collection of procedural macros for rustfmt"
76
license = "Apache-2.0/MIT"

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-07-23"
2+
channel = "nightly-2021-10-20"
33
components = ["rustc-dev"]

src/closures.rs

+1
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ fn rewrite_closure_with_block(
160160
.first()
161161
.map(|attr| attr.span.to(body.span))
162162
.unwrap_or(body.span),
163+
could_be_bare_literal: false,
163164
};
164165
let block = crate::expr::rewrite_block_with_visitor(
165166
context,

src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ struct ControlFlow<'a> {
616616

617617
fn extract_pats_and_cond(expr: &ast::Expr) -> (Option<&ast::Pat>, &ast::Expr) {
618618
match expr.kind {
619-
ast::ExprKind::Let(ref pat, ref cond) => (Some(pat), cond),
619+
ast::ExprKind::Let(ref pat, ref cond, _) => (Some(pat), cond),
620620
_ => (None, expr),
621621
}
622622
}

src/items.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering};
66
use regex::Regex;
77
use rustc_ast::visit;
88
use rustc_ast::{ast, ptr};
9-
use rustc_span::{symbol, BytePos, Span};
9+
use rustc_span::{symbol, BytePos, Span, DUMMY_SP};
1010

1111
use crate::attr::filter_inline_attrs;
1212
use crate::comment::{
@@ -31,7 +31,12 @@ use crate::stmt::Stmt;
3131
use crate::utils::*;
3232
use crate::vertical::rewrite_with_alignment;
3333
use crate::visitor::FmtVisitor;
34-
use crate::DEFAULT_VISIBILITY;
34+
35+
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
36+
kind: ast::VisibilityKind::Inherited,
37+
span: DUMMY_SP,
38+
tokens: None,
39+
};
3540

3641
fn type_annotation_separator(config: &Config) -> &str {
3742
colon_spaces(config)
@@ -48,7 +53,7 @@ impl Rewrite for ast::Local {
4853

4954
skip_out_of_file_lines_range!(context, self.span);
5055

51-
if contains_skip(&self.attrs) {
56+
if contains_skip(&self.attrs) || matches!(self.kind, ast::LocalKind::InitElse(..)) {
5257
return None;
5358
}
5459

@@ -97,7 +102,7 @@ impl Rewrite for ast::Local {
97102
infix.push_str(&rewrite);
98103
}
99104

100-
if self.init.is_some() {
105+
if self.kind.init().is_some() {
101106
infix.push_str(" =");
102107
}
103108

@@ -106,11 +111,12 @@ impl Rewrite for ast::Local {
106111

107112
result.push_str(&infix);
108113

109-
if let Some(ref ex) = self.init {
114+
if let Some((init, _els)) = self.kind.init_else_opt() {
110115
// 1 = trailing semicolon;
111116
let nested_shape = shape.sub_width(1)?;
112117

113-
result = rewrite_assign_rhs(context, result, &**ex, nested_shape)?;
118+
result = rewrite_assign_rhs(context, result, init, nested_shape)?;
119+
// todo else
114120
}
115121

116122
result.push(';');
@@ -972,7 +978,7 @@ impl<'a> StructParts<'a> {
972978
format_header(context, self.prefix, self.ident, self.vis, offset)
973979
}
974980

975-
pub(crate) fn from_variant(variant: &'a ast::Variant) -> Self {
981+
fn from_variant(variant: &'a ast::Variant) -> Self {
976982
StructParts {
977983
prefix: "",
978984
ident: variant.ident,

src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::path::PathBuf;
3232
use std::rc::Rc;
3333

3434
use rustc_ast::ast;
35-
use rustc_span::{symbol, DUMMY_SP};
35+
use rustc_span::symbol;
3636
use thiserror::Error;
3737

3838
use crate::comment::LineClasses;
@@ -96,11 +96,6 @@ mod types;
9696
mod vertical;
9797
pub(crate) mod visitor;
9898

99-
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
100-
kind: ast::VisibilityKind::Inherited,
101-
span: DUMMY_SP,
102-
tokens: None,
103-
};
10499
/// The various errors that can occur during formatting. Note that not all of
105100
/// these can currently be propagated to clients.
106101
#[derive(Error, Debug)]

src/macros.rs

+14-32
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ fn rewrite_macro_inner(
401401
handle_vec_semi(context, shape, arg_vec, macro_name, style)
402402
} else {
403403
// If we are rewriting `vec!` macro or other special macros,
404-
// then we can rewrite this as an usual array literal.
404+
// then we can rewrite this as a usual array literal.
405405
// Otherwise, we must preserve the original existence of trailing comma.
406406
let macro_name = &macro_name.as_str();
407407
let mut force_trailing_comma = if trailing_comma {
@@ -762,7 +762,6 @@ impl MacroArgKind {
762762
#[derive(Debug, Clone)]
763763
struct ParsedMacroArg {
764764
kind: MacroArgKind,
765-
span: Span,
766765
}
767766

768767
impl ParsedMacroArg {
@@ -780,14 +779,10 @@ impl ParsedMacroArg {
780779
struct MacroArgParser {
781780
/// Either a name of the next metavariable, a separator, or junk.
782781
buf: String,
783-
/// The start position on the current buffer.
784-
lo: BytePos,
785782
/// The first token of the current buffer.
786783
start_tok: Token,
787784
/// `true` if we are parsing a metavariable or a repeat.
788785
is_meta_var: bool,
789-
/// The position of the last token.
790-
hi: BytePos,
791786
/// The last token parsed.
792787
last_tok: Token,
793788
/// Holds the parsed arguments.
@@ -807,8 +802,6 @@ fn last_tok(tt: &TokenTree) -> Token {
807802
impl MacroArgParser {
808803
fn new() -> MacroArgParser {
809804
MacroArgParser {
810-
lo: BytePos(0),
811-
hi: BytePos(0),
812805
buf: String::new(),
813806
is_meta_var: false,
814807
last_tok: Token {
@@ -824,7 +817,6 @@ impl MacroArgParser {
824817
}
825818

826819
fn set_last_tok(&mut self, tok: &TokenTree) {
827-
self.hi = tok.span().hi();
828820
self.last_tok = last_tok(tok);
829821
}
830822

@@ -836,7 +828,6 @@ impl MacroArgParser {
836828
};
837829
self.result.push(ParsedMacroArg {
838830
kind: MacroArgKind::Separator(self.buf.clone(), prefix),
839-
span: mk_sp(self.lo, self.hi),
840831
});
841832
self.buf.clear();
842833
}
@@ -849,7 +840,6 @@ impl MacroArgParser {
849840
};
850841
self.result.push(ParsedMacroArg {
851842
kind: MacroArgKind::Other(self.buf.clone(), prefix),
852-
span: mk_sp(self.lo, self.hi),
853843
});
854844
self.buf.clear();
855845
}
@@ -858,11 +848,10 @@ impl MacroArgParser {
858848
match iter.next() {
859849
Some(TokenTree::Token(Token {
860850
kind: TokenKind::Ident(name, _),
861-
span,
851+
..
862852
})) => {
863853
self.result.push(ParsedMacroArg {
864854
kind: MacroArgKind::MetaVariable(name, self.buf.clone()),
865-
span: mk_sp(self.lo, span.hi()),
866855
});
867856

868857
self.buf.clear();
@@ -873,10 +862,9 @@ impl MacroArgParser {
873862
}
874863
}
875864

876-
fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken, span: Span) {
865+
fn add_delimited(&mut self, inner: Vec<ParsedMacroArg>, delim: DelimToken) {
877866
self.result.push(ParsedMacroArg {
878867
kind: MacroArgKind::Delimited(delim, inner),
879-
span,
880868
});
881869
}
882870

@@ -886,19 +874,15 @@ impl MacroArgParser {
886874
inner: Vec<ParsedMacroArg>,
887875
delim: DelimToken,
888876
iter: &mut Cursor,
889-
span: Span,
890877
) -> Option<()> {
891878
let mut buffer = String::new();
892879
let mut first = true;
893-
let mut lo = span.lo();
894-
let mut hi = span.hi();
895880

896881
// Parse '*', '+' or '?.
897882
for tok in iter {
898883
self.set_last_tok(&tok);
899884
if first {
900885
first = false;
901-
lo = tok.span().lo();
902886
}
903887

904888
match tok {
@@ -918,7 +902,6 @@ impl MacroArgParser {
918902
}
919903
TokenTree::Token(ref t) => {
920904
buffer.push_str(&pprust::token_to_string(&t));
921-
hi = t.span.hi();
922905
}
923906
_ => return None,
924907
}
@@ -930,20 +913,17 @@ impl MacroArgParser {
930913
} else {
931914
Some(Box::new(ParsedMacroArg {
932915
kind: MacroArgKind::Other(buffer, "".to_owned()),
933-
span: mk_sp(lo, hi),
934916
}))
935917
};
936918

937919
self.result.push(ParsedMacroArg {
938920
kind: MacroArgKind::Repeat(delim, inner, another, self.last_tok.clone()),
939-
span: mk_sp(self.lo, self.hi),
940921
});
941922
Some(())
942923
}
943924

944925
fn update_buffer(&mut self, t: &Token) {
945926
if self.buf.is_empty() {
946-
self.lo = t.span.lo();
947927
self.start_tok = t.clone();
948928
} else {
949929
let needs_space = match next_space(&self.last_tok.kind) {
@@ -999,7 +979,6 @@ impl MacroArgParser {
999979

1000980
// Start keeping the name of this metavariable in the buffer.
1001981
self.is_meta_var = true;
1002-
self.lo = span.lo();
1003982
self.start_tok = Token {
1004983
kind: TokenKind::Dollar,
1005984
span,
@@ -1012,7 +991,7 @@ impl MacroArgParser {
1012991
self.add_meta_variable(&mut iter)?;
1013992
}
1014993
TokenTree::Token(ref t) => self.update_buffer(t),
1015-
TokenTree::Delimited(delimited_span, delimited, ref tts) => {
994+
TokenTree::Delimited(_delimited_span, delimited, ref tts) => {
1016995
if !self.buf.is_empty() {
1017996
if next_space(&self.last_tok.kind) == SpaceState::Always {
1018997
self.add_separator();
@@ -1022,16 +1001,14 @@ impl MacroArgParser {
10221001
}
10231002

10241003
// Parse the stuff inside delimiters.
1025-
let mut parser = MacroArgParser::new();
1026-
parser.lo = delimited_span.open.lo();
1004+
let parser = MacroArgParser::new();
10271005
let delimited_arg = parser.parse(tts.clone())?;
10281006

1029-
let span = delimited_span.entire();
10301007
if self.is_meta_var {
1031-
self.add_repeat(delimited_arg, delimited, &mut iter, span)?;
1008+
self.add_repeat(delimited_arg, delimited, &mut iter)?;
10321009
self.is_meta_var = false;
10331010
} else {
1034-
self.add_delimited(delimited_arg, delimited, span);
1011+
self.add_delimited(delimited_arg, delimited);
10351012
}
10361013
}
10371014
}
@@ -1270,7 +1247,12 @@ impl MacroParser {
12701247
let data = delimited_span.entire().data();
12711248
(
12721249
data.hi,
1273-
Span::new(data.lo + BytePos(1), data.hi - BytePos(1), data.ctxt),
1250+
Span::new(
1251+
data.lo + BytePos(1),
1252+
data.hi - BytePos(1),
1253+
data.ctxt,
1254+
data.parent,
1255+
),
12741256
delimited_span.entire(),
12751257
)
12761258
}
@@ -1417,7 +1399,7 @@ impl MacroBranch {
14171399
}
14181400
}
14191401

1420-
/// Format `lazy_static!` from https://crates.io/crates/lazy_static.
1402+
/// Format `lazy_static!` from <https://crates.io/crates/lazy_static>.
14211403
///
14221404
/// # Expected syntax
14231405
///

src/modules.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>;
2727
pub(crate) struct Module<'a> {
2828
ast_mod_kind: Option<Cow<'a, ast::ModKind>>,
2929
pub(crate) items: Cow<'a, Vec<rustc_ast::ptr::P<ast::Item>>>,
30-
attrs: Cow<'a, Vec<ast::Attribute>>,
3130
inner_attr: Vec<ast::Attribute>,
3231
pub(crate) span: Span,
3332
}
@@ -46,7 +45,6 @@ impl<'a> Module<'a> {
4645
.collect();
4746
Module {
4847
items: mod_items,
49-
attrs: mod_attrs,
5048
inner_attr,
5149
span: mod_span,
5250
ast_mod_kind,

src/patterns.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ use crate::utils::{format_mutability, mk_sp, mk_sp_lo_plus_one, rewrite_ident};
2323
/// Returns `true` if the given pattern is "short".
2424
/// A short pattern is defined by the following grammar:
2525
///
26-
/// [small, ntp]:
26+
/// `[small, ntp]`:
2727
/// - single token
2828
/// - `&[single-line, ntp]`
2929
///
30-
/// [small]:
30+
/// `[small]`:
3131
/// - `[small, ntp]`
3232
/// - unary tuple constructor `([small, ntp])`
3333
/// - `&[small]`

src/string.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(crate) fn rewrite_string<'a>(
153153
wrap_str(result, fmt.config.max_width(), fmt.shape)
154154
}
155155

156-
/// Returns the index to the end of the URL if the split at index of the given string includes an
156+
/// Returns the index to the end of the URL if the split at index of the given string includes a
157157
/// URL or alike. Otherwise, returns `None`.
158158
fn detect_url(s: &[&str], index: usize) -> Option<usize> {
159159
let start = match s[..=index].iter().rposition(|g| is_whitespace(g)) {

src/syntux/session.rs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ mod tests {
317317
suggestions: vec![],
318318
span: span.unwrap_or_else(MultiSpan::new),
319319
sort_span: DUMMY_SP,
320+
is_lint: false,
320321
}
321322
}
322323

0 commit comments

Comments
 (0)