Skip to content

Commit bc0d5b6

Browse files
Fix most clippy warnings (#490)
1 parent 5b49902 commit bc0d5b6

File tree

14 files changed

+188
-207
lines changed

14 files changed

+188
-207
lines changed

cedar-policy-core/src/ast/expr.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,15 @@ impl<T> Expr<T> {
269269
/// An expression is projectable if it's guaranteed to never error on evaluation
270270
/// This is true if the expression is entirely composed of values or unknowns
271271
pub fn is_projectable(&self) -> bool {
272-
self.subexpressions().all(|e| match e.expr_kind() {
273-
ExprKind::Lit(_) => true,
274-
ExprKind::Unknown(_) => true,
275-
ExprKind::Set(_) => true,
276-
ExprKind::Var(_) => true,
277-
ExprKind::Record(_) => true,
278-
_ => false,
272+
self.subexpressions().all(|e| {
273+
matches!(
274+
e.expr_kind(),
275+
ExprKind::Lit(_)
276+
| ExprKind::Unknown(_)
277+
| ExprKind::Set(_)
278+
| ExprKind::Var(_)
279+
| ExprKind::Record(_)
280+
)
279281
})
280282
}
281283
}
@@ -1020,7 +1022,7 @@ impl<T: Clone> ExprBuilder<T> {
10201022
pub fn and_nary(self, first: Expr<T>, others: impl IntoIterator<Item = Expr<T>>) -> Expr<T> {
10211023
others.into_iter().fold(first, |acc, next| {
10221024
Self::with_data(self.data.clone())
1023-
.with_maybe_source_span(self.source_span.clone())
1025+
.with_maybe_source_span(self.source_span)
10241026
.and(acc, next)
10251027
})
10261028
}
@@ -1035,7 +1037,7 @@ impl<T: Clone> ExprBuilder<T> {
10351037
pub fn or_nary(self, first: Expr<T>, others: impl IntoIterator<Item = Expr<T>>) -> Expr<T> {
10361038
others.into_iter().fold(first, |acc, next| {
10371039
Self::with_data(self.data.clone())
1038-
.with_maybe_source_span(self.source_span.clone())
1040+
.with_maybe_source_span(self.source_span)
10391041
.or(acc, next)
10401042
})
10411043
}
@@ -1044,7 +1046,7 @@ impl<T: Clone> ExprBuilder<T> {
10441046
pub fn greater(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T> {
10451047
// e1 > e2 is defined as !(e1 <= e2)
10461048
let leq = Self::with_data(self.data.clone())
1047-
.with_maybe_source_span(self.source_span.clone())
1049+
.with_maybe_source_span(self.source_span)
10481050
.lesseq(e1, e2);
10491051
self.not(leq)
10501052
}
@@ -1053,7 +1055,7 @@ impl<T: Clone> ExprBuilder<T> {
10531055
pub fn greatereq(self, e1: Expr<T>, e2: Expr<T>) -> Expr<T> {
10541056
// e1 >= e2 is defined as !(e1 < e2)
10551057
let leq = Self::with_data(self.data.clone())
1056-
.with_maybe_source_span(self.source_span.clone())
1058+
.with_maybe_source_span(self.source_span)
10571059
.less(e1, e2);
10581060
self.not(leq)
10591061
}

cedar-policy-core/src/ast/restricted_expr.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ impl RestrictedExpr {
196196

197197
/// Iterate over the elements of the set if this `RestrictedExpr` is a set,
198198
/// or `None` if it is not a set
199-
pub fn as_set_elements<'s>(
200-
&'s self,
201-
) -> Option<impl Iterator<Item = BorrowedRestrictedExpr<'s>>> {
199+
pub fn as_set_elements(&self) -> Option<impl Iterator<Item = BorrowedRestrictedExpr<'_>>> {
202200
match self.expr_kind() {
203201
ExprKind::Set(set) => Some(set.iter().map(BorrowedRestrictedExpr::new_unchecked)), // since the RestrictedExpr invariant holds for the input set, it will hold for each element as well
204202
_ => None,
@@ -207,9 +205,9 @@ impl RestrictedExpr {
207205

208206
/// Iterate over the (key, value) pairs of the record if this
209207
/// `RestrictedExpr` is a record, or `None` if it is not a record
210-
pub fn as_record_pairs<'s>(
211-
&'s self,
212-
) -> Option<impl Iterator<Item = (&'s SmolStr, BorrowedRestrictedExpr<'s>)>> {
208+
pub fn as_record_pairs(
209+
&self,
210+
) -> Option<impl Iterator<Item = (&SmolStr, BorrowedRestrictedExpr<'_>)>> {
213211
match self.expr_kind() {
214212
ExprKind::Record(map) => Some(
215213
map.iter()
@@ -222,9 +220,9 @@ impl RestrictedExpr {
222220
/// Get the name and args of the called extension function if this
223221
/// `RestrictedExpr` is an extension function call, or `None` if it is not
224222
/// an extension function call
225-
pub fn as_extn_fn_call<'s>(
226-
&'s self,
227-
) -> Option<(&Name, impl Iterator<Item = BorrowedRestrictedExpr<'s>>)> {
223+
pub fn as_extn_fn_call(
224+
&self,
225+
) -> Option<(&Name, impl Iterator<Item = BorrowedRestrictedExpr<'_>>)> {
228226
match self.expr_kind() {
229227
ExprKind::ExtensionFunctionApp { fn_name, args } => Some((
230228
fn_name,

cedar-policy-core/src/entities/json/schema_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub fn schematype_of_value(value: &Value) -> Result<SchemaType, HeterogeneousSet
384384
match value {
385385
Value::Lit(lit) => Ok(schematype_of_lit(lit)),
386386
Value::Set(set) => {
387-
let element_types = set.iter().map(|el| schematype_of_value(el));
387+
let element_types = set.iter().map(schematype_of_value);
388388
schematype_of_set_elements(element_types)
389389
}
390390
Value::Record(map) => Ok(SchemaType::Record {

cedar-policy-core/src/est/expr.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ fn interpret_primary(
11241124
let (l, r) = match (path.first(), path.last()) {
11251125
(Some(l), Some(r)) => (
11261126
l.loc.offset(),
1127-
r.loc.offset() + r.loc.len() + ident_to_str_len(&id),
1127+
r.loc.offset() + r.loc.len() + ident_to_str_len(id),
11281128
),
11291129
(_, _) => (0, 0),
11301130
};
@@ -1146,13 +1146,13 @@ fn interpret_primary(
11461146
))),
11471147
cst::Primary::Expr(e) => Ok(Either::Right(e.try_into()?)),
11481148
cst::Primary::EList(nodes) => nodes
1149-
.into_iter()
1149+
.iter()
11501150
.map(|node| node.try_into())
11511151
.collect::<Result<Vec<Expr>, _>>()
11521152
.map(Expr::set)
11531153
.map(Either::Right),
11541154
cst::Primary::RInits(nodes) => nodes
1155-
.into_iter()
1155+
.iter()
11561156
.map(|node| {
11571157
let cst::RecInit(k, v) = node.ok_or_missing()?;
11581158
let mut errs = ParseErrors::new();
@@ -1210,15 +1210,16 @@ impl TryFrom<&ASTNode<Option<cst::Member>>> for Expr {
12101210
item = match item {
12111211
Either::Left(name) => Either::Right(Expr::ext_call(
12121212
name.to_string().into(),
1213-
args.into_iter()
1213+
args.iter()
12141214
.map(|node| node.try_into())
12151215
.collect::<Result<Vec<_>, _>>()?,
12161216
)),
12171217
Either::Right(Expr::ExprNoExt(ExprNoExt::GetAttr { left, attr })) => {
1218-
let args = args
1219-
.into_iter()
1220-
.map(|node| node.try_into())
1221-
.collect::<Result<Vec<Expr>, ParseErrors>>()?;
1218+
let args = args.iter().map(|node| node.try_into()).collect::<Result<
1219+
Vec<Expr>,
1220+
ParseErrors,
1221+
>>(
1222+
)?;
12221223
let args = args.into_iter();
12231224
match attr.as_str() {
12241225
"contains" => Either::Right(Expr::contains(
@@ -1324,7 +1325,7 @@ impl TryFrom<&ASTNode<Option<cst::Name>>> for Expr {
13241325
let (l, r) = match (path.first(), path.last()) {
13251326
(Some(l), Some(r)) => (
13261327
l.loc.offset(),
1327-
r.loc.offset() + r.loc.len() + ident_to_str_len(&id),
1328+
r.loc.offset() + r.loc.len() + ident_to_str_len(id),
13281329
),
13291330
(_, _) => (0, 0),
13301331
};

cedar-policy-core/src/parser/cst_to_ast.rs

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl ASTNode<Option<cst::Policy>> {
247247
let (e, is_when) = c.to_expr(errs)?;
248248
for slot in e.slots() {
249249
errs.push(c.to_ast_err(ToASTErrorKind::SlotsInConditionClause {
250-
slot: slot.clone().into(),
250+
slot: (*slot).into(),
251251
clausetype: if is_when { "when" } else { "unless" },
252252
}));
253253
}
@@ -775,13 +775,12 @@ impl ExprOrSpecial<'_> {
775775
fn to_ast_err(&self, kind: impl Into<ToASTErrorKind>) -> ToASTError {
776776
ToASTError::new(
777777
kind.into(),
778-
match self {
778+
*match self {
779779
ExprOrSpecial::Expr(_, span) => span,
780780
ExprOrSpecial::Var(_, span) => span,
781781
ExprOrSpecial::Name(_, span) => span,
782782
ExprOrSpecial::StrLit(_, span) => span,
783-
}
784-
.clone(),
783+
},
785784
)
786785
}
787786

@@ -1620,7 +1619,7 @@ impl ASTNode<Option<cst::Member>> {
16201619
// move the id out of the slice as well, to avoid cloning the internal string
16211620
let id = mem::replace(i, ast::Id::new_unchecked(""));
16221621
head = id
1623-
.to_meth(construct_expr_var(var, vl.clone()), args, errs, src)
1622+
.to_meth(construct_expr_var(var, *vl), args, errs, src)
16241623
.map(|e| Expr(e, src));
16251624
tail = rest;
16261625
}
@@ -1639,7 +1638,7 @@ impl ASTNode<Option<cst::Member>> {
16391638
let args = std::mem::take(a);
16401639
let id = mem::replace(i, ast::Id::new_unchecked(""));
16411640
let maybe_expr = match to_unescaped_string(s) {
1642-
Ok(s) => Some(construct_expr_string(s, sl.clone())),
1641+
Ok(s) => Some(construct_expr_string(s, *sl)),
16431642
Err(escape_errs) => {
16441643
errs.extend(
16451644
escape_errs
@@ -1676,11 +1675,7 @@ impl ASTNode<Option<cst::Member>> {
16761675
let var = mem::replace(v, ast::Var::Principal);
16771676
let id = mem::replace(i, ast::Id::new_unchecked(""));
16781677
head = Some(Expr(
1679-
construct_expr_attr(
1680-
construct_expr_var(var, vl.clone()),
1681-
id.to_smolstr(),
1682-
src,
1683-
),
1678+
construct_expr_attr(construct_expr_var(var, *vl), id.to_smolstr(), src),
16841679
src,
16851680
));
16861681
tail = rest;
@@ -1696,7 +1691,7 @@ impl ASTNode<Option<cst::Member>> {
16961691
(Some(StrLit(s, sl)), [Some(Field(i)), rest @ ..]) => {
16971692
let id = mem::replace(i, ast::Id::new_unchecked(""));
16981693
let maybe_expr = match to_unescaped_string(s) {
1699-
Ok(s) => Some(construct_expr_string(s, sl.clone())),
1694+
Ok(s) => Some(construct_expr_string(s, *sl)),
17001695
Err(escape_errs) => {
17011696
errs.extend(
17021697
escape_errs
@@ -1715,7 +1710,7 @@ impl ASTNode<Option<cst::Member>> {
17151710
let var = mem::replace(v, ast::Var::Principal);
17161711
let s = mem::take(i);
17171712
head = Some(Expr(
1718-
construct_expr_attr(construct_expr_var(var, vl.clone()), s, src),
1713+
construct_expr_attr(construct_expr_var(var, *vl), s, src),
17191714
src,
17201715
));
17211716
tail = rest;
@@ -1731,7 +1726,7 @@ impl ASTNode<Option<cst::Member>> {
17311726
(Some(StrLit(s, sl)), [Some(Index(i)), rest @ ..]) => {
17321727
let id = mem::take(i);
17331728
let maybe_expr = match to_unescaped_string(s) {
1734-
Ok(s) => Some(construct_expr_string(s, sl.clone())),
1729+
Ok(s) => Some(construct_expr_string(s, *sl)),
17351730
Err(escape_errs) => {
17361731
errs.extend(
17371732
escape_errs
@@ -2227,13 +2222,9 @@ fn construct_expr_or(
22272222
chained: impl IntoIterator<Item = ast::Expr>,
22282223
span: miette::SourceSpan,
22292224
) -> ast::Expr {
2230-
let first = ast::ExprBuilder::new()
2231-
.with_source_span(span.clone())
2232-
.or(f, s);
2225+
let first = ast::ExprBuilder::new().with_source_span(span).or(f, s);
22332226
chained.into_iter().fold(first, |a, n| {
2234-
ast::ExprBuilder::new()
2235-
.with_source_span(span.clone())
2236-
.or(a, n)
2227+
ast::ExprBuilder::new().with_source_span(span).or(a, n)
22372228
})
22382229
}
22392230
fn construct_expr_and(
@@ -2242,13 +2233,9 @@ fn construct_expr_and(
22422233
chained: impl IntoIterator<Item = ast::Expr>,
22432234
span: miette::SourceSpan,
22442235
) -> ast::Expr {
2245-
let first = ast::ExprBuilder::new()
2246-
.with_source_span(span.clone())
2247-
.and(f, s);
2236+
let first = ast::ExprBuilder::new().with_source_span(span).and(f, s);
22482237
chained.into_iter().fold(first, |a, n| {
2249-
ast::ExprBuilder::new()
2250-
.with_source_span(span.clone())
2251-
.and(a, n)
2238+
ast::ExprBuilder::new().with_source_span(span).and(a, n)
22522239
})
22532240
}
22542241
fn construct_expr_rel(
@@ -2276,7 +2263,7 @@ fn construct_expr_add(
22762263
) -> ast::Expr {
22772264
let mut expr = f;
22782265
for (op, next_expr) in chained {
2279-
let builder = ast::ExprBuilder::new().with_source_span(span.clone());
2266+
let builder = ast::ExprBuilder::new().with_source_span(span);
22802267
expr = match op {
22812268
cst::AddOp::Plus => builder.add(expr, next_expr),
22822269
cst::AddOp::Minus => builder.sub(expr, next_expr),
@@ -2293,7 +2280,7 @@ fn construct_expr_mul(
22932280
let mut expr = f;
22942281
for next_expr in chained {
22952282
expr = ast::ExprBuilder::new()
2296-
.with_source_span(span.clone())
2283+
.with_source_span(span)
22972284
.mul(expr, next_expr)
22982285
}
22992286
expr

cedar-policy-core/src/parser/text_to_cst.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn parse_collect_errors<'a, P, T>(
5252

5353
let mut errors: err::ParseErrors = errs
5454
.into_iter()
55-
.map(|recovery| err::ToCSTError::from_raw_err_recovery(recovery))
55+
.map(err::ToCSTError::from_raw_err_recovery)
5656
.collect();
5757
let parsed = match result {
5858
Ok(parsed) => parsed,

cedar-policy-validator/src/expr_iterator.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ fn text_in_expr(e: &'_ Expr) -> impl IntoIterator<Item = TextKind<'_>> {
108108
}
109109
}
110110

111-
fn text_in_lit<'a>(
111+
fn text_in_lit(
112112
span: Option<miette::SourceSpan>,
113-
lit: &'a Literal,
114-
) -> impl IntoIterator<Item = TextKind<'a>> {
113+
lit: &Literal,
114+
) -> impl IntoIterator<Item = TextKind<'_>> {
115115
match lit {
116116
Literal::Bool(_) => vec![],
117117
Literal::Long(_) => vec![],
@@ -120,10 +120,10 @@ fn text_in_lit<'a>(
120120
}
121121
}
122122

123-
fn text_in_euid<'a>(
123+
fn text_in_euid(
124124
span: Option<miette::SourceSpan>,
125-
euid: &'a EntityUID,
126-
) -> impl Iterator<Item = TextKind<'a>> {
125+
euid: &EntityUID,
126+
) -> impl Iterator<Item = TextKind<'_>> {
127127
text_in_entity_type(span, euid.entity_type())
128128
.into_iter()
129129
.chain(std::iter::once(TextKind::Identifier(
@@ -132,20 +132,20 @@ fn text_in_euid<'a>(
132132
)))
133133
}
134134

135-
fn text_in_entity_type<'a>(
135+
fn text_in_entity_type(
136136
span: Option<miette::SourceSpan>,
137-
ty: &'a EntityType,
138-
) -> impl IntoIterator<Item = TextKind<'a>> {
137+
ty: &EntityType,
138+
) -> impl IntoIterator<Item = TextKind<'_>> {
139139
match ty {
140140
EntityType::Specified(ty) => text_in_name(span, ty).collect::<Vec<_>>(),
141141
EntityType::Unspecified => vec![],
142142
}
143143
}
144144

145-
fn text_in_name<'a>(
145+
fn text_in_name(
146146
span: Option<miette::SourceSpan>,
147-
name: &'a Name,
148-
) -> impl Iterator<Item = TextKind<'a>> {
147+
name: &Name,
148+
) -> impl Iterator<Item = TextKind<'_>> {
149149
name.namespace_components()
150150
.map(move |id| TextKind::Identifier(span, id.as_ref()))
151151
.chain(std::iter::once(TextKind::Identifier(

cedar-policy-validator/src/schema.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ impl ValidatorSchema {
380380
for p_entity in action.applies_to.applicable_principal_types() {
381381
match p_entity {
382382
EntityType::Specified(p_entity) => {
383-
if !entity_types.contains_key(&p_entity) {
383+
if !entity_types.contains_key(p_entity) {
384384
undeclared_e.insert(p_entity.to_string());
385385
}
386386
}
@@ -391,7 +391,7 @@ impl ValidatorSchema {
391391
for r_entity in action.applies_to.applicable_resource_types() {
392392
match r_entity {
393393
EntityType::Specified(r_entity) => {
394-
if !entity_types.contains_key(&r_entity) {
394+
if !entity_types.contains_key(r_entity) {
395395
undeclared_e.insert(r_entity.to_string());
396396
}
397397
}
@@ -526,10 +526,7 @@ impl ValidatorSchema {
526526
&'a self,
527527
euids: impl IntoIterator<Item = &'a EntityUID> + 'a,
528528
) -> impl Iterator<Item = &Name> {
529-
euids
530-
.into_iter()
531-
.map(|e| self.get_entity_types_in(e))
532-
.flatten()
529+
euids.into_iter().flat_map(|e| self.get_entity_types_in(e))
533530
}
534531

535532
/// Get all action entities in the schema where `action in euids` evaluates

cedar-policy-validator/src/type_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub struct TypeError {
5151
impl Diagnostic for TypeError {
5252
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
5353
self.source_span().as_ref().map(|info| {
54-
let label = miette::LabeledSpan::underline(info.clone());
54+
let label = miette::LabeledSpan::underline(*info);
5555
let ret: Box<dyn Iterator<Item = miette::LabeledSpan>> =
5656
Box::new(std::iter::once(label));
5757
ret

0 commit comments

Comments
 (0)