Auto merge of #13561 - flip1995:rustup, r=flip1995

Rustup

r? `@ghost`

changelog: none
This commit is contained in:
bors 2024-10-18 11:31:05 +00:00
commit a109190d70
53 changed files with 138 additions and 156 deletions

View file

@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.83"
version = "0.1.84"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"

View file

@ -1,6 +1,6 @@
[package]
name = "clippy_config"
version = "0.1.83"
version = "0.1.84"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View file

@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.83"
version = "0.1.84"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"

View file

@ -1,15 +1,15 @@
use super::{ALLOW_ATTRIBUTES_WITHOUT_REASON, Attribute};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::is_from_proc_macro;
use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_ast::{MetaItemInner, MetaItemKind};
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMetaItem], attr: &'cx Attribute) {
pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[MetaItemInner], attr: &'cx Attribute) {
// Check if the reason is present
if let Some(item) = items.last().and_then(NestedMetaItem::meta_item)
if let Some(item) = items.last().and_then(MetaItemInner::meta_item)
&& let MetaItemKind::NameValue(_) = &item.kind
&& item.path == sym::reason
{

View file

@ -1,12 +1,12 @@
use super::BLANKET_CLIPPY_RESTRICTION_LINTS;
use super::utils::extract_clippy_lint;
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_lint::{LateContext, Level, LintContext};
use rustc_span::symbol::Symbol;
use rustc_span::{DUMMY_SP, sym};
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
pub(super) fn check(cx: &LateContext<'_>, name: Symbol, items: &[MetaItemInner]) {
for lint in items {
if let Some(lint_name) = extract_clippy_lint(lint) {
if lint_name.as_str() == "restriction" && name != sym::allow {

View file

@ -14,7 +14,7 @@ mod utils;
use clippy_config::Conf;
use clippy_config::msrvs::{self, Msrv};
use rustc_ast::{Attribute, MetaItemKind, NestedMetaItem};
use rustc_ast::{Attribute, MetaItemInner, MetaItemKind};
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_session::impl_lint_pass;
@ -456,7 +456,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
return;
}
for item in items {
if let NestedMetaItem::MetaItem(mi) = &item
if let MetaItemInner::MetaItem(mi) = &item
&& let MetaItemKind::NameValue(lit) = &mi.kind
&& mi.has_name(sym::since)
{

View file

@ -1,7 +1,7 @@
use super::{Attribute, NON_MINIMAL_CFG};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::SpanRangeExt;
use rustc_ast::{MetaItemKind, NestedMetaItem};
use rustc_ast::{MetaItemInner, MetaItemKind};
use rustc_errors::Applicability;
use rustc_lint::EarlyContext;
use rustc_span::sym;
@ -14,9 +14,9 @@ pub(super) fn check(cx: &EarlyContext<'_>, attr: &Attribute) {
}
}
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[MetaItemInner]) {
for item in items {
if let NestedMetaItem::MetaItem(meta) = item {
if let MetaItemInner::MetaItem(meta) = item {
if !meta.has_name(sym::any) && !meta.has_name(sym::all) {
continue;
}

View file

@ -2,7 +2,7 @@ use super::utils::{extract_clippy_lint, is_lint_level, is_word};
use super::{Attribute, USELESS_ATTRIBUTE};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::source::{SpanRangeExt, first_line_of_span};
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_errors::Applicability;
use rustc_hir::{Item, ItemKind};
use rustc_lint::{LateContext, LintContext};
@ -21,7 +21,7 @@ pub(super) fn check(cx: &LateContext<'_>, item: &Item<'_>, attrs: &[Attribute])
for lint in lint_list {
match item.kind {
ItemKind::Use(..) => {
if let NestedMetaItem::MetaItem(meta_item) = lint
if let MetaItemInner::MetaItem(meta_item) = lint
&& meta_item.is_word()
&& let Some(ident) = meta_item.ident()
&& matches!(

View file

@ -1,5 +1,5 @@
use clippy_utils::macros::{is_panic, macro_backtrace};
use rustc_ast::{AttrId, NestedMetaItem};
use rustc_ast::{AttrId, MetaItemInner};
use rustc_hir::{
Block, Expr, ExprKind, ImplItem, ImplItemKind, Item, ItemKind, StmtKind, TraitFn, TraitItem, TraitItemKind,
};
@ -8,8 +8,8 @@ use rustc_middle::ty;
use rustc_span::sym;
use rustc_span::symbol::Symbol;
pub(super) fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi {
pub(super) fn is_word(nmi: &MetaItemInner, expected: Symbol) -> bool {
if let MetaItemInner::MetaItem(mi) = &nmi {
mi.is_word() && mi.has_name(expected)
} else {
false
@ -74,7 +74,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
}
/// Returns the lint name if it is clippy lint.
pub(super) fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
pub(super) fn extract_clippy_lint(lint: &MetaItemInner) -> Option<Symbol> {
if let Some(meta_item) = lint.meta_item()
&& meta_item.path.segments.len() > 1
&& let tool_name = meta_item.path.segments[0].ident

View file

@ -1,5 +1,5 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::declare_lint_pass;
@ -47,7 +47,7 @@ impl EarlyLintPass for CfgNotTest {
}
}
fn contains_not_test(list: Option<&[NestedMetaItem]>, not: bool) -> bool {
fn contains_not_test(list: Option<&[MetaItemInner]>, not: bool) -> bool {
list.is_some_and(|list| {
list.iter().any(|item| {
item.ident().is_some_and(|ident| match ident.name {

View file

@ -6,7 +6,7 @@ use rustc_errors::Applicability;
use rustc_hir::intravisit::{Visitor, walk_impl_item, walk_item, walk_param_bound, walk_ty};
use rustc_hir::{
BodyId, ExprKind, GenericBound, GenericParam, GenericParamKind, Generics, ImplItem, ImplItemKind, Item, ItemKind,
PredicateOrigin, Ty, TyKind, WherePredicate,
PredicateOrigin, Ty, WherePredicate,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::nested_filter;
@ -199,12 +199,6 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
fn visit_ty(&mut self, t: &'tcx Ty<'tcx>) {
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
self.ty_params.remove(&def_id);
} else if let TyKind::OpaqueDef(id, _, _) = t.kind {
// Explicitly walk OpaqueDef. Normally `walk_ty` would do the job, but it calls
// `visit_nested_item`, which checks that `Self::NestedFilter::INTER` is set. We're
// using `OnlyBodies`, so the check ends up failing and the type isn't fully walked.
let item = self.nested_visit_map().item(id);
walk_item(self, item);
} else {
walk_ty(self, t);
}

View file

@ -3,8 +3,8 @@ use clippy_utils::source::snippet;
use rustc_errors::{Applicability, SuggestionStyle};
use rustc_hir::def_id::DefId;
use rustc_hir::{
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, ItemKind, PredicateOrigin, TraitBoundModifier,
TyKind, WherePredicate,
AssocItemConstraint, GenericArg, GenericBound, GenericBounds, PredicateOrigin, TraitBoundModifier, TyKind,
WherePredicate,
};
use rustc_hir_analysis::lower_ty;
use rustc_lint::{LateContext, LateLintPass};
@ -242,7 +242,8 @@ fn collect_supertrait_bounds<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds
bounds
.iter()
.filter_map(|bound| {
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
if let GenericBound::Trait(poly_trait) = bound
&& let TraitBoundModifier::None = poly_trait.modifiers
&& let [.., path] = poly_trait.trait_ref.path.segments
&& poly_trait.bound_generic_params.is_empty()
&& let Some(trait_def_id) = path.res.opt_def_id()
@ -307,7 +308,8 @@ fn check<'tcx>(cx: &LateContext<'tcx>, bounds: GenericBounds<'tcx>) {
// This involves some extra logic when generic arguments are present, since
// simply comparing trait `DefId`s won't be enough. We also need to compare the generics.
for (index, bound) in bounds.iter().enumerate() {
if let GenericBound::Trait(poly_trait, TraitBoundModifier::None) = bound
if let GenericBound::Trait(poly_trait) = bound
&& let TraitBoundModifier::None = poly_trait.modifiers
&& let [.., path] = poly_trait.trait_ref.path.segments
&& let implied_args = path.args.map_or([].as_slice(), |a| a.args)
&& let implied_constraints = path.args.map_or([].as_slice(), |a| a.constraints)
@ -342,11 +344,8 @@ impl<'tcx> LateLintPass<'tcx> for ImpliedBoundsInImpls {
}
}
fn check_ty(&mut self, cx: &LateContext<'_>, ty: &rustc_hir::Ty<'_>) {
if let TyKind::OpaqueDef(item_id, ..) = ty.kind
&& let item = cx.tcx.hir().item(item_id)
&& let ItemKind::OpaqueTy(opaque_ty) = item.kind
{
fn check_ty(&mut self, cx: &LateContext<'tcx>, ty: &rustc_hir::Ty<'tcx>) {
if let TyKind::OpaqueDef(opaque_ty, ..) = ty.kind {
check(cx, opaque_ty.bounds);
}
}

View file

@ -5,7 +5,7 @@ use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::higher::IfLet;
use clippy_utils::ty::is_copy;
use clippy_utils::{is_expn_of, is_lint_allowed, path_to_local};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_hir::HirId;
@ -133,7 +133,7 @@ fn lint_slice(cx: &LateContext<'_>, slice: &SliceLintInformation) {
.index_use
.iter()
.map(|(index, _)| *index)
.collect::<FxHashSet<_>>();
.collect::<FxIndexSet<_>>();
let value_name = |index| format!("{}_{index}", slice.ident.name);

View file

@ -308,13 +308,9 @@ enum LenOutput {
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
if let ty::Alias(_, alias_ty) = ty.kind()
&& let Some(Node::Item(item)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
&& let Item {
kind: ItemKind::OpaqueTy(opaque),
..
} = item
&& let OpaqueTyOrigin::AsyncFn(_) = opaque.origin
&& let [GenericBound::Trait(trait_ref, _)] = &opaque.bounds
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir().get_if_local(alias_ty.def_id)
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()
&& let Some(generic_args) = segment.args
&& let [constraint] = generic_args.constraints

View file

@ -2,7 +2,6 @@
#![feature(binary_heap_into_iter_sorted)]
#![feature(box_patterns)]
#![feature(macro_metavar_expr_concat)]
#![feature(control_flow_enum)]
#![feature(f128)]
#![feature(f16)]
#![feature(if_let_guard)]
@ -28,8 +27,6 @@
unused_qualifications,
rustc::internal
)]
// Disable this rustc lint for now, as it was also done in rustc
#![allow(rustc::potential_query_instability)]
// FIXME: switch to something more ergonomic here, once available.
// (Currently there is no way to opt into sysroot crates without `extern crate`.)

View file

@ -1,13 +1,13 @@
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
use clippy_utils::trait_ref_of_method;
use itertools::Itertools;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::Applicability;
use rustc_hir::FnRetTy::Return;
use rustc_hir::intravisit::nested_filter::{self as hir_nested_filter, NestedFilter};
use rustc_hir::intravisit::{
Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_item, walk_param_bound,
walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_where_predicate,
Visitor, walk_fn_decl, walk_generic_args, walk_generics, walk_impl_item_ref, walk_param_bound, walk_poly_trait_ref,
walk_trait_ref, walk_ty, walk_where_predicate,
};
use rustc_hir::{
BareFnTy, BodyId, FnDecl, FnSig, GenericArg, GenericArgs, GenericBound, GenericParam, GenericParamKind, Generics,
@ -163,7 +163,7 @@ fn check_fn_inner<'tcx>(
if visitor.lts.iter().any(|lt| matches!(lt.res, LifetimeName::Param(_))) {
return;
}
if let GenericBound::Trait(ref trait_ref, _) = *bound {
if let GenericBound::Trait(ref trait_ref) = *bound {
let params = &trait_ref
.trait_ref
.path
@ -311,7 +311,7 @@ fn could_use_elision<'tcx>(
Some((elidable_lts, usages))
}
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxHashSet<LocalDefId> {
fn allowed_lts_from(named_generics: &[GenericParam<'_>]) -> FxIndexSet<LocalDefId> {
named_generics
.iter()
.filter_map(|par| {
@ -420,11 +420,9 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
fn visit_ty(&mut self, ty: &'tcx Ty<'_>) {
match ty.kind {
TyKind::OpaqueDef(item, bounds, _) => {
let map = self.cx.tcx.hir();
let item = map.item(item);
TyKind::OpaqueDef(opaque, bounds) => {
let len = self.lts.len();
walk_item(self, item);
self.visit_opaque_ty(opaque);
self.lts.truncate(len);
self.lts.extend(bounds.iter().filter_map(|bound| match bound {
GenericArg::Lifetime(&l) => Some(l),
@ -440,7 +438,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> {
if !lt.is_elided() {
self.unelided_trait_object_lifetime = true;
}
for (bound, _) in bounds {
for bound in bounds {
self.visit_poly_trait_ref(bound);
}
},
@ -499,7 +497,7 @@ struct Usage {
struct LifetimeChecker<'cx, 'tcx, F> {
cx: &'cx LateContext<'tcx>,
map: FxHashMap<LocalDefId, Vec<Usage>>,
map: FxIndexMap<LocalDefId, Vec<Usage>>,
where_predicate_depth: usize,
generic_args_depth: usize,
phantom: std::marker::PhantomData<F>,
@ -621,7 +619,7 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<'
fn report_elidable_impl_lifetimes<'tcx>(
cx: &LateContext<'tcx>,
impl_: &'tcx Impl<'_>,
map: &FxHashMap<LocalDefId, Vec<Usage>>,
map: &FxIndexMap<LocalDefId, Vec<Usage>>,
) {
let single_usages = map
.iter()

View file

@ -5,7 +5,7 @@ use clippy_utils::ty::has_iter_method;
use clippy_utils::visitors::is_local_used;
use clippy_utils::{SpanlessEq, contains_name, higher, is_integer_const, sugg};
use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{Visitor, walk_expr};
@ -39,7 +39,7 @@ pub(super) fn check<'tcx>(
var: canonical_id,
indexed_mut: FxHashSet::default(),
indexed_indirectly: FxHashMap::default(),
indexed_directly: FxHashMap::default(),
indexed_directly: FxIndexMap::default(),
referenced: FxHashSet::default(),
nonindex: false,
prefer_mutable: false,
@ -229,7 +229,7 @@ struct VarVisitor<'a, 'tcx> {
indexed_indirectly: FxHashMap<Symbol, Option<region::Scope>>,
/// subset of `indexed` of vars that are indexed directly: `v[i]`
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
indexed_directly: FxHashMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
indexed_directly: FxIndexMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
/// Any names that are used outside an index operation.
/// Used to detect things like `&mut vec` used together with `vec[i]`
referenced: FxHashSet<Symbol>,

View file

@ -4,7 +4,7 @@ use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
Block, Body, Closure, ClosureKind, CoroutineDesugaring, CoroutineKind, CoroutineSource, Expr, ExprKind, FnDecl,
FnRetTy, GenericArg, GenericBound, ImplItem, Item, ItemKind, LifetimeName, Node, TraitRef, Ty, TyKind,
FnRetTy, GenericArg, GenericBound, ImplItem, Item, LifetimeName, Node, TraitRef, Ty, TyKind,
};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::declare_lint_pass;
@ -105,11 +105,9 @@ fn future_trait_ref<'tcx>(
cx: &LateContext<'tcx>,
ty: &'tcx Ty<'tcx>,
) -> Option<(&'tcx TraitRef<'tcx>, Vec<LifetimeName>)> {
if let TyKind::OpaqueDef(item_id, bounds, false) = ty.kind
&& let item = cx.tcx.hir().item(item_id)
&& let ItemKind::OpaqueTy(opaque) = &item.kind
if let TyKind::OpaqueDef(opaque, bounds) = ty.kind
&& let Some(trait_ref) = opaque.bounds.iter().find_map(|bound| {
if let GenericBound::Trait(poly, _) = bound {
if let GenericBound::Trait(poly) = bound {
Some(&poly.trait_ref)
} else {
None

View file

@ -7,6 +7,7 @@ use clippy_utils::ty::{for_each_top_level_late_bound_region, is_copy};
use clippy_utils::{get_attr, is_lint_allowed};
use itertools::Itertools;
use rustc_ast::Mutability;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{Applicability, Diag};
use rustc_hir::intravisit::{Visitor, walk_expr};
use rustc_hir::{Arm, Expr, ExprKind, MatchSource};
@ -475,19 +476,19 @@ impl<'tcx> Visitor<'tcx> for SigDropHelper<'_, 'tcx> {
struct ArmSigDropHelper<'a, 'tcx> {
sig_drop_checker: SigDropChecker<'a, 'tcx>,
found_sig_drop_spans: FxHashSet<Span>,
found_sig_drop_spans: FxIndexSet<Span>,
}
impl<'a, 'tcx> ArmSigDropHelper<'a, 'tcx> {
fn new(cx: &'a LateContext<'tcx>) -> ArmSigDropHelper<'a, 'tcx> {
ArmSigDropHelper {
sig_drop_checker: SigDropChecker::new(cx),
found_sig_drop_spans: FxHashSet::<Span>::default(),
found_sig_drop_spans: FxIndexSet::<Span>::default(),
}
}
}
fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &[&'tcx Expr<'_>]) -> FxHashSet<Span> {
fn has_significant_drop_in_arms<'tcx>(cx: &LateContext<'tcx>, arms: &[&'tcx Expr<'_>]) -> FxIndexSet<Span> {
let mut helper = ArmSigDropHelper::new(cx);
for arm in arms {
helper.visit_expr(arm);

View file

@ -8,7 +8,7 @@ use clippy_utils::visitors::for_each_expr_without_closures;
use clippy_utils::{eq_expr_value, hash_expr, higher};
use rustc_ast::{LitKind, RangeLimits};
use rustc_data_structures::packed::Pu128;
use rustc_data_structures::unhash::UnhashMap;
use rustc_data_structures::unhash::UnindexMap;
use rustc_errors::{Applicability, Diag};
use rustc_hir::{BinOp, Block, Body, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
@ -226,7 +226,7 @@ fn upper_index_expr(expr: &Expr<'_>) -> Option<usize> {
}
/// Checks if the expression is an index into a slice and adds it to `indexes`
fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap<u64, Vec<IndexEntry<'hir>>>) {
fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnindexMap<u64, Vec<IndexEntry<'hir>>>) {
if let ExprKind::Index(slice, index_lit, _) = expr.kind
&& cx.typeck_results().expr_ty_adjusted(slice).peel_refs().is_slice()
&& let Some(index) = upper_index_expr(index_lit)
@ -274,7 +274,7 @@ fn check_index<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut Unh
}
/// Checks if the expression is an `assert!` expression and adds it to `asserts`
fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnhashMap<u64, Vec<IndexEntry<'hir>>>) {
fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut UnindexMap<u64, Vec<IndexEntry<'hir>>>) {
if let Some((comparison, asserted_len, slice)) = assert_len_expr(cx, expr) {
let hash = hash_expr(cx, slice);
let indexes = map.entry(hash).or_default();
@ -311,7 +311,7 @@ fn check_assert<'hir>(cx: &LateContext<'_>, expr: &'hir Expr<'hir>, map: &mut Un
/// Inspects indexes and reports lints.
///
/// Called at the end of this lint after all indexing and `assert!` expressions have been collected.
fn report_indexes(cx: &LateContext<'_>, map: &UnhashMap<u64, Vec<IndexEntry<'_>>>) {
fn report_indexes(cx: &LateContext<'_>, map: &UnindexMap<u64, Vec<IndexEntry<'_>>>) {
for bucket in map.values() {
for entry in bucket {
let Some(full_span) = entry
@ -403,7 +403,7 @@ fn report_indexes(cx: &LateContext<'_>, map: &UnhashMap<u64, Vec<IndexEntry<'_>>
impl LateLintPass<'_> for MissingAssertsForIndexing {
fn check_body(&mut self, cx: &LateContext<'_>, body: &Body<'_>) {
let mut map = UnhashMap::default();
let mut map = UnindexMap::default();
for_each_expr_without_closures(body.value, |expr| {
check_index(cx, expr, &mut map);

View file

@ -193,8 +193,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
| hir::ItemKind::Trait(..)
| hir::ItemKind::TraitAlias(..)
| hir::ItemKind::TyAlias(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::OpaqueTy(..) => {},
| hir::ItemKind::Union(..) => {},
hir::ItemKind::ExternCrate(..)
| hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::GlobalAsm(..)

View file

@ -130,7 +130,6 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline {
| hir::ItemKind::GlobalAsm(..)
| hir::ItemKind::TyAlias(..)
| hir::ItemKind::Union(..)
| hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::ExternCrate(..)
| hir::ItemKind::ForeignMod { .. }
| hir::ItemKind::Impl { .. }

View file

@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use rustc_ast::ast;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::LOCAL_CRATE;
@ -87,7 +87,7 @@ impl EarlyLintPass for ModStyle {
// `folder_segments` is all unique folder path segments `path/to/foo.rs` gives
// `[path, to]` but not foo
let mut folder_segments = FxHashSet::default();
let mut folder_segments = FxIndexSet::default();
// `mod_folders` is all the unique folder names that contain a mod.rs file
let mut mod_folders = FxHashSet::default();
// `file_map` maps file names to the full path including the file name
@ -144,7 +144,7 @@ impl EarlyLintPass for ModStyle {
/// is `mod.rs` we add it's parent folder to `mod_folders`.
fn process_paths_for_mod_files<'a>(
path: &'a Path,
folder_segments: &mut FxHashSet<&'a OsStr>,
folder_segments: &mut FxIndexSet<&'a OsStr>,
mod_folders: &mut FxHashSet<&'a OsStr>,
) {
let mut comp = path.components().rev().peekable();

View file

@ -40,7 +40,6 @@ struct Bound<'tcx> {
ident: Ident,
trait_bound: &'tcx PolyTraitRef<'tcx>,
modifier: TraitBoundModifier,
predicate_pos: usize,
bound_pos: usize,
@ -65,11 +64,10 @@ fn type_param_bounds<'tcx>(generics: &'tcx Generics<'tcx>) -> impl Iterator<Item
.iter()
.enumerate()
.filter_map(move |(bound_pos, bound)| match bound {
&GenericBound::Trait(ref trait_bound, modifier) => Some(Bound {
GenericBound::Trait(trait_bound) => Some(Bound {
param,
ident,
trait_bound,
modifier,
predicate_pos,
bound_pos,
}),
@ -120,13 +118,13 @@ impl LateLintPass<'_> for NeedlessMaybeSized {
let maybe_sized_params: DefIdMap<_> = type_param_bounds(generics)
.filter(|bound| {
bound.trait_bound.trait_ref.trait_def_id() == Some(sized_trait)
&& bound.modifier == TraitBoundModifier::Maybe
&& bound.trait_bound.modifiers == TraitBoundModifier::Maybe
})
.map(|bound| (bound.param, bound))
.collect();
for bound in type_param_bounds(generics) {
if bound.modifier == TraitBoundModifier::None
if bound.trait_bound.modifiers == TraitBoundModifier::None
&& let Some(sized_bound) = maybe_sized_params.get(&bound.param)
&& let Some(path) = path_to_sized_bound(cx, bound.trait_bound)
{

View file

@ -5,7 +5,7 @@ use clippy_utils::source::snippet;
use clippy_utils::visitors::for_each_expr;
use clippy_utils::{inherits_cfg, is_from_proc_macro, is_self};
use core::ops::ControlFlow;
use rustc_data_structures::fx::{FxHashSet, FxIndexMap};
use rustc_data_structures::fx::{FxHashSet, FxIndexMap, FxIndexSet};
use rustc_errors::Applicability;
use rustc_hir::intravisit::FnKind;
use rustc_hir::{
@ -101,7 +101,7 @@ fn check_closures<'tcx>(
ctx: &mut MutablyUsedVariablesCtxt<'tcx>,
cx: &LateContext<'tcx>,
checked_closures: &mut FxHashSet<LocalDefId>,
closures: FxHashSet<LocalDefId>,
closures: FxIndexSet<LocalDefId>,
) {
let hir = cx.tcx.hir();
for closure in closures {
@ -196,7 +196,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
prev_bind: None,
prev_move_to_closure: HirIdSet::default(),
aliases: HirIdMap::default(),
async_closures: FxHashSet::default(),
async_closures: FxIndexSet::default(),
tcx: cx.tcx,
};
euv::ExprUseVisitor::for_clippy(cx, fn_def_id, &mut ctx)
@ -207,7 +207,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
// We retrieve all the closures declared in the function because they will not be found
// by `euv::Delegate`.
let mut closures: FxHashSet<LocalDefId> = FxHashSet::default();
let mut closures: FxIndexSet<LocalDefId> = FxIndexSet::default();
for_each_expr(cx, body, |expr| {
if let ExprKind::Closure(closure) = expr.kind {
closures.insert(closure.def_id);
@ -307,7 +307,7 @@ struct MutablyUsedVariablesCtxt<'tcx> {
/// use of a variable.
prev_move_to_closure: HirIdSet,
aliases: HirIdMap<HirId>,
async_closures: FxHashSet<LocalDefId>,
async_closures: FxIndexSet<LocalDefId>,
tcx: TyCtxt<'tcx>,
}

View file

@ -7,7 +7,7 @@ use clippy_utils::{
path_to_local_id, span_contains_cfg, span_find_starting_semi,
};
use core::ops::ControlFlow;
use rustc_ast::NestedMetaItem;
use rustc_ast::MetaItemInner;
use rustc_errors::Applicability;
use rustc_hir::LangItem::ResultErr;
use rustc_hir::intravisit::FnKind;
@ -421,7 +421,7 @@ fn check_final_expr<'tcx>(
if matches!(Level::from_attr(attr), Some(Level::Expect(_)))
&& let metas = attr.meta_item_list()
&& let Some(lst) = metas
&& let [NestedMetaItem::MetaItem(meta_item), ..] = lst.as_slice()
&& let [MetaItemInner::MetaItem(meta_item), ..] = lst.as_slice()
&& let [tool, lint_name] = meta_item.path.segments.as_slice()
&& tool.ident.name == sym::clippy
&& matches!(

View file

@ -6,9 +6,9 @@ use clippy_utils::ty::is_type_diagnostic_item;
use clippy_utils::{can_mut_borrow_both, eq_expr_value, is_in_const_context, std_or_core};
use itertools::Itertools;
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::intravisit::{Visitor, walk_expr};
use crate::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, LetStmt, PatKind, QPath, Stmt, StmtKind};
use rustc_lint::{LateContext, LateLintPass, LintContext};
@ -334,7 +334,7 @@ struct IndexBinding<'a, 'tcx> {
impl<'tcx> IndexBinding<'_, 'tcx> {
fn snippet_index_bindings(&mut self, exprs: &[&'tcx Expr<'tcx>]) -> String {
let mut bindings = FxHashSet::default();
let mut bindings = FxIndexSet::default();
for expr in exprs {
bindings.insert(self.snippet_index_binding(expr));
}

View file

@ -185,7 +185,7 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
// Iterate the bounds and add them to our seen hash
// If we haven't yet seen it, add it to the fixed traits
for (bound, _) in bounds {
for bound in bounds {
let Some(def_id) = bound.trait_ref.trait_def_id() else {
continue;
};
@ -200,9 +200,9 @@ impl<'tcx> LateLintPass<'tcx> for TraitBounds {
// If the number of unique traits isn't the same as the number of traits in the bounds,
// there must be 1 or more duplicates
if bounds.len() != unique_traits.len() {
let mut bounds_span = bounds[0].0.span;
let mut bounds_span = bounds[0].span;
for (bound, _) in bounds.iter().skip(1) {
for bound in bounds.iter().skip(1) {
bounds_span = bounds_span.to(bound.span);
}
@ -232,7 +232,8 @@ impl TraitBounds {
/// this MSRV? See <https://github.com/rust-lang/rust-clippy/issues/8772> for details.
fn cannot_combine_maybe_bound(&self, cx: &LateContext<'_>, bound: &GenericBound<'_>) -> bool {
if !self.msrv.meets(msrvs::MAYBE_BOUND_IN_WHERE)
&& let GenericBound::Trait(tr, TraitBoundModifier::Maybe) = bound
&& let GenericBound::Trait(tr) = bound
&& let TraitBoundModifier::Maybe = tr.modifiers
{
cx.tcx.lang_items().get(LangItem::Sized) == tr.trait_ref.path.res.opt_def_id()
} else {
@ -395,11 +396,11 @@ impl Hash for ComparableTraitRef<'_, '_> {
}
fn get_trait_info_from_bound<'a>(bound: &'a GenericBound<'_>) -> Option<(Res, &'a [PathSegment<'a>], Span)> {
if let GenericBound::Trait(t, tbm) = bound {
if let GenericBound::Trait(t) = bound {
let trait_path = t.trait_ref.path;
let trait_span = {
let path_span = trait_path.span;
if let TraitBoundModifier::Maybe = tbm {
if let TraitBoundModifier::Maybe = t.modifiers {
path_span.with_lo(path_span.lo() - BytePos(1)) // include the `?`
} else {
path_span
@ -421,12 +422,12 @@ fn rollup_traits<'cx, 'tcx>(
let mut repeated_res = false;
let only_comparable_trait_refs = |bound: &'tcx GenericBound<'tcx>| {
if let GenericBound::Trait(t, modifier) = bound {
if let GenericBound::Trait(t) = bound {
Some((
ComparableTraitRef {
cx,
trait_ref: &t.trait_ref,
modifier: *modifier,
modifier: t.modifiers,
},
t.span,
))

View file

@ -82,7 +82,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m
// Returns true if given type is `Any` trait.
fn is_any_trait(cx: &LateContext<'_>, t: &hir::Ty<'_>) -> bool {
if let TyKind::TraitObject(traits, ..) = t.kind {
return traits.iter().any(|(bound, _)| {
return traits.iter().any(|bound| {
if let Some(trait_did) = bound.trait_ref.trait_def_id()
&& cx.tcx.is_diagnostic_item(sym::Any, trait_did)
{

View file

@ -55,7 +55,6 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor {
TyKind::TraitObject(param_bounds, _, _) => {
let has_lifetime_parameters = param_bounds.iter().any(|bound| {
bound
.0
.bound_generic_params
.iter()
.any(|param| matches!(param.kind, GenericParamKind::Lifetime { .. }))

View file

@ -85,10 +85,6 @@ const SEGMENTS_MSG: &str = "segments should be composed of at least 1 element";
impl<'tcx> LateLintPass<'tcx> for UseSelf {
fn check_item(&mut self, cx: &LateContext<'tcx>, item: &Item<'tcx>) {
if matches!(item.kind, ItemKind::OpaqueTy(_)) {
// skip over `ItemKind::OpaqueTy` in order to lint `foo() -> impl <..>`
return;
}
// We push the self types of `impl`s on a stack here. Only the top type on the stack is
// relevant for linting, since this is the self type of the `impl` we're currently in. To
// avoid linting on nested items, we push `StackItem::NoCheck` on the stack to signal, that
@ -130,10 +126,8 @@ impl<'tcx> LateLintPass<'tcx> for UseSelf {
self.stack.push(stack_item);
}
fn check_item_post(&mut self, _: &LateContext<'_>, item: &Item<'_>) {
if !matches!(item.kind, ItemKind::OpaqueTy(_)) {
self.stack.pop();
}
fn check_item_post(&mut self, _: &LateContext<'_>, _: &Item<'_>) {
self.stack.pop();
}
fn check_impl_item(&mut self, cx: &LateContext<'_>, impl_item: &hir::ImplItem<'_>) {

View file

@ -2,7 +2,7 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help};
use clippy_utils::macros::root_macro_call_first_node;
use clippy_utils::{is_lint_allowed, match_def_path, paths};
use rustc_ast::ast::LitKind;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_hir::def::{DefKind, Res};
use rustc_hir::hir_id::CRATE_HIR_ID;
use rustc_hir::intravisit::Visitor;
@ -87,8 +87,8 @@ declare_clippy_lint! {
#[derive(Clone, Debug, Default)]
pub struct LintWithoutLintPass {
declared_lints: FxHashMap<Symbol, Span>,
registered_lints: FxHashSet<Symbol>,
declared_lints: FxIndexMap<Symbol, Span>,
registered_lints: FxIndexSet<Symbol>,
}
impl_lint_pass!(LintWithoutLintPass => [
@ -266,7 +266,7 @@ pub(super) fn extract_clippy_version_value(cx: &LateContext<'_>, item: &'_ Item<
}
struct LintCollector<'a, 'tcx> {
output: &'a mut FxHashSet<Symbol>,
output: &'a mut FxIndexSet<Symbol>,
cx: &'a LateContext<'tcx>,
}

View file

@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
version = "0.1.83"
version = "0.1.84"
edition = "2021"
publish = false

View file

@ -753,6 +753,9 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool {
(Ref(ll, l), Ref(rl, r)) => {
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
},
(PinnedRef(ll, l), PinnedRef(rl, r)) => {
both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty)
},
(BareFn(l), BareFn(r)) => {
l.safety == r.safety
&& eq_ext(&l.ext, &r.ext)
@ -783,7 +786,8 @@ pub fn eq_str_lit(l: &StrLit, r: &StrLit) -> bool {
}
pub fn eq_poly_ref_trait(l: &PolyTraitRef, r: &PolyTraitRef) -> bool {
eq_path(&l.trait_ref.path, &r.trait_ref.path)
l.modifiers == r.modifiers
&& eq_path(&l.trait_ref.path, &r.trait_ref.path)
&& over(&l.bound_generic_params, &r.bound_generic_params, |l, r| {
eq_generic_param(l, r)
})
@ -817,7 +821,7 @@ pub fn eq_generic_param(l: &GenericParam, r: &GenericParam) -> bool {
pub fn eq_generic_bound(l: &GenericBound, r: &GenericBound) -> bool {
use GenericBound::*;
match (l, r) {
(Trait(ptr1, tbm1), Trait(ptr2, tbm2)) => tbm1 == tbm2 && eq_poly_ref_trait(ptr1, ptr2),
(Trait(ptr1), Trait(ptr2)) => eq_poly_ref_trait(ptr1, ptr2),
(Outlives(l), Outlives(r)) => eq_id(l.ident, r.ident),
_ => false,
}

View file

@ -247,7 +247,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) {
ItemKind::Const(..) => (Pat::Str("const"), Pat::Str(";")),
ItemKind::Fn(sig, ..) => (fn_header_search_pat(sig.header), Pat::Str("")),
ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")),
ItemKind::TyAlias(..) | ItemKind::OpaqueTy(_) => (Pat::Str("type"), Pat::Str(";")),
ItemKind::TyAlias(..) => (Pat::Str("type"), Pat::Str(";")),
ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")),
ItemKind::Struct(VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")),
ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")),

View file

@ -1219,9 +1219,8 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
}
},
TyKind::Path(ref qpath) => self.hash_qpath(qpath),
TyKind::OpaqueDef(_, arg_list, in_trait) => {
TyKind::OpaqueDef(_, arg_list) => {
self.hash_generic_args(arg_list);
in_trait.hash(&mut self.s);
},
TyKind::TraitObject(_, lifetime, _) => {
self.hash_lifetime(lifetime);

View file

@ -1,6 +1,5 @@
#![feature(array_chunks)]
#![feature(box_patterns)]
#![feature(control_flow_enum)]
#![feature(f128)]
#![feature(f16)]
#![feature(if_let_guard)]

View file

@ -213,7 +213,7 @@ impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
self.bitset.0.clear();
let maybe_live = &mut self.maybe_live;
if let Some(bitset) = self.map.get(&borrowed) {
for b in bitset.iter().filter(move |b| maybe_live.contains(*b)) {
for b in bitset.iter().filter(move |b| maybe_live.get().contains(*b)) {
self.bitset.0.insert(b);
}
} else {
@ -238,6 +238,6 @@ impl<'b, 'tcx> PossibleBorrowerMap<'b, 'tcx> {
pub fn local_is_alive_at(&mut self, local: mir::Local, at: mir::Location) -> bool {
self.maybe_live.seek_after_primary_effect(at);
self.maybe_live.contains(local)
self.maybe_live.get().contains(local)
}
}

View file

@ -287,6 +287,7 @@ impl SourceFileRange {
self.sf
.src
.as_ref()
.map(|src| src.as_str())
.or_else(|| self.sf.external_src.get().and_then(|src| src.get_source()))
.and_then(|x| x.get(self.range.clone()))
}

View file

@ -1,4 +1,4 @@
[toolchain]
channel = "nightly-2024-10-03"
channel = "nightly-2024-10-18"
components = ["cargo", "llvm-tools", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]
profile = "minimal"

View file

@ -86,6 +86,7 @@ mod issue9612 {
util();
}
#[allow(unconditional_panic)]
fn util() {
let _a: u8 = 4.try_into().unwrap();
let _a: u8 = 5.try_into().expect("");

View file

@ -86,6 +86,7 @@ mod issue9612 {
util();
}
#[allow(unconditional_panic)]
fn util() {
let _a: u8 = 4.try_into().unwrap();
let _a: u8 = 5.try_into().expect("");

View file

@ -274,7 +274,7 @@ LL | let _ = &boxed_slice[1];
| ~~~~~~~~~~~~~~~
error: called `.get().unwrap()` on a slice
--> tests/ui-toml/unwrap_used/unwrap_used.rs:93:17
--> tests/ui-toml/unwrap_used/unwrap_used.rs:94:17
|
LL | let _ = Box::new([0]).get(1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,10 +0,0 @@
#![allow(incomplete_features)]
#![feature(unnamed_fields)]
#[repr(C)]
struct Foo {
_: struct {
},
}
fn main() {}

View file

@ -3,7 +3,7 @@
#![allow(dead_code, incomplete_features)]
#![warn(clippy::doc_markdown)]
#![feature(custom_inner_attributes, generic_const_exprs, const_option)]
#![feature(custom_inner_attributes, generic_const_exprs)]
#![rustfmt::skip]
/// The `foo_bar` function does _nothing_. See also `foo::bar`. (note the dot there)

View file

@ -3,7 +3,7 @@
#![allow(dead_code, incomplete_features)]
#![warn(clippy::doc_markdown)]
#![feature(custom_inner_attributes, generic_const_exprs, const_option)]
#![feature(custom_inner_attributes, generic_const_exprs)]
#![rustfmt::skip]
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)

View file

@ -70,6 +70,7 @@ fn main() {
mod issue9909 {
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
#[allow(unconditional_panic)]
fn reduced() {
let f = &[1, 2, 3];

View file

@ -70,6 +70,7 @@ fn main() {
mod issue9909 {
#![allow(clippy::identity_op, clippy::unwrap_used, dead_code)]
#[allow(unconditional_panic)]
fn reduced() {
let f = &[1, 2, 3];

View file

@ -266,7 +266,7 @@ LL | let _ = some_vec.get_mut(0..1).unwrap().to_vec();
= help: consider using `expect()` to provide a better panic message
error: called `.get().unwrap()` on a slice
--> tests/ui/get_unwrap.rs:77:24
--> tests/ui/get_unwrap.rs:78:24
|
LL | let _x: &i32 = f.get(1 + 2).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^
@ -277,7 +277,7 @@ LL | let _x: &i32 = &f[1 + 2];
| ~~~~~~~~~
error: called `.get().unwrap()` on a slice
--> tests/ui/get_unwrap.rs:80:18
--> tests/ui/get_unwrap.rs:81:18
|
LL | let _x = f.get(1 + 2).unwrap().to_string();
| ^^^^^^^^^^^^^^^^^^^^^
@ -288,7 +288,7 @@ LL | let _x = f[1 + 2].to_string();
| ~~~~~~~~
error: called `.get().unwrap()` on a slice
--> tests/ui/get_unwrap.rs:83:18
--> tests/ui/get_unwrap.rs:84:18
|
LL | let _x = f.get(1 + 2).unwrap().abs();
| ^^^^^^^^^^^^^^^^^^^^^
@ -299,7 +299,7 @@ LL | let _x = f[1 + 2].abs();
| ~~~~~~~~
error: called `.get_mut().unwrap()` on a slice
--> tests/ui/get_unwrap.rs:100:33
--> tests/ui/get_unwrap.rs:101:33
|
LL | let b = rest.get_mut(linidx(j, k) - linidx(i, k) - 1).unwrap();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,7 +1,7 @@
#![warn(clippy::transmute_float_to_int)]
#![allow(clippy::missing_transmute_annotations)]
#![feature(f128, f128_const)]
#![feature(f16, f16_const)]
#![feature(f128)]
#![feature(f16)]
fn float_to_int() {
let _: u32 = unsafe { 1f32.to_bits() };

View file

@ -1,7 +1,7 @@
#![warn(clippy::transmute_float_to_int)]
#![allow(clippy::missing_transmute_annotations)]
#![feature(f128, f128_const)]
#![feature(f16, f16_const)]
#![feature(f128)]
#![feature(f16)]
fn float_to_int() {
let _: u32 = unsafe { std::mem::transmute(1f32) };

View file

@ -84,8 +84,14 @@ fn issue_10449() {
}
// Pointers cannot be cast to integers in const contexts
#[allow(
ptr_to_integer_transmute_in_consts,
reason = "This is tested in the compiler test suite"
)]
const fn issue_12402<P>(ptr: *const P) {
unsafe { transmute::<*const i32, usize>(&42i32) };
unsafe { transmute::<fn(*const P), usize>(issue_12402) };
let _ = unsafe { transmute::<_, usize>(ptr) };
// This test exists even though the compiler lints against it
// to test that clippy's transmute lints do not trigger on this.
unsafe { std::mem::transmute::<*const i32, usize>(&42i32) };
unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) };
let _ = unsafe { std::mem::transmute::<_, usize>(ptr) };
}

View file

@ -84,8 +84,14 @@ fn issue_10449() {
}
// Pointers cannot be cast to integers in const contexts
#[allow(
ptr_to_integer_transmute_in_consts,
reason = "This is tested in the compiler test suite"
)]
const fn issue_12402<P>(ptr: *const P) {
unsafe { transmute::<*const i32, usize>(&42i32) };
unsafe { transmute::<fn(*const P), usize>(issue_12402) };
let _ = unsafe { transmute::<_, usize>(ptr) };
// This test exists even though the compiler lints against it
// to test that clippy's transmute lints do not trigger on this.
unsafe { std::mem::transmute::<*const i32, usize>(&42i32) };
unsafe { std::mem::transmute::<fn(*const P), usize>(issue_12402) };
let _ = unsafe { std::mem::transmute::<_, usize>(ptr) };
}