Skip to content

Commit 0a8331f

Browse files
committed
Express contracts as part of function header and lower it to the contract lang items
includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures. includes post-developed commit: removed tabs that creeped in into rustfmt tool source code. includes post-developed commit, placating rustfmt self dogfooding. includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/ includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures). Rebase Conflicts: - compiler/rustc_parse/src/parser/diagnostics.rs - compiler/rustc_parse/src/parser/item.rs - compiler/rustc_span/src/hygiene.rs Remove contracts keywords from diagnostic messages
1 parent 1112801 commit 0a8331f

File tree

1 file changed

+20
-0
lines changed
  • clippy_utils/src/ast_utils

1 file changed

+20
-0
lines changed

Diff for: clippy_utils/src/ast_utils/mod.rs

+20
Original file line numberDiff line numberDiff line change
@@ -362,18 +362,21 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool {
362362
defaultness: ld,
363363
sig: lf,
364364
generics: lg,
365+
contract: lc,
365366
body: lb,
366367
}),
367368
Fn(box ast::Fn {
368369
defaultness: rd,
369370
sig: rf,
370371
generics: rg,
372+
contract: rc,
371373
body: rb,
372374
}),
373375
) => {
374376
eq_defaultness(*ld, *rd)
375377
&& eq_fn_sig(lf, rf)
376378
&& eq_generics(lg, rg)
379+
&& eq_opt_fn_contract(lc, rc)
377380
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
378381
},
379382
(Mod(lu, lmk), Mod(ru, rmk)) => {
@@ -497,18 +500,21 @@ pub fn eq_foreign_item_kind(l: &ForeignItemKind, r: &ForeignItemKind) -> bool {
497500
defaultness: ld,
498501
sig: lf,
499502
generics: lg,
503+
contract: lc,
500504
body: lb,
501505
}),
502506
Fn(box ast::Fn {
503507
defaultness: rd,
504508
sig: rf,
505509
generics: rg,
510+
contract: rc,
506511
body: rb,
507512
}),
508513
) => {
509514
eq_defaultness(*ld, *rd)
510515
&& eq_fn_sig(lf, rf)
511516
&& eq_generics(lg, rg)
517+
&& eq_opt_fn_contract(lc, rc)
512518
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
513519
},
514520
(
@@ -559,18 +565,21 @@ pub fn eq_assoc_item_kind(l: &AssocItemKind, r: &AssocItemKind) -> bool {
559565
defaultness: ld,
560566
sig: lf,
561567
generics: lg,
568+
contract: lc,
562569
body: lb,
563570
}),
564571
Fn(box ast::Fn {
565572
defaultness: rd,
566573
sig: rf,
567574
generics: rg,
575+
contract: rc,
568576
body: rb,
569577
}),
570578
) => {
571579
eq_defaultness(*ld, *rd)
572580
&& eq_fn_sig(lf, rf)
573581
&& eq_generics(lg, rg)
582+
&& eq_opt_fn_contract(lc, rc)
574583
&& both(lb.as_ref(), rb.as_ref(), |l, r| eq_block(l, r))
575584
},
576585
(
@@ -653,6 +662,17 @@ pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool {
653662
&& eq_ext(&l.ext, &r.ext)
654663
}
655664

665+
pub fn eq_opt_fn_contract(l: &Option<P<FnContract>>, r: &Option<P<FnContract>>) -> bool {
666+
match (l, r) {
667+
(Some(l), Some(r)) => {
668+
eq_expr_opt(l.requires.as_ref(), r.requires.as_ref())
669+
&& eq_expr_opt(l.ensures.as_ref(), r.ensures.as_ref())
670+
}
671+
(None, None) => true,
672+
(Some(_), None) | (None, Some(_)) => false,
673+
}
674+
}
675+
656676
pub fn eq_generics(l: &Generics, r: &Generics) -> bool {
657677
over(&l.params, &r.params, eq_generic_param)
658678
&& over(&l.where_clause.predicates, &r.where_clause.predicates, |l, r| {

0 commit comments

Comments
 (0)