Skip to content

Commit 6093d48

Browse files
Merge pull request #6217 from compiler-errors/sync-from-rust-2024-06-24
subtree-push 2024-06-24
2 parents e494418 + c528496 commit 6093d48

File tree

11 files changed

+124
-26
lines changed

11 files changed

+124
-26
lines changed

Diff for: rust-toolchain

+1-1
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"]

Diff for: src/items.rs

-1
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
"{}{}{}{} {}{}{}",

Diff for: src/overflow.rs

+14-1
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>(

Diff for: src/parse/macros/cfg_if.rs

+1-1
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
);

Diff for: src/parse/macros/lazy_static.rs

+3-4
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);

Diff for: src/parse/macros/mod.rs

+6-6
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
);

Diff for: src/parse/session.rs

+5-3
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

Diff for: src/spanned.rs

+10
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ impl Spanned for ast::GenericBound {
181181
match *self {
182182
ast::GenericBound::Trait(ref ptr, _) => ptr.span,
183183
ast::GenericBound::Outlives(ref l) => l.ident.span,
184+
ast::GenericBound::Use(_, span) => span,
184185
}
185186
}
186187
}
@@ -202,3 +203,12 @@ impl Spanned for ast::NestedMetaItem {
202203
self.span()
203204
}
204205
}
206+
207+
impl Spanned for ast::PreciseCapturingArg {
208+
fn span(&self) -> Span {
209+
match self {
210+
ast::PreciseCapturingArg::Lifetime(lt) => lt.ident.span,
211+
ast::PreciseCapturingArg::Arg(path, _) => path.span,
212+
}
213+
}
214+
}

Diff for: src/types.rs

+20-9
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,17 @@ impl<'a> Rewrite for SegmentParam<'a> {
177177
}
178178
}
179179

180+
impl Rewrite for ast::PreciseCapturingArg {
181+
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
182+
match self {
183+
ast::PreciseCapturingArg::Lifetime(lt) => lt.rewrite(context, shape),
184+
ast::PreciseCapturingArg::Arg(p, _) => {
185+
rewrite_path(context, PathContext::Type, &None, p, shape)
186+
}
187+
}
188+
}
189+
}
190+
180191
impl Rewrite for ast::AssocItemConstraint {
181192
fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
182193
use ast::AssocItemConstraintKind::{Bound, Equality};
@@ -564,6 +575,9 @@ impl Rewrite for ast::GenericBound {
564575
.map(|s| format!("{constness}{asyncness}{polarity}{s}"))
565576
.map(|s| if has_paren { format!("({})", s) } else { s })
566577
}
578+
ast::GenericBound::Use(ref args, span) => {
579+
overflow::rewrite_with_angle_brackets(context, "use", args.iter(), shape, span)
580+
}
567581
ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
568582
}
569583
}
@@ -847,11 +861,7 @@ impl Rewrite for ast::Ty {
847861
rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
848862
}
849863
ast::TyKind::ImplicitSelf => Some(String::from("")),
850-
ast::TyKind::ImplTrait(_, ref it, ref captures) => {
851-
// FIXME(precise_capturing): Implement formatting.
852-
if captures.is_some() {
853-
return None;
854-
}
864+
ast::TyKind::ImplTrait(_, ref it) => {
855865
// Empty trait is not a parser error.
856866
if it.is_empty() {
857867
return Some("impl".to_owned());
@@ -935,7 +945,7 @@ fn rewrite_bare_fn(
935945
fn is_generic_bounds_in_order(generic_bounds: &[ast::GenericBound]) -> bool {
936946
let is_trait = |b: &ast::GenericBound| match b {
937947
ast::GenericBound::Outlives(..) => false,
938-
ast::GenericBound::Trait(..) => true,
948+
ast::GenericBound::Trait(..) | ast::GenericBound::Use(..) => true,
939949
};
940950
let is_lifetime = |b: &ast::GenericBound| !is_trait(b);
941951
let last_trait_index = generic_bounds.iter().rposition(is_trait);
@@ -969,7 +979,8 @@ fn join_bounds_inner(
969979
let generic_bounds_in_order = is_generic_bounds_in_order(items);
970980
let is_bound_extendable = |s: &str, b: &ast::GenericBound| match b {
971981
ast::GenericBound::Outlives(..) => true,
972-
ast::GenericBound::Trait(..) => last_line_extendable(s),
982+
// We treat `use<>` like a trait bound here.
983+
ast::GenericBound::Trait(..) | ast::GenericBound::Use(..) => last_line_extendable(s),
973984
};
974985

975986
// Whether a GenericBound item is a PathSegment segment that includes internal array
@@ -991,6 +1002,7 @@ fn join_bounds_inner(
9911002
}
9921003
}
9931004
}
1005+
ast::GenericBound::Use(args, _) => args.len() > 1,
9941006
_ => false,
9951007
};
9961008

@@ -1114,8 +1126,7 @@ fn join_bounds_inner(
11141126

11151127
pub(crate) fn opaque_ty(ty: &Option<ptr::P<ast::Ty>>) -> Option<&ast::GenericBounds> {
11161128
ty.as_ref().and_then(|t| match &t.kind {
1117-
// FIXME(precise_capturing): Implement support here
1118-
ast::TyKind::ImplTrait(_, bounds, _) => Some(bounds),
1129+
ast::TyKind::ImplTrait(_, bounds) => Some(bounds),
11191130
_ => None,
11201131
})
11211132
}

Diff for: tests/source/precise-capturing.rs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn hello() -> impl
2+
use<'a> + Sized {}
3+
4+
fn all_three() -> impl Sized + use<'a> + 'a;
5+
6+
fn pathological() -> impl use<'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
7+
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
8+
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a,
9+
'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a, 'a> + Sized {}

Diff for: tests/target/precise-capturing.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
fn hello() -> impl use<'a> + Sized {}
2+
3+
fn all_three() -> impl Sized + use<'a> + 'a;
4+
5+
fn pathological() -> impl use<
6+
'a,
7+
'a,
8+
'a,
9+
'a,
10+
'a,
11+
'a,
12+
'a,
13+
'a,
14+
'a,
15+
'a,
16+
'a,
17+
'a,
18+
'a,
19+
'a,
20+
'a,
21+
'a,
22+
'a,
23+
'a,
24+
'a,
25+
'a,
26+
'a,
27+
'a,
28+
'a,
29+
'a,
30+
'a,
31+
'a,
32+
'a,
33+
'a,
34+
'a,
35+
'a,
36+
'a,
37+
'a,
38+
'a,
39+
'a,
40+
'a,
41+
'a,
42+
'a,
43+
'a,
44+
'a,
45+
'a,
46+
'a,
47+
'a,
48+
'a,
49+
'a,
50+
'a,
51+
'a,
52+
'a,
53+
'a,
54+
> + Sized {
55+
}

0 commit comments

Comments
 (0)