@@ -61,12 +61,11 @@ use crate::lints::{
6161 BuiltinEllipsisInclusiveRangePatternsLint , BuiltinExplicitOutlives ,
6262 BuiltinExplicitOutlivesSuggestion , BuiltinFeatureIssueNote , BuiltinIncompleteFeatures ,
6363 BuiltinIncompleteFeaturesHelp , BuiltinInternalFeatures , BuiltinKeywordIdents ,
64- BuiltinMissingCopyImpl , BuiltinMissingDebugImpl , BuiltinMissingDoc , BuiltinMutablesTransmutes ,
65- BuiltinNoMangleGeneric , BuiltinNonShorthandFieldPatterns , BuiltinSpecialModuleNameUsed ,
66- BuiltinTrivialBounds , BuiltinTypeAliasBounds , BuiltinUngatedAsyncFnTrackCaller ,
67- BuiltinUnpermittedTypeInit , BuiltinUnpermittedTypeInitSub , BuiltinUnreachablePub ,
68- BuiltinUnsafe , BuiltinUnstableFeatures , BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub ,
69- BuiltinWhileTrue , InvalidAsmLabel ,
64+ BuiltinMissingCopyImpl , BuiltinMissingDebugImpl , BuiltinMissingDoc , BuiltinNoMangleGeneric ,
65+ BuiltinNonShorthandFieldPatterns , BuiltinSpecialModuleNameUsed , BuiltinTrivialBounds ,
66+ BuiltinTypeAliasBounds , BuiltinUngatedAsyncFnTrackCaller , BuiltinUnpermittedTypeInit ,
67+ BuiltinUnpermittedTypeInitSub , BuiltinUnreachablePub , BuiltinUnsafe , BuiltinUnstableFeatures ,
68+ BuiltinUnusedDocComment , BuiltinUnusedDocCommentSub , BuiltinWhileTrue , InvalidAsmLabel ,
7069} ;
7170use crate :: nonstandard_style:: { method_context, MethodLateContext } ;
7271use crate :: {
@@ -1100,72 +1099,6 @@ impl<'tcx> LateLintPass<'tcx> for InvalidNoMangleItems {
11001099 }
11011100}
11021101
1103- declare_lint ! {
1104- /// The `mutable_transmutes` lint catches transmuting from `&T` to `&mut
1105- /// T` because it is [undefined behavior].
1106- ///
1107- /// [undefined behavior]: https://doc.rust-lang.org/reference/behavior-considered-undefined.html
1108- ///
1109- /// ### Example
1110- ///
1111- /// ```rust,compile_fail
1112- /// unsafe {
1113- /// let y = std::mem::transmute::<&i32, &mut i32>(&5);
1114- /// }
1115- /// ```
1116- ///
1117- /// {{produces}}
1118- ///
1119- /// ### Explanation
1120- ///
1121- /// Certain assumptions are made about aliasing of data, and this transmute
1122- /// violates those assumptions. Consider using [`UnsafeCell`] instead.
1123- ///
1124- /// [`UnsafeCell`]: https://doc.rust-lang.org/std/cell/struct.UnsafeCell.html
1125- MUTABLE_TRANSMUTES ,
1126- Deny ,
1127- "transmuting &T to &mut T is undefined behavior, even if the reference is unused"
1128- }
1129-
1130- declare_lint_pass ! ( MutableTransmutes => [ MUTABLE_TRANSMUTES ] ) ;
1131-
1132- impl < ' tcx > LateLintPass < ' tcx > for MutableTransmutes {
1133- fn check_expr ( & mut self , cx : & LateContext < ' _ > , expr : & hir:: Expr < ' _ > ) {
1134- if let Some ( ( & ty:: Ref ( _, _, from_mutbl) , & ty:: Ref ( _, _, to_mutbl) ) ) =
1135- get_transmute_from_to ( cx, expr) . map ( |( ty1, ty2) | ( ty1. kind ( ) , ty2. kind ( ) ) )
1136- {
1137- if from_mutbl < to_mutbl {
1138- cx. emit_span_lint ( MUTABLE_TRANSMUTES , expr. span , BuiltinMutablesTransmutes ) ;
1139- }
1140- }
1141-
1142- fn get_transmute_from_to < ' tcx > (
1143- cx : & LateContext < ' tcx > ,
1144- expr : & hir:: Expr < ' _ > ,
1145- ) -> Option < ( Ty < ' tcx > , Ty < ' tcx > ) > {
1146- let def = if let hir:: ExprKind :: Path ( ref qpath) = expr. kind {
1147- cx. qpath_res ( qpath, expr. hir_id )
1148- } else {
1149- return None ;
1150- } ;
1151- if let Res :: Def ( DefKind :: Fn , did) = def {
1152- if !def_id_is_transmute ( cx, did) {
1153- return None ;
1154- }
1155- let sig = cx. typeck_results ( ) . node_type ( expr. hir_id ) . fn_sig ( cx. tcx ) ;
1156- let from = sig. inputs ( ) . skip_binder ( ) [ 0 ] ;
1157- let to = sig. output ( ) . skip_binder ( ) ;
1158- return Some ( ( from, to) ) ;
1159- }
1160- None
1161- }
1162-
1163- fn def_id_is_transmute ( cx : & LateContext < ' _ > , def_id : DefId ) -> bool {
1164- cx. tcx . is_intrinsic ( def_id, sym:: transmute)
1165- }
1166- }
1167- }
1168-
11691102declare_lint ! {
11701103 /// The `unstable_features` lint detects uses of `#![feature]`.
11711104 ///
@@ -1612,7 +1545,6 @@ declare_lint_pass!(
16121545 UNUSED_DOC_COMMENTS ,
16131546 NO_MANGLE_CONST_ITEMS ,
16141547 NO_MANGLE_GENERIC_ITEMS ,
1615- MUTABLE_TRANSMUTES ,
16161548 UNSTABLE_FEATURES ,
16171549 UNREACHABLE_PUB ,
16181550 TYPE_ALIAS_BOUNDS ,
0 commit comments