about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorRyan1729 <Ryan1729@gmail.com>2020-08-06 04:18:14 -0600
committerRyan1729 <Ryan1729@gmail.com>2020-08-06 04:24:25 -0600
commit54472478fa29c2d121da469bc8f10f8b68e3e134 (patch)
tree63670c5b570caecb59059a8b5328aefa846f7f1e /src
parentafd4909d41cd0316ef2a01fe583b95eab9cb6475 (diff)
downloadrust-54472478fa29c2d121da469bc8f10f8b68e3e134.tar.gz
rust-54472478fa29c2d121da469bc8f10f8b68e3e134.zip
change filter to assert, and update comments
Diffstat (limited to 'src')
-rw-r--r--src/tools/clippy/clippy_lints/src/transmute.rs20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/tools/clippy/clippy_lints/src/transmute.rs b/src/tools/clippy/clippy_lints/src/transmute.rs
index 231f13b236c..9f356811f22 100644
--- a/src/tools/clippy/clippy_lints/src/transmute.rs
+++ b/src/tools/clippy/clippy_lints/src/transmute.rs
@@ -697,7 +697,7 @@ fn is_layout_incompatible<'tcx>(cx: &LateContext<'tcx>, from: Ty<'tcx>, to: Ty<'
 /// Check if the the type conversion can be expressed as a pointer cast, instead of
 /// a transmute. In certain cases, including some invalid casts from array
 /// references to pointers, this may cause additional errors to be emitted and/or
-/// ICE error messages.
+/// ICE error messages. This function will panic if that occurs.
 fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> bool {
     use CastKind::*;
     matches!(
@@ -716,7 +716,7 @@ fn can_be_expressed_as_pointer_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<
 /// If a cast from from_ty to to_ty is valid, returns an Ok containing the kind of
 /// the cast. In certain cases, including some invalid casts from array references
 /// to pointers, this may cause additional errors to be emitted and/or ICE error
-/// messages.
+/// messages. This function will panic if that occurs.
 fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>, to_ty: Ty<'tcx>) -> Option<CastKind> {
     let hir_id = e.hir_id;
     let local_def_id = hir_id.owner;
@@ -743,11 +743,17 @@ fn check_cast<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>, from_ty: Ty<'tcx>
             DUMMY_SP,
             DUMMY_SP,
         ) {
-            check.do_check(&fn_ctxt)
-                .ok()
-                // do_check's documentation says that it might return Ok and create
-                // errors in the fcx instead of returing Err in some cases.
-                .filter(|_| !fn_ctxt.errors_reported_since_creation())
+            let res = check.do_check(&fn_ctxt);
+
+            // do_check's documentation says that it might return Ok and create
+            // errors in the fcx instead of returing Err in some cases. Those cases
+            // should be filtered out before getting here.
+            assert!(
+                !fn_ctxt.errors_reported_since_creation(),
+                "`fn_ctxt` contained errors after cast check!"
+            );
+
+            res.ok()
         } else {
             None
         }