Skip to content

Commit a2b29fb

Browse files
Rollup merge of rust-lang#152943 - CoCo-Japan-pan:impl-restriction-parse, r=Urgau,jhpratt
Parse `impl` restrictions This PR implements the parsing logic for `impl` restrictions (e.g., `pub impl(crate) trait Foo {}`) as proposed in [RFC 3323](https://rust-lang.github.io/rfcs/3323-restrictions.html). As the first step of the RFC implementation, this PR focuses strictly on the parsing phase. The new syntax is guarded by the `#![feature(impl_restriction)]` feature gate. This implementation basically follows the pattern used in rust-lang#141754. r? @jhpratt
2 parents 3b4e355 + 3ebcade commit a2b29fb

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

  • clippy_utils/src/ast_utils

clippy_utils/src/ast_utils/mod.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
449449
constness: lc,
450450
is_auto: la,
451451
safety: lu,
452+
impl_restriction: liprt,
452453
ident: li,
453454
generics: lg,
454455
bounds: lb,
@@ -458,6 +459,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
458459
constness: rc,
459460
is_auto: ra,
460461
safety: ru,
462+
impl_restriction: riprt,
461463
ident: ri,
462464
generics: rg,
463465
bounds: rb,
@@ -467,6 +469,7 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
467469
matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No)
468470
&& la == ra
469471
&& matches!(lu, Safety::Default) == matches!(ru, Safety::Default)
472+
&& eq_impl_restriction(liprt, riprt)
470473
&& eq_id(*li, *ri)
471474
&& eq_generics(lg, rg)
472475
&& over(lb, rb, eq_generic_bound)
@@ -834,6 +837,29 @@ pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
834837
}
835838
}
836839

840+
pub fn eq_impl_restriction(l: &ImplRestriction, r: &ImplRestriction) -> bool {
841+
eq_restriction_kind(&l.kind, &r.kind)
842+
}
843+
844+
fn eq_restriction_kind(l: &RestrictionKind, r: &RestrictionKind) -> bool {
845+
match (l, r) {
846+
(RestrictionKind::Unrestricted, RestrictionKind::Unrestricted) => true,
847+
(
848+
RestrictionKind::Restricted {
849+
path: l_path,
850+
shorthand: l_short,
851+
id: _,
852+
},
853+
RestrictionKind::Restricted {
854+
path: r_path,
855+
shorthand: r_short,
856+
id: _,
857+
},
858+
) => l_short == r_short && eq_path(l_path, r_path),
859+
_ => false,
860+
}
861+
}
862+
837863
pub fn eq_fn_decl(l: &FnDecl, r: &FnDecl) -> bool {
838864
eq_fn_ret_ty(&l.output, &r.output)
839865
&& over(&l.inputs, &r.inputs, |l, r| {

0 commit comments

Comments
 (0)