Merge pull request #5186 from calebcartwright/subtree-sync-2022-01-23
sync subtree
This commit is contained in:
commit
5c558e2c11
9 changed files with 41 additions and 17 deletions
|
|
@ -929,9 +929,9 @@ fn add_one(x: i32) -> i32 {
|
|||
## `format_generated_files`
|
||||
|
||||
Format generated files. A file is considered generated
|
||||
if any of the first five lines contains `@generated` marker.
|
||||
if any of the first five lines contain a `@generated` comment marker.
|
||||
|
||||
- **Default value**: `false`
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
- **Stable**: No (tracking issue: [#5080](https://github.com/rust-lang/rustfmt/issues/5080))
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
[toolchain]
|
||||
channel = "nightly-2021-12-29"
|
||||
channel = "nightly-2022-01-23"
|
||||
components = ["rustc-dev"]
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ create_config! {
|
|||
inline_attribute_width: usize, 0, false,
|
||||
"Write an item and its attribute on the same line \
|
||||
if their combined width is below a threshold";
|
||||
format_generated_files: bool, false, false, "Format generated files";
|
||||
format_generated_files: bool, true, false, "Format generated files";
|
||||
|
||||
// Options that can change the source code beyond whitespace/blocks (somewhat linty things)
|
||||
merge_derives: bool, true, true, "Merge multiple `#[derive(...)]` into a single one";
|
||||
|
|
@ -606,7 +606,7 @@ blank_lines_lower_bound = 0
|
|||
edition = "2015"
|
||||
version = "One"
|
||||
inline_attribute_width = 0
|
||||
format_generated_files = false
|
||||
format_generated_files = true
|
||||
merge_derives = true
|
||||
use_try_shorthand = false
|
||||
use_field_init_shorthand = false
|
||||
|
|
|
|||
|
|
@ -334,9 +334,7 @@ pub(crate) fn format_expr(
|
|||
// satisfy our width restrictions.
|
||||
// Style Guide RFC for InlineAsm variant pending
|
||||
// https://github.com/rust-dev-tools/fmt-rfcs/issues/152
|
||||
ast::ExprKind::LlvmInlineAsm(..) | ast::ExprKind::InlineAsm(..) => {
|
||||
Some(context.snippet(expr.span).to_owned())
|
||||
}
|
||||
ast::ExprKind::InlineAsm(..) => Some(context.snippet(expr.span).to_owned()),
|
||||
ast::ExprKind::TryBlock(ref block) => {
|
||||
if let rw @ Some(_) =
|
||||
rewrite_single_line_block(context, "try ", block, Some(&expr.attrs), None, shape)
|
||||
|
|
|
|||
|
|
@ -80,7 +80,9 @@ fn should_skip_module<T: FormatHandler>(
|
|||
return true;
|
||||
}
|
||||
|
||||
if !config.format_generated_files() {
|
||||
// FIXME(calebcartwright) - we need to determine how we'll handle the
|
||||
// `format_generated_files` option with stdin based input.
|
||||
if !input_is_stdin && !config.format_generated_files() {
|
||||
let source_file = context.parse_session.span_to_file_contents(module.span);
|
||||
let src = source_file.src.as_ref().expect("SourceFile without src");
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
#![warn(unreachable_pub)]
|
||||
#![recursion_limit = "256"]
|
||||
#![allow(clippy::match_like_matches_macro)]
|
||||
#![allow(unreachable_pub)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate derive_new;
|
||||
|
|
|
|||
|
|
@ -557,6 +557,27 @@ fn stdin_disable_all_formatting_test() {
|
|||
assert_eq!(input, String::from_utf8(output.stdout).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stdin_generated_files_issue_5172() {
|
||||
init_log();
|
||||
let input = Input::Text("//@generated\nfn main() {}".to_owned());
|
||||
let mut config = Config::default();
|
||||
config.set().emit_mode(EmitMode::Stdout);
|
||||
config.set().format_generated_files(false);
|
||||
config.set().newline_style(NewlineStyle::Unix);
|
||||
let mut buf: Vec<u8> = vec![];
|
||||
{
|
||||
let mut session = Session::new(config, Some(&mut buf));
|
||||
session.format(input).unwrap();
|
||||
assert!(session.has_no_errors());
|
||||
}
|
||||
// N.B. this should be changed once `format_generated_files` is supported with stdin
|
||||
assert_eq!(
|
||||
String::from_utf8(buf).unwrap(),
|
||||
"<stdin>:\n\n//@generated\nfn main() {}\n",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn format_lines_errors_are_reported() {
|
||||
init_log();
|
||||
|
|
|
|||
17
src/types.rs
17
src/types.rs
|
|
@ -1,7 +1,7 @@
|
|||
use std::iter::ExactSizeIterator;
|
||||
use std::ops::Deref;
|
||||
|
||||
use rustc_ast::ast::{self, FnRetTy, Mutability};
|
||||
use rustc_ast::ast::{self, FnRetTy, Mutability, Term};
|
||||
use rustc_ast::ptr;
|
||||
use rustc_span::{symbol::kw, BytePos, Pos, Span};
|
||||
|
||||
|
|
@ -141,7 +141,7 @@ pub(crate) enum SegmentParam<'a> {
|
|||
Const(&'a ast::AnonConst),
|
||||
LifeTime(&'a ast::Lifetime),
|
||||
Type(&'a ast::Ty),
|
||||
Binding(&'a ast::AssocTyConstraint),
|
||||
Binding(&'a ast::AssocConstraint),
|
||||
}
|
||||
|
||||
impl<'a> SegmentParam<'a> {
|
||||
|
|
@ -176,9 +176,9 @@ impl<'a> Rewrite for SegmentParam<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::AssocTyConstraint {
|
||||
impl Rewrite for ast::AssocConstraint {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||
use ast::AssocTyConstraintKind::{Bound, Equality};
|
||||
use ast::AssocConstraintKind::{Bound, Equality};
|
||||
|
||||
let mut result = String::with_capacity(128);
|
||||
result.push_str(rewrite_ident(context, self.ident));
|
||||
|
|
@ -206,11 +206,14 @@ impl Rewrite for ast::AssocTyConstraint {
|
|||
}
|
||||
}
|
||||
|
||||
impl Rewrite for ast::AssocTyConstraintKind {
|
||||
impl Rewrite for ast::AssocConstraintKind {
|
||||
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
|
||||
match self {
|
||||
ast::AssocTyConstraintKind::Equality { ty } => ty.rewrite(context, shape),
|
||||
ast::AssocTyConstraintKind::Bound { bounds } => bounds.rewrite(context, shape),
|
||||
ast::AssocConstraintKind::Equality { term } => match term {
|
||||
Term::Ty(ty) => ty.rewrite(context, shape),
|
||||
Term::Const(c) => c.rewrite(context, shape),
|
||||
},
|
||||
ast::AssocConstraintKind::Bound { bounds } => bounds.rewrite(context, shape),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,7 +507,6 @@ pub(crate) fn is_block_expr(context: &RewriteContext<'_>, expr: &ast::Expr, repr
|
|||
| ast::ExprKind::Err
|
||||
| ast::ExprKind::Field(..)
|
||||
| ast::ExprKind::InlineAsm(..)
|
||||
| ast::ExprKind::LlvmInlineAsm(..)
|
||||
| ast::ExprKind::Let(..)
|
||||
| ast::ExprKind::Path(..)
|
||||
| ast::ExprKind::Range(..)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue