Skip to content

Commit 53e290d

Browse files
calebcartwrightCalebLItalien
authored andcommitted
Merge pull request rust-lang#6217 from compiler-errors/sync-from-rust-2024-06-24
subtree-push 2024-06-24 Merge commit from master
2 parents e494418 + c528496 commit 53e290d

File tree

16 files changed

+158
-29
lines changed

16 files changed

+158
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@
238238

239239
### Added
240240

241-
- New configuration option (`skip_macro_invocations`)[https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations] [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
241+
- New configuration option [`skip_macro_invocations`](https://rust-lang.github.io/rustfmt/?version=master&search=#skip_macro_invocations) [#5347](https://github.com/rust-lang/rustfmt/pull/5347) that can be used to globally define a single enumerated list of macro calls that rustfmt should skip formatting. rustfmt [currently also supports this via a custom tool attribute](https://github.com/rust-lang/rustfmt#tips), however, these cannot be used in all contexts because [custom inner attributes are unstable](https://github.com/rust-lang/rust/issues/54726)
242242

243243
### Misc
244244

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-06-13"
2+
channel = "nightly-2024-06-25"
33
components = ["llvm-tools", "rustc-dev"]

src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ impl Config {
256256
/// one.
257257
pub(super) fn from_resolved_toml_path(dir: &Path) -> Result<(Config, Option<PathBuf>), Error> {
258258
/// Try to find a project file in the given directory and its parents.
259-
/// Returns the path of a the nearest project file if one exists,
259+
/// Returns the path of the nearest project file if one exists,
260260
/// or `None` if no project file was found.
261261
fn resolve_project_file(dir: &Path) -> Result<Option<PathBuf>, Error> {
262262
let mut current = if dir.is_relative() {

src/expr.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,11 @@ fn rewrite_let(
18601860
// TODO(ytmimi) comments could appear between `let` and the `pat`
18611861

18621862
// 4 = "let ".len()
1863-
let pat_shape = shape.offset_left(4)?;
1863+
let mut pat_shape = shape.offset_left(4)?;
1864+
if context.config.version() == Version::Two {
1865+
// 2 to account for the length of " ="
1866+
pat_shape = pat_shape.sub_width(2)?;
1867+
}
18641868
let pat_str = pat.rewrite(context, pat_shape)?;
18651869
result.push_str(&pat_str);
18661870

src/items.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1994,7 +1994,6 @@ fn rewrite_static(
19941994
static_parts: &StaticParts<'_>,
19951995
offset: Indent,
19961996
) -> Option<String> {
1997-
println!("rewriting static");
19981997
let colon = colon_spaces(context.config);
19991998
let mut prefix = format!(
20001999
"{}{}{}{} {}{}{}",

src/overflow.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub(crate) enum OverflowableItem<'a> {
8383
TuplePatField(&'a TuplePatField<'a>),
8484
Ty(&'a ast::Ty),
8585
Pat(&'a ast::Pat),
86+
PreciseCapturingArg(&'a ast::PreciseCapturingArg),
8687
}
8788

8889
impl<'a> Rewrite for OverflowableItem<'a> {
@@ -123,6 +124,7 @@ impl<'a> OverflowableItem<'a> {
123124
OverflowableItem::TuplePatField(pat) => f(*pat),
124125
OverflowableItem::Ty(ty) => f(*ty),
125126
OverflowableItem::Pat(pat) => f(*pat),
127+
OverflowableItem::PreciseCapturingArg(arg) => f(*arg),
126128
}
127129
}
128130

@@ -137,6 +139,9 @@ impl<'a> OverflowableItem<'a> {
137139
matches!(meta_item.kind, ast::MetaItemKind::Word)
138140
}
139141
},
142+
// FIXME: Why don't we consider `SegmentParam` to be simple?
143+
// FIXME: If we also fix `SegmentParam`, then we should apply the same
144+
// heuristic to `PreciseCapturingArg`.
140145
_ => false,
141146
}
142147
}
@@ -244,7 +249,15 @@ macro_rules! impl_into_overflowable_item_for_rustfmt_types {
244249
}
245250
}
246251

247-
impl_into_overflowable_item_for_ast_node!(Expr, GenericParam, NestedMetaItem, FieldDef, Ty, Pat);
252+
impl_into_overflowable_item_for_ast_node!(
253+
Expr,
254+
GenericParam,
255+
NestedMetaItem,
256+
FieldDef,
257+
Ty,
258+
Pat,
259+
PreciseCapturingArg
260+
);
248261
impl_into_overflowable_item_for_rustfmt_types!([MacroArg], [SegmentParam, TuplePatField]);
249262

250263
pub(crate) fn into_overflowable_list<'a, T>(

src/parse/macros/cfg_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn parse_cfg_if_inner<'a>(
6767
Ok(None) => continue,
6868
Err(err) => {
6969
err.cancel();
70-
parser.psess.dcx.reset_err_count();
70+
parser.psess.dcx().reset_err_count();
7171
return Err(
7272
"Expected item inside cfg_if block, but failed to parse it as an item",
7373
);

src/parse/macros/lazy_static.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@ pub(crate) fn parse_lazy_static(
1616
($method:ident $(,)* $($arg:expr),* $(,)*) => {
1717
match parser.$method($($arg,)*) {
1818
Ok(val) => {
19-
if parser.psess.dcx.has_errors().is_some() {
20-
parser.psess.dcx.reset_err_count();
19+
if parser.psess.dcx().has_errors().is_some() {
20+
parser.psess.dcx().reset_err_count();
2121
return None;
2222
} else {
2323
val
2424
}
2525
}
2626
Err(err) => {
2727
err.cancel();
28-
parser.psess.dcx.reset_err_count();
28+
parser.psess.dcx().reset_err_count();
2929
return None;
3030
}
3131
}
3232
}
3333
}
34-
3534
while parser.token.kind != TokenKind::Eof {
3635
// Parse a `lazy_static!` item.
3736
let vis = parse_or!(parse_visibility, rustc_parse::parser::FollowedByType::No);

src/parse/macros/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_ast::token::{Delimiter, NonterminalKind, TokenKind};
1+
use rustc_ast::token::{Delimiter, NonterminalKind, NtExprKind::*, NtPatKind::*, TokenKind};
22
use rustc_ast::tokenstream::TokenStream;
33
use rustc_ast::{ast, ptr};
44
use rustc_parse::parser::{ForceCollect, Parser, Recovery};
@@ -29,8 +29,8 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
2929
if Parser::nonterminal_may_begin_with($nt_kind, &cloned_parser.token) {
3030
match $try_parse(&mut cloned_parser) {
3131
Ok(x) => {
32-
if parser.psess.dcx.has_errors().is_some() {
33-
parser.psess.dcx.reset_err_count();
32+
if parser.psess.dcx().has_errors().is_some() {
33+
parser.psess.dcx().reset_err_count();
3434
} else {
3535
// Parsing succeeded.
3636
*parser = cloned_parser;
@@ -39,7 +39,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
3939
}
4040
Err(e) => {
4141
e.cancel();
42-
parser.psess.dcx.reset_err_count();
42+
parser.psess.dcx().reset_err_count();
4343
}
4444
}
4545
}
@@ -48,7 +48,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
4848

4949
parse_macro_arg!(
5050
Expr,
51-
NonterminalKind::Expr,
51+
NonterminalKind::Expr(Expr),
5252
|parser: &mut Parser<'b>| parser.parse_expr(),
5353
|x: ptr::P<ast::Expr>| Some(x)
5454
);
@@ -60,7 +60,7 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> {
6060
);
6161
parse_macro_arg!(
6262
Pat,
63-
NonterminalKind::PatParam { inferred: false },
63+
NonterminalKind::Pat(PatParam { inferred: false }),
6464
|parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None),
6565
|x: ptr::P<ast::Pat>| Some(x)
6666
);

src/parse/session.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ impl ParseSess {
210210
rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(),
211211
false,
212212
);
213-
self.raw_psess.dcx.make_silent(fallback_bundle, None, false);
213+
self.raw_psess
214+
.dcx()
215+
.make_silent(fallback_bundle, None, false);
214216
}
215217

216218
pub(crate) fn span_to_filename(&self, span: Span) -> FileName {
@@ -286,11 +288,11 @@ impl ParseSess {
286288
}
287289

288290
pub(super) fn has_errors(&self) -> bool {
289-
self.raw_psess.dcx.has_errors().is_some()
291+
self.raw_psess.dcx().has_errors().is_some()
290292
}
291293

292294
pub(super) fn reset_errors(&self) {
293-
self.raw_psess.dcx.reset_err_count();
295+
self.raw_psess.dcx().reset_err_count();
294296
}
295297
}
296298

0 commit comments

Comments
 (0)