authorbors <bors@rust-lang.org> 2026-01-31 16:24:16 UTC
committerbors <bors@rust-lang.org> 2026-01-31 16:24:16 UTC
log8afe9ff1caa97654c31fb8c259dac9fdf67d6302
tree68b5999685a4b0c604926c84aa7a5f467b8ed8bc
parent78865ca937ef3b77b214473db78b51ec82e2277a
parent874c5d2275481b519ad2621c52546843b7366adf

Auto merge of #151911 - JonathanBrouwer:rollup-ACi3J2a, r=JonathanBrouwer

Rollup of 3 pull requests Successful merges: - rust-lang/rust#151908 (Remove unused method `DroplessArena::contains_slice`) - rust-lang/rust#151850 (refactor: add an `enum DerefAdjustKind` in favor of `Option<OverloadedDeref>`) - rust-lang/rust#151889 (Fix ICE when parsing frontmatter without newline)

26 files changed, 110 insertions(+), 86 deletions(-)

compiler/rustc_arena/src/lib.rs-13
......@@ -510,19 +510,6 @@ impl DroplessArena {
510510 }
511511 }
512512
513 /// Used by `Lift` to check whether this slice is allocated
514 /// in this arena.
515 #[inline]
516 pub fn contains_slice<T>(&self, slice: &[T]) -> bool {
517 for chunk in self.chunks.borrow_mut().iter_mut() {
518 let ptr = slice.as_ptr().cast::<u8>().cast_mut();
519 if chunk.start() <= ptr && chunk.end() >= ptr {
520 return true;
521 }
522 }
523 false
524 }
525
526513 /// Allocates a string slice that is copied into the `DroplessArena`, returning a
527514 /// reference to it. Will panic if passed an empty string.
528515 ///
compiler/rustc_hir_typeck/src/autoderef.rs+12-10
......@@ -6,7 +6,7 @@ use itertools::Itertools;
66use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind};
77use rustc_infer::infer::InferOk;
88use rustc_infer::traits::PredicateObligations;
9use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
9use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind, OverloadedDeref};
1010use rustc_middle::ty::{self, Ty};
1111use rustc_span::Span;
1212
......@@ -45,22 +45,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4545 steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty()));
4646 let steps: Vec<_> = steps
4747 .iter()
48 .map(|&(source, kind)| {
49 if let AutoderefKind::Overloaded = kind {
50 self.try_overloaded_deref(autoderef.span(), source).and_then(
51 |InferOk { value: method, obligations: o }| {
48 .map(|&(source, kind)| match kind {
49 AutoderefKind::Overloaded => {
50 self.try_overloaded_deref(autoderef.span(), source)
51 .and_then(|InferOk { value: method, obligations: o }| {
5252 obligations.extend(o);
5353 // FIXME: we should assert the sig is &T here... there's no reason for this to be fallible.
5454 if let ty::Ref(_, _, mutbl) = *method.sig.output().kind() {
55 Some(OverloadedDeref { mutbl, span: autoderef.span() })
55 Some(DerefAdjustKind::Overloaded(OverloadedDeref {
56 mutbl,
57 span: autoderef.span(),
58 }))
5659 } else {
5760 None
5861 }
59 },
60 )
61 } else {
62 None
62 })
63 .unwrap_or(DerefAdjustKind::Builtin)
6364 }
65 AutoderefKind::Builtin => DerefAdjustKind::Builtin,
6466 })
6567 .zip_eq(targets)
6668 .map(|(autoderef, target)| Adjustment { kind: Adjust::Deref(autoderef), target })
compiler/rustc_hir_typeck/src/coercion.rs+5-4
......@@ -50,7 +50,8 @@ use rustc_infer::traits::{
5050};
5151use rustc_middle::span_bug;
5252use rustc_middle::ty::adjustment::{
53 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
53 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
54 PointerCoercion,
5455};
5556use rustc_middle::ty::error::TypeError;
5657use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
......@@ -595,7 +596,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
595596 let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
596597
597598 Some((
598 Adjustment { kind: Adjust::Deref(None), target: ty_a },
599 Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
599600 Adjustment {
600601 kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
601602 target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
......@@ -606,7 +607,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
606607 coerce_mutbls(mt_a, mt_b)?;
607608
608609 Some((
609 Adjustment { kind: Adjust::Deref(None), target: ty_a },
610 Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
610611 Adjustment {
611612 kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
612613 target: Ty::new_ptr(self.tcx, ty_a, mt_b),
......@@ -936,7 +937,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
936937 self.unify_and(
937938 a_raw,
938939 b,
939 [Adjustment { kind: Adjust::Deref(None), target: mt_a.ty }],
940 [Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: mt_a.ty }],
940941 Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)),
941942 ForceLeakCheck::No,
942943 )
compiler/rustc_hir_typeck/src/expr_use_visitor.rs+5-4
......@@ -22,6 +22,7 @@ use rustc_middle::hir::place::ProjectionKind;
2222pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection};
2323use rustc_middle::mir::FakeReadCause;
2424use rustc_middle::thir::DerefPatBorrowMode;
25use rustc_middle::ty::adjustment::DerefAdjustKind;
2526use rustc_middle::ty::{
2627 self, BorrowKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt as _, adjustment,
2728};
......@@ -733,14 +734,14 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
733734 self.consume_or_copy(&place_with_id, place_with_id.hir_id);
734735 }
735736
736 adjustment::Adjust::Deref(None) => {}
737 adjustment::Adjust::Deref(DerefAdjustKind::Builtin) => {}
737738
738739 // Autoderefs for overloaded Deref calls in fact reference
739740 // their receiver. That is, if we have `(*x)` where `x`
740741 // is of type `Rc<T>`, then this in fact is equivalent to
741742 // `x.deref()`. Since `deref()` is declared with `&self`,
742743 // this is an autoref of `x`.
743 adjustment::Adjust::Deref(Some(ref deref)) => {
744 adjustment::Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
744745 let bk = ty::BorrowKind::from_mutbl(deref.mutbl);
745746 self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk);
746747 }
......@@ -1272,9 +1273,9 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
12721273 {
12731274 let target = self.cx.resolve_vars_if_possible(adjustment.target);
12741275 match adjustment.kind {
1275 adjustment::Adjust::Deref(overloaded) => {
1276 adjustment::Adjust::Deref(deref_kind) => {
12761277 // Equivalent to *expr or something similar.
1277 let base = if let Some(deref) = overloaded {
1278 let base = if let DerefAdjustKind::Overloaded(deref) = deref_kind {
12781279 let ref_ty = Ty::new_ref(
12791280 self.cx.tcx(),
12801281 self.cx.tcx().lifetimes.re_erased,
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+5-3
......@@ -20,7 +20,9 @@ use rustc_hir_analysis::hir_ty_lowering::{
2020use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
2121use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
2222use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
23use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
23use rustc_middle::ty::adjustment::{
24 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
25};
2426use rustc_middle::ty::{
2527 self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity,
2628 SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs,
......@@ -266,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
266268 debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target);
267269 }
268270 }
269 Adjust::Deref(Some(overloaded_deref)) => {
271 Adjust::Deref(DerefAdjustKind::Overloaded(overloaded_deref)) => {
270272 self.enforce_context_effects(
271273 None,
272274 expr.span,
......@@ -274,7 +276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
274276 self.tcx.mk_args(&[expr_ty.into()]),
275277 );
276278 }
277 Adjust::Deref(None) => {
279 Adjust::Deref(DerefAdjustKind::Builtin) => {
278280 // FIXME(const_trait_impl): We *could* enforce `&T: [const] Deref` here.
279281 }
280282 Adjust::Pointer(_pointer_coercion) => {
compiler/rustc_hir_typeck/src/place_op.rs+4-3
......@@ -4,8 +4,8 @@ use rustc_infer::infer::InferOk;
44use rustc_infer::traits::{Obligation, ObligationCauseCode};
55use rustc_middle::span_bug;
66use rustc_middle::ty::adjustment::{
7 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, OverloadedDeref,
8 PointerCoercion,
7 Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind,
8 OverloadedDeref, PointerCoercion,
99};
1010use rustc_middle::ty::{self, Ty};
1111use rustc_span::{Span, sym};
......@@ -298,7 +298,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
298298 self.typeck_results.borrow_mut().adjustments_mut().remove(expr.hir_id);
299299 if let Some(mut adjustments) = previous_adjustments {
300300 for adjustment in &mut adjustments {
301 if let Adjust::Deref(Some(ref mut deref)) = adjustment.kind
301 if let Adjust::Deref(DerefAdjustKind::Overloaded(ref mut deref)) =
302 adjustment.kind
302303 && let Some(ok) = self.try_mutable_overloaded_place_op(
303304 expr.span,
304305 source,
compiler/rustc_lint/src/autorefs.rs+7-3
......@@ -1,7 +1,9 @@
11use rustc_ast::{BorrowKind, UnOp};
22use rustc_hir::attrs::AttributeKind;
33use rustc_hir::{Expr, ExprKind, Mutability, find_attr};
4use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, OverloadedDeref};
4use rustc_middle::ty::adjustment::{
5 Adjust, Adjustment, AutoBorrow, DerefAdjustKind, OverloadedDeref,
6};
57use rustc_session::{declare_lint, declare_lint_pass};
68
79use crate::lints::{
......@@ -165,12 +167,14 @@ fn peel_derefs_adjustments<'a>(mut adjs: &'a [Adjustment<'a>]) -> &'a [Adjustmen
165167/// an implicit borrow (or has an implicit borrow via an overloaded deref).
166168fn has_implicit_borrow(Adjustment { kind, .. }: &Adjustment<'_>) -> Option<(Mutability, bool)> {
167169 match kind {
168 &Adjust::Deref(Some(OverloadedDeref { mutbl, .. })) => Some((mutbl, true)),
170 &Adjust::Deref(DerefAdjustKind::Overloaded(OverloadedDeref { mutbl, .. })) => {
171 Some((mutbl, true))
172 }
169173 &Adjust::Borrow(AutoBorrow::Ref(mutbl)) => Some((mutbl.into(), false)),
170174 Adjust::NeverToAny
171175 | Adjust::Pointer(..)
172176 | Adjust::ReborrowPin(..)
173 | Adjust::Deref(None)
177 | Adjust::Deref(DerefAdjustKind::Builtin)
174178 | Adjust::Borrow(AutoBorrow::RawPtr(..)) => None,
175179 }
176180}
compiler/rustc_lint/src/noop_method_call.rs+5-2
......@@ -1,7 +1,7 @@
11use rustc_hir::def::DefKind;
22use rustc_hir::{Expr, ExprKind};
33use rustc_middle::ty;
4use rustc_middle::ty::adjustment::Adjust;
4use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
55use rustc_session::{declare_lint, declare_lint_pass};
66use rustc_span::sym;
77
......@@ -114,7 +114,10 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
114114
115115 // If there is any user defined auto-deref step, then we don't want to warn.
116116 // https://github.com/rust-lang/rust-clippy/issues/9272
117 if arg_adjustments.iter().any(|adj| matches!(adj.kind, Adjust::Deref(Some(_)))) {
117 if arg_adjustments
118 .iter()
119 .any(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Overloaded(_))))
120 {
118121 return;
119122 }
120123
compiler/rustc_middle/src/ty/adjustment.rs+7-1
......@@ -97,7 +97,7 @@ pub enum Adjust {
9797 NeverToAny,
9898
9999 /// Dereference once, producing a place.
100 Deref(Option<OverloadedDeref>),
100 Deref(DerefAdjustKind),
101101
102102 /// Take the address and produce either a `&` or `*` pointer.
103103 Borrow(AutoBorrow),
......@@ -108,6 +108,12 @@ pub enum Adjust {
108108 ReborrowPin(hir::Mutability),
109109}
110110
111#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
112pub enum DerefAdjustKind {
113 Builtin,
114 Overloaded(OverloadedDeref),
115}
116
111117/// An overloaded autoderef step, representing a `Deref(Mut)::deref(_mut)`
112118/// call, with the signature `&'a T -> &'a U` or `&'a mut T -> &'a mut U`.
113119/// The target type is `U` in both cases, with the region and mutability
compiler/rustc_mir_build/src/thir/cx/expr.rs+3-3
......@@ -14,7 +14,7 @@ use rustc_middle::middle::region;
1414use rustc_middle::mir::{self, AssignOp, BinOp, BorrowKind, UnOp};
1515use rustc_middle::thir::*;
1616use rustc_middle::ty::adjustment::{
17 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCoercion,
17 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, PointerCoercion,
1818};
1919use rustc_middle::ty::{
2020 self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs,
......@@ -140,11 +140,11 @@ impl<'tcx> ThirBuildCx<'tcx> {
140140 }
141141 Adjust::NeverToAny if adjustment.target.is_never() => return expr,
142142 Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
143 Adjust::Deref(None) => {
143 Adjust::Deref(DerefAdjustKind::Builtin) => {
144144 adjust_span(&mut expr);
145145 ExprKind::Deref { arg: self.thir.exprs.push(expr) }
146146 }
147 Adjust::Deref(Some(deref)) => {
147 Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
148148 // We don't need to do call adjust_span here since
149149 // deref coercions always start with a built-in deref.
150150 let call_def_id = deref.method_call(self.tcx);
compiler/rustc_parse/src/lexer/mod.rs+1-1
......@@ -623,7 +623,7 @@ impl<'psess, 'src> Lexer<'psess, 'src> {
623623 self.dcx().emit_err(errors::FrontmatterInvalidInfostring { span });
624624 }
625625
626 let last_line_start = real_s.rfind('\n').map_or(0, |i| i + 1);
626 let last_line_start = real_s.rfind('\n').map_or(line_end, |i| i + 1);
627627
628628 let content = &real_s[line_end..last_line_start];
629629 if let Some(cr_offset) = content.find('\r') {
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+2-2
......@@ -12,7 +12,7 @@ use rustc_hir::{
1212};
1313use rustc_middle::bug;
1414use rustc_middle::hir::nested_filter;
15use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
15use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind};
1616use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer};
1717use rustc_middle::ty::{
1818 self, GenericArg, GenericArgKind, GenericArgsRef, InferConst, IsSuggestable, Term, TermKind,
......@@ -615,7 +615,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
615615 // first adjustment was not a builtin deref.
616616 let adjustment = match typeck_results.expr_adjustments(receiver) {
617617 [
618 Adjustment { kind: Adjust::Deref(None), target: _ },
618 Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: _ },
619619 ..,
620620 Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ },
621621 ] => "",
src/tools/clippy/clippy_lints/src/eta_reduction.rs+2-2
......@@ -10,7 +10,7 @@ use rustc_hir::attrs::AttributeKind;
1010use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind, find_attr};
1111use rustc_infer::infer::TyCtxtInferExt;
1212use rustc_lint::{LateContext, LateLintPass};
13use rustc_middle::ty::adjustment::Adjust;
13use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
1414use rustc_middle::ty::{
1515 self, Binder, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, Ty, TypeVisitableExt, TypeckResults,
1616};
......@@ -236,7 +236,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx
236236 .iter()
237237 .rev()
238238 .fold(0, |acc, adjustment| match adjustment.kind {
239 Adjust::Deref(Some(_)) => acc + 1,
239 Adjust::Deref(DerefAdjustKind::Overloaded(_)) => acc + 1,
240240 Adjust::Deref(_) if acc > 0 => acc + 1,
241241 _ => acc,
242242 })
src/tools/clippy/clippy_lints/src/format_args.rs+3-3
......@@ -24,7 +24,7 @@ use rustc_errors::SuggestionStyle::{CompletelyHidden, ShowCode};
2424use rustc_hir::attrs::AttributeKind;
2525use rustc_hir::{Expr, ExprKind, LangItem, RustcVersion, find_attr};
2626use rustc_lint::{LateContext, LateLintPass, LintContext};
27use rustc_middle::ty::adjustment::{Adjust, Adjustment};
27use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
2828use rustc_middle::ty::{self, GenericArg, List, TraitRef, Ty, TyCtxt, Upcast};
2929use rustc_session::impl_lint_pass;
3030use rustc_span::edition::Edition::Edition2021;
......@@ -704,12 +704,12 @@ where
704704 let mut n_needed = 0;
705705 loop {
706706 if let Some(Adjustment {
707 kind: Adjust::Deref(overloaded_deref),
707 kind: Adjust::Deref(deref),
708708 target,
709709 }) = iter.next()
710710 {
711711 n_total += 1;
712 if overloaded_deref.is_some() {
712 if let DerefAdjustKind::Overloaded(..) = deref {
713713 n_needed = n_total;
714714 }
715715 ty = *target;
src/tools/clippy/clippy_lints/src/loops/while_let_on_iterator.rs+2-2
......@@ -12,7 +12,7 @@ use rustc_hir::intravisit::{Visitor, walk_expr};
1212use rustc_hir::{Closure, Expr, ExprKind, HirId, LetStmt, Mutability, UnOp};
1313use rustc_lint::LateContext;
1414use rustc_middle::hir::nested_filter::OnlyBodies;
15use rustc_middle::ty::adjustment::Adjust;
15use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
1616use rustc_span::Symbol;
1717use rustc_span::symbol::sym;
1818
......@@ -88,7 +88,7 @@ fn try_parse_iter_expr(cx: &LateContext<'_>, mut e: &Expr<'_>) -> Option<IterExp
8888 .typeck_results()
8989 .expr_adjustments(e)
9090 .iter()
91 .any(|a| matches!(a.kind, Adjust::Deref(Some(..))))
91 .any(|a| matches!(a.kind, Adjust::Deref(DerefAdjustKind::Overloaded(..))))
9292 {
9393 // Custom deref impls need to borrow the whole value as it's captured by reference
9494 can_move = false;
src/tools/clippy/clippy_lints/src/methods/map_clone.rs+2-2
......@@ -10,7 +10,7 @@ use rustc_hir::{self as hir, LangItem};
1010use rustc_lint::LateContext;
1111use rustc_middle::mir::{Mutability, Pinnedness};
1212use rustc_middle::ty;
13use rustc_middle::ty::adjustment::Adjust;
13use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
1414use rustc_span::symbol::Ident;
1515use rustc_span::{Span, sym};
1616
......@@ -73,7 +73,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
7373 && cx.tcx.lang_items().clone_trait() == Some(trait_id)
7474 // no autoderefs
7575 && !cx.typeck_results().expr_adjustments(obj).iter()
76 .any(|a| matches!(a.kind, Adjust::Deref(Some(..))))
76 .any(|a| matches!(a.kind, Adjust::Deref(DerefAdjustKind::Overloaded(..))))
7777 {
7878 let obj_ty = cx.typeck_results().expr_ty(obj);
7979 if let ty::Ref(_, ty, mutability) = obj_ty.kind() {
src/tools/clippy/clippy_lints/src/methods/option_as_ref_deref.rs+1-1
......@@ -58,7 +58,7 @@ pub(super) fn check(
5858 .iter()
5959 .map(|x| &x.kind)
6060 .collect::<Box<[_]>>()
61 && let [ty::adjustment::Adjust::Deref(None), ty::adjustment::Adjust::Borrow(_)] = *adj
61 && let [ty::adjustment::Adjust::Deref(ty::adjustment::DerefAdjustKind::Builtin), ty::adjustment::Adjust::Borrow(_)] = *adj
6262 && let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap()
6363 && let Some(method_name) = cx.tcx.get_diagnostic_name(method_did)
6464 {
src/tools/clippy/clippy_lints/src/methods/swap_with_temporary.rs+2-2
......@@ -4,7 +4,7 @@ use rustc_ast::BorrowKind;
44use rustc_errors::{Applicability, Diag};
55use rustc_hir::{Expr, ExprKind, Node, QPath};
66use rustc_lint::LateContext;
7use rustc_middle::ty::adjustment::Adjust;
7use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
88use rustc_span::sym;
99
1010use super::SWAP_WITH_TEMPORARY;
......@@ -47,7 +47,7 @@ impl<'tcx> ArgKind<'tcx> {
4747 && let adjustments = cx.typeck_results().expr_adjustments(arg)
4848 && adjustments
4949 .first()
50 .is_some_and(|adj| matches!(adj.kind, Adjust::Deref(None)))
50 .is_some_and(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Builtin)))
5151 && adjustments
5252 .last()
5353 .is_some_and(|adj| matches!(adj.kind, Adjust::Borrow(_)))
src/tools/clippy/clippy_lints/src/methods/type_id_on_box.rs+2-2
......@@ -4,7 +4,7 @@ use clippy_utils::source::snippet;
44use rustc_errors::Applicability;
55use rustc_hir::Expr;
66use rustc_lint::LateContext;
7use rustc_middle::ty::adjustment::{Adjust, Adjustment};
7use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
88use rustc_middle::ty::print::with_forced_trimmed_paths;
99use rustc_middle::ty::{self, ExistentialPredicate, Ty};
1010use rustc_span::{Span, sym};
......@@ -58,7 +58,7 @@ pub(super) fn check(cx: &LateContext<'_>, receiver: &Expr<'_>, call_span: Span)
5858 |diag| {
5959 let derefs = recv_adjusts
6060 .iter()
61 .filter(|adj| matches!(adj.kind, Adjust::Deref(None)))
61 .filter(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Builtin)))
6262 .count();
6363
6464 diag.note(
src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs+5-5
......@@ -14,7 +14,7 @@ use rustc_hir::{BorrowKind, Expr, ExprKind, ItemKind, LangItem, Node};
1414use rustc_infer::infer::TyCtxtInferExt;
1515use rustc_lint::LateContext;
1616use rustc_middle::mir::Mutability;
17use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref};
17use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind, OverloadedDeref};
1818use rustc_middle::ty::{
1919 self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty,
2020};
......@@ -78,7 +78,7 @@ fn check_addr_of_expr(
7878 // For matching uses of `Cow::from`
7979 [
8080 Adjustment {
81 kind: Adjust::Deref(None),
81 kind: Adjust::Deref(DerefAdjustKind::Builtin),
8282 target: referent_ty,
8383 },
8484 Adjustment {
......@@ -89,7 +89,7 @@ fn check_addr_of_expr(
8989 // For matching uses of arrays
9090 | [
9191 Adjustment {
92 kind: Adjust::Deref(None),
92 kind: Adjust::Deref(DerefAdjustKind::Builtin),
9393 target: referent_ty,
9494 },
9595 Adjustment {
......@@ -104,11 +104,11 @@ fn check_addr_of_expr(
104104 // For matching everything else
105105 | [
106106 Adjustment {
107 kind: Adjust::Deref(None),
107 kind: Adjust::Deref(DerefAdjustKind::Builtin),
108108 target: referent_ty,
109109 },
110110 Adjustment {
111 kind: Adjust::Deref(Some(OverloadedDeref { .. })),
111 kind: Adjust::Deref(DerefAdjustKind::Overloaded(OverloadedDeref { .. })),
112112 ..
113113 },
114114 Adjustment {
src/tools/clippy/clippy_lints/src/methods/useless_asref.rs+2-2
......@@ -7,7 +7,7 @@ use rustc_errors::Applicability;
77use rustc_hir::def::{DefKind, Res};
88use rustc_hir::{self as hir, LangItem, Node};
99use rustc_lint::LateContext;
10use rustc_middle::ty::adjustment::Adjust;
10use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
1111use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor};
1212use rustc_span::{Span, Symbol, sym};
1313
......@@ -161,7 +161,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool {
161161 && cx.tcx.lang_items().clone_trait().is_some_and(|id| id == trait_id)
162162 // no autoderefs
163163 && !cx.typeck_results().expr_adjustments(obj).iter()
164 .any(|a| matches!(a.kind, Adjust::Deref(Some(..))))
164 .any(|a| matches!(a.kind, Adjust::Deref(DerefAdjustKind::Overloaded(..))))
165165 && obj.res_local_id() == Some(local_id)
166166 {
167167 true
src/tools/clippy/clippy_lints/src/non_copy_const.rs+2-2
......@@ -33,7 +33,7 @@ use rustc_hir::{
3333};
3434use rustc_lint::{LateContext, LateLintPass, LintContext};
3535use rustc_middle::mir::{ConstValue, UnevaluatedConst};
36use rustc_middle::ty::adjustment::{Adjust, Adjustment};
36use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
3737use rustc_middle::ty::{
3838 self, AliasTyKind, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable,
3939 TypeckResults, TypingEnv,
......@@ -907,7 +907,7 @@ fn does_adjust_borrow(adjust: &Adjustment<'_>) -> Option<BorrowCause> {
907907 match adjust.kind {
908908 Adjust::Borrow(_) => Some(BorrowCause::AutoBorrow),
909909 // Custom deref calls `<T as Deref>::deref(&x)` resulting in a borrow.
910 Adjust::Deref(Some(_)) => Some(BorrowCause::AutoDeref),
910 Adjust::Deref(DerefAdjustKind::Overloaded(_)) => Some(BorrowCause::AutoDeref),
911911 // All other adjustments read the value.
912912 _ => None,
913913 }
src/tools/clippy/clippy_utils/src/eager_or_lazy.rs+3-8
......@@ -19,7 +19,7 @@ use rustc_hir::intravisit::{Visitor, walk_expr};
1919use rustc_hir::{BinOpKind, Block, Expr, ExprKind, QPath, UnOp};
2020use rustc_lint::LateContext;
2121use rustc_middle::ty;
22use rustc_middle::ty::adjustment::Adjust;
22use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind};
2323use rustc_span::Symbol;
2424use std::{cmp, ops};
2525
......@@ -132,7 +132,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
132132 .typeck_results()
133133 .expr_adjustments(e)
134134 .iter()
135 .any(|adj| matches!(adj.kind, Adjust::Deref(Some(_))))
135 .any(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Overloaded(_))))
136136 {
137137 self.eagerness |= NoChange;
138138 return;
......@@ -211,12 +211,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS
211211
212212 // Custom `Deref` impl might have side effects
213213 ExprKind::Unary(UnOp::Deref, e)
214 if self
215 .cx
216 .typeck_results()
217 .expr_ty(e)
218 .builtin_deref(true)
219 .is_none() =>
214 if self.cx.typeck_results().expr_ty(e).builtin_deref(true).is_none() =>
220215 {
221216 self.eagerness |= NoChange;
222217 },
src/tools/clippy/clippy_utils/src/lib.rs+6-4
......@@ -108,7 +108,7 @@ use rustc_middle::hir::nested_filter;
108108use rustc_middle::hir::place::PlaceBase;
109109use rustc_middle::lint::LevelAndSource;
110110use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementKind, TerminatorKind};
111use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, PointerCoercion};
111use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind, PointerCoercion};
112112use rustc_middle::ty::layout::IntegerExt;
113113use rustc_middle::ty::{
114114 self as rustc_ty, Binder, BorrowKind, ClosureKind, EarlyBinder, GenericArgKind, GenericArgsRef, IntTy, Ty, TyCtxt,
......@@ -477,8 +477,8 @@ pub fn expr_custom_deref_adjustment(cx: &LateContext<'_>, e: &Expr<'_>) -> Optio
477477 .expr_adjustments(e)
478478 .iter()
479479 .find_map(|a| match a.kind {
480 Adjust::Deref(Some(d)) => Some(Some(d.mutbl)),
481 Adjust::Deref(None) => None,
480 Adjust::Deref(DerefAdjustKind::Overloaded(d)) => Some(Some(d.mutbl)),
481 Adjust::Deref(DerefAdjustKind::Builtin) => None,
482482 _ => Some(None),
483483 })
484484 .and_then(|x| x)
......@@ -3537,7 +3537,9 @@ pub fn expr_adjustment_requires_coercion(cx: &LateContext<'_>, expr: &Expr<'_>)
35373537 cx.typeck_results().expr_adjustments(expr).iter().any(|adj| {
35383538 matches!(
35393539 adj.kind,
3540 Adjust::Deref(Some(_)) | Adjust::Pointer(PointerCoercion::Unsize) | Adjust::NeverToAny
3540 Adjust::Deref(DerefAdjustKind::Overloaded(_))
3541 | Adjust::Pointer(PointerCoercion::Unsize)
3542 | Adjust::NeverToAny
35413543 )
35423544 })
35433545}
src/tools/clippy/clippy_utils/src/ty/mod.rs+3-2
......@@ -17,7 +17,7 @@ use rustc_lint::LateContext;
1717use rustc_middle::mir::ConstValue;
1818use rustc_middle::mir::interpret::Scalar;
1919use rustc_middle::traits::EvaluationResult;
20use rustc_middle::ty::adjustment::{Adjust, Adjustment};
20use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind};
2121use rustc_middle::ty::layout::ValidityRequirement;
2222use rustc_middle::ty::{
2323 self, AdtDef, AliasTy, AssocItem, AssocTag, Binder, BoundRegion, BoundVarIndexKind, FnSig, GenericArg,
......@@ -1345,6 +1345,7 @@ pub fn get_field_idx_by_name(ty: Ty<'_>, name: Symbol) -> Option<usize> {
13451345pub fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool {
13461346 adjustments.iter().any(|a| {
13471347 let ty = mem::replace(&mut ty, a.target);
1348 matches!(a.kind, Adjust::Deref(Some(op)) if op.mutbl == Mutability::Mut) && is_manually_drop(ty)
1348 matches!(a.kind, Adjust::Deref(DerefAdjustKind::Overloaded(op)) if op.mutbl == Mutability::Mut)
1349 && is_manually_drop(ty)
13491350 })
13501351}
tests/run-make/frontmatter-no-trailing-newline/rmake.rs created+19
......@@ -0,0 +1,19 @@
1// Regression test for issue #151882
2// See https://github.com/rust-lang/rust/issues/151882
3
4//@ only-nightly
5//@ needs-target-std
6
7use run_make_support::{rfs, rustc};
8
9fn main() {
10 rfs::write("test.rs", b"----");
11
12 // Ensure rustc does not ICE when parsing a file with frontmatter syntax
13 // that has no trailing newline
14 rustc()
15 .input("test.rs")
16 .run_fail()
17 .assert_stderr_contains("invalid infostring for frontmatter")
18 .assert_stderr_not_contains("unexpectedly panicked");
19}