Skip to content

Commit f28a382

Browse files
committed
Fix clippy::try_err
1 parent 1cce911 commit f28a382

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

chalk-integration/src/lowering.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
282282
let (adt_defn, adt_id) = self;
283283

284284
if adt_defn.flags.fundamental && adt_defn.all_parameters().len() < 1 {
285-
Err(RustIrError::InvalidFundamentalTypesParameters(
285+
return Err(RustIrError::InvalidFundamentalTypesParameters(
286286
adt_defn.name.clone(),
287-
))?;
287+
));
288288
}
289289

290290
let binders = env.in_binders(adt_defn.all_parameters(), |env| {
@@ -448,7 +448,7 @@ impl LowerWithEnv for TraitBound {
448448

449449
let k = env.trait_kind(trait_id);
450450
if k.sort != TypeSort::Trait {
451-
Err(RustIrError::NotTrait(self.trait_name.clone()))?;
451+
return Err(RustIrError::NotTrait(self.trait_name.clone()));
452452
}
453453

454454
let parameters = self
@@ -458,20 +458,20 @@ impl LowerWithEnv for TraitBound {
458458
.collect::<LowerResult<Vec<_>>>()?;
459459

460460
if parameters.len() != k.binders.len(interner) {
461-
Err(RustIrError::IncorrectNumberOfTypeParameters {
461+
return Err(RustIrError::IncorrectNumberOfTypeParameters {
462462
identifier: self.trait_name.clone(),
463463
expected: k.binders.len(interner),
464464
actual: parameters.len(),
465-
})?;
465+
});
466466
}
467467

468468
for (binder, param) in k.binders.binders.iter(interner).zip(parameters.iter()) {
469469
if binder.kind() != param.kind() {
470-
Err(RustIrError::IncorrectTraitParameterKind {
470+
return Err(RustIrError::IncorrectTraitParameterKind {
471471
identifier: self.trait_name.clone(),
472472
expected: binder.kind(),
473473
actual: param.kind(),
474-
})?;
474+
});
475475
}
476476
}
477477

@@ -495,20 +495,20 @@ impl LowerWithEnv for AliasEqBound {
495495
.collect::<LowerResult<_>>()?;
496496

497497
if args.len() != lookup.addl_variable_kinds.len() {
498-
Err(RustIrError::IncorrectNumberOfAssociatedTypeParameters {
498+
return Err(RustIrError::IncorrectNumberOfAssociatedTypeParameters {
499499
identifier: self.name.clone(),
500500
expected: lookup.addl_variable_kinds.len(),
501501
actual: args.len(),
502-
})?;
502+
});
503503
}
504504

505505
for (param, arg) in lookup.addl_variable_kinds.iter().zip(args.iter()) {
506506
if param.kind() != arg.kind() {
507-
Err(RustIrError::IncorrectAssociatedTypeParameterKind {
507+
return Err(RustIrError::IncorrectAssociatedTypeParameterKind {
508508
identifier: self.name.clone(),
509509
expected: param.kind(),
510510
actual: arg.kind(),
511-
})?;
511+
});
512512
}
513513
}
514514

@@ -631,20 +631,20 @@ impl LowerWithEnv for ProjectionTy {
631631
.collect::<LowerResult<_>>()?;
632632

633633
if args.len() != lookup.addl_variable_kinds.len() {
634-
Err(RustIrError::IncorrectNumberOfAssociatedTypeParameters {
634+
return Err(RustIrError::IncorrectNumberOfAssociatedTypeParameters {
635635
identifier: self.name.clone(),
636636
expected: lookup.addl_variable_kinds.len(),
637637
actual: args.len(),
638-
})?;
638+
});
639639
}
640640

641641
for (param, arg) in lookup.addl_variable_kinds.iter().zip(args.iter()) {
642642
if param.kind() != arg.kind() {
643-
Err(RustIrError::IncorrectAssociatedTypeParameterKind {
643+
return Err(RustIrError::IncorrectAssociatedTypeParameterKind {
644644
identifier: self.name.clone(),
645645
expected: param.kind(),
646646
actual: arg.kind(),
647-
})?;
647+
});
648648
}
649649
}
650650

@@ -707,16 +707,16 @@ impl LowerWithEnv for Ty {
707707
macro_rules! tykind {
708708
($k:expr, $tykind:ident, $id:expr) => {{
709709
if $k.binders.len(interner) != args.len() {
710-
Err(RustIrError::IncorrectNumberOfTypeParameters {
710+
return Err(RustIrError::IncorrectNumberOfTypeParameters {
711711
identifier: name.clone(),
712712
expected: $k.binders.len(interner),
713713
actual: args.len(),
714-
})?;
714+
});
715715
}
716716

717717
let substitution = chalk_ir::Substitution::from_fallible(
718718
interner,
719-
args.iter().map(|t| Ok(t.lower(env)?)),
719+
args.iter().map(|t| t.lower(env)),
720720
)?;
721721

722722
for (param, arg) in $k
@@ -726,11 +726,11 @@ impl LowerWithEnv for Ty {
726726
.zip(substitution.iter(interner))
727727
{
728728
if param.kind() != arg.kind() {
729-
Err(RustIrError::IncorrectParameterKind {
729+
return Err(RustIrError::IncorrectParameterKind {
730730
identifier: name.clone(),
731731
expected: param.kind(),
732732
actual: arg.kind(),
733-
})?;
733+
});
734734
}
735735
}
736736
chalk_ir::TyKind::$tykind($id, substitution).intern(interner)
@@ -896,9 +896,9 @@ impl LowerWithEnv for (&Impl, ImplId<ChalkIr>, &AssociatedTyValueIds) {
896896
debug!(?trait_ref);
897897

898898
if !polarity.is_positive() && !impl_.assoc_ty_values.is_empty() {
899-
Err(RustIrError::NegativeImplAssociatedValues(
899+
return Err(RustIrError::NegativeImplAssociatedValues(
900900
impl_.trait_ref.trait_name.clone(),
901-
))?;
901+
));
902902
}
903903

904904
let where_clauses = impl_.where_clauses.lower(env)?;
@@ -980,10 +980,10 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {
980980
let binders = env.in_binders(all_parameters, |env| {
981981
if trait_defn.flags.auto {
982982
if all_parameters_len > 1 {
983-
Err(RustIrError::AutoTraitParameters(trait_defn.name.clone()))?;
983+
return Err(RustIrError::AutoTraitParameters(trait_defn.name.clone()));
984984
}
985985
if !trait_defn.where_clauses.is_empty() {
986-
Err(RustIrError::AutoTraitWhereClauses(trait_defn.name.clone()))?;
986+
return Err(RustIrError::AutoTraitWhereClauses(trait_defn.name.clone()));
987987
}
988988
}
989989

chalk-integration/src/lowering/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl Env<'_> {
253253
.chain(binders)
254254
.collect();
255255
if parameter_map.len() != self.parameter_map.len() + len {
256-
Err(RustIrError::DuplicateOrShadowedParameters)?;
256+
return Err(RustIrError::DuplicateOrShadowedParameters);
257257
}
258258
Ok(Env {
259259
parameter_map,

chalk-integration/src/lowering/program_lowerer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl ProgramLowerer {
5959
match item {
6060
Item::TraitDefn(d) => {
6161
if d.flags.auto && !d.assoc_ty_defns.is_empty() {
62-
Err(RustIrError::AutoTraitAssociatedTypes(d.name.clone()))?;
62+
return Err(RustIrError::AutoTraitAssociatedTypes(d.name.clone()));
6363
}
6464
for defn in &d.assoc_ty_defns {
6565
let addl_variable_kinds = defn.all_parameters();

chalk-parse/src/lib.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
1616
pub fn parse_program(text: &str) -> Result<ast::Program> {
1717
match parser::ProgramParser::new().parse(text) {
1818
Ok(v) => Ok(v),
19-
Err(e) => Err(format!("parse error: {}", e))?,
19+
Err(e) => Err(format!("parse error: {}", e).into()),
2020
}
2121
}
2222

2323
pub fn parse_ty(text: &str) -> Result<ast::Ty> {
2424
match parser::TyParser::new().parse(text) {
2525
Ok(v) => Ok(v),
26-
Err(e) => Err(format!("error parsing `{}`: {}", text, e))?,
26+
Err(e) => Err(format!("error parsing `{}`: {}", text, e).into()),
2727
}
2828
}
2929

@@ -45,24 +45,17 @@ pub fn parse_goal(text: &str) -> Result<Box<ast::Goal>> {
4545
"parse error: {}\n{}",
4646
e,
4747
position_string(location, location + 1)
48-
))?,
48+
)
49+
.into()),
4950
ParseError::UnrecognizedToken {
5051
token: (start, _, end),
5152
..
52-
} => Err(format!(
53-
"parse error: {}\n{}",
54-
e,
55-
position_string(start, end)
56-
))?,
53+
} => Err(format!("parse error: {}\n{}", e, position_string(start, end)).into()),
5754
ParseError::ExtraToken {
5855
token: (start, _, end),
5956
..
60-
} => Err(format!(
61-
"parse error: {}\n{}",
62-
e,
63-
position_string(start, end)
64-
))?,
65-
_ => Err(format!("parse error: {}", e))?,
57+
} => Err(format!("parse error: {}\n{}", e, position_string(start, end)).into()),
58+
_ => Err(format!("parse error: {}", e).into()),
6659
}
6760
}
6861
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ where
184184
Err(ReadlineError::Eof) => break,
185185

186186
// Some other error occurred.
187-
Err(e) => Err(e)?,
187+
Err(e) => return Err(e.into()),
188188
}
189189
}
190190

0 commit comments

Comments
 (0)