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 d73e30f

Browse files
Introduce impl_is_of_trait
1 parent 0b6e2e2 commit d73e30f

File tree

12 files changed

+25
-15
lines changed

12 files changed

+25
-15
lines changed

‎compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
535535
// subroutine's self-type.
536536
if let Some(impl_def_id) = cx.tcx.impl_of_assoc(instance.def_id()) {
537537
// If the method does *not* belong to a trait, proceed
538-
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
538+
if !cx.tcx.impl_is_of_trait(impl_def_id) {
539539
let impl_self_ty = cx.tcx.instantiate_and_normalize_erasing_regions(
540540
instance.args,
541541
cx.typing_env(),

‎compiler/rustc_hir_analysis/src/collect/type_of.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
198198
}
199199
}
200200
ImplItemKind::Type(ty) => {
201-
if tcx.impl_trait_ref(tcx.hir_get_parent_item(hir_id)).is_none() {
201+
if !tcx.impl_is_of_trait(tcx.hir_get_parent_item(hir_id)) {
202202
check_feature_inherent_assoc_ty(tcx, item.span);
203203
}
204204

‎compiler/rustc_hir_typeck/src/method/confirm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
284284
probe::InherentImplPick => {
285285
let impl_def_id = pick.item.container_id(self.tcx);
286286
assert!(
287-
self.tcx.impl_trait_ref(impl_def_id).is_none(),
287+
!self.tcx.impl_is_of_trait(impl_def_id),
288288
"impl {impl_def_id:?} is not an inherent impl"
289289
);
290290
self.fresh_args_for_item(self.span, impl_def_id)

‎compiler/rustc_lint/src/nonstandard_style.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ pub(crate) fn method_context(cx: &LateContext<'_>, id: LocalDefId) -> MethodLate
3131
let item = cx.tcx.associated_item(id);
3232
match item.container {
3333
ty::AssocItemContainer::Trait => MethodLateContext::TraitAutoImpl,
34-
ty::AssocItemContainer::Impl => match cx.tcx.impl_trait_ref(item.container_id(cx.tcx)) {
35-
Some(_) => MethodLateContext::TraitImpl,
36-
None => MethodLateContext::PlainImpl,
37-
},
34+
ty::AssocItemContainer::Impl => {
35+
if cx.tcx.impl_is_of_trait(item.container_id(cx.tcx)) {
36+
MethodLateContext::TraitImpl
37+
} else {
38+
MethodLateContext::PlainImpl
39+
}
40+
}
3841
}
3942
}
4043

‎compiler/rustc_lint/src/pass_by_value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
2525
match &ty.kind {
2626
TyKind::Ref(_, hir::MutTy { ty: inner_ty, mutbl: hir::Mutability::Not }) => {
2727
if let Some(impl_did) = cx.tcx.impl_of_assoc(ty.hir_id.owner.to_def_id()) {
28-
if cx.tcx.impl_trait_ref(impl_did).is_some() {
28+
if cx.tcx.impl_is_of_trait(impl_did) {
2929
return;
3030
}
3131
}

‎compiler/rustc_lint/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1907,7 +1907,7 @@ impl InvalidAtomicOrdering {
19071907
&& let Some(impl_did) = cx.tcx.impl_of_assoc(m_def_id)
19081908
&& let Some(adt) = cx.tcx.type_of(impl_did).instantiate_identity().ty_adt_def()
19091909
// skip extension traits, only lint functions from the standard library
1910-
&& cx.tcx.trait_id_of_impl(impl_did).is_none()
1910+
&& !cx.tcx.impl_is_of_trait(impl_did)
19111911
&& let parent = cx.tcx.parent(adt.did())
19121912
&& cx.tcx.is_diagnostic_item(sym::atomic_mod, parent)
19131913
&& ATOMIC_TYPES.contains(&cx.tcx.item_name(adt.did()))

‎compiler/rustc_middle/src/middle/privacy.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ impl EffectiveVisibilities {
183183
let is_impl = matches!(tcx.def_kind(def_id), DefKind::Impl { .. });
184184
let is_associated_item_in_trait_impl = tcx
185185
.impl_of_assoc(def_id.to_def_id())
186-
.and_then(|impl_id| tcx.trait_id_of_impl(impl_id))
187-
.is_some();
186+
.is_some_and(|impl_id| tcx.impl_is_of_trait(impl_id));
188187
if !is_impl && !is_associated_item_in_trait_impl {
189188
let nominal_vis = tcx.visibility(def_id);
190189
if !nominal_vis.is_at_least(ev.reachable, tcx) {

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,7 @@ impl<'tcx> TyCtxt<'tcx> {
22632263
/// Checks if the bound region is in Impl Item.
22642264
pub fn is_bound_region_in_impl_item(self, suitable_region_binding_scope: LocalDefId) -> bool {
22652265
let container_id = self.parent(suitable_region_binding_scope.to_def_id());
2266-
if self.impl_trait_ref(container_id).is_some() {
2266+
if self.impl_is_of_trait(container_id) {
22672267
// For now, we do not try to target impls of traits. This is
22682268
// because this message is going to suggest that the user
22692269
// change the fn signature, but they may not be free to do so,

‎compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,14 @@ impl<'tcx> TyCtxt<'tcx> {
20092009
self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity)
20102010
}
20112011

2012+
pub fn impl_is_of_trait(self, def_id: impl IntoQueryParam<DefId>) -> bool {
2013+
let def_id = def_id.into_query_param();
2014+
let DefKind::Impl { of_trait } = self.def_kind(def_id) else {
2015+
panic!("expected Impl for {def_id:?}");
2016+
};
2017+
of_trait
2018+
}
2019+
20122020
/// Given an `impl_id`, return the trait it implements.
20132021
/// Return `None` if this is an inherent impl.
20142022
pub fn impl_trait_ref(

‎compiler/rustc_passes/src/dead.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl<'tcx> MarkSymbolVisitor<'tcx> {
436436
}
437437
Node::ImplItem(impl_item) => {
438438
let item = self.tcx.local_parent(impl_item.owner_id.def_id);
439-
if self.tcx.impl_trait_ref(item).is_none() {
439+
if !self.tcx.impl_is_of_trait(item) {
440440
//// If it's a type whose items are live, then it's live, too.
441441
//// This is done to handle the case where, for example, the static
442442
//// method of a private type is used, but the type itself is never

0 commit comments

Comments
(0)

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