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 a322848

Browse files
committed
Auto merge of #107472 - matthiaskrgr:rollup-s9gn4n7, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #107125 (Add and use expect methods to hir.) - #107172 (Reimplement NormalizeArrayLen based on SsaLocals) - #107177 (Keep all theme-updating logic together) - #107424 (Make Vec::clone_from and slice::clone_into share the same code) - #107455 (use a more descriptive name) - #107465 (`has_allow_dead_code_or_lang_attr` micro refactor) - #107469 (Change turbofish context link to an archive link) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 006ca9b + d79a40d commit a322848

34 files changed

+685
-586
lines changed

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 360 additions & 3 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,8 +3140,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
31403140

31413141
let hir::Node::ImplItem(hir::ImplItem { kind: hir::ImplItemKind::Fn(..), ident, .. }) =
31423142
hir.get(fn_hir_id) else { return None };
3143-
let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(i), .. }) =
3144-
hir.get_parent(fn_hir_id) else { bug!("ImplItem should have Impl parent") };
3143+
let i = hir.get_parent(fn_hir_id).expect_item().expect_impl();
31453144

31463145
let trait_ref = self.instantiate_mono_trait_ref(
31473146
i.of_trait.as_ref()?,

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{
88
use rustc_hir as hir;
99
use rustc_hir::def::{DefKind, Res};
1010
use rustc_hir::intravisit;
11-
use rustc_hir::{GenericParamKind, ImplItemKind,TraitItemKind};
11+
use rustc_hir::{GenericParamKind, ImplItemKind};
1212
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
1313
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1414
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
@@ -918,7 +918,7 @@ fn report_trait_method_mismatch<'tcx>(
918918
// When the `impl` receiver is an arbitrary self type, like `self: Box<Self>`, the
919919
// span points only at the type `Box<Self`>, but we want to cover the whole
920920
// argument pattern and type.
921-
let ImplItemKind::Fn(refsig, body) = tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kindelse{bug!("{impl_m:?} is not a method")};
921+
let (sig, body) = tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
922922
let span = tcx
923923
.hir()
924924
.body_param_names(body)
@@ -1080,12 +1080,12 @@ fn extract_spans_for_error_reporting<'tcx>(
10801080
) -> (Span, Option<Span>) {
10811081
let tcx = infcx.tcx;
10821082
let mut impl_args = {
1083-
let ImplItemKind::Fn(sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kindelse{bug!("{:?} is not a method", impl_m)};
1083+
let (sig, _) = tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
10841084
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
10851085
};
10861086

10871087
let trait_args = trait_m.def_id.as_local().map(|def_id| {
1088-
let TraitItemKind::Fn(sig, _) = &tcx.hir().expect_trait_item(def_id).kindelse{bug!("{:?} is not a TraitItemKind::Fn", trait_m)};
1088+
let (sig, _) = tcx.hir().expect_trait_item(def_id).expect_fn();
10891089
sig.decl.inputs.iter().map(|t| t.span).chain(iter::once(sig.decl.output.span()))
10901090
});
10911091

@@ -1358,7 +1358,7 @@ fn compare_number_of_method_arguments<'tcx>(
13581358
.def_id
13591359
.as_local()
13601360
.and_then(|def_id| {
1361-
let TraitItemKind::Fn(trait_m_sig, _) = &tcx.hir().expect_trait_item(def_id).kindelse{bug!("{:?} is not a method", impl_m)};
1361+
let (trait_m_sig, _) = &tcx.hir().expect_trait_item(def_id).expect_fn();
13621362
let pos = trait_number_args.saturating_sub(1);
13631363
trait_m_sig.decl.inputs.get(pos).map(|arg| {
13641364
if pos == 0 {
@@ -1370,7 +1370,7 @@ fn compare_number_of_method_arguments<'tcx>(
13701370
})
13711371
.or(trait_item_span);
13721372

1373-
let ImplItemKind::Fn(impl_m_sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kindelse{bug!("{:?} is not a method", impl_m)};
1373+
let (impl_m_sig, _) = &tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
13741374
let pos = impl_number_args.saturating_sub(1);
13751375
let impl_span = impl_m_sig
13761376
.decl
@@ -1506,7 +1506,7 @@ fn compare_synthetic_generics<'tcx>(
15061506
let _: Option<_> = try {
15071507
let impl_m = impl_m.def_id.as_local()?;
15081508
let impl_m = tcx.hir().expect_impl_item(impl_m);
1509-
let hir::ImplItemKind::Fn(sig, _) = &impl_m.kindelse{unreachable!()};
1509+
let (sig, _) = impl_m.expect_fn();
15101510
let input_tys = sig.decl.inputs;
15111511

15121512
struct Visitor(Option<Span>, hir::def_id::LocalDefId);
@@ -1704,7 +1704,7 @@ pub(super) fn compare_impl_const_raw(
17041704
);
17051705

17061706
// Locate the Span containing just the type of the offending impl
1707-
let ImplItemKind::Const(ty, _) = tcx.hir().expect_impl_item(impl_const_item_def).kindelse{bug!("{impl_const_item:?} is not a impl const")};
1707+
let (ty, _) = tcx.hir().expect_impl_item(impl_const_item_def).expect_const();
17081708
cause.span = ty.span;
17091709

17101710
let mut diag = struct_span_err!(
@@ -1717,7 +1717,7 @@ pub(super) fn compare_impl_const_raw(
17171717

17181718
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
17191719
// Add a label to the Span containing just the type of the const
1720-
let TraitItemKind::Const(ty, _) = tcx.hir().expect_trait_item(trait_c_def_id).kindelse{bug!("{trait_const_item:?} is not a trait const")};
1720+
let (ty, _) = tcx.hir().expect_trait_item(trait_c_def_id).expect_const();
17211721
ty.span
17221722
});
17231723

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,8 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
10721072
// All field types must be well-formed.
10731073
for field in &variant.fields {
10741074
let field_id = field.did.expect_local();
1075-
let hir::Node::Field(hir::FieldDef { ty: hir_ty, .. }) = tcx.hir().get_by_def_id(field_id)
1076-
else{bug!()};
1075+
let hir::FieldDef { ty: hir_ty, .. } =
1076+
tcx.hir().get_by_def_id(field_id).expect_field();
10771077
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did));
10781078
wfcx.register_wf_obligation(
10791079
hir_ty.span,
@@ -1106,8 +1106,8 @@ fn check_type_defn<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'tcx>, all_sized: b
11061106
{
11071107
let last = idx == variant.fields.len() - 1;
11081108
let field_id = field.did.expect_local();
1109-
let hir::Node::Field(hir::FieldDef { ty: hir_ty, .. }) = tcx.hir().get_by_def_id(field_id)
1110-
else{bug!()};
1109+
let hir::FieldDef { ty: hir_ty, .. } =
1110+
tcx.hir().get_by_def_id(field_id).expect_field();
11111111
let ty = wfcx.normalize(hir_ty.span, None, tcx.type_of(field.did));
11121112
wfcx.register_bound(
11131113
traits::ObligationCause::new(

‎compiler/rustc_hir_analysis/src/check_unused.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) {
2929
if item.span.is_dummy() {
3030
continue;
3131
}
32-
let hir::ItemKind::Use(path, _) = item.kindelse{unreachable!()};
32+
let (path, _) = item.expect_use();
3333
let msg = if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(path.span) {
3434
format!("unused import: `{}`", snippet)
3535
} else {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ fn visit_implementation_of_drop(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
5656
_ => {}
5757
}
5858

59-
let ItemKind::Impl(impl_) = tcx.hir().expect_item(impl_did).kindelse{bug!("expected Drop impl item")};
59+
let impl_ = tcx.hir().expect_item(impl_did).expect_impl();
6060

6161
tcx.sess.emit_err(DropImplOnWrongItem { span: impl_.self_ty.span });
6262
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
44
use rustc_errors::struct_span_err;
55
use rustc_hir as hir;
6-
use rustc_hir::def::DefKind;
76
use rustc_hir::Unsafety;
87
use rustc_middle::ty::TyCtxt;
98
use rustc_span::def_id::LocalDefId;
109

1110
pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
12-
debug_assert!(matches!(tcx.def_kind(def_id), DefKind::Impl));
1311
let item = tcx.hir().expect_item(def_id);
14-
let hir::ItemKind::Impl(impl_) = item.kindelse{bug!()};
12+
let impl_ = item.expect_impl();
1513

1614
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
1715
let trait_ref = trait_ref.subst_identity();

‎compiler/rustc_hir_analysis/src/collect.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1348,8 +1348,7 @@ fn suggest_impl_trait<'tcx>(
13481348

13491349
fn impl_trait_ref(tcx: TyCtxt<'_>, def_id: DefId) -> Option<ty::EarlyBinder<ty::TraitRef<'_>>> {
13501350
let icx = ItemCtxt::new(tcx, def_id);
1351-
let item = tcx.hir().expect_item(def_id.expect_local());
1352-
let hir::ItemKind::Impl(impl_) = item.kind else { bug!() };
1351+
let impl_ = tcx.hir().expect_item(def_id.expect_local()).expect_impl();
13531352
impl_
13541353
.of_trait
13551354
.as_ref()

‎compiler/rustc_middle/src/mir/mono.rs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,16 +318,19 @@ impl<'tcx> CodegenUnit<'tcx> {
318318
base_n::encode(hash, base_n::CASE_INSENSITIVE)
319319
}
320320

321-
pub fn estimate_size(&mut self, tcx: TyCtxt<'tcx>) {
321+
pub fn create_size_estimate(&mut self, tcx: TyCtxt<'tcx>) {
322322
// Estimate the size of a codegen unit as (approximately) the number of MIR
323323
// statements it corresponds to.
324324
self.size_estimate = Some(self.items.keys().map(|mi| mi.size_estimate(tcx)).sum());
325325
}
326326

327327
#[inline]
328+
/// Should only be called if [`create_size_estimate`] has previously been called.
329+
///
330+
/// [`create_size_estimate`]: Self::create_size_estimate
328331
pub fn size_estimate(&self) -> usize {
329-
// Should only be called if `estimate_size` has previously been called.
330-
self.size_estimate.expect("estimate_size must be called before getting a size_estimate")
332+
self.size_estimate
333+
.expect("create_size_estimate must be called before getting a size_estimate")
331334
}
332335

333336
pub fn modify_size_estimate(&mut self, delta: usize) {

‎compiler/rustc_mir_transform/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
548548
&[
549549
&reveal_all::RevealAll, // has to be done before inlining, since inlined code is in RevealAll mode.
550550
&lower_slice_len::LowerSliceLenCalls, // has to be done before inlining, otherwise actual call will be almost always inlined. Also simple, so can just do first
551-
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
552551
&unreachable_prop::UnreachablePropagation,
553552
&uninhabited_enum_branching::UninhabitedEnumBranching,
554553
&o1(simplify::SimplifyCfg::new("after-uninhabited-enum-branching")),
555554
&inline::Inline,
556555
&remove_storage_markers::RemoveStorageMarkers,
557556
&remove_zsts::RemoveZsts,
557+
&normalize_array_len::NormalizeArrayLen, // has to run after `slice::len` lowering
558558
&const_goto::ConstGoto,
559559
&remove_unneeded_drops::RemoveUnneededDrops,
560560
&sroa::ScalarReplacementOfAggregates,

0 commit comments

Comments
(0)

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