Skip to content

Commit 64c7431

Browse files
authored
r? @ghost changelog: none
2 parents 3be3a9c + bf8aa08 commit 64c7431

18 files changed

Lines changed: 82 additions & 87 deletions

File tree

clippy_lints/src/functions/must_use.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustc_errors::Applicability;
44
use rustc_hir::def::Res;
55
use rustc_hir::def_id::DefIdSet;
66
use rustc_hir::{self as hir, Attribute, QPath, find_attr};
7-
use rustc_infer::infer::TyCtxtInferExt;
87
use rustc_lint::{LateContext, LintContext};
98
use rustc_middle::ty::{self, Ty};
109
use rustc_span::{Span, sym};
@@ -16,7 +15,6 @@ use clippy_utils::ty::is_must_use_ty;
1615
use clippy_utils::visitors::for_each_expr_without_closures;
1716
use clippy_utils::{is_entrypoint_fn, return_ty, trait_ref_of_method};
1817
use rustc_span::Symbol;
19-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
2018

2119
use core::ops::ControlFlow;
2220

@@ -165,13 +163,11 @@ fn check_needless_must_use(
165163
);
166164
} else if reason.is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) {
167165
// Ignore async functions unless Future::Output type is a must_use type
168-
if sig.header.is_async() {
169-
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());
170-
if let Some(future_ty) = infcx.err_ctxt().get_impl_future_output_ty(return_ty(cx, item_id))
171-
&& !is_must_use_ty(cx, future_ty)
172-
{
173-
return;
174-
}
166+
if sig.header.is_async()
167+
&& let Some(future_ty) = cx.tcx.get_impl_future_output_ty(return_ty(cx, item_id))
168+
&& !is_must_use_ty(cx, future_ty)
169+
{
170+
return;
175171
}
176172

177173
span_lint_and_then(

clippy_lints/src/functions/result.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ use clippy_utils::msrvs::{self, Msrv};
22
use clippy_utils::res::MaybeDef;
33
use rustc_errors::Diag;
44
use rustc_hir as hir;
5-
use rustc_infer::infer::TyCtxtInferExt as _;
65
use rustc_lint::{LateContext, LintContext};
76
use rustc_middle::ty::{self, Ty};
87
use rustc_span::def_id::DefIdSet;
98
use rustc_span::{Span, sym};
10-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt as _;
119

1210
use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_then};
1311
use clippy_utils::ty::{AdtVariantInfo, approx_ty_size};
@@ -32,12 +30,7 @@ fn result_err_ty<'tcx>(
3230

3331
// for async functions, peel through `impl Future<Output = T>` to get `T`
3432
if cx.tcx.ty_is_opaque_future(ty)
35-
&& let Some(future_output_ty) = cx
36-
.tcx
37-
.infer_ctxt()
38-
.build(cx.typing_mode())
39-
.err_ctxt()
40-
.get_impl_future_output_ty(ty)
33+
&& let Some(future_output_ty) = cx.tcx.get_impl_future_output_ty(ty)
4134
{
4235
ty = future_output_ty;
4336
}

clippy_lints/src/len_without_is_empty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,11 @@ fn check_trait_items(cx: &LateContext<'_>, visited_trait: &Item<'_>, ident: Iden
149149
}
150150

151151
fn extract_future_output<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<&'tcx PathSegment<'tcx>> {
152-
if let ty::Alias(alias_ty) = ty.kind()
153-
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(alias_ty.kind.def_id())
152+
if let ty::Alias(ty::AliasTy {
153+
kind: ty::Opaque { def_id },
154+
..
155+
}) = *ty.kind()
156+
&& let Some(Node::OpaqueTy(opaque)) = cx.tcx.hir_get_if_local(def_id)
154157
&& let OpaqueTyOrigin::AsyncFn { .. } = opaque.origin
155158
&& let [GenericBound::Trait(trait_ref)] = &opaque.bounds
156159
&& let Some(segment) = trait_ref.trait_ref.path.segments.last()

clippy_lints/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
454454
// NOTE: Do not add any more pre-expansion passes. These should be removed eventually.
455455
// Due to the architecture of the compiler, currently `cfg_attr` attributes on crate
456456
// level (i.e `#![cfg_attr(...)]`) will still be expanded even when using a pre-expansion pass.
457-
store.register_pre_expansion_pass(move || Box::new(attrs::EarlyAttributes::new(conf)));
457+
store.register_pre_expansion_pass(Box::new(move || Box::new(attrs::EarlyAttributes::new(conf))));
458458

459459
let format_args_storage = FormatArgsStorage::default();
460460
let attr_storage = AttrStorage::default();

clippy_lints/src/methods/needless_collect.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
247247
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, sym::Item, [collect_ty])
248248
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
249249
cx.typing_env(),
250-
Unnormalized::new_wip(Ty::new_projection_from_args(
251-
cx.tcx,
252-
into_iter_item_proj.kind.def_id(),
253-
into_iter_item_proj.args,
254-
)),
250+
Unnormalized::new_wip(Ty::new_alias(cx.tcx, into_iter_item_proj)),
255251
)
256252
{
257253
iter_item_ty == into_iter_item_ty

clippy_lints/src/missing_fields_in_debug.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ fn check_struct<'tcx>(
185185
.filter_map(|field| {
186186
if field_accesses.contains(&field.ident.name)
187187
|| field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
188+
|| field.ty.basic_res().is_diag_item(cx, sym::PhantomPinned)
188189
{
189190
None
190191
} else {

clippy_lints/src/no_effect.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ use rustc_hir::{
99
BinOpKind, BlockCheckMode, Expr, ExprKind, HirId, HirIdMap, ItemKind, LocalSource, Node, PatKind, Stmt, StmtKind,
1010
StructTailExpr, UnsafeSource, is_range_literal,
1111
};
12-
use rustc_infer::infer::TyCtxtInferExt as _;
1312
use rustc_lint::{LateContext, LateLintPass, LintContext};
1413
use rustc_session::impl_lint_pass;
1514
use rustc_span::Span;
16-
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
1715
use std::ops::Deref;
1816

1917
declare_clippy_lint! {
@@ -162,12 +160,7 @@ impl NoEffect {
162160

163161
// Remove `impl Future<Output = T>` to get `T`
164162
if cx.tcx.ty_is_opaque_future(ret_ty)
165-
&& let Some(true_ret_ty) = cx
166-
.tcx
167-
.infer_ctxt()
168-
.build(cx.typing_mode())
169-
.err_ctxt()
170-
.get_impl_future_output_ty(ret_ty)
163+
&& let Some(true_ret_ty) = cx.tcx.get_impl_future_output_ty(ret_ty)
171164
{
172165
ret_ty = true_ret_ty;
173166
}

clippy_lints/src/non_copy_const.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> {
757757
}
758758

759759
fn check_trait_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx TraitItem<'_>) {
760-
if let TraitItemKind::Const(_, ct_rhs_opt, _) = item.kind
760+
if let TraitItemKind::Const(_, ct_rhs_opt) = item.kind
761761
&& let ty = cx.tcx.type_of(item.owner_id).instantiate_identity().skip_norm_wip()
762762
&& match self.is_ty_freeze(cx.tcx, cx.typing_env(), ty) {
763763
IsFreeze::No => true,
@@ -958,7 +958,7 @@ fn get_const_hir_value<'tcx>(
958958
{
959959
match tcx.hir_node(tcx.local_def_id_to_hir_id(did)) {
960960
Node::ImplItem(item) if let ImplItemKind::Const(.., ct_rhs) = item.kind => (did, ct_rhs),
961-
Node::TraitItem(item) if let TraitItemKind::Const(_, Some(ct_rhs), _) = item.kind => (did, ct_rhs),
961+
Node::TraitItem(item) if let TraitItemKind::Const(_, Some(ct_rhs)) = item.kind => (did, ct_rhs),
962962
_ => return None,
963963
}
964964
},

clippy_lints/src/pub_underscore_fields.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use clippy_config::types::PubUnderscoreFieldsBehaviour;
33
use clippy_utils::attrs::is_doc_hidden;
44
use clippy_utils::diagnostics::span_lint_hir_and_then;
55
use clippy_utils::res::{MaybeDef, MaybeResPath};
6+
use clippy_utils::sym::PhantomPinned;
67
use rustc_hir::{FieldDef, Item, ItemKind, LangItem};
78
use rustc_lint::{LateContext, LateLintPass};
89
use rustc_session::impl_lint_pass;
@@ -75,8 +76,9 @@ impl<'tcx> LateLintPass<'tcx> for PubUnderscoreFields {
7576
if field.ident.as_str().starts_with('_') && is_visible(field)
7677
// We ignore fields that have `#[doc(hidden)]`.
7778
&& !is_doc_hidden(cx.tcx.hir_attrs(field.hir_id))
78-
// We ignore fields that are `PhantomData`.
79+
// We ignore fields that are `PhantomData` and `PhantomPinned`.
7980
&& !field.ty.basic_res().is_lang_item(cx, LangItem::PhantomData)
81+
&& !field.ty.basic_res().is_diag_item(cx, PhantomPinned)
8082
{
8183
span_lint_hir_and_then(
8284
cx,

clippy_lints/src/types/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ impl<'tcx> LateLintPass<'tcx> for Types {
514514
};
515515

516516
match item.kind {
517-
TraitItemKind::Const(ty, _, _) | TraitItemKind::Type(_, Some(ty)) => {
517+
TraitItemKind::Const(ty, _) | TraitItemKind::Type(_, Some(ty)) => {
518518
self.check_ty(cx, ty, context);
519519
},
520520
TraitItemKind::Fn(ref sig, trait_method) => {

0 commit comments

Comments
 (0)