Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 23e28d3

Browse files
committed
make hir::Ty/ConstArg methods generic where applicable
1 parent 3b5ea05 commit 23e28d3

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

‎compiler/rustc_hir/src/hir.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<'hir> ConstArg<'hir> {
315315
}
316316
}
317317

318-
impl<'hir> ConstArg<'hir> {
318+
impl<'hir,Unambig> ConstArg<'hir,Unambig> {
319319
pub fn anon_const_hir_id(&self) -> Option<HirId> {
320320
match self.kind {
321321
ConstArgKind::Anon(ac) => Some(ac.hir_id),
@@ -383,7 +383,7 @@ impl GenericArg<'_> {
383383
match self {
384384
GenericArg::Lifetime(l) => l.ident.span,
385385
GenericArg::Type(t) => t.span,
386-
GenericArg::Const(c) => c.as_unambig_ct().span(),
386+
GenericArg::Const(c) => c.span(),
387387
GenericArg::Infer(i) => i.span,
388388
}
389389
}
@@ -3022,7 +3022,25 @@ impl<'hir> Ty<'hir> {
30223022
}
30233023
}
30243024

3025+
impl<'hir> Ty<'hir, AmbigArg> {
3026+
pub fn peel_refs(&self) -> &Ty<'hir> {
3027+
let mut final_ty = self.as_unambig_ty();
3028+
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
3029+
final_ty = ty;
3030+
}
3031+
final_ty
3032+
}
3033+
}
3034+
30253035
impl<'hir> Ty<'hir> {
3036+
pub fn peel_refs(&self) -> &Self {
3037+
let mut final_ty = self;
3038+
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
3039+
final_ty = ty;
3040+
}
3041+
final_ty
3042+
}
3043+
30263044
/// Returns `true` if `param_def_id` matches the `bounded_ty` of this predicate.
30273045
pub fn as_generic_param(&self) -> Option<(DefId, Ident)> {
30283046
let TyKind::Path(QPath::Resolved(None, path)) = self.kind else {
@@ -3039,14 +3057,6 @@ impl<'hir> Ty<'hir> {
30393057
}
30403058
}
30413059

3042-
pub fn peel_refs(&self) -> &Self {
3043-
let mut final_ty = self;
3044-
while let TyKind::Ref(_, MutTy { ty, .. }) = &final_ty.kind {
3045-
final_ty = ty;
3046-
}
3047-
final_ty
3048-
}
3049-
30503060
pub fn find_self_aliases(&self) -> Vec<Span> {
30513061
use crate::intravisit::Visitor;
30523062
struct MyVisitor(Vec<Span>);

‎compiler/rustc_lint/src/pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ fn gen_args(cx: &LateContext<'_>, segment: &PathSegment<'_>) -> String {
7777
.tcx
7878
.sess
7979
.source_map()
80-
.span_to_snippet(c.as_unambig_ct().span())
80+
.span_to_snippet(c.span())
8181
.unwrap_or_else(|_| "_".into()),
8282
GenericArg::Infer(_) => String::from("_"),
8383
})

‎src/tools/clippy/clippy_lints/src/extra_unused_type_parameters.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'tcx> Visitor<'tcx> for TypeWalker<'_, 'tcx> {
197197
type NestedFilter = nested_filter::OnlyBodies;
198198

199199
fn visit_ty(&mut self, t: &'tcx Ty<'tcx, AmbigArg>) {
200-
if let Some((def_id, _)) = t.as_unambig_ty().peel_refs().as_generic_param() {
200+
if let Some((def_id, _)) = t.peel_refs().as_generic_param() {
201201
self.ty_params.remove(&def_id);
202202
} else {
203203
walk_ty(self, t);

‎src/tools/clippy/clippy_lints/src/from_over_into.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'tcx> LateLintPass<'tcx> for FromOverInto {
9292
|diag| {
9393
// If the target type is likely foreign mention the orphan rules as it's a common source of
9494
// confusion
95-
if path_def_id(cx, target_ty.as_unambig_ty().peel_refs()).is_none_or(|id| !id.is_local()) {
95+
if path_def_id(cx, target_ty.peel_refs()).is_none_or(|id| !id.is_local()) {
9696
diag.help(
9797
"`impl From<Local> for Foreign` is allowed by the orphan rules, for more information see\n\
9898
https://doc.rust-lang.org/reference/items/implementations.html#trait-implementation-coherence"

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /