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 d04a529

Browse files
Remove Option from impl_trait_header
1 parent 72bf112 commit d04a529

File tree

24 files changed

+64
-64
lines changed

24 files changed

+64
-64
lines changed

‎compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::TyCtxt;
77
fn parent_impl_or_trait_constness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Constness {
88
let parent_id = tcx.local_parent(def_id);
99
match tcx.def_kind(parent_id) {
10-
DefKind::Impl { of_trait: true } => tcx.impl_trait_header(parent_id).unwrap().constness,
10+
DefKind::Impl { of_trait: true } => tcx.impl_trait_header(parent_id).constness,
1111
DefKind::Trait => {
1212
if tcx.is_const_trait(parent_id.into()) {
1313
hir::Constness::Const

‎compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,10 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
806806
DefKind::Impl { of_trait } => {
807807
tcx.ensure_ok().generics_of(def_id);
808808
tcx.ensure_ok().type_of(def_id);
809-
tcx.ensure_ok().impl_trait_header(def_id);
810809
tcx.ensure_ok().predicates_of(def_id);
811810
tcx.ensure_ok().associated_items(def_id);
812-
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
811+
if of_trait {
812+
let impl_trait_header = tcx.impl_trait_header(def_id);
813813
res = res.and(
814814
tcx.ensure_ok()
815815
.coherent_trait(impl_trait_header.trait_ref.instantiate_identity().def_id),

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ pub(super) fn check_item<'tcx>(
248248
crate::impl_wf_check::check_impl_wf(tcx, def_id)?;
249249
let mut res = Ok(());
250250
if impl_.of_trait.is_some() {
251-
let header = tcx.impl_trait_header(def_id).unwrap();
251+
let header = tcx.impl_trait_header(def_id);
252252
let is_auto = tcx.trait_is_auto(header.trait_ref.skip_binder().def_id);
253253
if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) {
254254
let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span);

‎compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
165165
let mut res = tcx.ensure_ok().specialization_graph_of(def_id);
166166

167167
for &impl_def_id in impls {
168-
let impl_header = tcx.impl_trait_header(impl_def_id).unwrap();
168+
let impl_header = tcx.impl_trait_header(impl_def_id);
169169
let trait_ref = impl_header.trait_ref.instantiate_identity();
170170
let trait_def = tcx.trait_def(trait_ref.def_id);
171171

‎compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1291,24 +1291,26 @@ pub fn suggest_impl_trait<'tcx>(
12911291
None
12921292
}
12931293

1294-
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTraitHeader<'_>> {
1294+
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ImplTraitHeader<'_> {
12951295
let icx = ItemCtxt::new(tcx, def_id);
12961296
let item = tcx.hir_expect_item(def_id);
12971297
let impl_ = item.expect_impl();
1298-
impl_.of_trait.as_ref().map(|ast_trait_ref| {
1299-
let selfty = tcx.type_of(def_id).instantiate_identity();
1298+
let ast_trait_ref = impl_
1299+
.of_trait
1300+
.as_ref()
1301+
.unwrap_or_else(|| panic!("expected impl trait, found inherent impl on {def_id:?}"));
1302+
let selfty = tcx.type_of(def_id).instantiate_identity();
13001303

1301-
check_impl_constness(tcx, impl_.constness, ast_trait_ref);
1304+
check_impl_constness(tcx, impl_.constness, ast_trait_ref);
13021305

1303-
let trait_ref = icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty);
1306+
let trait_ref = icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty);
13041307

1305-
ty::ImplTraitHeader {
1306-
trait_ref: ty::EarlyBinder::bind(trait_ref),
1307-
safety: impl_.safety,
1308-
polarity: polarity_of_impl(tcx, def_id, impl_, item.span),
1309-
constness: impl_.constness,
1310-
}
1311-
})
1308+
ty::ImplTraitHeader {
1309+
trait_ref: ty::EarlyBinder::bind(trait_ref),
1310+
safety: impl_.safety,
1311+
polarity: polarity_of_impl(tcx, def_id, impl_, item.span),
1312+
constness: impl_.constness,
1313+
}
13121314
}
13131315

13141316
fn check_impl_constness(

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -496,17 +496,15 @@ pub(super) fn impl_super_outlives(
496496
tcx: TyCtxt<'_>,
497497
def_id: DefId,
498498
) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
499-
tcx.impl_trait_header(def_id).expect("expected an impl of trait").trait_ref.map_bound(
500-
|trait_ref| {
501-
let clause: ty::Clause<'_> = trait_ref.upcast(tcx);
502-
tcx.mk_clauses_from_iter(util::elaborate(tcx, [clause]).filter(|clause| {
503-
matches!(
504-
clause.kind().skip_binder(),
505-
ty::ClauseKind::TypeOutlives(_) | ty::ClauseKind::RegionOutlives(_)
506-
)
507-
}))
508-
},
509-
)
499+
tcx.impl_trait_header(def_id).trait_ref.map_bound(|trait_ref| {
500+
let clause: ty::Clause<'_> = trait_ref.upcast(tcx);
501+
tcx.mk_clauses_from_iter(util::elaborate(tcx, [clause]).filter(|clause| {
502+
matches!(
503+
clause.kind().skip_binder(),
504+
ty::ClauseKind::TypeOutlives(_) | ty::ClauseKind::RegionOutlives(_)
505+
)
506+
}))
507+
})
510508
}
511509

512510
struct AssocTyToOpaque<'tcx> {

‎compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,7 @@ fn create_generic_args<'tcx>(
272272
(FnKind::AssocTraitImpl, FnKind::AssocTrait) => {
273273
let callee_generics = tcx.generics_of(sig_id);
274274
let parent = tcx.parent(def_id.into());
275-
let parent_args =
276-
tcx.impl_trait_header(parent).unwrap().trait_ref.instantiate_identity().args;
275+
let parent_args = tcx.impl_trait_header(parent).trait_ref.instantiate_identity().args;
277276

278277
let trait_args = ty::GenericArgs::identity_for_item(tcx, sig_id);
279278
let method_args = tcx.mk_args(&trait_args[callee_generics.parent_count..]);

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
473473
} else {
474474
// Find all the types that have an `impl` for the trait.
475475
tcx.all_impls(trait_def_id)
476-
.filter_map(|impl_def_id| tcx.impl_trait_header(impl_def_id))
476+
.map(|impl_def_id| tcx.impl_trait_header(impl_def_id))
477477
.filter(|header| {
478478
// Consider only accessible traits
479479
tcx.visibility(trait_def_id).is_accessible_from(self.item_def_id(), tcx)

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
16061606
.is_accessible_from(self.item_def_id(), tcx)
16071607
&& tcx.all_impls(*trait_def_id)
16081608
.any(|impl_def_id| {
1609-
let header = tcx.impl_trait_header(impl_def_id).unwrap();
1609+
let header = tcx.impl_trait_header(impl_def_id);
16101610
let trait_ref = header.trait_ref.instantiate(
16111611
tcx,
16121612
infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18321832
.tcx
18331833
.all_impls(def_id)
18341834
.filter(|&impl_def_id| {
1835-
let header = self.tcx.impl_trait_header(impl_def_id).unwrap();
1835+
let header = self.tcx.impl_trait_header(impl_def_id);
18361836
let trait_ref = header.trait_ref.instantiate(
18371837
self.tcx,
18381838
self.infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
@@ -4122,11 +4122,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
41224122
if self
41234123
.tcx
41244124
.all_impls(candidate.def_id)
4125-
.map(|imp_did| {
4126-
self.tcx.impl_trait_header(imp_did).expect(
4127-
"inherent impls can't be candidates, only trait impls can be",
4128-
)
4129-
})
4125+
.map(|imp_did| self.tcx.impl_trait_header(imp_did))
41304126
.filter(|header| header.polarity != ty::ImplPolarity::Positive)
41314127
.any(|header| {
41324128
let imp = header.trait_ref.instantiate_identity();

0 commit comments

Comments
(0)

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