Skip to content

Commit b699035

Browse files
committed
add parens: bool to PolyTraitRef
1 parent 25f0294 commit b699035

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,6 +1391,7 @@ impl Expr {
13911391
path.clone(),
13921392
TraitBoundModifiers::NONE,
13931393
self.span,
1394+
false,
13941395
))),
13951396
_ => None,
13961397
}
@@ -3372,6 +3373,9 @@ pub struct PolyTraitRef {
33723373
pub trait_ref: TraitRef,
33733374

33743375
pub span: Span,
3376+
3377+
/// Whether first and last character of `span` are an opening and a closing paren.
3378+
pub parens: bool,
33753379
}
33763380

33773381
impl PolyTraitRef {
@@ -3380,12 +3384,14 @@ impl PolyTraitRef {
33803384
path: Path,
33813385
modifiers: TraitBoundModifiers,
33823386
span: Span,
3387+
parens: bool,
33833388
) -> Self {
33843389
PolyTraitRef {
33853390
bound_generic_params: generic_params,
33863391
modifiers,
33873392
trait_ref: TraitRef { path, ref_id: DUMMY_NODE_ID },
33883393
span,
3394+
parens,
33893395
}
33903396
}
33913397
}

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ macro_rules! common_visitor_and_walkers {
11421142
vis: &mut V,
11431143
p: &$($lt)? $($mut)? PolyTraitRef,
11441144
) -> V::Result {
1145-
let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span } = p;
1145+
let PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens: _ } = p;
11461146
try_visit!(visit_modifiers(vis, modifiers));
11471147
try_visit!(visit_generic_params(vis, bound_generic_params));
11481148
try_visit!(vis.visit_trait_ref(trait_ref));

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12091209
modifiers: TraitBoundModifiers::NONE,
12101210
trait_ref: TraitRef { path: path.clone(), ref_id: t.id },
12111211
span: t.span,
1212+
parens: false,
12121213
},
12131214
itctx,
12141215
);

compiler/rustc_expand/src/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ impl<'a> ExtCtxt<'a> {
195195
},
196196
trait_ref: self.trait_ref(path),
197197
span,
198+
parens: false,
198199
}
199200
}
200201

compiler/rustc_parse/src/parser/ty.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,13 @@ impl<'a> Parser<'a> {
305305
let removal_span = kw.span.with_hi(self.token.span.lo());
306306
let path = self.parse_path(PathStyle::Type)?;
307307
let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus();
308-
let kind =
309-
self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)?;
308+
let kind = self.parse_remaining_bounds_path(
309+
lifetime_defs,
310+
path,
311+
lo,
312+
parse_plus,
313+
false,
314+
)?;
310315
let err = self.dcx().create_err(errors::TransposeDynOrImpl {
311316
span: kw.span,
312317
kw: kw.name.as_str(),
@@ -333,7 +338,7 @@ impl<'a> Parser<'a> {
333338
} else {
334339
let path = self.parse_path(PathStyle::Type)?;
335340
let parse_plus = allow_plus == AllowPlus::Yes && self.check_plus();
336-
self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus)?
341+
self.parse_remaining_bounds_path(lifetime_defs, path, lo, parse_plus, false)?
337342
}
338343
}
339344
} else if self.eat_keyword(exp!(Impl)) {
@@ -414,7 +419,7 @@ impl<'a> Parser<'a> {
414419
match ty.kind {
415420
// `(TY_BOUND_NOPAREN) + BOUND + ...`.
416421
TyKind::Path(None, path) if maybe_bounds => {
417-
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true)
422+
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true, true)
418423
}
419424
// For `('a) + …`, we know that `'a` in type position already lead to an error being
420425
// emitted. To reduce output, let's indirectly suppress E0178 (bad `+` in type) and
@@ -495,12 +500,14 @@ impl<'a> Parser<'a> {
495500
path: ast::Path,
496501
lo: Span,
497502
parse_plus: bool,
503+
has_parens: bool,
498504
) -> PResult<'a, TyKind> {
499505
let poly_trait_ref = PolyTraitRef::new(
500506
generic_params,
501507
path,
502508
TraitBoundModifiers::NONE,
503509
lo.to(self.prev_token.span),
510+
has_parens,
504511
);
505512
let bounds = vec![GenericBound::Trait(poly_trait_ref)];
506513
self.parse_remaining_bounds(bounds, parse_plus)
@@ -832,7 +839,7 @@ impl<'a> Parser<'a> {
832839
Ok(TyKind::MacCall(P(MacCall { path, args: self.parse_delim_args()? })))
833840
} else if allow_plus == AllowPlus::Yes && self.check_plus() {
834841
// `Trait1 + Trait2 + 'a`
835-
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true)
842+
self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true, false)
836843
} else {
837844
// Just a type path.
838845
Ok(TyKind::Path(None, path))
@@ -1190,8 +1197,13 @@ impl<'a> Parser<'a> {
11901197
}
11911198
}
11921199

1193-
let poly_trait =
1194-
PolyTraitRef::new(lifetime_defs, path, modifiers, lo.to(self.prev_token.span));
1200+
let poly_trait = PolyTraitRef::new(
1201+
lifetime_defs,
1202+
path,
1203+
modifiers,
1204+
lo.to(self.prev_token.span),
1205+
has_parens,
1206+
);
11951207
Ok(GenericBound::Trait(poly_trait))
11961208
}
11971209

compiler/rustc_resolve/src/late/diagnostics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,6 +3832,7 @@ fn mk_where_bound_predicate(
38323832
ref_id: DUMMY_NODE_ID,
38333833
},
38343834
span: DUMMY_SP,
3835+
parens: false,
38353836
})],
38363837
};
38373838

0 commit comments

Comments
 (0)