Skip to content

Commit 5c558e2

Browse files
Merge pull request rust-lang#5186 from calebcartwright/subtree-sync-2022-01-23
sync subtree
2 parents 5056f4c + 9e1973f commit 5c558e2

9 files changed

+41
-17
lines changed

Configurations.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,9 @@ fn add_one(x: i32) -> i32 {
929929
## `format_generated_files`
930930

931931
Format generated files. A file is considered generated
932-
if any of the first five lines contains `@generated` marker.
932+
if any of the first five lines contain a `@generated` comment marker.
933933

934-
- **Default value**: `false`
934+
- **Default value**: `true`
935935
- **Possible values**: `true`, `false`
936936
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))
937937

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-12-29"
2+
channel = "nightly-2022-01-23"
33
components = ["rustc-dev"]

src/config/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ create_config! {
138138
inline_attribute_width: usize, 0, false,
139139
"Write an item and its attribute on the same line \
140140
if their combined width is below a threshold";
141-
format_generated_files: bool, false, false, "Format generated files";
141+
format_generated_files: bool, true, false, "Format generated files";
142142

143143
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
144144
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
@@ -606,7 +606,7 @@ blank_lines_lower_bound = 0
606606
edition = "2015"
607607
version = "One"
608608
inline_attribute_width = 0
609-
format_generated_files = false
609+
format_generated_files = true
610610
merge_derives = true
611611
use_try_shorthand = false
612612
use_field_init_shorthand = false

src/expr.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -334,9 +334,7 @@ pub(crate) fn format_expr(
334334
// satisfy our width restrictions.
335335
// Style Guide RFC for InlineAsm variant pending
336336
// https://github.com/rust-dev-tools/fmt-rfcs/issues/152
337-
ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::InlineAsm(..) => {
338-
Some(context.snippet(expr.span).to_owned())
339-
}
337+
ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
340338
ast::ExprKind::TryBlock(ref block) => {
341339
if let rw @ Some(_) =
342340
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)

src/formatting.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ fn should_skip_module<T: FormatHandler>(
8080
return true;
8181
}
8282

83-
if !config.format_generated_files() {
83+
// FIXME(calebcartwright) - we need to determine how we'll handle the
84+
// `format_generated_files` option with stdin based input.
85+
if !input_is_stdin && !config.format_generated_files() {
8486
let source_file = context.parse_session.span_to_file_contents(module.span);
8587
let src = source_file.src.as_ref().expect("SourceFile without src");
8688

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![warn(unreachable_pub)]
44
#![recursion_limit = "256"]
55
#![allow(clippy::match_like_matches_macro)]
6+
#![allow(unreachable_pub)]
67

78
#[macro_use]
89
extern crate derive_new;

src/test/mod.rs

+21
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,27 @@ fn stdin_disable_all_formatting_test() {
557557
assert_eq!(input, String::from_utf8(output.stdout).unwrap());
558558
}
559559

560+
#[test]
561+
fn stdin_generated_files_issue_5172() {
562+
init_log();
563+
let input = Input::Text("//@generated\nfn main() {}".to_owned());
564+
let mut config = Config::default();
565+
config.set().emit_mode(EmitMode::Stdout);
566+
config.set().format_generated_files(false);
567+
config.set().newline_style(NewlineStyle::Unix);
568+
let mut buf: Vec<u8> = vec![];
569+
{
570+
let mut session = Session::new(config, Some(&mut buf));
571+
session.format(input).unwrap();
572+
assert!(session.has_no_errors());
573+
}
574+
// N.B. this should be changed once `format_generated_files` is supported with stdin
575+
assert_eq!(
576+
String::from_utf8(buf).unwrap(),
577+
"<stdin>:\n\n//@generated\nfn main() {}\n",
578+
);
579+
}
580+
560581
#[test]
561582
fn format_lines_errors_are_reported() {
562583
init_log();

src/types.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::iter::ExactSizeIterator;
22
use std::ops::Deref;
33

4-
use rustc_ast::ast::{self, FnRetTy, Mutability};
4+
use rustc_ast::ast::{self, FnRetTy, Mutability, Term};
55
use rustc_ast::ptr;
66
use rustc_span::{symbol::kw, BytePos, Pos, Span};
77

@@ -141,7 +141,7 @@ pub(crate) enum SegmentParam<'a> {
141141
Const(&'a ast::AnonConst),
142142
LifeTime(&'a ast::Lifetime),
143143
Type(&'a ast::Ty),
144-
Binding(&'a ast::AssocTyConstraint),
144+
Binding(&'a ast::AssocConstraint),
145145
}
146146

147147
impl<'a> SegmentParam<'a> {
@@ -176,9 +176,9 @@ impl<'a> Rewrite for SegmentParam<'a> {
176176
}
177177
}
178178

179-
impl Rewrite for ast::AssocTyConstraint {
179+
impl Rewrite for ast::AssocConstraint {
180180
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
181-
use ast::AssocTyConstraintKind::{Bound, Equality};
181+
use ast::AssocConstraintKind::{Bound, Equality};
182182

183183
let mut result = String::with_capacity(128);
184184
result.push_str(rewrite_ident(context, self.ident));
@@ -206,11 +206,14 @@ impl Rewrite for ast::AssocTyConstraint {
206206
}
207207
}
208208

209-
impl Rewrite for ast::AssocTyConstraintKind {
209+
impl Rewrite for ast::AssocConstraintKind {
210210
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
211211
match self {
212-
ast::AssocTyConstraintKind::Equality { ty } => ty.rewrite(context, shape),
213-
ast::AssocTyConstraintKind::Bound { bounds } => bounds.rewrite(context, shape),
212+
ast::AssocConstraintKind::Equality { term } => match term {
213+
Term::Ty(ty) => ty.rewrite(context, shape),
214+
Term::Const(c) => c.rewrite(context, shape),
215+
},
216+
ast::AssocConstraintKind::Bound { bounds } => bounds.rewrite(context, shape),
214217
}
215218
}
216219
}

src/utils.rs

-1
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,6 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
507507
| ast::ExprKind::Err
508508
| ast::ExprKind::Field(..)
509509
| ast::ExprKind::InlineAsm(..)
510-
| ast::ExprKind::LlvmInlineAsm(..)
511510
| ast::ExprKind::Let(..)
512511
| ast::ExprKind::Path(..)
513512
| ast::ExprKind::Range(..)

0 commit comments

Comments
 (0)