Skip to content

Commit 9a3f296

Browse files
committed
Make Iterator a lang item
1 parent b66fe58 commit 9a3f296

File tree

9 files changed

+14
-6
lines changed

9 files changed

+14
-6
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
14141414
&& let Some(loop_span) = finder.loop_span
14151415
&& let Some(def_id) = typeck_results.type_dependent_def_id(body_expr.hir_id)
14161416
&& let Some(trait_did) = tcx.trait_of_item(def_id)
1417-
&& tcx.is_diagnostic_item(sym::Iterator, trait_did)
1417+
&& tcx.lang_items().iterator_trait() == Some(trait_did)
14181418
{
14191419
if let Some(loop_bind) = finder.loop_bind {
14201420
err.note(format!(
@@ -2457,7 +2457,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
24572457
let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
24582458

24592459
// to avoid panics
2460-
if let Some(iter_trait) = tcx.get_diagnostic_item(sym::Iterator)
2460+
if let Some(iter_trait) = tcx.lang_items().iterator_trait()
24612461
&& self
24622462
.infcx
24632463
.type_implements_trait(iter_trait, [return_ty], self.param_env)

compiler/rustc_hir/src/lang_items.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ language_item_table! {
210210

211211
FnOnceOutput, sym::fn_once_output, fn_once_output, Target::AssocTy, GenericRequirement::None;
212212

213+
Iterator, sym::iterator, iterator_trait, Target::Trait, GenericRequirement::Exact(0);
213214
Future, sym::future_trait, future_trait, Target::Trait, GenericRequirement::Exact(0);
214215
CoroutineState, sym::coroutine_state, gen_state, Target::Enum, GenericRequirement::None;
215216
Coroutine, sym::coroutine, gen_trait, Target::Trait, GenericRequirement::Minimum(1);

compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1296,7 +1296,7 @@ fn suggest_impl_trait<'tcx>(
12961296

12971297
for (trait_def_id, assoc_item_def_id, formatter) in [
12981298
(
1299-
tcx.get_diagnostic_item(sym::Iterator),
1299+
tcx.lang_items().iterator_trait(),
13001300
tcx.get_diagnostic_item(sym::IteratorItem),
13011301
format_as_assoc,
13021302
),

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
549549
} else {
550550
err.span_label(span, msg);
551551
}
552-
if let Some(iterator_trait) = self.tcx.get_diagnostic_item(sym::Iterator) {
552+
if let Some(iterator_trait) = self.tcx.lang_items().iterator_trait() {
553553
let iterator_trait = self.tcx.def_path_str(iterator_trait);
554554
err.note(format!(
555555
"`count` is defined on `{iterator_trait}`, which `{rcvr_ty}` does not implement"

compiler/rustc_interface/src/passes.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,11 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
856856
// This check has to be run after all lints are done processing. We don't
857857
// define a lint filter, as all lint checks should have finished at this point.
858858
sess.time("check_lint_expectations", || tcx.ensure().check_expectations(None));
859+
860+
// This query is only invoked normally if a diagnostic is emitted that needs any
861+
// diagnostic item. If the crate compiles without checking any diagnostic items,
862+
// we will fail to emit overlap diagnostics. Thus we invoke it here unconditionally.
863+
let _ = tcx.all_diagnostic_items(());
859864
});
860865

861866
if sess.opts.unstable_opts.print_vtable_sizes {

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations {
685685

686686
// We shouldn't recommend implementing `Copy` on stateful things,
687687
// such as iterators.
688-
if let Some(iter_trait) = cx.tcx.get_diagnostic_item(sym::Iterator)
688+
if let Some(iter_trait) = cx.tcx.lang_items().iterator_trait()
689689
&& cx
690690
.tcx
691691
.infer_ctxt()

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ symbols! {
910910
iter,
911911
iter_mut,
912912
iter_repeat,
913+
iterator,
913914
iterator_collect_fn,
914915
kcfi,
915916
keyword,

compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15171517
"expected `{self_ty}` to be a future that resolves to `{expected_ty}`, but it \
15181518
resolves to `{normalized_ty}`"
15191519
))
1520-
} else if Some(trait_def_id) == self.tcx.get_diagnostic_item(sym::Iterator) {
1520+
} else if Some(trait_def_id) == self.tcx.lang_items().iterator_trait() {
15211521
Some(format!(
15221522
"expected `{self_ty}` to be an iterator that yields `{expected_ty}`, but it \
15231523
yields `{normalized_ty}`"

library/core/src/iter/traits/iterator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
6969
message = "`{Self}` is not an iterator"
7070
)]
7171
#[doc(notable_trait)]
72+
#[cfg_attr(not(bootstrap), lang = "iterator")]
7273
#[rustc_diagnostic_item = "Iterator"]
7374
#[must_use = "iterators are lazy and do nothing unless consumed"]
7475
pub trait Iterator {

0 commit comments

Comments
 (0)