|
28 | 28 | //! expression, `e as U2` is not necessarily so (in fact it will only be valid if |
29 | 29 | //! `U1` coerces to `U2`). |
30 | 30 |
|
31 | | -use rustc_ast::util::parser::ExprPrecedence; |
32 | 31 | use rustc_data_structures::fx::FxHashSet; |
33 | 32 | use rustc_errors::codes::*; |
34 | 33 | use rustc_errors::{Applicability, Diag, ErrorGuaranteed}; |
@@ -860,19 +859,14 @@ impl<'a, 'tcx> CastCheck<'tcx> { |
860 | 859 | (Ptr(m_e), Ptr(m_c)) => self.check_ptr_ptr_cast(fcx, m_e, m_c), // ptr-ptr-cast |
861 | 860 |
|
862 | 861 | // ptr-addr-cast |
863 | | - (Ptr(m_expr), Int(t_c)) => { |
864 | | - self.lossy_provenance_ptr2int_lint(fcx, t_c); |
865 | | - self.check_ptr_addr_cast(fcx, m_expr) |
866 | | - } |
| 862 | + (Ptr(m_expr), Int(_)) => self.check_ptr_addr_cast(fcx, m_expr), |
| 863 | + |
867 | 864 | (FnPtr, Int(_)) => { |
868 | 865 | // FIXME(#95489): there should eventually be a lint for these casts |
869 | 866 | Ok(CastKind::FnPtrAddrCast) |
870 | 867 | } |
871 | 868 | // addr-ptr-cast |
872 | | - (Int(_), Ptr(mt)) => { |
873 | | - self.fuzzy_provenance_int2ptr_lint(fcx); |
874 | | - self.check_addr_ptr_cast(fcx, mt) |
875 | | - } |
| 869 | + (Int(_), Ptr(mt)) => self.check_addr_ptr_cast(fcx, mt), |
876 | 870 | // fn-ptr-cast |
877 | 871 | (FnPtr, Ptr(mt)) => self.check_fptr_ptr_cast(fcx, mt), |
878 | 872 |
|
@@ -1133,59 +1127,6 @@ impl<'a, 'tcx> CastCheck<'tcx> { |
1133 | 1127 | } |
1134 | 1128 | } |
1135 | 1129 |
|
1136 | | - fn lossy_provenance_ptr2int_lint(&self, fcx: &FnCtxt<'a, 'tcx>, t_c: ty::cast::IntTy) { |
1137 | | - let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); |
1138 | | - let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); |
1139 | | - |
1140 | | - let sugg = self.span.can_be_used_for_suggestions().then(|| { |
1141 | | - let expr_prec = fcx.precedence(self.expr); |
1142 | | - let needs_parens = expr_prec < ExprPrecedence::Unambiguous; |
1143 | | - let needs_cast = !matches!(t_c, ty::cast::IntTy::U(ty::UintTy::Usize)); |
1144 | | - let cast_span = self.expr_span.shrink_to_hi().to(self.cast_span); |
1145 | | - let expr_span = self.expr_span.shrink_to_lo(); |
1146 | | - match (needs_parens, needs_cast) { |
1147 | | - (true, true) => errors::LossyProvenancePtr2IntSuggestion::NeedsParensCast { |
1148 | | - expr_span, |
1149 | | - cast_span, |
1150 | | - cast_ty, |
1151 | | - }, |
1152 | | - (true, false) => { |
1153 | | - errors::LossyProvenancePtr2IntSuggestion::NeedsParens { expr_span, cast_span } |
1154 | | - } |
1155 | | - (false, true) => { |
1156 | | - errors::LossyProvenancePtr2IntSuggestion::NeedsCast { cast_span, cast_ty } |
1157 | | - } |
1158 | | - (false, false) => errors::LossyProvenancePtr2IntSuggestion::Other { cast_span }, |
1159 | | - } |
1160 | | - }); |
1161 | | - |
1162 | | - let lint = errors::LossyProvenancePtr2Int { expr_ty, cast_ty, sugg }; |
1163 | | - fcx.tcx.emit_node_span_lint( |
1164 | | - lint::builtin::LOSSY_PROVENANCE_CASTS, |
1165 | | - self.expr.hir_id, |
1166 | | - self.span, |
1167 | | - lint, |
1168 | | - ); |
1169 | | - } |
1170 | | - |
1171 | | - fn fuzzy_provenance_int2ptr_lint(&self, fcx: &FnCtxt<'a, 'tcx>) { |
1172 | | - let sugg = self.span.can_be_used_for_suggestions().then(|| { |
1173 | | - errors::LossyProvenanceInt2PtrSuggestion { |
1174 | | - lo: self.expr_span.shrink_to_lo(), |
1175 | | - hi: self.expr_span.shrink_to_hi().to(self.cast_span), |
1176 | | - } |
1177 | | - }); |
1178 | | - let expr_ty = fcx.resolve_vars_if_possible(self.expr_ty); |
1179 | | - let cast_ty = fcx.resolve_vars_if_possible(self.cast_ty); |
1180 | | - let lint = errors::LossyProvenanceInt2Ptr { expr_ty, cast_ty, sugg }; |
1181 | | - fcx.tcx.emit_node_span_lint( |
1182 | | - lint::builtin::FUZZY_PROVENANCE_CASTS, |
1183 | | - self.expr.hir_id, |
1184 | | - self.span, |
1185 | | - lint, |
1186 | | - ); |
1187 | | - } |
1188 | | - |
1189 | 1130 | /// Attempt to suggest using `.is_empty` when trying to cast from a |
1190 | 1131 | /// collection type to a boolean. |
1191 | 1132 | fn try_suggest_collection_to_bool(&self, fcx: &FnCtxt<'a, 'tcx>, err: &mut Diag<'_>) { |
|
0 commit comments