We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c17b2dc commit ca50737Copy full SHA for ca50737
compiler/rustc_hir_analysis/src/check/wfcheck.rs
@@ -245,7 +245,7 @@ pub(super) fn check_item<'tcx>(
245
// won't be allowed unless there's an *explicit* implementation of `Send`
246
// for `T`
247
hir::ItemKind::Impl(ref impl_) => {
248
- crate::impl_wf_check::check_impl_wf(tcx, def_id)?;
+ crate::impl_wf_check::check_impl_wf(tcx, def_id, impl_.of_trait.is_some())?;
249
let mut res = Ok(());
250
if let Some(of_trait) = impl_.of_trait {
251
let header = tcx.impl_trait_header(def_id).unwrap();
compiler/rustc_hir_analysis/src/collect/predicates_of.rs
@@ -350,9 +350,12 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
350
// before uses of `U`. This avoids false ambiguity errors
351
// in trait checking. See `setup_constraining_predicates`
352
// for details.
353
- if let Node::Item(&Item { kind: ItemKind::Impl { .. }, .. }) = node {
+ if let Node::Item(&Item { kind: ItemKind::Impl(impl_), .. }) = node {
354
let self_ty = tcx.type_of(def_id).instantiate_identity();
355
- let trait_ref = tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::instantiate_identity);
+ let trait_ref = impl_
356
+ .of_trait
357
+ .is_some()
358
+ .then(|| tcx.impl_trait_ref(def_id).unwrap().instantiate_identity());
359
cgp::setup_constraining_predicates(
360
tcx,
361
&mut predicates,
@@ -460,11 +463,12 @@ fn const_evaluatable_predicates_of<'tcx>(
460
463
}
461
464
462
465
if let hir::Node::Item(item) = node
- && let hir::ItemKind::Impl(_) = item.kind
466
+ && let hir::ItemKind::Impl(impl_) = item.kind
467
{
- if let Some(of_trait) = tcx.impl_trait_ref(def_id) {
468
+ if impl_.of_trait.is_some() {
469
debug!("visit impl trait_ref");
- of_trait.instantiate_identity().visit_with(&mut collector);
470
+ let trait_ref = tcx.impl_trait_ref(def_id).unwrap();
471
+ trait_ref.instantiate_identity().visit_with(&mut collector);
472
473
474
debug!("visit self_ty");
compiler/rustc_hir_analysis/src/impl_wf_check.rs
@@ -56,16 +56,17 @@ mod min_specialization;
56
pub(crate) fn check_impl_wf(
57
tcx: TyCtxt<'_>,
58
impl_def_id: LocalDefId,
59
+ of_trait: bool,
60
) -> Result<(), ErrorGuaranteed> {
61
debug_assert_matches!(tcx.def_kind(impl_def_id), DefKind::Impl { .. });
62
63
// Check that the args are constrained. We queryfied the check for ty/const params
64
// since unconstrained type/const params cause ICEs in projection, so we want to
65
// detect those specifically and project those to `TyKind::Error`.
66
let mut res = tcx.ensure_ok().enforce_impl_non_lifetime_params_are_constrained(impl_def_id);
- res = res.and(enforce_impl_lifetime_params_are_constrained(tcx, impl_def_id));
67
+ res = res.and(enforce_impl_lifetime_params_are_constrained(tcx, impl_def_id, of_trait));
68
- if tcx.features().min_specialization() {
69
+ if of_trait && tcx.features().min_specialization() {
70
res = res.and(check_min_specialization(tcx, impl_def_id));
71
72
res
@@ -74,6 +75,7 @@ pub(crate) fn check_impl_wf(
74
75
pub(crate) fn enforce_impl_lifetime_params_are_constrained(
76
77
78
79
80
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
81
@@ -83,7 +85,8 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
83
85
84
86
let impl_generics = tcx.generics_of(impl_def_id);
87
let impl_predicates = tcx.predicates_of(impl_def_id);
- let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);
88
+ let impl_trait_ref =
89
+ of_trait.then(|| tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity());
90
91
impl_trait_ref.error_reported()?;
92
compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs
@@ -93,7 +93,7 @@ pub(super) fn check_min_specialization(
93
94
95
fn parent_specialization_node(tcx: TyCtxt<'_>, impl1_def_id: LocalDefId) -> Option<Node> {
96
- let trait_ref = tcx.impl_trait_ref(impl1_def_id)?;
+ let trait_ref = tcx.impl_trait_ref(impl1_def_id).unwrap();
97
let trait_def = tcx.trait_def(trait_ref.skip_binder().def_id);
98
99
let impl2_node = trait_def.ancestors(tcx, impl1_def_id.to_def_id()).ok()?.nth(1)?;
compiler/rustc_hir_typeck/src/method/confirm.rs
@@ -18,8 +18,8 @@ use rustc_middle::ty::adjustment::{
18
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
19
};
20
use rustc_middle::ty::{
21
- self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
22
- TypeVisitableExt, UserArgs,
+ self, AssocContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt,
+ TypeFoldable, TypeVisitableExt, UserArgs,
23
24
use rustc_middle::{bug, span_bug};
25
use rustc_span::{DUMMY_SP, Span};
@@ -272,7 +272,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
272
probe::InherentImplPick => {
273
let impl_def_id = pick.item.container_id(self.tcx);
274
assert!(
275
- self.tcx.impl_trait_ref(impl_def_id).is_none(),
+ matches!(pick.item.container, AssocContainer::InherentImpl),
276
"impl {impl_def_id:?} is not an inherent impl"
277
);
278
self.fresh_args_for_item(self.span, impl_def_id)
compiler/rustc_middle/src/ty/trait_def.rs
@@ -271,9 +271,7 @@ pub(super) fn traits_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
271
pub(super) fn trait_impls_in_crate_provider(tcx: TyCtxt<'_>, _: LocalCrate) -> &[DefId] {
let mut trait_impls = Vec::new();
for id in tcx.hir_free_items() {
- if matches!(tcx.def_kind(id.owner_id), DefKind::Impl { .. })
- && tcx.impl_trait_ref(id.owner_id).is_some()
- {
+ if tcx.def_kind(id.owner_id) == (DefKind::Impl { of_trait: true }) {
trait_impls.push(id.owner_id.to_def_id())
279
compiler/rustc_ty_utils/src/implied_bounds.rs
@@ -42,12 +42,14 @@ fn assumed_wf_types<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx [(Ty<'
42
));
43
tcx.arena.alloc_slice(&assumed_wf_types)
44
45
- DefKind::Impl { .. } => {
+ DefKind::Impl { of_trait } => {
46
// Trait arguments and the self type for trait impls or only the self type for
47
// inherent impls.
48
- let tys = match tcx.impl_trait_ref(def_id) {
49
- Some(trait_ref) => trait_ref.skip_binder().args.types().collect(),
50
- None => vec![tcx.type_of(def_id).instantiate_identity()],
+ let tys = if of_trait {
+ trait_ref.skip_binder().args.types().collect()
51
+ } else {
52
+ vec![tcx.type_of(def_id).instantiate_identity()]
53
54
55
let mut impl_spans = impl_spans(tcx, def_id);
compiler/rustc_ty_utils/src/opaque_types.rs
@@ -62,24 +62,6 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
self.span = old;
- fn parent_impl_trait_ref(&self) -> Option<ty::TraitRef<'tcx>> {
- let parent = self.parent()?;
- if matches!(self.tcx.def_kind(parent), DefKind::Impl { .. }) {
- Some(self.tcx.impl_trait_ref(parent)?.instantiate_identity())
- } else {
- None
- }
73
-
- fn parent(&self) -> Option<LocalDefId> {
- match self.tcx.def_kind(self.item) {
- DefKind::AssocFn | DefKind::AssocTy | DefKind::AssocConst => {
- Some(self.tcx.local_parent(self.item))
- _ => None,
82
#[instrument(level = "trace", skip(self))]
fn collect_taits_declared_in_body(&mut self) {
let body = self.tcx.hir_body_owned_by(self.item).value;
@@ -236,13 +218,13 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector<'tcx> {
236
218
// This avoids having to do normalization of `Self::AssocTy` by only
237
219
// supporting the case of a method defining opaque types from assoc types
238
220
// in the same impl block.
239
- if let Some(impl_trait_ref) = self.parent_impl_trait_ref() {
221
+ if let Some(parent) = self.tcx.trait_impl_of_assoc(self.item.to_def_id()) {
222
223
+ self.tcx.impl_trait_ref(parent).unwrap().instantiate_identity();
240
224
// If the trait ref of the associated item and the impl differs,
241
225
// then we can't use the impl's identity args below, so
242
226
// just skip.
243
227
if alias_ty.trait_ref(self.tcx) == impl_trait_ref {
244
- let parent = self.parent().expect("we should have a parent here");
228
for &assoc in self.tcx.associated_items(parent).in_definition_order() {
229
trace!(?assoc);
230
if assoc.expect_trait_impl() != Ok(alias_ty.def_id) {
0 commit comments