Skip to content

Commit 7a82702

Browse files
committed
Auto merge of rust-lang#120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#119592 (resolve: Unload speculatively resolved crates before freezing cstore) - rust-lang#120103 (Make it so that async-fn-in-trait is compatible with a concrete future in implementation) - rust-lang#120206 (hir: Make sure all `HirId`s have corresponding HIR `Node`s) - rust-lang#120214 (match lowering: consistently lower bindings deepest-first) - rust-lang#120688 (GVN: also turn moves into copies with projections) - rust-lang#120702 (docs: also check the inline stmt during redundant link check) - rust-lang#120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered") - rust-lang#120734 (Add `SubdiagnosticMessageOp` as a trait alias.) - rust-lang#120739 (improve pretty printing for associated items in trait objects) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 96ff004 + b247f41 commit 7a82702

19 files changed

+32
-37
lines changed

clippy_lints/src/absolute_paths.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl LateLintPass<'_> for AbsolutePaths {
6262
} = self;
6363

6464
if !path.span.from_expansion()
65-
&& let Some(node) = cx.tcx.opt_hir_node(hir_id)
65+
&& let node = cx.tcx.hir_node(hir_id)
6666
&& !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _)))
6767
&& let [first, rest @ ..] = path.segments
6868
// Handle `::std`

clippy_lints/src/casts/cast_slice_different_sizes.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,8 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>, msrv: &Msrv
6868

