| author | bors <bors@rust-lang.org> 2026-01-31 16:24:16 UTC |
| committer | bors <bors@rust-lang.org> 2026-01-31 16:24:16 UTC |
| log | 8afe9ff1caa97654c31fb8c259dac9fdf67d6302 |
| tree | 68b5999685a4b0c604926c84aa7a5f467b8ed8bc |
| parent | 78865ca937ef3b77b214473db78b51ec82e2277a |
| parent | 874c5d2275481b519ad2621c52546843b7366adf |
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 { |
| 510 | 510 | } |
| 511 | 511 | } |
| 512 | 512 | |
| 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 | ||
| 526 | 513 | /// Allocates a string slice that is copied into the `DroplessArena`, returning a |
| 527 | 514 | /// reference to it. Will panic if passed an empty string. |
| 528 | 515 | /// |
compiler/rustc_hir_typeck/src/autoderef.rs+12-10| ... | ... | @@ -6,7 +6,7 @@ use itertools::Itertools; |
| 6 | 6 | use rustc_hir_analysis::autoderef::{Autoderef, AutoderefKind}; |
| 7 | 7 | use rustc_infer::infer::InferOk; |
| 8 | 8 | use rustc_infer::traits::PredicateObligations; |
| 9 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; | |
| 9 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind, OverloadedDeref}; | |
| 10 | 10 | use rustc_middle::ty::{self, Ty}; |
| 11 | 11 | use rustc_span::Span; |
| 12 | 12 | |
| ... | ... | @@ -45,22 +45,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 45 | 45 | steps.iter().skip(1).map(|&(ty, _)| ty).chain(iter::once(autoderef.final_ty())); |
| 46 | 46 | let steps: Vec<_> = steps |
| 47 | 47 | .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 }| { | |
| 52 | 52 | obligations.extend(o); |
| 53 | 53 | // FIXME: we should assert the sig is &T here... there's no reason for this to be fallible. |
| 54 | 54 | 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 | })) | |
| 56 | 59 | } else { |
| 57 | 60 | None |
| 58 | 61 | } |
| 59 | }, | |
| 60 | ) | |
| 61 | } else { | |
| 62 | None | |
| 62 | }) | |
| 63 | .unwrap_or(DerefAdjustKind::Builtin) | |
| 63 | 64 | } |
| 65 | AutoderefKind::Builtin => DerefAdjustKind::Builtin, | |
| 64 | 66 | }) |
| 65 | 67 | .zip_eq(targets) |
| 66 | 68 | .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::{ |
| 50 | 50 | }; |
| 51 | 51 | use rustc_middle::span_bug; |
| 52 | 52 | use rustc_middle::ty::adjustment::{ |
| 53 | Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion, | |
| 53 | Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, | |
| 54 | PointerCoercion, | |
| 54 | 55 | }; |
| 55 | 56 | use rustc_middle::ty::error::TypeError; |
| 56 | 57 | use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; |
| ... | ... | @@ -595,7 +596,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { |
| 595 | 596 | let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No); |
| 596 | 597 | |
| 597 | 598 | Some(( |
| 598 | Adjustment { kind: Adjust::Deref(None), target: ty_a }, | |
| 599 | Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a }, | |
| 599 | 600 | Adjustment { |
| 600 | 601 | kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)), |
| 601 | 602 | target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b), |
| ... | ... | @@ -606,7 +607,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { |
| 606 | 607 | coerce_mutbls(mt_a, mt_b)?; |
| 607 | 608 | |
| 608 | 609 | Some(( |
| 609 | Adjustment { kind: Adjust::Deref(None), target: ty_a }, | |
| 610 | Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a }, | |
| 610 | 611 | Adjustment { |
| 611 | 612 | kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)), |
| 612 | 613 | target: Ty::new_ptr(self.tcx, ty_a, mt_b), |
| ... | ... | @@ -936,7 +937,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> { |
| 936 | 937 | self.unify_and( |
| 937 | 938 | a_raw, |
| 938 | 939 | b, |
| 939 | [Adjustment { kind: Adjust::Deref(None), target: mt_a.ty }], | |
| 940 | [Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: mt_a.ty }], | |
| 940 | 941 | Adjust::Borrow(AutoBorrow::RawPtr(mutbl_b)), |
| 941 | 942 | ForceLeakCheck::No, |
| 942 | 943 | ) |
compiler/rustc_hir_typeck/src/expr_use_visitor.rs+5-4| ... | ... | @@ -22,6 +22,7 @@ use rustc_middle::hir::place::ProjectionKind; |
| 22 | 22 | pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection}; |
| 23 | 23 | use rustc_middle::mir::FakeReadCause; |
| 24 | 24 | use rustc_middle::thir::DerefPatBorrowMode; |
| 25 | use rustc_middle::ty::adjustment::DerefAdjustKind; | |
| 25 | 26 | use rustc_middle::ty::{ |
| 26 | 27 | self, BorrowKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt as _, adjustment, |
| 27 | 28 | }; |
| ... | ... | @@ -733,14 +734,14 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx |
| 733 | 734 | self.consume_or_copy(&place_with_id, place_with_id.hir_id); |
| 734 | 735 | } |
| 735 | 736 | |
| 736 | adjustment::Adjust::Deref(None) => {} | |
| 737 | adjustment::Adjust::Deref(DerefAdjustKind::Builtin) => {} | |
| 737 | 738 | |
| 738 | 739 | // Autoderefs for overloaded Deref calls in fact reference |
| 739 | 740 | // their receiver. That is, if we have `(*x)` where `x` |
| 740 | 741 | // is of type `Rc<T>`, then this in fact is equivalent to |
| 741 | 742 | // `x.deref()`. Since `deref()` is declared with `&self`, |
| 742 | 743 | // this is an autoref of `x`. |
| 743 | adjustment::Adjust::Deref(Some(ref deref)) => { | |
| 744 | adjustment::Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => { | |
| 744 | 745 | let bk = ty::BorrowKind::from_mutbl(deref.mutbl); |
| 745 | 746 | self.delegate.borrow_mut().borrow(&place_with_id, place_with_id.hir_id, bk); |
| 746 | 747 | } |
| ... | ... | @@ -1272,9 +1273,9 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx |
| 1272 | 1273 | { |
| 1273 | 1274 | let target = self.cx.resolve_vars_if_possible(adjustment.target); |
| 1274 | 1275 | match adjustment.kind { |
| 1275 | adjustment::Adjust::Deref(overloaded) => { | |
| 1276 | adjustment::Adjust::Deref(deref_kind) => { | |
| 1276 | 1277 | // Equivalent to *expr or something similar. |
| 1277 | let base = if let Some(deref) = overloaded { | |
| 1278 | let base = if let DerefAdjustKind::Overloaded(deref) = deref_kind { | |
| 1278 | 1279 | let ref_ty = Ty::new_ref( |
| 1279 | 1280 | self.cx.tcx(), |
| 1280 | 1281 | 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::{ |
| 20 | 20 | use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse}; |
| 21 | 21 | use rustc_infer::infer::{DefineOpaqueTypes, InferResult}; |
| 22 | 22 | use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM; |
| 23 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; | |
| 23 | use rustc_middle::ty::adjustment::{ | |
| 24 | Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, | |
| 25 | }; | |
| 24 | 26 | use rustc_middle::ty::{ |
| 25 | 27 | self, AdtKind, CanonicalUserType, GenericArgsRef, GenericParamDefKind, IsIdentity, |
| 26 | 28 | SizedTraitKind, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs, |
| ... | ... | @@ -266,7 +268,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 266 | 268 | debug!("apply_adjustments: adding `{:?}` as diverging type var", a.target); |
| 267 | 269 | } |
| 268 | 270 | } |
| 269 | Adjust::Deref(Some(overloaded_deref)) => { | |
| 271 | Adjust::Deref(DerefAdjustKind::Overloaded(overloaded_deref)) => { | |
| 270 | 272 | self.enforce_context_effects( |
| 271 | 273 | None, |
| 272 | 274 | expr.span, |
| ... | ... | @@ -274,7 +276,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 274 | 276 | self.tcx.mk_args(&[expr_ty.into()]), |
| 275 | 277 | ); |
| 276 | 278 | } |
| 277 | Adjust::Deref(None) => { | |
| 279 | Adjust::Deref(DerefAdjustKind::Builtin) => { | |
| 278 | 280 | // FIXME(const_trait_impl): We *could* enforce `&T: [const] Deref` here. |
| 279 | 281 | } |
| 280 | 282 | Adjust::Pointer(_pointer_coercion) => { |
compiler/rustc_hir_typeck/src/place_op.rs+4-3| ... | ... | @@ -4,8 +4,8 @@ use rustc_infer::infer::InferOk; |
| 4 | 4 | use rustc_infer::traits::{Obligation, ObligationCauseCode}; |
| 5 | 5 | use rustc_middle::span_bug; |
| 6 | 6 | use rustc_middle::ty::adjustment::{ |
| 7 | Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, OverloadedDeref, | |
| 8 | PointerCoercion, | |
| 7 | Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, | |
| 8 | OverloadedDeref, PointerCoercion, | |
| 9 | 9 | }; |
| 10 | 10 | use rustc_middle::ty::{self, Ty}; |
| 11 | 11 | use rustc_span::{Span, sym}; |
| ... | ... | @@ -298,7 +298,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { |
| 298 | 298 | self.typeck_results.borrow_mut().adjustments_mut().remove(expr.hir_id); |
| 299 | 299 | if let Some(mut adjustments) = previous_adjustments { |
| 300 | 300 | 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 | |
| 302 | 303 | && let Some(ok) = self.try_mutable_overloaded_place_op( |
| 303 | 304 | expr.span, |
| 304 | 305 | source, |
compiler/rustc_lint/src/autorefs.rs+7-3| ... | ... | @@ -1,7 +1,9 @@ |
| 1 | 1 | use rustc_ast::{BorrowKind, UnOp}; |
| 2 | 2 | use rustc_hir::attrs::AttributeKind; |
| 3 | 3 | use rustc_hir::{Expr, ExprKind, Mutability, find_attr}; |
| 4 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, OverloadedDeref}; | |
| 4 | use rustc_middle::ty::adjustment::{ | |
| 5 | Adjust, Adjustment, AutoBorrow, DerefAdjustKind, OverloadedDeref, | |
| 6 | }; | |
| 5 | 7 | use rustc_session::{declare_lint, declare_lint_pass}; |
| 6 | 8 | |
| 7 | 9 | use crate::lints::{ |
| ... | ... | @@ -165,12 +167,14 @@ fn peel_derefs_adjustments<'a>(mut adjs: &'a [Adjustment<'a>]) -> &'a [Adjustmen |
| 165 | 167 | /// an implicit borrow (or has an implicit borrow via an overloaded deref). |
| 166 | 168 | fn has_implicit_borrow(Adjustment { kind, .. }: &Adjustment<'_>) -> Option<(Mutability, bool)> { |
| 167 | 169 | match kind { |
| 168 | &Adjust::Deref(Some(OverloadedDeref { mutbl, .. })) => Some((mutbl, true)), | |
| 170 | &Adjust::Deref(DerefAdjustKind::Overloaded(OverloadedDeref { mutbl, .. })) => { | |
| 171 | Some((mutbl, true)) | |
| 172 | } | |
| 169 | 173 | &Adjust::Borrow(AutoBorrow::Ref(mutbl)) => Some((mutbl.into(), false)), |
| 170 | 174 | Adjust::NeverToAny |
| 171 | 175 | | Adjust::Pointer(..) |
| 172 | 176 | | Adjust::ReborrowPin(..) |
| 173 | | Adjust::Deref(None) | |
| 177 | | Adjust::Deref(DerefAdjustKind::Builtin) | |
| 174 | 178 | | Adjust::Borrow(AutoBorrow::RawPtr(..)) => None, |
| 175 | 179 | } |
| 176 | 180 | } |
compiler/rustc_lint/src/noop_method_call.rs+5-2| ... | ... | @@ -1,7 +1,7 @@ |
| 1 | 1 | use rustc_hir::def::DefKind; |
| 2 | 2 | use rustc_hir::{Expr, ExprKind}; |
| 3 | 3 | use rustc_middle::ty; |
| 4 | use rustc_middle::ty::adjustment::Adjust; | |
| 4 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 5 | 5 | use rustc_session::{declare_lint, declare_lint_pass}; |
| 6 | 6 | use rustc_span::sym; |
| 7 | 7 | |
| ... | ... | @@ -114,7 +114,10 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { |
| 114 | 114 | |
| 115 | 115 | // If there is any user defined auto-deref step, then we don't want to warn. |
| 116 | 116 | // 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 | { | |
| 118 | 121 | return; |
| 119 | 122 | } |
| 120 | 123 |
compiler/rustc_middle/src/ty/adjustment.rs+7-1| ... | ... | @@ -97,7 +97,7 @@ pub enum Adjust { |
| 97 | 97 | NeverToAny, |
| 98 | 98 | |
| 99 | 99 | /// Dereference once, producing a place. |
| 100 | Deref(Option<OverloadedDeref>), | |
| 100 | Deref(DerefAdjustKind), | |
| 101 | 101 | |
| 102 | 102 | /// Take the address and produce either a `&` or `*` pointer. |
| 103 | 103 | Borrow(AutoBorrow), |
| ... | ... | @@ -108,6 +108,12 @@ pub enum Adjust { |
| 108 | 108 | ReborrowPin(hir::Mutability), |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | #[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)] | |
| 112 | pub enum DerefAdjustKind { | |
| 113 | Builtin, | |
| 114 | Overloaded(OverloadedDeref), | |
| 115 | } | |
| 116 | ||
| 111 | 117 | /// An overloaded autoderef step, representing a `Deref(Mut)::deref(_mut)` |
| 112 | 118 | /// call, with the signature `&'a T -> &'a U` or `&'a mut T -> &'a mut U`. |
| 113 | 119 | /// 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; |
| 14 | 14 | use rustc_middle::mir::{self, AssignOp, BinOp, BorrowKind, UnOp}; |
| 15 | 15 | use rustc_middle::thir::*; |
| 16 | 16 | use rustc_middle::ty::adjustment::{ |
| 17 | Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, PointerCoercion, | |
| 17 | Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, PointerCoercion, | |
| 18 | 18 | }; |
| 19 | 19 | use rustc_middle::ty::{ |
| 20 | 20 | self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs, |
| ... | ... | @@ -140,11 +140,11 @@ impl<'tcx> ThirBuildCx<'tcx> { |
| 140 | 140 | } |
| 141 | 141 | Adjust::NeverToAny if adjustment.target.is_never() => return expr, |
| 142 | 142 | Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) }, |
| 143 | Adjust::Deref(None) => { | |
| 143 | Adjust::Deref(DerefAdjustKind::Builtin) => { | |
| 144 | 144 | adjust_span(&mut expr); |
| 145 | 145 | ExprKind::Deref { arg: self.thir.exprs.push(expr) } |
| 146 | 146 | } |
| 147 | Adjust::Deref(Some(deref)) => { | |
| 147 | Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => { | |
| 148 | 148 | // We don't need to do call adjust_span here since |
| 149 | 149 | // deref coercions always start with a built-in deref. |
| 150 | 150 | 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> { |
| 623 | 623 | self.dcx().emit_err(errors::FrontmatterInvalidInfostring { span }); |
| 624 | 624 | } |
| 625 | 625 | |
| 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); | |
| 627 | 627 | |
| 628 | 628 | let content = &real_s[line_end..last_line_start]; |
| 629 | 629 | 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::{ |
| 12 | 12 | }; |
| 13 | 13 | use rustc_middle::bug; |
| 14 | 14 | use rustc_middle::hir::nested_filter; |
| 15 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow}; | |
| 15 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind}; | |
| 16 | 16 | use rustc_middle::ty::print::{FmtPrinter, PrettyPrinter, Print, Printer}; |
| 17 | 17 | use rustc_middle::ty::{ |
| 18 | 18 | self, GenericArg, GenericArgKind, GenericArgsRef, InferConst, IsSuggestable, Term, TermKind, |
| ... | ... | @@ -615,7 +615,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { |
| 615 | 615 | // first adjustment was not a builtin deref. |
| 616 | 616 | let adjustment = match typeck_results.expr_adjustments(receiver) { |
| 617 | 617 | [ |
| 618 | Adjustment { kind: Adjust::Deref(None), target: _ }, | |
| 618 | Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: _ }, | |
| 619 | 619 | .., |
| 620 | 620 | Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ }, |
| 621 | 621 | ] => "", |
src/tools/clippy/clippy_lints/src/eta_reduction.rs+2-2| ... | ... | @@ -10,7 +10,7 @@ use rustc_hir::attrs::AttributeKind; |
| 10 | 10 | use rustc_hir::{BindingMode, Expr, ExprKind, FnRetTy, GenericArgs, Param, PatKind, QPath, Safety, TyKind, find_attr}; |
| 11 | 11 | use rustc_infer::infer::TyCtxtInferExt; |
| 12 | 12 | use rustc_lint::{LateContext, LateLintPass}; |
| 13 | use rustc_middle::ty::adjustment::Adjust; | |
| 13 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 14 | 14 | use rustc_middle::ty::{ |
| 15 | 15 | self, Binder, ClosureKind, FnSig, GenericArg, GenericArgKind, List, Region, Ty, TypeVisitableExt, TypeckResults, |
| 16 | 16 | }; |
| ... | ... | @@ -236,7 +236,7 @@ fn check_closure<'tcx>(cx: &LateContext<'tcx>, outer_receiver: Option<&Expr<'tcx |
| 236 | 236 | .iter() |
| 237 | 237 | .rev() |
| 238 | 238 | .fold(0, |acc, adjustment| match adjustment.kind { |
| 239 | Adjust::Deref(Some(_)) => acc + 1, | |
| 239 | Adjust::Deref(DerefAdjustKind::Overloaded(_)) => acc + 1, | |
| 240 | 240 | Adjust::Deref(_) if acc > 0 => acc + 1, |
| 241 | 241 | _ => acc, |
| 242 | 242 | }) |
src/tools/clippy/clippy_lints/src/format_args.rs+3-3| ... | ... | @@ -24,7 +24,7 @@ use rustc_errors::SuggestionStyle::{CompletelyHidden, ShowCode}; |
| 24 | 24 | use rustc_hir::attrs::AttributeKind; |
| 25 | 25 | use rustc_hir::{Expr, ExprKind, LangItem, RustcVersion, find_attr}; |
| 26 | 26 | use rustc_lint::{LateContext, LateLintPass, LintContext}; |
| 27 | use rustc_middle::ty::adjustment::{Adjust, Adjustment}; | |
| 27 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; | |
| 28 | 28 | use rustc_middle::ty::{self, GenericArg, List, TraitRef, Ty, TyCtxt, Upcast}; |
| 29 | 29 | use rustc_session::impl_lint_pass; |
| 30 | 30 | use rustc_span::edition::Edition::Edition2021; |
| ... | ... | @@ -704,12 +704,12 @@ where |
| 704 | 704 | let mut n_needed = 0; |
| 705 | 705 | loop { |
| 706 | 706 | if let Some(Adjustment { |
| 707 | kind: Adjust::Deref(overloaded_deref), | |
| 707 | kind: Adjust::Deref(deref), | |
| 708 | 708 | target, |
| 709 | 709 | }) = iter.next() |
| 710 | 710 | { |
| 711 | 711 | n_total += 1; |
| 712 | if overloaded_deref.is_some() { | |
| 712 | if let DerefAdjustKind::Overloaded(..) = deref { | |
| 713 | 713 | n_needed = n_total; |
| 714 | 714 | } |
| 715 | 715 | 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}; |
| 12 | 12 | use rustc_hir::{Closure, Expr, ExprKind, HirId, LetStmt, Mutability, UnOp}; |
| 13 | 13 | use rustc_lint::LateContext; |
| 14 | 14 | use rustc_middle::hir::nested_filter::OnlyBodies; |
| 15 | use rustc_middle::ty::adjustment::Adjust; | |
| 15 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 16 | 16 | use rustc_span::Symbol; |
| 17 | 17 | use rustc_span::symbol::sym; |
| 18 | 18 | |
| ... | ... | @@ -88,7 +88,7 @@ fn try_parse_iter_expr(cx: &LateContext<'_>, mut e: &Expr<'_>) -> Option<IterExp |
| 88 | 88 | .typeck_results() |
| 89 | 89 | .expr_adjustments(e) |
| 90 | 90 | .iter() |
| 91 | .any(|a| matches!(a.kind, Adjust::Deref(Some(..)))) | |
| 91 | .any(|a| matches!(a.kind, Adjust::Deref(DerefAdjustKind::Overloaded(..)))) | |
| 92 | 92 | { |
| 93 | 93 | // Custom deref impls need to borrow the whole value as it's captured by reference |
| 94 | 94 | 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}; |
| 10 | 10 | use rustc_lint::LateContext; |
| 11 | 11 | use rustc_middle::mir::{Mutability, Pinnedness}; |
| 12 | 12 | use rustc_middle::ty; |
| 13 | use rustc_middle::ty::adjustment::Adjust; | |
| 13 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 14 | 14 | use rustc_span::symbol::Ident; |
| 15 | 15 | use rustc_span::{Span, sym}; |
| 16 | 16 | |
| ... | ... | @@ -73,7 +73,7 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_ |
| 73 | 73 | && cx.tcx.lang_items().clone_trait() == Some(trait_id) |
| 74 | 74 | // no autoderefs |
| 75 | 75 | && !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(..)))) | |
| 77 | 77 | { |
| 78 | 78 | let obj_ty = cx.typeck_results().expr_ty(obj); |
| 79 | 79 | 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( |
| 58 | 58 | .iter() |
| 59 | 59 | .map(|x| &x.kind) |
| 60 | 60 | .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 | |
| 62 | 62 | && let method_did = cx.typeck_results().type_dependent_def_id(closure_expr.hir_id).unwrap() |
| 63 | 63 | && let Some(method_name) = cx.tcx.get_diagnostic_name(method_did) |
| 64 | 64 | { |
src/tools/clippy/clippy_lints/src/methods/swap_with_temporary.rs+2-2| ... | ... | @@ -4,7 +4,7 @@ use rustc_ast::BorrowKind; |
| 4 | 4 | use rustc_errors::{Applicability, Diag}; |
| 5 | 5 | use rustc_hir::{Expr, ExprKind, Node, QPath}; |
| 6 | 6 | use rustc_lint::LateContext; |
| 7 | use rustc_middle::ty::adjustment::Adjust; | |
| 7 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 8 | 8 | use rustc_span::sym; |
| 9 | 9 | |
| 10 | 10 | use super::SWAP_WITH_TEMPORARY; |
| ... | ... | @@ -47,7 +47,7 @@ impl<'tcx> ArgKind<'tcx> { |
| 47 | 47 | && let adjustments = cx.typeck_results().expr_adjustments(arg) |
| 48 | 48 | && adjustments |
| 49 | 49 | .first() |
| 50 | .is_some_and(|adj| matches!(adj.kind, Adjust::Deref(None))) | |
| 50 | .is_some_and(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Builtin))) | |
| 51 | 51 | && adjustments |
| 52 | 52 | .last() |
| 53 | 53 | .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; |
| 4 | 4 | use rustc_errors::Applicability; |
| 5 | 5 | use rustc_hir::Expr; |
| 6 | 6 | use rustc_lint::LateContext; |
| 7 | use rustc_middle::ty::adjustment::{Adjust, Adjustment}; | |
| 7 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; | |
| 8 | 8 | use rustc_middle::ty::print::with_forced_trimmed_paths; |
| 9 | 9 | use rustc_middle::ty::{self, ExistentialPredicate, Ty}; |
| 10 | 10 | use rustc_span::{Span, sym}; |
| ... | ... | @@ -58,7 +58,7 @@ pub(super) fn check(cx: &LateContext<'_>, receiver: &Expr<'_>, call_span: Span) |
| 58 | 58 | |diag| { |
| 59 | 59 | let derefs = recv_adjusts |
| 60 | 60 | .iter() |
| 61 | .filter(|adj| matches!(adj.kind, Adjust::Deref(None))) | |
| 61 | .filter(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Builtin))) | |
| 62 | 62 | .count(); |
| 63 | 63 | |
| 64 | 64 | 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}; |
| 14 | 14 | use rustc_infer::infer::TyCtxtInferExt; |
| 15 | 15 | use rustc_lint::LateContext; |
| 16 | 16 | use rustc_middle::mir::Mutability; |
| 17 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, OverloadedDeref}; | |
| 17 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind, OverloadedDeref}; | |
| 18 | 18 | use rustc_middle::ty::{ |
| 19 | 19 | self, ClauseKind, GenericArg, GenericArgKind, GenericArgsRef, ParamTy, ProjectionPredicate, TraitPredicate, Ty, |
| 20 | 20 | }; |
| ... | ... | @@ -78,7 +78,7 @@ fn check_addr_of_expr( |
| 78 | 78 | // For matching uses of `Cow::from` |
| 79 | 79 | [ |
| 80 | 80 | Adjustment { |
| 81 | kind: Adjust::Deref(None), | |
| 81 | kind: Adjust::Deref(DerefAdjustKind::Builtin), | |
| 82 | 82 | target: referent_ty, |
| 83 | 83 | }, |
| 84 | 84 | Adjustment { |
| ... | ... | @@ -89,7 +89,7 @@ fn check_addr_of_expr( |
| 89 | 89 | // For matching uses of arrays |
| 90 | 90 | | [ |
| 91 | 91 | Adjustment { |
| 92 | kind: Adjust::Deref(None), | |
| 92 | kind: Adjust::Deref(DerefAdjustKind::Builtin), | |
| 93 | 93 | target: referent_ty, |
| 94 | 94 | }, |
| 95 | 95 | Adjustment { |
| ... | ... | @@ -104,11 +104,11 @@ fn check_addr_of_expr( |
| 104 | 104 | // For matching everything else |
| 105 | 105 | | [ |
| 106 | 106 | Adjustment { |
| 107 | kind: Adjust::Deref(None), | |
| 107 | kind: Adjust::Deref(DerefAdjustKind::Builtin), | |
| 108 | 108 | target: referent_ty, |
| 109 | 109 | }, |
| 110 | 110 | Adjustment { |
| 111 | kind: Adjust::Deref(Some(OverloadedDeref { .. })), | |
| 111 | kind: Adjust::Deref(DerefAdjustKind::Overloaded(OverloadedDeref { .. })), | |
| 112 | 112 | .. |
| 113 | 113 | }, |
| 114 | 114 | Adjustment { |
src/tools/clippy/clippy_lints/src/methods/useless_asref.rs+2-2| ... | ... | @@ -7,7 +7,7 @@ use rustc_errors::Applicability; |
| 7 | 7 | use rustc_hir::def::{DefKind, Res}; |
| 8 | 8 | use rustc_hir::{self as hir, LangItem, Node}; |
| 9 | 9 | use rustc_lint::LateContext; |
| 10 | use rustc_middle::ty::adjustment::Adjust; | |
| 10 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 11 | 11 | use rustc_middle::ty::{Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; |
| 12 | 12 | use rustc_span::{Span, Symbol, sym}; |
| 13 | 13 | |
| ... | ... | @@ -161,7 +161,7 @@ fn is_calling_clone(cx: &LateContext<'_>, arg: &hir::Expr<'_>) -> bool { |
| 161 | 161 | && cx.tcx.lang_items().clone_trait().is_some_and(|id| id == trait_id) |
| 162 | 162 | // no autoderefs |
| 163 | 163 | && !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(..)))) | |
| 165 | 165 | && obj.res_local_id() == Some(local_id) |
| 166 | 166 | { |
| 167 | 167 | true |
src/tools/clippy/clippy_lints/src/non_copy_const.rs+2-2| ... | ... | @@ -33,7 +33,7 @@ use rustc_hir::{ |
| 33 | 33 | }; |
| 34 | 34 | use rustc_lint::{LateContext, LateLintPass, LintContext}; |
| 35 | 35 | use rustc_middle::mir::{ConstValue, UnevaluatedConst}; |
| 36 | use rustc_middle::ty::adjustment::{Adjust, Adjustment}; | |
| 36 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; | |
| 37 | 37 | use rustc_middle::ty::{ |
| 38 | 38 | self, AliasTyKind, EarlyBinder, GenericArgs, GenericArgsRef, Instance, Ty, TyCtxt, TypeFolder, TypeSuperFoldable, |
| 39 | 39 | TypeckResults, TypingEnv, |
| ... | ... | @@ -907,7 +907,7 @@ fn does_adjust_borrow(adjust: &Adjustment<'_>) -> Option<BorrowCause> { |
| 907 | 907 | match adjust.kind { |
| 908 | 908 | Adjust::Borrow(_) => Some(BorrowCause::AutoBorrow), |
| 909 | 909 | // 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), | |
| 911 | 911 | // All other adjustments read the value. |
| 912 | 912 | _ => None, |
| 913 | 913 | } |
src/tools/clippy/clippy_utils/src/eager_or_lazy.rs+3-8| ... | ... | @@ -19,7 +19,7 @@ use rustc_hir::intravisit::{Visitor, walk_expr}; |
| 19 | 19 | use rustc_hir::{BinOpKind, Block, Expr, ExprKind, QPath, UnOp}; |
| 20 | 20 | use rustc_lint::LateContext; |
| 21 | 21 | use rustc_middle::ty; |
| 22 | use rustc_middle::ty::adjustment::Adjust; | |
| 22 | use rustc_middle::ty::adjustment::{Adjust, DerefAdjustKind}; | |
| 23 | 23 | use rustc_span::Symbol; |
| 24 | 24 | use std::{cmp, ops}; |
| 25 | 25 | |
| ... | ... | @@ -132,7 +132,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS |
| 132 | 132 | .typeck_results() |
| 133 | 133 | .expr_adjustments(e) |
| 134 | 134 | .iter() |
| 135 | .any(|adj| matches!(adj.kind, Adjust::Deref(Some(_)))) | |
| 135 | .any(|adj| matches!(adj.kind, Adjust::Deref(DerefAdjustKind::Overloaded(_)))) | |
| 136 | 136 | { |
| 137 | 137 | self.eagerness |= NoChange; |
| 138 | 138 | return; |
| ... | ... | @@ -211,12 +211,7 @@ fn expr_eagerness<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> EagernessS |
| 211 | 211 | |
| 212 | 212 | // Custom `Deref` impl might have side effects |
| 213 | 213 | 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() => | |
| 220 | 215 | { |
| 221 | 216 | self.eagerness |= NoChange; |
| 222 | 217 | }, |
src/tools/clippy/clippy_utils/src/lib.rs+6-4| ... | ... | @@ -108,7 +108,7 @@ use rustc_middle::hir::nested_filter; |
| 108 | 108 | use rustc_middle::hir::place::PlaceBase; |
| 109 | 109 | use rustc_middle::lint::LevelAndSource; |
| 110 | 110 | use rustc_middle::mir::{AggregateKind, Operand, RETURN_PLACE, Rvalue, StatementKind, TerminatorKind}; |
| 111 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, PointerCoercion}; | |
| 111 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, DerefAdjustKind, PointerCoercion}; | |
| 112 | 112 | use rustc_middle::ty::layout::IntegerExt; |
| 113 | 113 | use rustc_middle::ty::{ |
| 114 | 114 | 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 |
| 477 | 477 | .expr_adjustments(e) |
| 478 | 478 | .iter() |
| 479 | 479 | .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, | |
| 482 | 482 | _ => Some(None), |
| 483 | 483 | }) |
| 484 | 484 | .and_then(|x| x) |
| ... | ... | @@ -3537,7 +3537,9 @@ pub fn expr_adjustment_requires_coercion(cx: &LateContext<'_>, expr: &Expr<'_>) |
| 3537 | 3537 | cx.typeck_results().expr_adjustments(expr).iter().any(|adj| { |
| 3538 | 3538 | matches!( |
| 3539 | 3539 | 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 | |
| 3541 | 3543 | ) |
| 3542 | 3544 | }) |
| 3543 | 3545 | } |
src/tools/clippy/clippy_utils/src/ty/mod.rs+3-2| ... | ... | @@ -17,7 +17,7 @@ use rustc_lint::LateContext; |
| 17 | 17 | use rustc_middle::mir::ConstValue; |
| 18 | 18 | use rustc_middle::mir::interpret::Scalar; |
| 19 | 19 | use rustc_middle::traits::EvaluationResult; |
| 20 | use rustc_middle::ty::adjustment::{Adjust, Adjustment}; | |
| 20 | use rustc_middle::ty::adjustment::{Adjust, Adjustment, DerefAdjustKind}; | |
| 21 | 21 | use rustc_middle::ty::layout::ValidityRequirement; |
| 22 | 22 | use rustc_middle::ty::{ |
| 23 | 23 | 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> { |
| 1345 | 1345 | pub fn adjust_derefs_manually_drop<'tcx>(adjustments: &'tcx [Adjustment<'tcx>], mut ty: Ty<'tcx>) -> bool { |
| 1346 | 1346 | adjustments.iter().any(|a| { |
| 1347 | 1347 | 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) | |
| 1349 | 1350 | }) |
| 1350 | 1351 | } |
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 | ||
| 7 | use run_make_support::{rfs, rustc}; | |
| 8 | ||
| 9 | fn 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 | } |