Skip to content

Commit 10a152b

Browse files
authored
Merge pull request rust-lang#2479 from rust-lang/rustc-pull
Rustc pull update
2 parents 71f40ce + b2540da commit 10a152b

24 files changed

+161
-110
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5858
[features]
5959
integration = ["dep:tempfile"]
6060
internal = ["dep:clippy_lints_internal", "dep:tempfile"]
61+
jemalloc = []
6162

6263
[package.metadata.rust-analyzer]
6364
# This package uses #[feature(rustc_private)]

clippy_dev/src/update_lints.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::utils::{
22
ErrAction, File, FileUpdater, RustSearcher, Token, UpdateMode, UpdateStatus, expect_action, update_text_region_fn,
33
};
44
use itertools::Itertools;
5+
use rustc_lexer::{LiteralKind, TokenKind, tokenize};
56
use std::collections::HashSet;
67
use std::fmt::Write;
78
use std::ops::Range;
@@ -342,7 +343,7 @@ fn parse_str_lit(s: &str) -> String {
342343
.and_then(|s| s.strip_suffix('"'))
343344
.unwrap_or_else(|| panic!("expected quoted string, found `{s}`"));
344345
let mut res = String::with_capacity(s.len());
345-
rustc_literal_escaper::unescape_unicode(s, mode, &mut |_, ch| {
346+
rustc_literal_escaper::unescape_str(s, |range, ch| {
346347
if let Ok(ch) = ch {
347348
res.push(ch);
348349
}

clippy_lints/src/bool_assert_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
5656
.and_then(|trait_id| {
5757
cx.tcx.associated_items(trait_id).find_by_ident_and_kind(
5858
cx.tcx,
59-
Ident::from_str("Output"),
59+
Ident::with_dummy_span(sym::Output),
6060
ty::AssocTag::Type,
6161
trait_id,
6262
)

clippy_lints/src/casts/manual_dangling_ptr.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::SpanRangeExt;
3-
use clippy_utils::{expr_or_init, path_def_id, paths, std_or_core};
3+
use clippy_utils::{expr_or_init, is_path_diagnostic_item, std_or_core, sym};
44
use rustc_ast::LitKind;
55
use rustc_errors::Applicability;
66
use rustc_hir::{Expr, ExprKind, GenericArg, Mutability, QPath, Ty, TyKind};
@@ -53,8 +53,7 @@ fn is_expr_const_aligned(cx: &LateContext<'_>, expr: &Expr<'_>, to: &Ty<'_>) ->
5353

5454
fn is_align_of_call(cx: &LateContext<'_>, fun: &Expr<'_>, to: &Ty<'_>) -> bool {
5555
if let ExprKind::Path(QPath::Resolved(_, path)) = fun.kind
56-
&& let Some(fun_id) = path_def_id(cx, fun)
57-
&& paths::ALIGN_OF.matches(cx, fun_id)
56+
&& is_path_diagnostic_item(cx, fun, sym::mem_align_of)
5857
&& let Some(args) = path.segments.last().and_then(|seg| seg.args)
5958
&& let [GenericArg::Type(generic_ty)] = args.args
6059
{

clippy_lints/src/doc/doc_suspicious_footnotes.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2+
use rustc_ast::attr::AttributeExt as _;
23
use rustc_ast::token::CommentKind;
34
use rustc_errors::Applicability;
45
use rustc_hir::{AttrStyle, Attribute};
@@ -43,13 +44,19 @@ pub fn check(cx: &LateContext<'_>, doc: &str, range: Range<usize>, fragments: &F
4344
"looks like a footnote ref, but has no matching footnote",
4445
|diag| {
4546
if this_fragment.kind == DocFragmentKind::SugaredDoc {
46-
let (doc_attr, (_, doc_attr_comment_kind)) = attrs
47+
let (doc_attr, (_, doc_attr_comment_kind), attr_style) = attrs
4748
.iter()
4849
.filter(|attr| attr.span().overlaps(this_fragment.span))
4950
.rev()
50-
.find_map(|attr| Some((attr, attr.doc_str_and_comment_kind()?)))
51+
.find_map(|attr| {
52+
Some((
53+
attr,
54+
attr.doc_str_and_comment_kind()?,
55+
attr.doc_resolution_scope()?,
56+
))
57+
})
5158
.unwrap();
52-
let (to_add, terminator) = match (doc_attr_comment_kind, doc_attr.style()) {
59+
let (to_add, terminator) = match (doc_attr_comment_kind, attr_style) {
5360
(CommentKind::Line, AttrStyle::Outer) => ("\n///\n/// ", ""),
5461
(CommentKind::Line, AttrStyle::Inner) => ("\n//!\n//! ", ""),
5562
(CommentKind::Block, AttrStyle::Outer) => ("\n/** ", " */"),

clippy_lints/src/doc/needless_doctest_main.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ pub fn check(
4242
let mut test_attr_spans = vec![];
4343
let filename = FileName::anon_source_code(&code);
4444

45-
let fallback_bundle =
46-
rustc_errors::fallback_fluent_bundle(rustc_driver::DEFAULT_LOCALE_RESOURCES.to_vec(), false);
47-
let emitter = HumanEmitter::new(Box::new(io::sink()), fallback_bundle);
45+
let translator = rustc_driver::default_translator();
46+
let emitter = HumanEmitter::new(Box::new(io::sink()), translator);
4847
let dcx = DiagCtxt::new(Box::new(emitter)).disable_warnings();
4948
#[expect(clippy::arc_with_non_send_sync)] // `Arc` is expected by with_dcx
5049
let sm = Arc::new(SourceMap::new(FilePathMapping::empty()));

clippy_lints/src/eta_reduction.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use clippy_utils::{
77
get_path_from_caller_to_method_type, is_adjusted, is_no_std_crate, path_to_local, path_to_local_id,
88
};
99
use rustc_abi::ExternAbi;
10+
use rustc_attr_data_structures::{AttributeKind, find_attr};
1011
use rustc_errors::Applicability;
1112
use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind};
1213
use rustc_infer::infer::TyCtxtInferExt;
@@ -155,7 +156,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
155156
let sig = match callee_ty_adjusted.kind() {
156157
ty::FnDef(def, _) => {
157158
// Rewriting `x(|| f())` to `x(f)` where f is marked `#[track_caller]` moves the `Location`
158-
if cx.tcx.has_attr(*def, sym::track_caller) {
159+
if find_attr!(cx.tcx.get_all_attrs(*def), AttributeKind::TrackCaller(..)) {
159160
return;
160161
}
161162

@@ -236,7 +237,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
236237
},
237238
ExprKind::MethodCall(path, self_, args, _) if check_inputs(typeck, body.params, Some(self_), args) => {
238239
if let Some(method_def_id) = typeck.type_dependent_def_id(body.value.hir_id)
239-
&& !cx.tcx.has_attr(method_def_id, sym::track_caller)
240+
&& !find_attr!(cx.tcx.get_all_attrs(method_def_id), AttributeKind::TrackCaller(..))
240241
&& check_sig(closure_sig, cx.tcx.fn_sig(method_def_id).skip_binder().skip_binder())
241242
{
242243
let mut app = Applicability::MachineApplicable;

clippy_lints/src/functions/must_use.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ use clippy_utils::ty::is_must_use_ty;
1515
use clippy_utils::visitors::for_each_expr_without_closures;
1616
use clippy_utils::{return_ty, trait_ref_of_method};
1717
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
18+
use rustc_span::Symbol;
19+
use rustc_attr_data_structures::{AttributeKind, find_attr};
1820

1921
use core::ops::ControlFlow;
2022

2123
use super::{DOUBLE_MUST_USE, MUST_USE_CANDIDATE, MUST_USE_UNIT};
2224

2325
pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>) {
2426
let attrs = cx.tcx.hir_attrs(item.hir_id());
25-
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
27+
let attr = find_attr!(cx.tcx.hir_attrs(item.hir_id()), AttributeKind::MustUse { span, reason } => (span, reason));
2628
if let hir::ItemKind::Fn {
2729
ref sig,
2830
body: ref body_id,
@@ -31,9 +33,9 @@ pub(super) fn check_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Item<'_>
3133
{
3234
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
3335
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
34-
if let Some(attr) = attr {
35-
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
36-
} else if is_public && !is_proc_macro(attrs) && !attrs.iter().any(|a| a.has_name(sym::no_mangle)) {
36+
if let Some((attr_span, reason)) = attr {
37+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, *attr_span, *reason, attrs, sig);
38+
} else if is_public && !is_proc_macro(attrs) && !find_attr!(attrs, AttributeKind::NoMangle(..)) {
3739
check_must_use_candidate(
3840
cx,
3941
sig.decl,
@@ -52,9 +54,9 @@ pub(super) fn check_impl_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Imp
5254
let is_public = cx.effective_visibilities.is_exported(item.owner_id.def_id);
5355
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
5456
let attrs = cx.tcx.hir_attrs(item.hir_id());
55-
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
56-
if let Some(attr) = attr {
57-
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
57+
let attr = find_attr!(cx.tcx.hir_attrs(item.hir_id()), AttributeKind::MustUse { span, reason } => (span, reason));
58+
if let Some((attr_span, reason)) = attr {
59+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, *attr_span, *reason, attrs, sig);
5860
} else if is_public && !is_proc_macro(attrs) && trait_ref_of_method(cx, item.owner_id).is_none() {
5961
check_must_use_candidate(
6062
cx,
@@ -75,9 +77,9 @@ pub(super) fn check_trait_item<'tcx>(cx: &LateContext<'tcx>, item: &'tcx hir::Tr
7577
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
7678

7779
let attrs = cx.tcx.hir_attrs(item.hir_id());
78-
let attr = cx.tcx.get_attr(item.owner_id, sym::must_use);
79-
if let Some(attr) = attr {
80-
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, attr, attrs, sig);
80+
let attr = find_attr!(cx.tcx.hir_attrs(item.hir_id()), AttributeKind::MustUse { span, reason } => (span, reason));
81+
if let Some((attr_span, reason)) = attr {
82+
check_needless_must_use(cx, sig.decl, item.owner_id, item.span, fn_header_span, *attr_span, *reason, attrs, sig);
8183
} else if let hir::TraitFn::Provided(eid) = *eid {
8284
let body = cx.tcx.hir_body(eid);
8385
if attr.is_none() && is_public && !is_proc_macro(attrs) {
@@ -103,7 +105,8 @@ fn check_needless_must_use(
103105
item_id: hir::OwnerId,
104106
item_span: Span,
105107
fn_header_span: Span,
106-
attr: &Attribute,
108+
attr_span: Span,
109+
reason: Option<Symbol>,
107110
attrs: &[Attribute],
108111
sig: &FnSig<'_>,
109112
) {
@@ -119,7 +122,7 @@ fn check_needless_must_use(
119122
"this unit-returning function has a `#[must_use]` attribute",
120123
|diag| {
121124
diag.span_suggestion(
122-
attr.span(),
125+
attr_span,
123126
"remove the attribute",
124127
"",
125128
Applicability::MachineApplicable,
@@ -137,11 +140,11 @@ fn check_needless_must_use(
137140
MUST_USE_UNIT,
138141
fn_header_span,
139142
"this unit-returning function has a `#[must_use]` attribute",
140-
Some(attr.span()),
143+
Some(attr_span),
141144
"remove `must_use`",
142145
);
143146
}
144-
} else if attr.value_str().is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) {
147+
} else if reason.is_none() && is_must_use_ty(cx, return_ty(cx, item_id)) {
145148
// Ignore async functions unless Future::Output type is a must_use type
146149
if sig.header.is_async() {
147150
let infcx = cx.tcx.infer_ctxt().build(cx.typing_mode());

clippy_lints/src/manual_option_as_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_config::Conf;
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
33
use clippy_utils::msrvs::Msrv;
4-
use clippy_utils::{is_none_arm, msrvs, paths, peel_hir_expr_refs, sym};
4+
use clippy_utils::{is_none_arm, msrvs, peel_hir_expr_refs, sym};
55
use rustc_errors::Applicability;
66
use rustc_hir::def::{DefKind, Res};
77
use rustc_hir::{Arm, Expr, ExprKind, LangItem, Pat, PatKind, QPath, is_range_literal};
@@ -220,5 +220,5 @@ fn is_empty_slice(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
220220
}
221221

222222
fn is_slice_from_ref(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
223-
paths::SLICE_FROM_REF.matches_path(cx, expr)
223+
clippy_utils::is_path_diagnostic_item(cx, expr, sym::slice_from_ref)
224224
}

clippy_lints/src/methods/io_other_error.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::msrvs::{self, Msrv};
3-
use clippy_utils::{expr_or_init, paths};
3+
use clippy_utils::{expr_or_init, is_path_diagnostic_item, sym};
44
use rustc_errors::Applicability;
55
use rustc_hir::{Expr, ExprKind, QPath};
66
use rustc_lint::LateContext;
@@ -10,8 +10,11 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, path: &Expr<'_>, args
1010
&& !expr.span.from_expansion()
1111
&& !error_kind.span.from_expansion()
1212
&& let ExprKind::Path(QPath::TypeRelative(_, new_segment)) = path.kind
13-
&& paths::IO_ERROR_NEW.matches_path(cx, path)
14-
&& paths::IO_ERRORKIND_OTHER_CTOR.matches_path(cx, expr_or_init(cx, error_kind))
13+
&& is_path_diagnostic_item(cx, path, sym::io_error_new)
14+
&& let ExprKind::Path(QPath::Resolved(_, init_path)) = &expr_or_init(cx, error_kind).kind
15+
&& let [.., error_kind_ty, error_kind_variant] = init_path.segments
16+
&& cx.tcx.is_diagnostic_item(sym::io_errorkind, error_kind_ty.res.def_id())
17+
&& error_kind_variant.ident.name == sym::Other
1518
&& msrv.meets(cx, msrvs::IO_ERROR_OTHER)
1619
{
1720
span_lint_and_then(

0 commit comments

Comments
 (0)