Skip to content

Commit bb201b5

Browse files
authored
Rollup merge of rust-lang#103875 - oli-obk:ast_conv_simplification, r=spastorino
Simplify astconv item def id handling
2 parents 5784a03 + ecea616 commit bb201b5

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

compiler/rustc_hir_analysis/src/astconv/errors.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
177177
.all_traits()
178178
.filter(|trait_def_id| {
179179
let viz = self.tcx().visibility(*trait_def_id);
180-
if let Some(def_id) = self.item_def_id() {
181-
viz.is_accessible_from(def_id, self.tcx())
182-
} else {
183-
viz.is_visible_locally()
184-
}
180+
let def_id = self.item_def_id();
181+
viz.is_accessible_from(def_id, self.tcx())
185182
})
186183
.collect();
187184

compiler/rustc_hir_analysis/src/astconv/mod.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct PathSeg(pub DefId, pub usize);
5454
pub trait AstConv<'tcx> {
5555
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
5656

57-
fn item_def_id(&self) -> Option<DefId>;
57+
fn item_def_id(&self) -> DefId;
5858

5959
/// Returns predicates in scope of the form `X: Foo<T>`, where `X`
6060
/// is a type parameter `X` with the given id `def_id` and T
@@ -2082,17 +2082,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20822082

20832083
debug!("qpath_to_ty: self.item_def_id()={:?}", def_id);
20842084

2085-
let parent_def_id = def_id
2086-
.and_then(|def_id| {
2087-
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
2088-
})
2085+
let parent_def_id = def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
20892086
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
20902087

20912088
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
20922089

20932090
// If the trait in segment is the same as the trait defining the item,
20942091
// use the `<Self as ..>` syntax in the error.
2095-
let is_part_of_self_trait_constraints = def_id == Some(trait_def_id);
2092+
let is_part_of_self_trait_constraints = def_id == trait_def_id;
20962093
let is_part_of_fn_in_self_trait = parent_def_id == Some(trait_def_id);
20972094

20982095
let type_name = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait {

compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
379379
self.tcx
380380
}
381381

382-
fn item_def_id(&self) -> Option<DefId> {
383-
Some(self.item_def_id)
382+
fn item_def_id(&self) -> DefId {
383+
self.item_def_id
384384
}
385385

386386
fn get_type_parameter_bounds(

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
194194
self.tcx
195195
}
196196

197-
fn item_def_id(&self) -> Option<DefId> {
198-
None
197+
fn item_def_id(&self) -> DefId {
198+
self.body_id.owner.to_def_id()
199199
}
200200

201201
fn get_type_parameter_bounds(

0 commit comments

Comments
 (0)