Skip to content

Commit ce5cccc

Browse files
authored
Update rustc-ap-* crates to 407.0.0 (rust-lang#3447)
1 parent 331a050 commit ce5cccc

15 files changed

+293
-396
lines changed

Cargo.lock

+225-165
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ env_logger = "0.6"
4949
getopts = "0.2"
5050
derive-new = "0.5"
5151
cargo_metadata = "0.7"
52-
rustc-ap-rustc_target = "373.0.0"
53-
rustc-ap-syntax = "373.0.0"
54-
rustc-ap-syntax_pos = "373.0.0"
52+
rustc-ap-rustc_target = "407.0.0"
53+
rustc-ap-syntax = "407.0.0"
54+
rustc-ap-syntax_pos = "407.0.0"
5555
failure = "0.1.3"
5656
bytecount = "0.5"
5757
unicode-width = "0.1.5"

src/config/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub mod file_lines;
2121
pub mod license;
2222
pub mod lists;
2323

24-
/// This macro defines configuration options used in rustfmt. Each option
25-
/// is defined as follows:
26-
///
27-
/// `name: value type, default value, is stable, description;`
24+
// This macro defines configuration options used in rustfmt. Each option
25+
// is defined as follows:
26+
//
27+
// `name: value type, default value, is stable, description;`
2828
create_config! {
2929
// Fundamental stuff
3030
max_width: usize, 100, true, "Maximum width of each line";

src/config/options.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,11 @@ configuration_option_enum! { Heuristics:
237237
}
238238

239239
impl Density {
240-
pub fn to_list_tactic(self) -> ListTactic {
240+
pub fn to_list_tactic(self, len: usize) -> ListTactic {
241241
match self {
242242
Density::Compressed => ListTactic::Mixed,
243243
Density::Tall => ListTactic::HorizontalVertical,
244+
Density::Vertical if len == 1 => ListTactic::Horizontal,
244245
Density::Vertical => ListTactic::Vertical,
245246
}
246247
}
@@ -443,7 +444,7 @@ pub trait CliOptions {
443444
fn config_path(&self) -> Option<&Path>;
444445
}
445446

446-
/// The edition of the compiler (RFC 2052)
447+
// The edition of the compiler (RFC 2052)
447448
configuration_option_enum! { Edition:
448449
Edition2015: 2015,
449450
Edition2018: 2018,

src/formatting.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn format_project<T: FormatHandler>(
8383

8484
// Suppress error output if we have to do any further parsing.
8585
let silent_emitter = silent_emitter(source_map);
86-
parse_session.span_diagnostic = Handler::with_emitter(true, false, silent_emitter);
86+
parse_session.span_diagnostic = Handler::with_emitter(true, None, silent_emitter);
8787

8888
let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
8989

@@ -657,15 +657,15 @@ fn silent_emitter(source_map: Rc<SourceMap>) -> Box<EmitterWriter> {
657657
fn make_parse_sess(source_map: Rc<SourceMap>, config: &Config) -> ParseSess {
658658
let tty_handler = if config.hide_parse_errors() {
659659
let silent_emitter = silent_emitter(source_map.clone());
660-
Handler::with_emitter(true, false, silent_emitter)
660+
Handler::with_emitter(true, None, silent_emitter)
661661
} else {
662662
let supports_color = term::stderr().map_or(false, |term| term.supports_color());
663663
let color_cfg = if supports_color {
664664
ColorConfig::Auto
665665
} else {
666666
ColorConfig::Never
667667
};
668-
Handler::with_tty_emitter(color_cfg, true, false, Some(source_map.clone()))
668+
Handler::with_tty_emitter(color_cfg, true, None, Some(source_map.clone()))
669669
};
670670

671671
ParseSess::with_span_handler(tty_handler, source_map)

src/items.rs

+37-177
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ use crate::expr::{
1919
format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
2020
ExprType, RhsTactics,
2121
};
22-
use crate::lists::{
23-
definitive_tactic, extract_post_comment, extract_pre_comment, get_comment_end,
24-
has_extra_newline, itemize_list, write_list, ListFormatting, ListItem, Separator,
25-
};
22+
use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
2623
use crate::macros::{rewrite_macro, MacroPosition};
2724
use crate::overflow;
2825
use crate::rewrite::{Rewrite, RewriteContext};
@@ -194,7 +191,7 @@ impl<'a> FnSig<'a> {
194191
) -> FnSig<'a> {
195192
FnSig {
196193
unsafety: method_sig.header.unsafety,
197-
is_async: method_sig.header.asyncness,
194+
is_async: method_sig.header.asyncness.node,
198195
constness: method_sig.header.constness.node,
199196
defaultness: ast::Defaultness::Final,
200197
abi: method_sig.header.abi,
@@ -216,7 +213,7 @@ impl<'a> FnSig<'a> {
216213
generics,
217214
abi: fn_header.abi,
218215
constness: fn_header.constness.node,
219-
is_async: fn_header.asyncness,
216+
is_async: fn_header.asyncness.node,
220217
defaultness,
221218
unsafety: fn_header.unsafety,
222219
visibility: visibility.clone(),
@@ -1833,7 +1830,9 @@ fn is_empty_infer(ty: &ast::Ty, pat_span: Span) -> bool {
18331830

18341831
impl Rewrite for ast::Arg {
18351832
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
1836-
if is_named_arg(self) {
1833+
if let Some(ref explicit_self) = self.to_self() {
1834+
rewrite_explicit_self(context, explicit_self)
1835+
} else if is_named_arg(self) {
18371836
let mut result = self
18381837
.pat
18391838
.rewrite(context, Shape::legacy(shape.width, shape.indent))?;
@@ -1862,9 +1861,8 @@ impl Rewrite for ast::Arg {
18621861
}
18631862

18641863
fn rewrite_explicit_self(
1865-
explicit_self: &ast::ExplicitSelf,
1866-
args: &[ast::Arg],
18671864
context: &RewriteContext<'_>,
1865+
explicit_self: &ast::ExplicitSelf,
18681866
) -> Option<String> {
18691867
match explicit_self.node {
18701868
ast::SelfKind::Region(lt, m) => {
@@ -1880,10 +1878,7 @@ fn rewrite_explicit_self(
18801878
None => Some(format!("&{}self", mut_str)),
18811879
}
18821880
}
1883-
ast::SelfKind::Explicit(ref ty, _) => {
1884-
assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty.");
1885-
1886-
let mutability = explicit_self_mutability(&args[0]);
1881+
ast::SelfKind::Explicit(ref ty, mutability) => {
18871882
let type_str = ty.rewrite(
18881883
context,
18891884
Shape::legacy(context.config.max_width(), Indent::empty()),
@@ -1895,23 +1890,7 @@ fn rewrite_explicit_self(
18951890
type_str
18961891
))
18971892
}
1898-
ast::SelfKind::Value(_) => {
1899-
assert!(!args.is_empty(), "&[ast::Arg] shouldn't be empty.");
1900-
1901-
let mutability = explicit_self_mutability(&args[0]);
1902-
1903-
Some(format!("{}self", format_mutability(mutability)))
1904-
}
1905-
}
1906-
}
1907-
1908-
// Hacky solution caused by absence of `Mutability` in `SelfValue` and
1909-
// `SelfExplicit` variants of `ast::ExplicitSelf_`.
1910-
fn explicit_self_mutability(arg: &ast::Arg) -> ast::Mutability {
1911-
if let ast::PatKind::Ident(ast::BindingMode::ByValue(mutability), _, _) = arg.pat.node {
1912-
mutability
1913-
} else {
1914-
unreachable!()
1893+
ast::SelfKind::Value(mutability) => Some(format!("{}self", format_mutability(mutability))),
19151894
}
19161895
}
19171896

@@ -2048,14 +2027,12 @@ fn rewrite_fn_base(
20482027
let arg_str = rewrite_args(
20492028
context,
20502029
&fd.inputs,
2051-
fd.get_self().as_ref(),
20522030
one_line_budget,
20532031
multi_line_budget,
20542032
indent,
20552033
arg_indent,
20562034
args_span,
2057-
fd.variadic,
2058-
generics_str.contains('\n'),
2035+
fd.c_variadic,
20592036
)?;
20602037

20612038
let put_args_in_block = match context.config.indent_style() {
@@ -2272,19 +2249,13 @@ impl WhereClauseOption {
22722249
fn rewrite_args(
22732250
context: &RewriteContext<'_>,
22742251
args: &[ast::Arg],
2275-
explicit_self: Option<&ast::ExplicitSelf>,
22762252
one_line_budget: usize,
22772253
multi_line_budget: usize,
22782254
indent: Indent,
22792255
arg_indent: Indent,
22802256
span: Span,
22812257
variadic: bool,
2282-
generics_str_contains_newline: bool,
22832258
) -> Option<String> {
2284-
let terminator = ")";
2285-
let separator = ",";
2286-
let next_span_start = span.hi();
2287-
22882259
if args.len() == 0 {
22892260
let comment = context
22902261
.snippet(mk_sp(
@@ -2295,158 +2266,47 @@ fn rewrite_args(
22952266
.trim();
22962267
return Some(comment.to_owned());
22972268
}
2298-
2299-
let mut arg_item_strs = args
2300-
.iter()
2301-
.map(|arg| {
2269+
let arg_items: Vec<_> = itemize_list(
2270+
context.snippet_provider,
2271+
args.iter(),
2272+
")",
2273+
",",
2274+
|arg| span_lo_for_arg(arg),
2275+
|arg| arg.ty.span.hi(),
2276+
|arg| {
23022277
arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
2303-
.unwrap_or_else(|| context.snippet(arg.span()).to_owned())
2304-
})
2305-
.collect::<Vec<_>>();
2306-
2307-
// Account for sugary self.
2308-
let mut pre_comment_str = "";
2309-
let mut post_comment_str = "";
2310-
let min_args = explicit_self
2311-
.and_then(|explicit_self| rewrite_explicit_self(explicit_self, args, context))
2312-
.map_or(1, |self_str| {
2313-
pre_comment_str = context.snippet(mk_sp(span.lo(), args[0].pat.span.lo()));
2314-
2315-
let next_start = if args.len() > 1 {
2316-
args[1].pat.span().lo()
2317-
} else {
2318-
span.hi()
2319-
};
2320-
post_comment_str = context.snippet(mk_sp(args[0].ty.span.hi(), next_start));
2321-
2322-
arg_item_strs[0] = self_str;
2323-
2
2324-
});
2325-
2326-
// Comments between args.
2327-
let mut arg_items = Vec::new();
2328-
if min_args == 2 {
2329-
arg_items.push(ListItem::from_str(""));
2330-
}
2331-
2332-
if args.len() >= min_args || variadic {
2333-
let comment_span_start = if min_args == 2 {
2334-
let remove_comma_byte_pos = context
2335-
.snippet_provider
2336-
.span_after(mk_sp(args[0].ty.span.hi(), args[1].pat.span.lo()), ",");
2337-
let first_post_and_second_pre_span =
2338-
mk_sp(remove_comma_byte_pos, args[1].pat.span.lo());
2339-
if count_newlines(context.snippet(first_post_and_second_pre_span)) > 0 {
2340-
context
2341-
.snippet_provider
2342-
.span_after(first_post_and_second_pre_span, "\n")
2343-
} else {
2344-
remove_comma_byte_pos
2345-
}
2346-
} else {
2347-
span.lo()
2348-
};
2349-
2350-
enum ArgumentKind<'a> {
2351-
Regular(&'a ast::Arg),
2352-
Variadic(BytePos),
2353-
}
2354-
2355-
let variadic_arg = if variadic {
2356-
let variadic_span = mk_sp(args.last().unwrap().ty.span.hi(), span.hi());
2357-
let variadic_start =
2358-
context.snippet_provider.span_after(variadic_span, "...") - BytePos(3);
2359-
Some(ArgumentKind::Variadic(variadic_start))
2360-
} else {
2361-
None
2362-
};
2363-
2364-
let more_items = itemize_list(
2365-
context.snippet_provider,
2366-
args[min_args - 1..]
2367-
.iter()
2368-
.map(ArgumentKind::Regular)
2369-
.chain(variadic_arg),
2370-
terminator,
2371-
separator,
2372-
|arg| match *arg {
2373-
ArgumentKind::Regular(arg) => span_lo_for_arg(arg),
2374-
ArgumentKind::Variadic(start) => start,
2375-
},
2376-
|arg| match *arg {
2377-
ArgumentKind::Regular(arg) => arg.ty.span.hi(),
2378-
ArgumentKind::Variadic(start) => start + BytePos(3),
2379-
},
2380-
|arg| match *arg {
2381-
ArgumentKind::Regular(..) => None,
2382-
ArgumentKind::Variadic(..) => Some("...".to_owned()),
2383-
},
2384-
comment_span_start,
2385-
next_span_start,
2386-
false,
2387-
);
2388-
2389-
arg_items.extend(more_items);
2390-
}
2391-
2392-
let arg_items_len = arg_items.len();
2393-
let fits_in_one_line = !generics_str_contains_newline
2394-
&& (arg_items.is_empty()
2395-
|| arg_items_len == 1 && arg_item_strs[0].len() <= one_line_budget);
2396-
2397-
for (index, (item, arg)) in arg_items.iter_mut().zip(arg_item_strs).enumerate() {
2398-
// add pre comment and post comment for first arg(self)
2399-
if index == 0 && explicit_self.is_some() {
2400-
let (pre_comment, pre_comment_style) = extract_pre_comment(pre_comment_str);
2401-
item.pre_comment = pre_comment;
2402-
item.pre_comment_style = pre_comment_style;
2403-
2404-
let comment_end =
2405-
get_comment_end(post_comment_str, separator, terminator, arg_items_len == 1);
2406-
2407-
item.new_lines = has_extra_newline(post_comment_str, comment_end);
2408-
item.post_comment = extract_post_comment(post_comment_str, comment_end, separator);
2409-
}
2410-
item.item = Some(arg);
2411-
}
2412-
2413-
let last_line_ends_with_comment = arg_items
2414-
.iter()
2415-
.last()
2416-
.and_then(|item| item.post_comment.as_ref())
2417-
.map_or(false, |s| s.trim().starts_with("//"));
2418-
2419-
let (indent, trailing_comma) = match context.config.indent_style() {
2420-
IndentStyle::Block if fits_in_one_line => {
2421-
(indent.block_indent(context.config), SeparatorTactic::Never)
2422-
}
2423-
IndentStyle::Block => (
2424-
indent.block_indent(context.config),
2425-
context.config.trailing_comma(),
2426-
),
2427-
IndentStyle::Visual if last_line_ends_with_comment => {
2428-
(arg_indent, context.config.trailing_comma())
2429-
}
2430-
IndentStyle::Visual => (arg_indent, SeparatorTactic::Never),
2431-
};
2278+
.or_else(|| Some(context.snippet(arg.span()).to_owned()))
2279+
},
2280+
span.lo(),
2281+
span.hi(),
2282+
false,
2283+
)
2284+
.collect();
24322285

24332286
let tactic = definitive_tactic(
24342287
&arg_items,
2435-
context.config.fn_args_density().to_list_tactic(),
2288+
context
2289+
.config
2290+
.fn_args_density()
2291+
.to_list_tactic(arg_items.len()),
24362292
Separator::Comma,
24372293
one_line_budget,
24382294
);
24392295
let budget = match tactic {
24402296
DefinitiveListTactic::Horizontal => one_line_budget,
24412297
_ => multi_line_budget,
24422298
};
2443-
2444-
debug!("rewrite_args: budget: {}, tactic: {:?}", budget, tactic);
2445-
2299+
let indent = match context.config.indent_style() {
2300+
IndentStyle::Block => indent.block_indent(context.config),
2301+
IndentStyle::Visual => arg_indent,
2302+
};
24462303
let trailing_separator = if variadic {
24472304
SeparatorTactic::Never
24482305
} else {
2449-
trailing_comma
2306+
match context.config.indent_style() {
2307+
IndentStyle::Block => context.config.trailing_comma(),
2308+
IndentStyle::Visual => SeparatorTactic::Never,
2309+
}
24502310
};
24512311
let fmt = ListFormatting::new(Shape::legacy(budget, indent), context.config)
24522312
.tactic(tactic)

0 commit comments

Comments
 (0)