diff --git a/clippy_lints/src/endian_bytes.rs b/clippy_lints/src/endian_bytes.rs index d76729047cdc..3a70ab079fbb 100644 --- a/clippy_lints/src/endian_bytes.rs +++ b/clippy_lints/src/endian_bytes.rs @@ -1,12 +1,12 @@ -use crate::Lint; use clippy_utils::diagnostics::span_lint_and_then; +use clippy_utils::res::{MaybeDef, MaybeTypeckRes}; use clippy_utils::{is_lint_allowed, sym}; -use rustc_hir::{Expr, ExprKind}; -use rustc_lint::{LateContext, LateLintPass, LintContext}; -use rustc_middle::ty::Ty; +use core::ptr; +use rustc_errors::Applicability; +use rustc_hir::{Expr, ExprKind, QPath}; +use rustc_lint::{LateContext, LateLintPass}; +use rustc_middle::ty; use rustc_session::declare_lint_pass; -use rustc_span::Symbol; -use std::fmt::Write; declare_clippy_lint! { /// ### What it does @@ -69,133 +69,67 @@ declare_lint_pass!(EndianBytes => [ LITTLE_ENDIAN_BYTES, ]); -const HOST_NAMES: [Symbol; 2] = [sym::from_ne_bytes, sym::to_ne_bytes]; -const LITTLE_NAMES: [Symbol; 2] = [sym::from_le_bytes, sym::to_le_bytes]; -const BIG_NAMES: [Symbol; 2] = [sym::from_be_bytes, sym::to_be_bytes]; - -#[derive(Clone, Debug)] -enum LintKind { - Host, - Little, - Big, -} - -#[derive(Clone, Copy, PartialEq)] -enum Prefix { +#[derive(Clone, Copy)] +enum Direction { From, To, } -impl LintKind { - fn allowed(&self, cx: &LateContext<'_>, expr: &Expr<'_>) -> bool { - is_lint_allowed(cx, self.as_lint(), expr.hir_id) - } - - fn as_lint(&self) -> &'static Lint { - match self { - LintKind::Host => HOST_ENDIAN_BYTES, - LintKind::Little => LITTLE_ENDIAN_BYTES, - LintKind::Big => BIG_ENDIAN_BYTES, - } - } - - fn as_name(&self, prefix: Prefix) -> Symbol { - let index = usize::from(prefix == Prefix::To); - - match self { - LintKind::Host => HOST_NAMES[index], - LintKind::Little => LITTLE_NAMES[index], - LintKind::Big => BIG_NAMES[index], - } - } -} - impl LateLintPass<'_> for EndianBytes { - fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) { - let (prefix, name, ty_expr) = match expr.kind { - ExprKind::MethodCall(method_name, receiver, [], ..) => (Prefix::To, method_name.ident.name, receiver), - ExprKind::Call(function, ..) - if let ExprKind::Path(qpath) = function.kind - && let Some(def_id) = cx.qpath_res(&qpath, function.hir_id).opt_def_id() - && let Some(function_name) = cx.get_def_path(def_id).last() => - { - (Prefix::From, *function_name, expr) + fn check_expr(&mut self, cx: &LateContext<'_>, e: &Expr<'_>) { + let (sp, direction, lint, msg) = match e.kind { + // rustfmt wants to break each arm into one line per tuple element which + // really hurts readability. + #[rustfmt::skip] + ExprKind::MethodCall(seg, _, [], _) => match seg.ident.name { + sym::to_ne_bytes => (seg.ident.span, Direction::To, HOST_ENDIAN_BYTES, "use of `to_ne_bytes`"), + sym::to_le_bytes => (seg.ident.span, Direction::To, LITTLE_ENDIAN_BYTES, "use of `to_le_bytes`"), + sym::to_be_bytes => (seg.ident.span, Direction::To, BIG_ENDIAN_BYTES, "use of `to_be_bytes`"), + _ => return, + }, + #[rustfmt::skip] + ExprKind::Path(QPath::TypeRelative(_, seg)) => match seg.ident.name { + sym::from_ne_bytes => (seg.ident.span, Direction::From, HOST_ENDIAN_BYTES, "use of `from_ne_bytes`"), + sym::from_le_bytes => (seg.ident.span, Direction::From, LITTLE_ENDIAN_BYTES, "use of `from_le_bytes`"), + sym::from_be_bytes => (seg.ident.span, Direction::From, BIG_ENDIAN_BYTES, "use of `from_be_bytes`"), + sym::to_ne_bytes => (seg.ident.span, Direction::To, HOST_ENDIAN_BYTES, "use of `to_ne_bytes`"), + sym::to_le_bytes => (seg.ident.span, Direction::To, LITTLE_ENDIAN_BYTES, "use of `to_le_bytes`"), + sym::to_be_bytes => (seg.ident.span, Direction::To, BIG_ENDIAN_BYTES, "use of `to_be_bytes`"), + _ => return, }, _ => return, }; - if !expr.span.in_external_macro(cx.sess().source_map()) - && let ty = cx.typeck_results().expr_ty(ty_expr) - && ty.is_primitive_ty() + if let Some(ty) = cx.ty_based_def(e.hir_id).opt_parent(cx).opt_impl_ty(cx) + && let ty::Uint(_) | ty::Int(_) | ty::Float(_) = *ty.instantiate_identity().skip_normalization().kind() + // Only check where the name itself comes from. The point of the lints is to + // catch when the wrong byte order is used so we only care if the current crate + // decided on the byte order. Which crate actually assembled the path/call + // isn't relevant for these lints. + && !sp.in_external_macro(cx.tcx.sess.source_map()) { - maybe_lint_endian_bytes(cx, expr, prefix, name, ty); - } - } -} - -fn maybe_lint_endian_bytes(cx: &LateContext<'_>, expr: &Expr<'_>, prefix: Prefix, name: Symbol, ty: Ty<'_>) { - let ne = LintKind::Host.as_name(prefix); - let le = LintKind::Little.as_name(prefix); - let be = LintKind::Big.as_name(prefix); - - let (lint, other_lints) = match name { - name if name == ne => ((&LintKind::Host), [(&LintKind::Little), (&LintKind::Big)]), - name if name == le => ((&LintKind::Little), [(&LintKind::Host), (&LintKind::Big)]), - name if name == be => ((&LintKind::Big), [(&LintKind::Host), (&LintKind::Little)]), - _ => return, - }; - - span_lint_and_then( - cx, - lint.as_lint(), - expr.span, - format!( - "usage of the {}`{ty}::{}`{}", - if prefix == Prefix::From { "function " } else { "" }, - lint.as_name(prefix), - if prefix == Prefix::To { " method" } else { "" }, - ), - move |diag| { - // all lints disallowed, don't give help here - if [&[lint], other_lints.as_slice()] - .concat() - .iter() - .all(|lint| !lint.allowed(cx, expr)) - { - return; - } - - // ne_bytes and all other lints allowed - if lint.as_name(prefix) == ne && other_lints.iter().all(|lint| lint.allowed(cx, expr)) { - diag.help("specify the desired endianness explicitly"); - return; - } - - // le_bytes where ne_bytes allowed but be_bytes is not, or le_bytes where ne_bytes allowed but - // le_bytes is not - if (lint.as_name(prefix) == le || lint.as_name(prefix) == be) && LintKind::Host.allowed(cx, expr) { - diag.help("use the native endianness instead"); - return; - } - - let allowed_lints = other_lints.iter().filter(|lint| lint.allowed(cx, expr)); - let len = allowed_lints.clone().count(); - - let mut help_str = "use ".to_owned(); - - for (i, lint) in allowed_lints.enumerate() { - let only_one = len == 1; - if !only_one { - help_str.push_str("either of "); + span_lint_and_then(cx, lint, sp, msg, |diag| { + if !ptr::addr_eq(lint, HOST_ENDIAN_BYTES) && is_lint_allowed(cx, HOST_ENDIAN_BYTES, e.hir_id) { + let (msg, sugg) = match direction { + Direction::From => ("convert from native endian", "from_ne_bytes"), + Direction::To => ("convert to native endian", "to_ne_bytes"), + }; + diag.span_suggestion(sp, msg, sugg, Applicability::MaybeIncorrect); } - - write!(help_str, "`{ty}::{}` ", lint.as_name(prefix)).unwrap(); - - if i != len && !only_one { - help_str.push_str("or "); + if !ptr::addr_eq(lint, LITTLE_ENDIAN_BYTES) && is_lint_allowed(cx, LITTLE_ENDIAN_BYTES, e.hir_id) { + let (msg, sugg) = match direction { + Direction::From => ("convert from little endian", "from_le_bytes"), + Direction::To => ("convert to little endian", "to_le_bytes"), + }; + diag.span_suggestion(sp, msg, sugg, Applicability::MaybeIncorrect); } - } - help_str.push_str("instead"); - diag.help(help_str); - }, - ); + if !ptr::addr_eq(lint, BIG_ENDIAN_BYTES) && is_lint_allowed(cx, BIG_ENDIAN_BYTES, e.hir_id) { + let (msg, sugg) = match direction { + Direction::From => ("convert from big endian", "from_be_bytes"), + Direction::To => ("convert to big endian", "to_be_bytes"), + }; + diag.span_suggestion(sp, msg, sugg, Applicability::MaybeIncorrect); + } + }); + } + } } diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 0514c86d0bec..c7e35a5ed35c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -414,7 +414,6 @@ mod zombie_processes; use clippy_config::{Conf, get_configuration_metadata, sanitize_explanation}; use clippy_utils::macros::FormatArgsStorage; use rustc_data_structures::fx::FxHashSet; -use rustc_lint::Lint; use rustc_middle::ty::TyCtxt; use utils::attr_collector::AttrStorage; diff --git a/clippy_utils/src/res.rs b/clippy_utils/src/res.rs index 23afb25f1bbf..d397c6407e8a 100644 --- a/clippy_utils/src/res.rs +++ b/clippy_utils/src/res.rs @@ -339,6 +339,8 @@ impl<'tcx, T: Copy + MaybeQPath<'tcx>> MaybeQPath<'tcx> for &Option { /// A resolved path and the explicit `Self` type if there is one. type OptResPath<'tcx> = (Option<&'tcx hir::Ty<'tcx>>, Option<&'tcx Path<'tcx>>); +type OptTyRelPath<'tcx> = Option<(&'tcx hir::Ty<'tcx>, &'tcx PathSegment<'tcx>)>; + /// A HIR node which might be a `QPath::Resolved`. /// /// The following are resolved paths: @@ -354,6 +356,10 @@ pub trait MaybeResPath<'a>: Copy { /// type associated with it. fn opt_res_path(self) -> OptResPath<'a>; + /// If this node is a type relative path gets both the type and the final + /// segments of the path. + fn opt_ty_rel_path(self) -> OptTyRelPath<'a>; + /// If this node is a resolved path gets it's resolution. Returns `Res::Err` /// otherwise. #[inline] @@ -391,6 +397,11 @@ impl<'a> MaybeResPath<'a> for &'a Path<'a> { (None, Some(self)) } + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + None + } + #[inline] fn basic_res(self) -> &'a Res { &self.res @@ -404,6 +415,14 @@ impl<'a> MaybeResPath<'a> for &QPath<'a> { QPath::TypeRelative(..) => (None, None), } } + + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + match *self { + QPath::TypeRelative(ty, seg) => Some((ty, seg)), + QPath::Resolved(..) => None, + } + } } impl<'a> MaybeResPath<'a> for &Expr<'a> { #[inline] @@ -413,6 +432,14 @@ impl<'a> MaybeResPath<'a> for &Expr<'a> { _ => (None, None), } } + + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + match &self.kind { + ExprKind::Path(qpath) => qpath.opt_ty_rel_path(), + _ => None, + } + } } impl<'a> MaybeResPath<'a> for &PatExpr<'a> { #[inline] @@ -422,6 +449,14 @@ impl<'a> MaybeResPath<'a> for &PatExpr<'a> { PatExprKind::Lit { .. } => (None, None), } } + + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + match &self.kind { + PatExprKind::Path(qpath) => qpath.opt_ty_rel_path(), + PatExprKind::Lit { .. } => None, + } + } } impl<'a, AmbigArg> MaybeResPath<'a> for &hir::Ty<'a, AmbigArg> { #[inline] @@ -431,6 +466,14 @@ impl<'a, AmbigArg> MaybeResPath<'a> for &hir::Ty<'a, AmbigArg> { _ => (None, None), } } + + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + match &self.kind { + TyKind::Path(qpath) => qpath.opt_ty_rel_path(), + _ => None, + } + } } impl<'a> MaybeResPath<'a> for &Pat<'a> { #[inline] @@ -440,6 +483,14 @@ impl<'a> MaybeResPath<'a> for &Pat<'a> { _ => (None, None), } } + + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + match self.kind { + PatKind::Expr(e) => e.opt_ty_rel_path(), + _ => None, + } + } } impl<'a, T: MaybeResPath<'a>> MaybeResPath<'a> for Option { #[inline] @@ -450,6 +501,11 @@ impl<'a, T: MaybeResPath<'a>> MaybeResPath<'a> for Option { } } + #[inline] + fn opt_ty_rel_path(self) -> OptTyRelPath<'a> { + self.and_then(T::opt_ty_rel_path) + } + #[inline] fn basic_res(self) -> &'a Res { self.map_or(&Res::Err, T::basic_res) diff --git a/tests/ui/big_endian_bytes.1.fixed b/tests/ui/big_endian_bytes.1.fixed new file mode 100644 index 000000000000..138899d4cc6e --- /dev/null +++ b/tests/ui/big_endian_bytes.1.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::big_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_ne_bytes(); //~ big_endian_bytes + let _ = 0u16.to_ne_bytes(); //~ big_endian_bytes + let _ = 0u32.to_ne_bytes(); //~ big_endian_bytes + let _ = 0u64.to_ne_bytes(); //~ big_endian_bytes + let _ = 0u128.to_ne_bytes(); //~ big_endian_bytes + let _ = 0usize.to_ne_bytes(); //~ big_endian_bytes + + let _ = 0i8.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i16.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i32.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i64.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i128.to_ne_bytes(); //~ big_endian_bytes + let _ = 0isize.to_ne_bytes(); //~ big_endian_bytes + + let _ = 0f16.to_ne_bytes(); //~ big_endian_bytes + let _ = 0f32.to_ne_bytes(); //~ big_endian_bytes + let _ = 0f64.to_ne_bytes(); //~ big_endian_bytes + let _ = 0f128.to_ne_bytes(); //~ big_endian_bytes + + let _ = u8::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = u16::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = u32::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = u64::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = u128::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = usize::from_ne_bytes([0; _]); //~ big_endian_bytes + + let _ = i8::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i16::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i32::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i64::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i128::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = isize::from_ne_bytes([0; _]); //~ big_endian_bytes + + let _ = f16::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = f32::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = f64::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = f128::from_ne_bytes([0; _]); //~ big_endian_bytes + }; + + { + let _ = u8::from_ne_bytes; //~ big_endian_bytes + let _ = u8::to_ne_bytes; //~ big_endian_bytes + } + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ big_endian_bytes + let _ = 0i8.to_le_bytes(); //~ big_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ big_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ big_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ big_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_ne_bytes(); //~ big_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = 0u8.$to_ne_bytes(); //~ big_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ big_endian_bytes + }} + + external! { + let _ = 0u8.to_be_bytes(); + let _ = u8::from_be_bytes([0; _]); + let _ = 0u8.$to_ne_bytes(); //~ big_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ big_endian_bytes + } + } +} diff --git a/tests/ui/big_endian_bytes.2.fixed b/tests/ui/big_endian_bytes.2.fixed new file mode 100644 index 000000000000..3adcb7ae3782 --- /dev/null +++ b/tests/ui/big_endian_bytes.2.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::big_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_le_bytes(); //~ big_endian_bytes + let _ = 0u16.to_le_bytes(); //~ big_endian_bytes + let _ = 0u32.to_le_bytes(); //~ big_endian_bytes + let _ = 0u64.to_le_bytes(); //~ big_endian_bytes + let _ = 0u128.to_le_bytes(); //~ big_endian_bytes + let _ = 0usize.to_le_bytes(); //~ big_endian_bytes + + let _ = 0i8.to_le_bytes(); //~ big_endian_bytes + let _ = 0i16.to_le_bytes(); //~ big_endian_bytes + let _ = 0i32.to_le_bytes(); //~ big_endian_bytes + let _ = 0i64.to_le_bytes(); //~ big_endian_bytes + let _ = 0i128.to_le_bytes(); //~ big_endian_bytes + let _ = 0isize.to_le_bytes(); //~ big_endian_bytes + + let _ = 0f16.to_le_bytes(); //~ big_endian_bytes + let _ = 0f32.to_le_bytes(); //~ big_endian_bytes + let _ = 0f64.to_le_bytes(); //~ big_endian_bytes + let _ = 0f128.to_le_bytes(); //~ big_endian_bytes + + let _ = u8::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = u16::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = u32::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = u64::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = u128::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = usize::from_le_bytes([0; _]); //~ big_endian_bytes + + let _ = i8::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i16::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i32::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i64::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i128::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = isize::from_le_bytes([0; _]); //~ big_endian_bytes + + let _ = f16::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = f32::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = f64::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = f128::from_le_bytes([0; _]); //~ big_endian_bytes + }; + + { + let _ = u8::from_le_bytes; //~ big_endian_bytes + let _ = u8::to_le_bytes; //~ big_endian_bytes + } + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ big_endian_bytes + let _ = 0i8.to_le_bytes(); //~ big_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ big_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ big_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ big_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ big_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_le_bytes(); //~ big_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ big_endian_bytes + let _ = 0u8.$to_le_bytes(); //~ big_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ big_endian_bytes + }} + + external! { + let _ = 0u8.to_be_bytes(); + let _ = u8::from_be_bytes([0; _]); + let _ = 0u8.$to_le_bytes(); //~ big_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ big_endian_bytes + } + } +} diff --git a/tests/ui/big_endian_bytes.rs b/tests/ui/big_endian_bytes.rs new file mode 100644 index 000000000000..b0116f35e8c1 --- /dev/null +++ b/tests/ui/big_endian_bytes.rs @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::big_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_be_bytes(); //~ big_endian_bytes + let _ = 0u16.to_be_bytes(); //~ big_endian_bytes + let _ = 0u32.to_be_bytes(); //~ big_endian_bytes + let _ = 0u64.to_be_bytes(); //~ big_endian_bytes + let _ = 0u128.to_be_bytes(); //~ big_endian_bytes + let _ = 0usize.to_be_bytes(); //~ big_endian_bytes + + let _ = 0i8.to_be_bytes(); //~ big_endian_bytes + let _ = 0i16.to_be_bytes(); //~ big_endian_bytes + let _ = 0i32.to_be_bytes(); //~ big_endian_bytes + let _ = 0i64.to_be_bytes(); //~ big_endian_bytes + let _ = 0i128.to_be_bytes(); //~ big_endian_bytes + let _ = 0isize.to_be_bytes(); //~ big_endian_bytes + + let _ = 0f16.to_be_bytes(); //~ big_endian_bytes + let _ = 0f32.to_be_bytes(); //~ big_endian_bytes + let _ = 0f64.to_be_bytes(); //~ big_endian_bytes + let _ = 0f128.to_be_bytes(); //~ big_endian_bytes + + let _ = u8::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = u16::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = u32::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = u64::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = u128::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = usize::from_be_bytes([0; _]); //~ big_endian_bytes + + let _ = i8::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i16::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i32::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i64::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i128::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = isize::from_be_bytes([0; _]); //~ big_endian_bytes + + let _ = f16::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = f32::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = f64::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = f128::from_be_bytes([0; _]); //~ big_endian_bytes + }; + + { + let _ = u8::from_be_bytes; //~ big_endian_bytes + let _ = u8::to_be_bytes; //~ big_endian_bytes + } + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ big_endian_bytes + let _ = 0i8.to_be_bytes(); //~ big_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ big_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ big_endian_bytes + let _ = 0i8.to_be_bytes(); //~ big_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ big_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_be_bytes(); //~ big_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ big_endian_bytes + let _ = 0u8.$to_be_bytes(); //~ big_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ big_endian_bytes + }} + + external! { + let _ = 0u8.to_be_bytes(); + let _ = u8::from_be_bytes([0; _]); + let _ = 0u8.$to_be_bytes(); //~ big_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ big_endian_bytes + } + } +} diff --git a/tests/ui/big_endian_bytes.stderr b/tests/ui/big_endian_bytes.stderr new file mode 100644 index 000000000000..6c01b2c08653 --- /dev/null +++ b/tests/ui/big_endian_bytes.stderr @@ -0,0 +1,734 @@ +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:12:21 + | +LL | let _ = 0u8.to_be_bytes(); + | ^^^^^^^^^^^ + | + = note: `-D clippy::big-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::big_endian_bytes)]` +help: convert to native endian + | +LL - let _ = 0u8.to_be_bytes(); +LL + let _ = 0u8.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u8.to_be_bytes(); +LL + let _ = 0u8.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:13:22 + | +LL | let _ = 0u16.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u16.to_be_bytes(); +LL + let _ = 0u16.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u16.to_be_bytes(); +LL + let _ = 0u16.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:14:22 + | +LL | let _ = 0u32.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u32.to_be_bytes(); +LL + let _ = 0u32.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u32.to_be_bytes(); +LL + let _ = 0u32.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:15:22 + | +LL | let _ = 0u64.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u64.to_be_bytes(); +LL + let _ = 0u64.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u64.to_be_bytes(); +LL + let _ = 0u64.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:16:23 + | +LL | let _ = 0u128.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u128.to_be_bytes(); +LL + let _ = 0u128.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u128.to_be_bytes(); +LL + let _ = 0u128.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:17:24 + | +LL | let _ = 0usize.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0usize.to_be_bytes(); +LL + let _ = 0usize.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0usize.to_be_bytes(); +LL + let _ = 0usize.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:19:21 + | +LL | let _ = 0i8.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i8.to_be_bytes(); +LL + let _ = 0i8.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0i8.to_be_bytes(); +LL + let _ = 0i8.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:20:22 + | +LL | let _ = 0i16.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i16.to_be_bytes(); +LL + let _ = 0i16.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0i16.to_be_bytes(); +LL + let _ = 0i16.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:21:22 + | +LL | let _ = 0i32.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i32.to_be_bytes(); +LL + let _ = 0i32.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0i32.to_be_bytes(); +LL + let _ = 0i32.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:22:22 + | +LL | let _ = 0i64.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i64.to_be_bytes(); +LL + let _ = 0i64.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0i64.to_be_bytes(); +LL + let _ = 0i64.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:23:23 + | +LL | let _ = 0i128.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i128.to_be_bytes(); +LL + let _ = 0i128.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0i128.to_be_bytes(); +LL + let _ = 0i128.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:24:24 + | +LL | let _ = 0isize.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0isize.to_be_bytes(); +LL + let _ = 0isize.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0isize.to_be_bytes(); +LL + let _ = 0isize.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:26:22 + | +LL | let _ = 0f16.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f16.to_be_bytes(); +LL + let _ = 0f16.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0f16.to_be_bytes(); +LL + let _ = 0f16.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:27:22 + | +LL | let _ = 0f32.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f32.to_be_bytes(); +LL + let _ = 0f32.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0f32.to_be_bytes(); +LL + let _ = 0f32.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:28:22 + | +LL | let _ = 0f64.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f64.to_be_bytes(); +LL + let _ = 0f64.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0f64.to_be_bytes(); +LL + let _ = 0f64.to_le_bytes(); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:29:23 + | +LL | let _ = 0f128.to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f128.to_be_bytes(); +LL + let _ = 0f128.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0f128.to_be_bytes(); +LL + let _ = 0f128.to_le_bytes(); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:31:21 + | +LL | let _ = u8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::from_be_bytes([0; _]); +LL + let _ = u8::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u8::from_be_bytes([0; _]); +LL + let _ = u8::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:32:22 + | +LL | let _ = u16::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u16::from_be_bytes([0; _]); +LL + let _ = u16::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u16::from_be_bytes([0; _]); +LL + let _ = u16::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:33:22 + | +LL | let _ = u32::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u32::from_be_bytes([0; _]); +LL + let _ = u32::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u32::from_be_bytes([0; _]); +LL + let _ = u32::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:34:22 + | +LL | let _ = u64::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u64::from_be_bytes([0; _]); +LL + let _ = u64::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u64::from_be_bytes([0; _]); +LL + let _ = u64::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:35:23 + | +LL | let _ = u128::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u128::from_be_bytes([0; _]); +LL + let _ = u128::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u128::from_be_bytes([0; _]); +LL + let _ = u128::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:36:24 + | +LL | let _ = usize::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = usize::from_be_bytes([0; _]); +LL + let _ = usize::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = usize::from_be_bytes([0; _]); +LL + let _ = usize::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:38:21 + | +LL | let _ = i8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i8::from_be_bytes([0; _]); +LL + let _ = i8::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = i8::from_be_bytes([0; _]); +LL + let _ = i8::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:39:22 + | +LL | let _ = i16::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i16::from_be_bytes([0; _]); +LL + let _ = i16::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = i16::from_be_bytes([0; _]); +LL + let _ = i16::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:40:22 + | +LL | let _ = i32::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i32::from_be_bytes([0; _]); +LL + let _ = i32::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = i32::from_be_bytes([0; _]); +LL + let _ = i32::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:41:22 + | +LL | let _ = i64::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i64::from_be_bytes([0; _]); +LL + let _ = i64::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = i64::from_be_bytes([0; _]); +LL + let _ = i64::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:42:23 + | +LL | let _ = i128::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i128::from_be_bytes([0; _]); +LL + let _ = i128::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = i128::from_be_bytes([0; _]); +LL + let _ = i128::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:43:24 + | +LL | let _ = isize::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = isize::from_be_bytes([0; _]); +LL + let _ = isize::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = isize::from_be_bytes([0; _]); +LL + let _ = isize::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:45:22 + | +LL | let _ = f16::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f16::from_be_bytes([0; _]); +LL + let _ = f16::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = f16::from_be_bytes([0; _]); +LL + let _ = f16::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:46:22 + | +LL | let _ = f32::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f32::from_be_bytes([0; _]); +LL + let _ = f32::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = f32::from_be_bytes([0; _]); +LL + let _ = f32::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:47:22 + | +LL | let _ = f64::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f64::from_be_bytes([0; _]); +LL + let _ = f64::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = f64::from_be_bytes([0; _]); +LL + let _ = f64::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:48:23 + | +LL | let _ = f128::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f128::from_be_bytes([0; _]); +LL + let _ = f128::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = f128::from_be_bytes([0; _]); +LL + let _ = f128::from_le_bytes([0; _]); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:52:21 + | +LL | let _ = u8::from_be_bytes; + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::from_be_bytes; +LL + let _ = u8::from_ne_bytes; + | +help: convert from little endian + | +LL - let _ = u8::from_be_bytes; +LL + let _ = u8::from_le_bytes; + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:53:21 + | +LL | let _ = u8::to_be_bytes; + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = u8::to_be_bytes; +LL + let _ = u8::to_ne_bytes; + | +help: convert to little endian + | +LL - let _ = u8::to_be_bytes; +LL + let _ = u8::to_le_bytes; + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:58:21 + | +LL | let _ = 0u8.to_be_bytes(); + | ^^^^^^^^^^^ help: convert to little endian: `to_le_bytes` + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:59:21 + | +LL | let _ = 0i8.to_be_bytes(); + | ^^^^^^^^^^^ help: convert to little endian: `to_le_bytes` + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:60:21 + | +LL | let _ = u8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from little endian: `from_le_bytes` + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:61:21 + | +LL | let _ = i8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from little endian: `from_le_bytes` + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:66:21 + | +LL | let _ = 0u8.to_be_bytes(); + | ^^^^^^^^^^^ help: convert to native endian: `to_ne_bytes` + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:67:21 + | +LL | let _ = 0i8.to_be_bytes(); + | ^^^^^^^^^^^ help: convert to native endian: `to_ne_bytes` + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:68:21 + | +LL | let _ = u8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from native endian: `from_ne_bytes` + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:69:21 + | +LL | let _ = i8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from native endian: `from_ne_bytes` + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:74:25 + | +LL | let _ = 0u8.to_be_bytes(); + | ^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert to native endian + | +LL - let _ = 0u8.to_be_bytes(); +LL + let _ = 0u8.to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u8.to_be_bytes(); +LL + let _ = 0u8.to_le_bytes(); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:75:25 + | +LL | let _ = u8::from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert from native endian + | +LL - let _ = u8::from_be_bytes([0; _]); +LL + let _ = u8::from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u8::from_be_bytes([0; _]); +LL + let _ = u8::from_le_bytes([0; _]); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:76:26 + | +LL | let _ = 0u8.$to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u8.$to_be_bytes(); +LL + let _ = 0u8.$to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u8.$to_be_bytes(); +LL + let _ = 0u8.$to_le_bytes(); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:77:26 + | +LL | let _ = u8::$from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::$from_be_bytes([0; _]); +LL + let _ = u8::$from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u8::$from_be_bytes([0; _]); +LL + let _ = u8::$from_le_bytes([0; _]); + | + +error: use of `to_be_bytes` + --> tests/ui/big_endian_bytes.rs:83:26 + | +LL | let _ = 0u8.$to_be_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u8.$to_be_bytes(); +LL + let _ = 0u8.$to_ne_bytes(); + | +help: convert to little endian + | +LL - let _ = 0u8.$to_be_bytes(); +LL + let _ = 0u8.$to_le_bytes(); + | + +error: use of `from_be_bytes` + --> tests/ui/big_endian_bytes.rs:84:26 + | +LL | let _ = u8::$from_be_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::$from_be_bytes([0; _]); +LL + let _ = u8::$from_ne_bytes([0; _]); + | +help: convert from little endian + | +LL - let _ = u8::$from_be_bytes([0; _]); +LL + let _ = u8::$from_le_bytes([0; _]); + | + +error: aborting due to 48 previous errors + diff --git a/tests/ui/endian_bytes.rs b/tests/ui/endian_bytes.rs deleted file mode 100644 index 9d3e25300a6c..000000000000 --- a/tests/ui/endian_bytes.rs +++ /dev/null @@ -1,214 +0,0 @@ -#![expect(clippy::diverging_sub_expression)] -#![no_main] - -// FIXME(f16_f128): add these types when `{to_from}_*_bytes` are available - -macro_rules! fn_body { - () => { - 2u8.to_ne_bytes(); - //~^ host_endian_bytes - 2i8.to_ne_bytes(); - //~^ host_endian_bytes - 2u16.to_ne_bytes(); - //~^ host_endian_bytes - 2i16.to_ne_bytes(); - //~^ host_endian_bytes - 2u32.to_ne_bytes(); - //~^ host_endian_bytes - 2i32.to_ne_bytes(); - //~^ host_endian_bytes - 2u64.to_ne_bytes(); - //~^ host_endian_bytes - 2i64.to_ne_bytes(); - //~^ host_endian_bytes - 2u128.to_ne_bytes(); - //~^ host_endian_bytes - 2i128.to_ne_bytes(); - //~^ host_endian_bytes - 2.0f32.to_ne_bytes(); - //~^ host_endian_bytes - 2.0f64.to_ne_bytes(); - //~^ host_endian_bytes - 2usize.to_ne_bytes(); - //~^ host_endian_bytes - 2isize.to_ne_bytes(); - //~^ host_endian_bytes - u8::from_ne_bytes(todo!()); - //~^ host_endian_bytes - i8::from_ne_bytes(todo!()); - //~^ host_endian_bytes - u16::from_ne_bytes(todo!()); - //~^ host_endian_bytes - i16::from_ne_bytes(todo!()); - //~^ host_endian_bytes - u32::from_ne_bytes(todo!()); - //~^ host_endian_bytes - i32::from_ne_bytes(todo!()); - //~^ host_endian_bytes - u64::from_ne_bytes(todo!()); - //~^ host_endian_bytes - i64::from_ne_bytes(todo!()); - //~^ host_endian_bytes - u128::from_ne_bytes(todo!()); - //~^ host_endian_bytes - i128::from_ne_bytes(todo!()); - //~^ host_endian_bytes - usize::from_ne_bytes(todo!()); - //~^ host_endian_bytes - isize::from_ne_bytes(todo!()); - //~^ host_endian_bytes - f32::from_ne_bytes(todo!()); - //~^ host_endian_bytes - f64::from_ne_bytes(todo!()); - //~^ host_endian_bytes - - 2u8.to_le_bytes(); - //~^ little_endian_bytes - 2i8.to_le_bytes(); - //~^ little_endian_bytes - 2u16.to_le_bytes(); - //~^ little_endian_bytes - 2i16.to_le_bytes(); - //~^ little_endian_bytes - 2u32.to_le_bytes(); - //~^ little_endian_bytes - 2i32.to_le_bytes(); - //~^ little_endian_bytes - 2u64.to_le_bytes(); - //~^ little_endian_bytes - 2i64.to_le_bytes(); - //~^ little_endian_bytes - 2u128.to_le_bytes(); - //~^ little_endian_bytes - 2i128.to_le_bytes(); - //~^ little_endian_bytes - 2.0f32.to_le_bytes(); - //~^ little_endian_bytes - 2.0f64.to_le_bytes(); - //~^ little_endian_bytes - 2usize.to_le_bytes(); - //~^ little_endian_bytes - 2isize.to_le_bytes(); - //~^ little_endian_bytes - u8::from_le_bytes(todo!()); - //~^ little_endian_bytes - i8::from_le_bytes(todo!()); - //~^ little_endian_bytes - u16::from_le_bytes(todo!()); - //~^ little_endian_bytes - i16::from_le_bytes(todo!()); - //~^ little_endian_bytes - u32::from_le_bytes(todo!()); - //~^ little_endian_bytes - i32::from_le_bytes(todo!()); - //~^ little_endian_bytes - u64::from_le_bytes(todo!()); - //~^ little_endian_bytes - i64::from_le_bytes(todo!()); - //~^ little_endian_bytes - u128::from_le_bytes(todo!()); - //~^ little_endian_bytes - i128::from_le_bytes(todo!()); - //~^ little_endian_bytes - usize::from_le_bytes(todo!()); - //~^ little_endian_bytes - isize::from_le_bytes(todo!()); - //~^ little_endian_bytes - f32::from_le_bytes(todo!()); - //~^ little_endian_bytes - f64::from_le_bytes(todo!()); - //~^ little_endian_bytes - }; -} - -// bless breaks if I use fn_body too much (oops) -macro_rules! fn_body_smol { - () => { - 2u8.to_ne_bytes(); - //~^ host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - u8::from_ne_bytes(todo!()); - //~^ host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - //~| host_endian_bytes - - 2u8.to_le_bytes(); - //~^ little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - u8::from_le_bytes(todo!()); - //~^ little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - //~| little_endian_bytes - - 2u8.to_be_bytes(); - //~^ big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - u8::from_be_bytes(todo!()); - //~^ big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - //~| big_endian_bytes - }; -} - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -fn host() { fn_body!(); } - -#[rustfmt::skip] -#[warn(clippy::little_endian_bytes)] -fn little() { fn_body!(); } - -#[rustfmt::skip] -#[warn(clippy::big_endian_bytes)] -fn big() { fn_body!(); } - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -#[warn(clippy::big_endian_bytes)] -fn host_encourage_little() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -#[warn(clippy::little_endian_bytes)] -fn host_encourage_big() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -#[warn(clippy::little_endian_bytes)] -#[warn(clippy::big_endian_bytes)] -fn no_help() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::little_endian_bytes)] -#[warn(clippy::big_endian_bytes)] -fn little_encourage_host() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -#[warn(clippy::little_endian_bytes)] -fn little_encourage_big() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::big_endian_bytes)] -#[warn(clippy::little_endian_bytes)] -fn big_encourage_host() { fn_body_smol!(); } - -#[rustfmt::skip] -#[warn(clippy::host_endian_bytes)] -#[warn(clippy::big_endian_bytes)] -fn big_encourage_little() { fn_body_smol!(); } diff --git a/tests/ui/endian_bytes.stderr b/tests/ui/endian_bytes.stderr deleted file mode 100644 index f1f27dca8db2..000000000000 --- a/tests/ui/endian_bytes.stderr +++ /dev/null @@ -1,1034 +0,0 @@ -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:8:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: `-D clippy::host-endian-bytes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::host_endian_bytes)]` - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:10:9 - | -LL | 2i8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:12:9 - | -LL | 2u16.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i16::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:14:9 - | -LL | 2i16.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:16:9 - | -LL | 2u32.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:18:9 - | -LL | 2i32.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:20:9 - | -LL | 2u64.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:22:9 - | -LL | 2i64.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:24:9 - | -LL | 2u128.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i128::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:26:9 - | -LL | 2i128.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `f32::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:28:9 - | -LL | 2.0f32.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `f64::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:30:9 - | -LL | 2.0f64.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `usize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:32:9 - | -LL | 2usize.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `isize::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:34:9 - | -LL | 2isize.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:36:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:38:9 - | -LL | i8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:40:9 - | -LL | u16::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i16::from_ne_bytes` - --> tests/ui/endian_bytes.rs:42:9 - | -LL | i16::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:44:9 - | -LL | u32::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:46:9 - | -LL | i32::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:48:9 - | -LL | u64::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:50:9 - | -LL | i64::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:52:9 - | -LL | u128::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i128::from_ne_bytes` - --> tests/ui/endian_bytes.rs:54:9 - | -LL | i128::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `usize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:56:9 - | -LL | usize::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `isize::from_ne_bytes` - --> tests/ui/endian_bytes.rs:58:9 - | -LL | isize::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `f32::from_ne_bytes` - --> tests/ui/endian_bytes.rs:60:9 - | -LL | f32::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `f64::from_ne_bytes` - --> tests/ui/endian_bytes.rs:62:9 - | -LL | f64::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host() { fn_body!(); } - | ---------- in this macro invocation - | - = help: specify the desired endianness explicitly - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:65:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: `-D clippy::little-endian-bytes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::little_endian_bytes)]` - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:67:9 - | -LL | 2i8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:69:9 - | -LL | 2u16.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i16::to_le_bytes` method - --> tests/ui/endian_bytes.rs:71:9 - | -LL | 2i16.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:73:9 - | -LL | 2u32.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:75:9 - | -LL | 2i32.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:77:9 - | -LL | 2u64.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:79:9 - | -LL | 2i64.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:81:9 - | -LL | 2u128.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `i128::to_le_bytes` method - --> tests/ui/endian_bytes.rs:83:9 - | -LL | 2i128.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `f32::to_le_bytes` method - --> tests/ui/endian_bytes.rs:85:9 - | -LL | 2.0f32.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `f64::to_le_bytes` method - --> tests/ui/endian_bytes.rs:87:9 - | -LL | 2.0f64.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `usize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:89:9 - | -LL | 2usize.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `isize::to_le_bytes` method - --> tests/ui/endian_bytes.rs:91:9 - | -LL | 2isize.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:93:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i8::from_le_bytes` - --> tests/ui/endian_bytes.rs:95:9 - | -LL | i8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u16::from_le_bytes` - --> tests/ui/endian_bytes.rs:97:9 - | -LL | u16::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i16::from_le_bytes` - --> tests/ui/endian_bytes.rs:99:9 - | -LL | i16::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u32::from_le_bytes` - --> tests/ui/endian_bytes.rs:101:9 - | -LL | u32::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i32::from_le_bytes` - --> tests/ui/endian_bytes.rs:103:9 - | -LL | i32::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u64::from_le_bytes` - --> tests/ui/endian_bytes.rs:105:9 - | -LL | u64::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i64::from_le_bytes` - --> tests/ui/endian_bytes.rs:107:9 - | -LL | i64::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u128::from_le_bytes` - --> tests/ui/endian_bytes.rs:109:9 - | -LL | u128::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `i128::from_le_bytes` - --> tests/ui/endian_bytes.rs:111:9 - | -LL | i128::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `usize::from_le_bytes` - --> tests/ui/endian_bytes.rs:113:9 - | -LL | usize::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `isize::from_le_bytes` - --> tests/ui/endian_bytes.rs:115:9 - | -LL | isize::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `f32::from_le_bytes` - --> tests/ui/endian_bytes.rs:117:9 - | -LL | f32::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `f64::from_le_bytes` - --> tests/ui/endian_bytes.rs:119:9 - | -LL | f64::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little() { fn_body!(); } - | ---------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:127:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:133:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:153:9 - | -LL | 2u8.to_be_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_le_bytes` instead - = note: `-D clippy::big-endian-bytes` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::big_endian_bytes)]` - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:159:9 - | -LL | u8::from_be_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:127:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:133:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:140:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:146:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn host_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:127:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:133:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:140:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:146:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:153:9 - | -LL | 2u8.to_be_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:159:9 - | -LL | u8::from_be_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn no_help() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:140:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:146:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:153:9 - | -LL | 2u8.to_be_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:159:9 - | -LL | u8::from_be_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:127:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:133:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:140:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:146:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn little_encourage_big() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_be_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_le_bytes` method - --> tests/ui/endian_bytes.rs:140:9 - | -LL | 2u8.to_le_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_le_bytes` - --> tests/ui/endian_bytes.rs:146:9 - | -LL | u8::from_le_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:153:9 - | -LL | 2u8.to_be_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:159:9 - | -LL | u8::from_be_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_host() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use the native endianness instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_ne_bytes` method - --> tests/ui/endian_bytes.rs:127:9 - | -LL | 2u8.to_ne_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_ne_bytes` - --> tests/ui/endian_bytes.rs:133:9 - | -LL | u8::from_ne_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the `u8::to_be_bytes` method - --> tests/ui/endian_bytes.rs:153:9 - | -LL | 2u8.to_be_bytes(); - | ^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::to_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: usage of the function `u8::from_be_bytes` - --> tests/ui/endian_bytes.rs:159:9 - | -LL | u8::from_be_bytes(todo!()); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -... -LL | fn big_encourage_little() { fn_body_smol!(); } - | --------------- in this macro invocation - | - = help: use `u8::from_le_bytes` instead - = note: this error originates in the macro `fn_body_smol` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 86 previous errors - diff --git a/tests/ui/host_endian_bytes.1.fixed b/tests/ui/host_endian_bytes.1.fixed new file mode 100644 index 000000000000..d5f005c352a1 --- /dev/null +++ b/tests/ui/host_endian_bytes.1.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::host_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_le_bytes(); //~ host_endian_bytes + let _ = 0u16.to_le_bytes(); //~ host_endian_bytes + let _ = 0u32.to_le_bytes(); //~ host_endian_bytes + let _ = 0u64.to_le_bytes(); //~ host_endian_bytes + let _ = 0u128.to_le_bytes(); //~ host_endian_bytes + let _ = 0usize.to_le_bytes(); //~ host_endian_bytes + + let _ = 0i8.to_le_bytes(); //~ host_endian_bytes + let _ = 0i16.to_le_bytes(); //~ host_endian_bytes + let _ = 0i32.to_le_bytes(); //~ host_endian_bytes + let _ = 0i64.to_le_bytes(); //~ host_endian_bytes + let _ = 0i128.to_le_bytes(); //~ host_endian_bytes + let _ = 0isize.to_le_bytes(); //~ host_endian_bytes + + let _ = 0f16.to_le_bytes(); //~ host_endian_bytes + let _ = 0f32.to_le_bytes(); //~ host_endian_bytes + let _ = 0f64.to_le_bytes(); //~ host_endian_bytes + let _ = 0f128.to_le_bytes(); //~ host_endian_bytes + + let _ = u8::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = u16::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = u32::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = u64::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = u128::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = usize::from_le_bytes([0; _]); //~ host_endian_bytes + + let _ = i8::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i16::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i32::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i64::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i128::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = isize::from_le_bytes([0; _]); //~ host_endian_bytes + + let _ = f16::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = f32::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = f64::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = f128::from_le_bytes([0; _]); //~ host_endian_bytes + }; + + { + let _ = u8::from_le_bytes; //~ host_endian_bytes + let _ = u8::to_le_bytes; //~ host_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ host_endian_bytes + let _ = 0i8.to_le_bytes(); //~ host_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ host_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ host_endian_bytes + let _ = 0i8.to_be_bytes(); //~ host_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ host_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_le_bytes(); //~ host_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = 0u8.$to_le_bytes(); //~ host_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ host_endian_bytes + }} + + external! { + let _ = 0u8.to_ne_bytes(); + let _ = u8::from_ne_bytes([0; _]); + let _ = 0u8.$to_le_bytes(); //~ host_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ host_endian_bytes + } + } +} diff --git a/tests/ui/host_endian_bytes.2.fixed b/tests/ui/host_endian_bytes.2.fixed new file mode 100644 index 000000000000..4d75defb8e23 --- /dev/null +++ b/tests/ui/host_endian_bytes.2.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::host_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_be_bytes(); //~ host_endian_bytes + let _ = 0u16.to_be_bytes(); //~ host_endian_bytes + let _ = 0u32.to_be_bytes(); //~ host_endian_bytes + let _ = 0u64.to_be_bytes(); //~ host_endian_bytes + let _ = 0u128.to_be_bytes(); //~ host_endian_bytes + let _ = 0usize.to_be_bytes(); //~ host_endian_bytes + + let _ = 0i8.to_be_bytes(); //~ host_endian_bytes + let _ = 0i16.to_be_bytes(); //~ host_endian_bytes + let _ = 0i32.to_be_bytes(); //~ host_endian_bytes + let _ = 0i64.to_be_bytes(); //~ host_endian_bytes + let _ = 0i128.to_be_bytes(); //~ host_endian_bytes + let _ = 0isize.to_be_bytes(); //~ host_endian_bytes + + let _ = 0f16.to_be_bytes(); //~ host_endian_bytes + let _ = 0f32.to_be_bytes(); //~ host_endian_bytes + let _ = 0f64.to_be_bytes(); //~ host_endian_bytes + let _ = 0f128.to_be_bytes(); //~ host_endian_bytes + + let _ = u8::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = u16::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = u32::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = u64::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = u128::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = usize::from_be_bytes([0; _]); //~ host_endian_bytes + + let _ = i8::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i16::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i32::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i64::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i128::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = isize::from_be_bytes([0; _]); //~ host_endian_bytes + + let _ = f16::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = f32::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = f64::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = f128::from_be_bytes([0; _]); //~ host_endian_bytes + }; + + { + let _ = u8::from_be_bytes; //~ host_endian_bytes + let _ = u8::to_be_bytes; //~ host_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ host_endian_bytes + let _ = 0i8.to_le_bytes(); //~ host_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ host_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ host_endian_bytes + let _ = 0i8.to_be_bytes(); //~ host_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ host_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_be_bytes(); //~ host_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ host_endian_bytes + let _ = 0u8.$to_be_bytes(); //~ host_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ host_endian_bytes + }} + + external! { + let _ = 0u8.to_ne_bytes(); + let _ = u8::from_ne_bytes([0; _]); + let _ = 0u8.$to_be_bytes(); //~ host_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ host_endian_bytes + } + } +} diff --git a/tests/ui/host_endian_bytes.rs b/tests/ui/host_endian_bytes.rs new file mode 100644 index 000000000000..d1f978da2f9a --- /dev/null +++ b/tests/ui/host_endian_bytes.rs @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::host_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_ne_bytes(); //~ host_endian_bytes + let _ = 0u16.to_ne_bytes(); //~ host_endian_bytes + let _ = 0u32.to_ne_bytes(); //~ host_endian_bytes + let _ = 0u64.to_ne_bytes(); //~ host_endian_bytes + let _ = 0u128.to_ne_bytes(); //~ host_endian_bytes + let _ = 0usize.to_ne_bytes(); //~ host_endian_bytes + + let _ = 0i8.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i16.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i32.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i64.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i128.to_ne_bytes(); //~ host_endian_bytes + let _ = 0isize.to_ne_bytes(); //~ host_endian_bytes + + let _ = 0f16.to_ne_bytes(); //~ host_endian_bytes + let _ = 0f32.to_ne_bytes(); //~ host_endian_bytes + let _ = 0f64.to_ne_bytes(); //~ host_endian_bytes + let _ = 0f128.to_ne_bytes(); //~ host_endian_bytes + + let _ = u8::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = u16::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = u32::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = u64::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = u128::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = usize::from_ne_bytes([0; _]); //~ host_endian_bytes + + let _ = i8::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i16::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i32::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i64::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i128::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = isize::from_ne_bytes([0; _]); //~ host_endian_bytes + + let _ = f16::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = f32::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = f64::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = f128::from_ne_bytes([0; _]); //~ host_endian_bytes + }; + + { + let _ = u8::from_ne_bytes; //~ host_endian_bytes + let _ = u8::to_ne_bytes; //~ host_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ host_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ host_endian_bytes + }; + + #[warn(clippy::little_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ host_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ host_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ host_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_ne_bytes(); //~ host_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ host_endian_bytes + let _ = 0u8.$to_ne_bytes(); //~ host_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ host_endian_bytes + }} + + external! { + let _ = 0u8.to_ne_bytes(); + let _ = u8::from_ne_bytes([0; _]); + let _ = 0u8.$to_ne_bytes(); //~ host_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ host_endian_bytes + } + } +} diff --git a/tests/ui/host_endian_bytes.stderr b/tests/ui/host_endian_bytes.stderr new file mode 100644 index 000000000000..a00126ea5ac3 --- /dev/null +++ b/tests/ui/host_endian_bytes.stderr @@ -0,0 +1,734 @@ +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:12:21 + | +LL | let _ = 0u8.to_ne_bytes(); + | ^^^^^^^^^^^ + | + = note: `-D clippy::host-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::host_endian_bytes)]` +help: convert to little endian + | +LL - let _ = 0u8.to_ne_bytes(); +LL + let _ = 0u8.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.to_ne_bytes(); +LL + let _ = 0u8.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:13:22 + | +LL | let _ = 0u16.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u16.to_ne_bytes(); +LL + let _ = 0u16.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u16.to_ne_bytes(); +LL + let _ = 0u16.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:14:22 + | +LL | let _ = 0u32.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u32.to_ne_bytes(); +LL + let _ = 0u32.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u32.to_ne_bytes(); +LL + let _ = 0u32.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:15:22 + | +LL | let _ = 0u64.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u64.to_ne_bytes(); +LL + let _ = 0u64.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u64.to_ne_bytes(); +LL + let _ = 0u64.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:16:23 + | +LL | let _ = 0u128.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u128.to_ne_bytes(); +LL + let _ = 0u128.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u128.to_ne_bytes(); +LL + let _ = 0u128.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:17:24 + | +LL | let _ = 0usize.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0usize.to_ne_bytes(); +LL + let _ = 0usize.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0usize.to_ne_bytes(); +LL + let _ = 0usize.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:19:21 + | +LL | let _ = 0i8.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0i8.to_ne_bytes(); +LL + let _ = 0i8.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i8.to_ne_bytes(); +LL + let _ = 0i8.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:20:22 + | +LL | let _ = 0i16.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0i16.to_ne_bytes(); +LL + let _ = 0i16.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i16.to_ne_bytes(); +LL + let _ = 0i16.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:21:22 + | +LL | let _ = 0i32.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0i32.to_ne_bytes(); +LL + let _ = 0i32.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i32.to_ne_bytes(); +LL + let _ = 0i32.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:22:22 + | +LL | let _ = 0i64.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0i64.to_ne_bytes(); +LL + let _ = 0i64.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i64.to_ne_bytes(); +LL + let _ = 0i64.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:23:23 + | +LL | let _ = 0i128.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0i128.to_ne_bytes(); +LL + let _ = 0i128.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i128.to_ne_bytes(); +LL + let _ = 0i128.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:24:24 + | +LL | let _ = 0isize.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0isize.to_ne_bytes(); +LL + let _ = 0isize.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0isize.to_ne_bytes(); +LL + let _ = 0isize.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:26:22 + | +LL | let _ = 0f16.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0f16.to_ne_bytes(); +LL + let _ = 0f16.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f16.to_ne_bytes(); +LL + let _ = 0f16.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:27:22 + | +LL | let _ = 0f32.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0f32.to_ne_bytes(); +LL + let _ = 0f32.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f32.to_ne_bytes(); +LL + let _ = 0f32.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:28:22 + | +LL | let _ = 0f64.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0f64.to_ne_bytes(); +LL + let _ = 0f64.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f64.to_ne_bytes(); +LL + let _ = 0f64.to_be_bytes(); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:29:23 + | +LL | let _ = 0f128.to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0f128.to_ne_bytes(); +LL + let _ = 0f128.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f128.to_ne_bytes(); +LL + let _ = 0f128.to_be_bytes(); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:31:21 + | +LL | let _ = u8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u8::from_ne_bytes([0; _]); +LL + let _ = u8::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::from_ne_bytes([0; _]); +LL + let _ = u8::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:32:22 + | +LL | let _ = u16::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u16::from_ne_bytes([0; _]); +LL + let _ = u16::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u16::from_ne_bytes([0; _]); +LL + let _ = u16::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:33:22 + | +LL | let _ = u32::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u32::from_ne_bytes([0; _]); +LL + let _ = u32::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u32::from_ne_bytes([0; _]); +LL + let _ = u32::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:34:22 + | +LL | let _ = u64::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u64::from_ne_bytes([0; _]); +LL + let _ = u64::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u64::from_ne_bytes([0; _]); +LL + let _ = u64::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:35:23 + | +LL | let _ = u128::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u128::from_ne_bytes([0; _]); +LL + let _ = u128::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u128::from_ne_bytes([0; _]); +LL + let _ = u128::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:36:24 + | +LL | let _ = usize::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = usize::from_ne_bytes([0; _]); +LL + let _ = usize::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = usize::from_ne_bytes([0; _]); +LL + let _ = usize::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:38:21 + | +LL | let _ = i8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = i8::from_ne_bytes([0; _]); +LL + let _ = i8::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i8::from_ne_bytes([0; _]); +LL + let _ = i8::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:39:22 + | +LL | let _ = i16::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = i16::from_ne_bytes([0; _]); +LL + let _ = i16::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i16::from_ne_bytes([0; _]); +LL + let _ = i16::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:40:22 + | +LL | let _ = i32::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = i32::from_ne_bytes([0; _]); +LL + let _ = i32::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i32::from_ne_bytes([0; _]); +LL + let _ = i32::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:41:22 + | +LL | let _ = i64::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = i64::from_ne_bytes([0; _]); +LL + let _ = i64::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i64::from_ne_bytes([0; _]); +LL + let _ = i64::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:42:23 + | +LL | let _ = i128::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = i128::from_ne_bytes([0; _]); +LL + let _ = i128::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i128::from_ne_bytes([0; _]); +LL + let _ = i128::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:43:24 + | +LL | let _ = isize::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = isize::from_ne_bytes([0; _]); +LL + let _ = isize::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = isize::from_ne_bytes([0; _]); +LL + let _ = isize::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:45:22 + | +LL | let _ = f16::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = f16::from_ne_bytes([0; _]); +LL + let _ = f16::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f16::from_ne_bytes([0; _]); +LL + let _ = f16::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:46:22 + | +LL | let _ = f32::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = f32::from_ne_bytes([0; _]); +LL + let _ = f32::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f32::from_ne_bytes([0; _]); +LL + let _ = f32::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:47:22 + | +LL | let _ = f64::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = f64::from_ne_bytes([0; _]); +LL + let _ = f64::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f64::from_ne_bytes([0; _]); +LL + let _ = f64::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:48:23 + | +LL | let _ = f128::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = f128::from_ne_bytes([0; _]); +LL + let _ = f128::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f128::from_ne_bytes([0; _]); +LL + let _ = f128::from_be_bytes([0; _]); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:52:21 + | +LL | let _ = u8::from_ne_bytes; + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u8::from_ne_bytes; +LL + let _ = u8::from_le_bytes; + | +help: convert from big endian + | +LL - let _ = u8::from_ne_bytes; +LL + let _ = u8::from_be_bytes; + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:53:21 + | +LL | let _ = u8::to_ne_bytes; + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = u8::to_ne_bytes; +LL + let _ = u8::to_le_bytes; + | +help: convert to big endian + | +LL - let _ = u8::to_ne_bytes; +LL + let _ = u8::to_be_bytes; + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:58:21 + | +LL | let _ = 0u8.to_ne_bytes(); + | ^^^^^^^^^^^ help: convert to little endian: `to_le_bytes` + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:59:21 + | +LL | let _ = 0i8.to_ne_bytes(); + | ^^^^^^^^^^^ help: convert to little endian: `to_le_bytes` + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:60:21 + | +LL | let _ = u8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from little endian: `from_le_bytes` + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:61:21 + | +LL | let _ = i8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from little endian: `from_le_bytes` + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:66:21 + | +LL | let _ = 0u8.to_ne_bytes(); + | ^^^^^^^^^^^ help: convert to big endian: `to_be_bytes` + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:67:21 + | +LL | let _ = 0i8.to_ne_bytes(); + | ^^^^^^^^^^^ help: convert to big endian: `to_be_bytes` + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:68:21 + | +LL | let _ = u8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from big endian: `from_be_bytes` + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:69:21 + | +LL | let _ = i8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from big endian: `from_be_bytes` + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:74:25 + | +LL | let _ = 0u8.to_ne_bytes(); + | ^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert to little endian + | +LL - let _ = 0u8.to_ne_bytes(); +LL + let _ = 0u8.to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.to_ne_bytes(); +LL + let _ = 0u8.to_be_bytes(); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:75:25 + | +LL | let _ = u8::from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert from little endian + | +LL - let _ = u8::from_ne_bytes([0; _]); +LL + let _ = u8::from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::from_ne_bytes([0; _]); +LL + let _ = u8::from_be_bytes([0; _]); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:76:26 + | +LL | let _ = 0u8.$to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u8.$to_ne_bytes(); +LL + let _ = 0u8.$to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.$to_ne_bytes(); +LL + let _ = 0u8.$to_be_bytes(); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:77:26 + | +LL | let _ = u8::$from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u8::$from_ne_bytes([0; _]); +LL + let _ = u8::$from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::$from_ne_bytes([0; _]); +LL + let _ = u8::$from_be_bytes([0; _]); + | + +error: use of `to_ne_bytes` + --> tests/ui/host_endian_bytes.rs:83:26 + | +LL | let _ = 0u8.$to_ne_bytes(); + | ^^^^^^^^^^^ + | +help: convert to little endian + | +LL - let _ = 0u8.$to_ne_bytes(); +LL + let _ = 0u8.$to_le_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.$to_ne_bytes(); +LL + let _ = 0u8.$to_be_bytes(); + | + +error: use of `from_ne_bytes` + --> tests/ui/host_endian_bytes.rs:84:26 + | +LL | let _ = u8::$from_ne_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from little endian + | +LL - let _ = u8::$from_ne_bytes([0; _]); +LL + let _ = u8::$from_le_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::$from_ne_bytes([0; _]); +LL + let _ = u8::$from_be_bytes([0; _]); + | + +error: aborting due to 48 previous errors + diff --git a/tests/ui/little_endian_bytes.1.fixed b/tests/ui/little_endian_bytes.1.fixed new file mode 100644 index 000000000000..674d4169cea6 --- /dev/null +++ b/tests/ui/little_endian_bytes.1.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::little_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_ne_bytes(); //~ little_endian_bytes + let _ = 0u16.to_ne_bytes(); //~ little_endian_bytes + let _ = 0u32.to_ne_bytes(); //~ little_endian_bytes + let _ = 0u64.to_ne_bytes(); //~ little_endian_bytes + let _ = 0u128.to_ne_bytes(); //~ little_endian_bytes + let _ = 0usize.to_ne_bytes(); //~ little_endian_bytes + + let _ = 0i8.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i16.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i32.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i64.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i128.to_ne_bytes(); //~ little_endian_bytes + let _ = 0isize.to_ne_bytes(); //~ little_endian_bytes + + let _ = 0f16.to_ne_bytes(); //~ little_endian_bytes + let _ = 0f32.to_ne_bytes(); //~ little_endian_bytes + let _ = 0f64.to_ne_bytes(); //~ little_endian_bytes + let _ = 0f128.to_ne_bytes(); //~ little_endian_bytes + + let _ = u8::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = u16::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = u32::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = u64::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = u128::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = usize::from_ne_bytes([0; _]); //~ little_endian_bytes + + let _ = i8::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i16::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i32::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i64::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i128::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = isize::from_ne_bytes([0; _]); //~ little_endian_bytes + + let _ = f16::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = f32::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = f64::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = f128::from_ne_bytes([0; _]); //~ little_endian_bytes + }; + + { + let _ = u8::from_ne_bytes; //~ little_endian_bytes + let _ = u8::to_ne_bytes; //~ little_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ little_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ little_endian_bytes + }; + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ little_endian_bytes + let _ = 0i8.to_be_bytes(); //~ little_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ little_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_ne_bytes(); //~ little_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = 0u8.$to_ne_bytes(); //~ little_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ little_endian_bytes + }} + + external! { + let _ = 0u8.to_le_bytes(); + let _ = u8::from_le_bytes([0; _]); + let _ = 0u8.$to_ne_bytes(); //~ little_endian_bytes + let _ = u8::$from_ne_bytes([0; _]); //~ little_endian_bytes + } + } +} diff --git a/tests/ui/little_endian_bytes.2.fixed b/tests/ui/little_endian_bytes.2.fixed new file mode 100644 index 000000000000..d286e417c72e --- /dev/null +++ b/tests/ui/little_endian_bytes.2.fixed @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::little_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_be_bytes(); //~ little_endian_bytes + let _ = 0u16.to_be_bytes(); //~ little_endian_bytes + let _ = 0u32.to_be_bytes(); //~ little_endian_bytes + let _ = 0u64.to_be_bytes(); //~ little_endian_bytes + let _ = 0u128.to_be_bytes(); //~ little_endian_bytes + let _ = 0usize.to_be_bytes(); //~ little_endian_bytes + + let _ = 0i8.to_be_bytes(); //~ little_endian_bytes + let _ = 0i16.to_be_bytes(); //~ little_endian_bytes + let _ = 0i32.to_be_bytes(); //~ little_endian_bytes + let _ = 0i64.to_be_bytes(); //~ little_endian_bytes + let _ = 0i128.to_be_bytes(); //~ little_endian_bytes + let _ = 0isize.to_be_bytes(); //~ little_endian_bytes + + let _ = 0f16.to_be_bytes(); //~ little_endian_bytes + let _ = 0f32.to_be_bytes(); //~ little_endian_bytes + let _ = 0f64.to_be_bytes(); //~ little_endian_bytes + let _ = 0f128.to_be_bytes(); //~ little_endian_bytes + + let _ = u8::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = u16::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = u32::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = u64::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = u128::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = usize::from_be_bytes([0; _]); //~ little_endian_bytes + + let _ = i8::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i16::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i32::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i64::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i128::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = isize::from_be_bytes([0; _]); //~ little_endian_bytes + + let _ = f16::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = f32::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = f64::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = f128::from_be_bytes([0; _]); //~ little_endian_bytes + }; + + { + let _ = u8::from_be_bytes; //~ little_endian_bytes + let _ = u8::to_be_bytes; //~ little_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_ne_bytes(); //~ little_endian_bytes + let _ = 0i8.to_ne_bytes(); //~ little_endian_bytes + let _ = u8::from_ne_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_ne_bytes([0; _]); //~ little_endian_bytes + }; + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_be_bytes(); //~ little_endian_bytes + let _ = 0i8.to_be_bytes(); //~ little_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_be_bytes([0; _]); //~ little_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_be_bytes(); //~ little_endian_bytes + let _ = u8::from_be_bytes([0; _]); //~ little_endian_bytes + let _ = 0u8.$to_be_bytes(); //~ little_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ little_endian_bytes + }} + + external! { + let _ = 0u8.to_le_bytes(); + let _ = u8::from_le_bytes([0; _]); + let _ = 0u8.$to_be_bytes(); //~ little_endian_bytes + let _ = u8::$from_be_bytes([0; _]); //~ little_endian_bytes + } + } +} diff --git a/tests/ui/little_endian_bytes.rs b/tests/ui/little_endian_bytes.rs new file mode 100644 index 000000000000..e280f8952d73 --- /dev/null +++ b/tests/ui/little_endian_bytes.rs @@ -0,0 +1,87 @@ +//@ aux-build:proc_macros.rs + +#![warn(clippy::little_endian_bytes)] +#![feature(f16, f128)] + +extern crate proc_macros; +use proc_macros::{external, inline_macros}; + +#[inline_macros] +fn main() { + { + let _ = 0u8.to_le_bytes(); //~ little_endian_bytes + let _ = 0u16.to_le_bytes(); //~ little_endian_bytes + let _ = 0u32.to_le_bytes(); //~ little_endian_bytes + let _ = 0u64.to_le_bytes(); //~ little_endian_bytes + let _ = 0u128.to_le_bytes(); //~ little_endian_bytes + let _ = 0usize.to_le_bytes(); //~ little_endian_bytes + + let _ = 0i8.to_le_bytes(); //~ little_endian_bytes + let _ = 0i16.to_le_bytes(); //~ little_endian_bytes + let _ = 0i32.to_le_bytes(); //~ little_endian_bytes + let _ = 0i64.to_le_bytes(); //~ little_endian_bytes + let _ = 0i128.to_le_bytes(); //~ little_endian_bytes + let _ = 0isize.to_le_bytes(); //~ little_endian_bytes + + let _ = 0f16.to_le_bytes(); //~ little_endian_bytes + let _ = 0f32.to_le_bytes(); //~ little_endian_bytes + let _ = 0f64.to_le_bytes(); //~ little_endian_bytes + let _ = 0f128.to_le_bytes(); //~ little_endian_bytes + + let _ = u8::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = u16::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = u32::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = u64::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = u128::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = usize::from_le_bytes([0; _]); //~ little_endian_bytes + + let _ = i8::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i16::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i32::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i64::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i128::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = isize::from_le_bytes([0; _]); //~ little_endian_bytes + + let _ = f16::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = f32::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = f64::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = f128::from_le_bytes([0; _]); //~ little_endian_bytes + }; + + { + let _ = u8::from_le_bytes; //~ little_endian_bytes + let _ = u8::to_le_bytes; //~ little_endian_bytes + } + + #[warn(clippy::big_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ little_endian_bytes + let _ = 0i8.to_le_bytes(); //~ little_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ little_endian_bytes + }; + + #[warn(clippy::host_endian_bytes)] + { + let _ = 0u8.to_le_bytes(); //~ little_endian_bytes + let _ = 0i8.to_le_bytes(); //~ little_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = i8::from_le_bytes([0; _]); //~ little_endian_bytes + }; + + { + inline! {{ + let _ = 0u8.to_le_bytes(); //~ little_endian_bytes + let _ = u8::from_le_bytes([0; _]); //~ little_endian_bytes + let _ = 0u8.$to_le_bytes(); //~ little_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ little_endian_bytes + }} + + external! { + let _ = 0u8.to_le_bytes(); + let _ = u8::from_le_bytes([0; _]); + let _ = 0u8.$to_le_bytes(); //~ little_endian_bytes + let _ = u8::$from_le_bytes([0; _]); //~ little_endian_bytes + } + } +} diff --git a/tests/ui/little_endian_bytes.stderr b/tests/ui/little_endian_bytes.stderr new file mode 100644 index 000000000000..986b54ca1c42 --- /dev/null +++ b/tests/ui/little_endian_bytes.stderr @@ -0,0 +1,734 @@ +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:12:21 + | +LL | let _ = 0u8.to_le_bytes(); + | ^^^^^^^^^^^ + | + = note: `-D clippy::little-endian-bytes` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::little_endian_bytes)]` +help: convert to native endian + | +LL - let _ = 0u8.to_le_bytes(); +LL + let _ = 0u8.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.to_le_bytes(); +LL + let _ = 0u8.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:13:22 + | +LL | let _ = 0u16.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u16.to_le_bytes(); +LL + let _ = 0u16.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u16.to_le_bytes(); +LL + let _ = 0u16.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:14:22 + | +LL | let _ = 0u32.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u32.to_le_bytes(); +LL + let _ = 0u32.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u32.to_le_bytes(); +LL + let _ = 0u32.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:15:22 + | +LL | let _ = 0u64.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u64.to_le_bytes(); +LL + let _ = 0u64.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u64.to_le_bytes(); +LL + let _ = 0u64.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:16:23 + | +LL | let _ = 0u128.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u128.to_le_bytes(); +LL + let _ = 0u128.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u128.to_le_bytes(); +LL + let _ = 0u128.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:17:24 + | +LL | let _ = 0usize.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0usize.to_le_bytes(); +LL + let _ = 0usize.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0usize.to_le_bytes(); +LL + let _ = 0usize.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:19:21 + | +LL | let _ = 0i8.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i8.to_le_bytes(); +LL + let _ = 0i8.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i8.to_le_bytes(); +LL + let _ = 0i8.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:20:22 + | +LL | let _ = 0i16.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i16.to_le_bytes(); +LL + let _ = 0i16.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i16.to_le_bytes(); +LL + let _ = 0i16.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:21:22 + | +LL | let _ = 0i32.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i32.to_le_bytes(); +LL + let _ = 0i32.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i32.to_le_bytes(); +LL + let _ = 0i32.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:22:22 + | +LL | let _ = 0i64.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i64.to_le_bytes(); +LL + let _ = 0i64.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i64.to_le_bytes(); +LL + let _ = 0i64.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:23:23 + | +LL | let _ = 0i128.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0i128.to_le_bytes(); +LL + let _ = 0i128.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0i128.to_le_bytes(); +LL + let _ = 0i128.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:24:24 + | +LL | let _ = 0isize.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0isize.to_le_bytes(); +LL + let _ = 0isize.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0isize.to_le_bytes(); +LL + let _ = 0isize.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:26:22 + | +LL | let _ = 0f16.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f16.to_le_bytes(); +LL + let _ = 0f16.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f16.to_le_bytes(); +LL + let _ = 0f16.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:27:22 + | +LL | let _ = 0f32.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f32.to_le_bytes(); +LL + let _ = 0f32.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f32.to_le_bytes(); +LL + let _ = 0f32.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:28:22 + | +LL | let _ = 0f64.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f64.to_le_bytes(); +LL + let _ = 0f64.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f64.to_le_bytes(); +LL + let _ = 0f64.to_be_bytes(); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:29:23 + | +LL | let _ = 0f128.to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0f128.to_le_bytes(); +LL + let _ = 0f128.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0f128.to_le_bytes(); +LL + let _ = 0f128.to_be_bytes(); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:31:21 + | +LL | let _ = u8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::from_le_bytes([0; _]); +LL + let _ = u8::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::from_le_bytes([0; _]); +LL + let _ = u8::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:32:22 + | +LL | let _ = u16::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u16::from_le_bytes([0; _]); +LL + let _ = u16::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u16::from_le_bytes([0; _]); +LL + let _ = u16::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:33:22 + | +LL | let _ = u32::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u32::from_le_bytes([0; _]); +LL + let _ = u32::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u32::from_le_bytes([0; _]); +LL + let _ = u32::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:34:22 + | +LL | let _ = u64::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u64::from_le_bytes([0; _]); +LL + let _ = u64::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u64::from_le_bytes([0; _]); +LL + let _ = u64::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:35:23 + | +LL | let _ = u128::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u128::from_le_bytes([0; _]); +LL + let _ = u128::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u128::from_le_bytes([0; _]); +LL + let _ = u128::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:36:24 + | +LL | let _ = usize::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = usize::from_le_bytes([0; _]); +LL + let _ = usize::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = usize::from_le_bytes([0; _]); +LL + let _ = usize::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:38:21 + | +LL | let _ = i8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i8::from_le_bytes([0; _]); +LL + let _ = i8::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i8::from_le_bytes([0; _]); +LL + let _ = i8::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:39:22 + | +LL | let _ = i16::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i16::from_le_bytes([0; _]); +LL + let _ = i16::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i16::from_le_bytes([0; _]); +LL + let _ = i16::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:40:22 + | +LL | let _ = i32::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i32::from_le_bytes([0; _]); +LL + let _ = i32::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i32::from_le_bytes([0; _]); +LL + let _ = i32::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:41:22 + | +LL | let _ = i64::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i64::from_le_bytes([0; _]); +LL + let _ = i64::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i64::from_le_bytes([0; _]); +LL + let _ = i64::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:42:23 + | +LL | let _ = i128::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = i128::from_le_bytes([0; _]); +LL + let _ = i128::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = i128::from_le_bytes([0; _]); +LL + let _ = i128::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:43:24 + | +LL | let _ = isize::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = isize::from_le_bytes([0; _]); +LL + let _ = isize::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = isize::from_le_bytes([0; _]); +LL + let _ = isize::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:45:22 + | +LL | let _ = f16::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f16::from_le_bytes([0; _]); +LL + let _ = f16::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f16::from_le_bytes([0; _]); +LL + let _ = f16::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:46:22 + | +LL | let _ = f32::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f32::from_le_bytes([0; _]); +LL + let _ = f32::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f32::from_le_bytes([0; _]); +LL + let _ = f32::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:47:22 + | +LL | let _ = f64::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f64::from_le_bytes([0; _]); +LL + let _ = f64::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f64::from_le_bytes([0; _]); +LL + let _ = f64::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:48:23 + | +LL | let _ = f128::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = f128::from_le_bytes([0; _]); +LL + let _ = f128::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = f128::from_le_bytes([0; _]); +LL + let _ = f128::from_be_bytes([0; _]); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:52:21 + | +LL | let _ = u8::from_le_bytes; + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::from_le_bytes; +LL + let _ = u8::from_ne_bytes; + | +help: convert from big endian + | +LL - let _ = u8::from_le_bytes; +LL + let _ = u8::from_be_bytes; + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:53:21 + | +LL | let _ = u8::to_le_bytes; + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = u8::to_le_bytes; +LL + let _ = u8::to_ne_bytes; + | +help: convert to big endian + | +LL - let _ = u8::to_le_bytes; +LL + let _ = u8::to_be_bytes; + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:58:21 + | +LL | let _ = 0u8.to_le_bytes(); + | ^^^^^^^^^^^ help: convert to native endian: `to_ne_bytes` + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:59:21 + | +LL | let _ = 0i8.to_le_bytes(); + | ^^^^^^^^^^^ help: convert to native endian: `to_ne_bytes` + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:60:21 + | +LL | let _ = u8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from native endian: `from_ne_bytes` + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:61:21 + | +LL | let _ = i8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from native endian: `from_ne_bytes` + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:66:21 + | +LL | let _ = 0u8.to_le_bytes(); + | ^^^^^^^^^^^ help: convert to big endian: `to_be_bytes` + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:67:21 + | +LL | let _ = 0i8.to_le_bytes(); + | ^^^^^^^^^^^ help: convert to big endian: `to_be_bytes` + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:68:21 + | +LL | let _ = u8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from big endian: `from_be_bytes` + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:69:21 + | +LL | let _ = i8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ help: convert from big endian: `from_be_bytes` + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:74:25 + | +LL | let _ = 0u8.to_le_bytes(); + | ^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert to native endian + | +LL - let _ = 0u8.to_le_bytes(); +LL + let _ = 0u8.to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.to_le_bytes(); +LL + let _ = 0u8.to_be_bytes(); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:75:25 + | +LL | let _ = u8::from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | + = note: this error originates in the macro `__inline_mac_fn_main` (in Nightly builds, run with -Z macro-backtrace for more info) +help: convert from native endian + | +LL - let _ = u8::from_le_bytes([0; _]); +LL + let _ = u8::from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::from_le_bytes([0; _]); +LL + let _ = u8::from_be_bytes([0; _]); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:76:26 + | +LL | let _ = 0u8.$to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u8.$to_le_bytes(); +LL + let _ = 0u8.$to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.$to_le_bytes(); +LL + let _ = 0u8.$to_be_bytes(); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:77:26 + | +LL | let _ = u8::$from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::$from_le_bytes([0; _]); +LL + let _ = u8::$from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::$from_le_bytes([0; _]); +LL + let _ = u8::$from_be_bytes([0; _]); + | + +error: use of `to_le_bytes` + --> tests/ui/little_endian_bytes.rs:83:26 + | +LL | let _ = 0u8.$to_le_bytes(); + | ^^^^^^^^^^^ + | +help: convert to native endian + | +LL - let _ = 0u8.$to_le_bytes(); +LL + let _ = 0u8.$to_ne_bytes(); + | +help: convert to big endian + | +LL - let _ = 0u8.$to_le_bytes(); +LL + let _ = 0u8.$to_be_bytes(); + | + +error: use of `from_le_bytes` + --> tests/ui/little_endian_bytes.rs:84:26 + | +LL | let _ = u8::$from_le_bytes([0; _]); + | ^^^^^^^^^^^^^ + | +help: convert from native endian + | +LL - let _ = u8::$from_le_bytes([0; _]); +LL + let _ = u8::$from_ne_bytes([0; _]); + | +help: convert from big endian + | +LL - let _ = u8::$from_le_bytes([0; _]); +LL + let _ = u8::$from_be_bytes([0; _]); + | + +error: aborting due to 48 previous errors +