diff options
| author | Ryan1729 <Ryan1729@gmail.com> | 2020-08-06 04:18:14 -0600 |
|---|---|---|
| committer | Ryan1729 <Ryan1729@gmail.com> | 2020-08-06 04:24:25 -0600 |
| commit | 54472478fa29c2d121da469bc8f10f8b68e3e134 (patch) | |
| tree | 63670c5b570caecb59059a8b5328aefa846f7f1e /src | |
| parent | afd4909d41cd0316ef2a01fe583b95eab9cb6475 (diff) | |
| download | rust-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.rs | 20 |
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 } |