6969
fn is_child_of_cast(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
7070
let map = cx.tcx.hir();
71-
if let Some(parent_id) = map.opt_parent_id(expr.hir_id)
72-
&& let Some(parent) = cx.tcx.opt_hir_node(parent_id)
73-
{
71+
if let Some(parent_id) = map.opt_parent_id(expr.hir_id) {
72+
let parent = cx.tcx.hir_node(parent_id);
7473
let expr = match parent {
7574
Node::Block(block) => {
7675
if let Some(parent_expr) = block.expr {

clippy_lints/src/casts/unnecessary_cast.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ pub(super) fn check<'tcx>(
144144

145145
if cast_from.kind() == cast_to.kind() && !in_external_macro(cx.sess(), expr.span) {
146146
if let Some(id) = path_to_local(cast_expr)
147-
&& let Some(span) = cx.tcx.hir().opt_span(id)
148-
&& !span.eq_ctxt(cast_expr.span)
147+
&& !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span)
149148
{
150149
// Binding context is different than the identifiers context.
151150
// Weird macro wizardry could be involved here.

clippy_lints/src/derivable_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for DerivableImpls {
195195
&& let Some(def_id) = trait_ref.trait_def_id()
196196
&& cx.tcx.is_diagnostic_item(sym::Default, def_id)
197197
&& let impl_item_hir = child.id.hir_id()
198-
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
198+
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
199199
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
200200
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
201201
&& let &Adt(adt_def, args) = cx.tcx.type_of(item.owner_id).instantiate_identity().kind()

clippy_lints/src/empty_drop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl LateLintPass<'_> for EmptyDrop {
4242
}) = item.kind
4343
&& trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait()
4444
&& let impl_item_hir = child.id.hir_id()
45-
&& let Some(Node::ImplItem(impl_item)) = cx.tcx.opt_hir_node(impl_item_hir)
45+
&& let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir)
4646
&& let ImplItemKind::Fn(_, b) = &impl_item.kind
4747
&& let Body { value: func_expr, .. } = cx.tcx.hir().body(*b)
4848
&& let func_expr = peel_blocks(func_expr)

clippy_lints/src/escape.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,11 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
123123

124124
// TODO: Replace with Map::is_argument(..) when it's fixed
125125
fn is_argument(tcx: TyCtxt<'_>, id: HirId) -> bool {
126-
match tcx.opt_hir_node(id) {
127-
Some(Node::Pat(Pat {
126+
match tcx.hir_node(id) {
127+
Node::Pat(Pat {
128128
kind: PatKind::Binding(..),
129129
..
130-
})) => (),
130+
}) => (),
131131
_ => return false,
132132
}
133133

clippy_lints/src/explicit_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn look_in_block<'tcx, 'hir>(cx: &LateContext<'tcx>, kind: &'tcx ExprKind<'hir>)
111111
// Find id of the local that expr_end_of_block resolves to
112112
&& let ExprKind::Path(QPath::Resolved(None, expr_path)) = expr_end_of_block.kind
113113
&& let Res::Local(expr_res) = expr_path.res
114-
&& let Some(Node::Pat(res_pat)) = cx.tcx.opt_hir_node(expr_res)
114+
&& let Node::Pat(res_pat) = cx.tcx.hir_node(expr_res)
115115

116116
// Find id of the local we found in the block
117117
&& let PatKind::Binding(BindingAnnotation::NONE, local_hir_id, _ident, None) = local.pat.kind

clippy_lints/src/index_refutable_slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ impl<'a, 'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'a, 'tcx> {
248248

249249
// Checking for slice indexing
250250
&& let parent_id = map.parent_id(expr.hir_id)
251-
&& let Some(hir::Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id)
251+
&& let hir::Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id)
252252
&& let hir::ExprKind::Index(_, index_expr, _) = parent_expr.kind
253253
&& let Some(Constant::Int(index_value)) = constant(cx, cx.typeck_results(), index_expr)
254254
&& let Ok(index_value) = index_value.try_into()
255255
&& index_value < max_suggested_slice
256256

257257
// Make sure that this slice index is read only
258258
&& let maybe_addrof_id = map.parent_id(parent_id)
259-
&& let Some(hir::Node::Expr(maybe_addrof_expr)) = cx.tcx.opt_hir_node(maybe_addrof_id)
259+
&& let hir::Node::Expr(maybe_addrof_expr) = cx.tcx.hir_node(maybe_addrof_id)
260260
&& let hir::ExprKind::AddrOf(_kind, hir::Mutability::Not, _inner_expr) = maybe_addrof_expr.kind
261261
{
262262
use_info.index_use.push((index_value, map.span(parent_expr.hir_id)));

clippy_lints/src/len_zero.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ impl<'tcx> LateLintPass<'tcx> for LenZero {
147147
&& let Some(output) =
148148
parse_len_output(cx, cx.tcx.fn_sig(item.owner_id).instantiate_identity().skip_binder())
149149
{
150-
let (name, kind) = match cx.tcx.opt_hir_node(ty_hir_id) {
151-
Some(Node::ForeignItem(x)) => (x.ident.name, "extern type"),
152-
Some(Node::Item(x)) => match x.kind {
150+
let (name, kind) = match cx.tcx.hir_node(ty_hir_id) {
151+
Node::ForeignItem(x) => (x.ident.name, "extern type"),
152+
Node::Item(x) => match x.kind {
153153
ItemKind::Struct(..) => (x.ident.name, "struct"),
154154
ItemKind::Enum(..) => (x.ident.name, "enum"),
155155
ItemKind::Union(..) => (x.ident.name, "union"),

clippy_lints/src/loops/same_item_push.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub(super) fn check<'tcx>(
6363
&& let PatKind::Binding(bind_ann, ..) = pat.kind
6464
&& !matches!(bind_ann, BindingAnnotation(_, Mutability::Mut))
6565
&& let parent_node = cx.tcx.hir().parent_id(hir_id)
66-
&& let Some(Node::Local(parent_let_expr)) = cx.tcx.opt_hir_node(parent_node)
66+
&& let Node::Local(parent_let_expr) = cx.tcx.hir_node(parent_node)
6767
&& let Some(init) = parent_let_expr.init
6868
{
6969
match init.kind {

clippy_lints/src/manual_rem_euclid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for ManualRemEuclid {
7676
// Also ensures the const is nonzero since zero can't be a divisor
7777
&& const1 == const2 && const2 == const3
7878
&& let Some(hir_id) = path_to_local(expr3)
79-
&& let Some(Node::Pat(_)) = cx.tcx.opt_hir_node(hir_id)
79+
&& let Node::Pat(_) = cx.tcx.hir_node(hir_id)
8080
{
8181
// Apply only to params or locals with annotated types
8282
match cx.tcx.hir().find_parent(hir_id) {

clippy_lints/src/methods/filter_next.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub(super) fn check<'tcx>(
4444
// add note if not multi-line
4545
span_lint_and_then(cx, FILTER_NEXT, expr.span, msg, |diag| {
4646
let (applicability, pat) = if let Some(id) = path_to_local(recv)
47-
&& let Some(hir::Node::Pat(pat)) = cx.tcx.opt_hir_node(id)
47+
&& let hir::Node::Pat(pat) = cx.tcx.hir_node(id)
4848
&& let hir::PatKind::Binding(BindingAnnotation(_, Mutability::Not), _, ident, _) = pat.kind
4949
{
5050
(Applicability::Unspecified, Some((pat.span, ident)))

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnwrapVisitor<'a, 'tcx> {
135135

136136
fn visit_path(&mut self, path: &Path<'tcx>, _: HirId) {
137137
if let Res::Local(local_id) = path.res
138-
&& let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id)
138+
&& let Node::Pat(pat) = self.cx.tcx.hir_node(local_id)
139139
&& let PatKind::Binding(_, local_id, ..) = pat.kind
140140
{
141141
self.identifiers.insert(local_id);
@@ -166,7 +166,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReferenceVisitor<'a, 'tcx> {
166166
&& let ExprKind::Path(ref path) = expr.kind
167167
&& let QPath::Resolved(_, path) = path
168168
&& let Res::Local(local_id) = path.res
169-
&& let Some(Node::Pat(pat)) = self.cx.tcx.opt_hir_node(local_id)
169+
&& let Node::Pat(pat) = self.cx.tcx.hir_node(local_id)
170170
&& let PatKind::Binding(_, local_id, ..) = pat.kind
171171
&& self.identifiers.contains(&local_id)
172172
{

clippy_lints/src/min_ident_chars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ impl Visitor<'_> for IdentVisitor<'_, '_> {
9191
let node = if hir_id.local_id == ItemLocalId::from_u32(0) {
9292
// In this case, we can just use `find`, `Owner`'s `node` field is private anyway so we can't
9393
// reimplement it even if we wanted to
94-
cx.tcx.opt_hir_node(hir_id)
94+
Some(cx.tcx.hir_node(hir_id))
9595
} else {
9696
let owner = cx.tcx.hir_owner_nodes(hir_id.owner);
97-
owner.nodes.get(hir_id.local_id).copied().flatten().map(|p| p.node)
97+
owner.nodes.get(hir_id.local_id).copied().map(|p| p.node)
9898
};
9999
let Some(node) = node else {
100100
return;

clippy_lints/src/mixed_read_write_in_expression.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,8 @@ fn check_for_unsequenced_reads(vis: &mut ReadVisitor<'_, '_>) {
213213
if parent_id == cur_id {
214214
break;
215215
}
216-
let Some(parent_node) = vis.cx.tcx.opt_hir_node(parent_id) else {
217-
break;
218-
};
219216

220-
let stop_early = match parent_node {
217+
let stop_early = match vis.cx.tcx.hir_node(parent_id) {
221218
Node::Expr(expr) => check_expr(vis, expr),
222219
Node::Stmt(stmt) => check_stmt(vis, stmt),
223220
Node::Item(_) => {

clippy_lints/src/non_copy_const.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst {
453453
if parent_id == cur_expr.hir_id {
454454
break;
455455
}
456-
if let Some(Node::Expr(parent_expr)) = cx.tcx.opt_hir_node(parent_id) {
456+
if let Node::Expr(parent_expr) = cx.tcx.hir_node(parent_id) {
457457
match &parent_expr.kind {
458458
ExprKind::AddrOf(..) => {
459459
// `&e` => `e` must be referenced.

clippy_lints/src/same_name_method.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod {
7676
match of_trait {
7777
Some(trait_ref) => {
7878
let mut methods_in_trait: BTreeSet<Symbol> =
79-
if let Some(Node::TraitRef(TraitRef { path, .. })) =
80-
cx.tcx.opt_hir_node(trait_ref.hir_ref_id)
79+
if let Node::TraitRef(TraitRef { path, .. }) =
80+
cx.tcx.hir_node(trait_ref.hir_ref_id)
8181
&& let Res::Def(DefKind::Trait, did) = path.res
8282
{
8383
// FIXME: if

clippy_lints/src/self_named_constructors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'tcx> LateLintPass<'tcx> for SelfNamedConstructors {
7373
if let Some(self_def) = self_ty.ty_adt_def()
7474
&& let Some(self_local_did) = self_def.did().as_local()
7575
&& let self_id = cx.tcx.local_def_id_to_hir_id(self_local_did)
76-
&& let Some(Node::Item(x)) = cx.tcx.opt_hir_node(self_id)
76+
&& let Node::Item(x) = cx.tcx.hir_node(self_id)
7777
&& let type_name = x.ident.name.as_str().to_lowercase()
7878
&& (impl_item.ident.name.as_str() == type_name
7979
|| impl_item.ident.name.as_str().replace('_', "") == type_name)

clippy_utils/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ pub fn expr_or_init<'a, 'b, 'tcx: 'b>(cx: &LateContext<'tcx>, mut expr: &'a Expr
177177
/// canonical binding `HirId`.
178178
pub fn find_binding_init<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Option<&'tcx Expr<'tcx>> {
179179
let hir = cx.tcx.hir();
180-
if let Some(Node::Pat(pat)) = cx.tcx.opt_hir_node(hir_id)
180+
if let Node::Pat(pat) = cx.tcx.hir_node(hir_id)
181181
&& matches!(pat.kind, PatKind::Binding(BindingAnnotation::NONE, ..))
182182
&& let parent = hir.parent_id(hir_id)
183-
&& let Some(Node::Local(local)) = cx.tcx.opt_hir_node(parent)
183+
&& let Node::Local(local) = cx.tcx.hir_node(parent)
184184
{
185185
return local.init;
186186
}
@@ -1327,7 +1327,7 @@ pub fn get_enclosing_block<'tcx>(cx: &LateContext<'tcx>, hir_id: HirId) -> Optio
13271327
let map = &cx.tcx.hir();
13281328
let enclosing_node = map
13291329
.get_enclosing_scope(hir_id)
1330-
.and_then(|enclosing_id| cx.tcx.opt_hir_node(enclosing_id));
1330+
.map(|enclosing_id| cx.tcx.hir_node(enclosing_id));
13311331
enclosing_node.and_then(|node| match node {
13321332
Node::Block(block) => Some(block),
13331333
Node::Item(&Item {
@@ -2696,10 +2696,10 @@ impl<'tcx> ExprUseNode<'tcx> {
26962696
)),
26972697
Self::Return(id) => {
26982698
let hir_id = cx.tcx.local_def_id_to_hir_id(id.def_id);
2699-
if let Some(Node::Expr(Expr {
2699+
if let Node::Expr(Expr {
27002700
kind: ExprKind::Closure(c),
27012701
..
2702-
})) = cx.tcx.opt_hir_node(hir_id)
2702+
}) = cx.tcx.hir_node(hir_id)
27032703
{
27042704
match c.fn_decl.output {
27052705
FnRetTy::DefaultReturn(_) => None,

0 commit comments

Comments
 (0)