Skip to content

Commit f5fb745

Browse files
committed
Make Iterator a lang item
1 parent 4c11e0e commit f5fb745

File tree

22 files changed

+26
-22
lines changed

22 files changed

+26
-22
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
@@ -1294,7 +1294,7 @@ fn suggest_impl_trait<'tcx>(
12941294

12951295
for (trait_def_id, assoc_item_def_id, formatter) in [
12961296
(
1297-
tcx.get_diagnostic_item(sym::Iterator),
1297+
tcx.lang_items().iterator_trait(),
12981298
tcx.get_diagnostic_item(sym::IteratorItem),
12991299
format_as_assoc,
13001300
),

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,9 @@ fn analysis(tcx: TyCtxt<'_>, (): ()) -> Result<()> {
852852
// This check has to be run after all lints are done processing. We don't
853853
// define a lint filter, as all lint checks should have finished at this point.
854854
sess.time("check_lint_expectations", || tcx.ensure().check_expectations(None));
855+
856+
// Make sure we check for diagnostic item conflicts between different crates.
857+
let _ = tcx.all_diagnostic_items(());
855858
});
856859

857860
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_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
@@ -1522,7 +1522,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
15221522
"expected `{self_ty}` to be a future that resolves to `{expected_ty}`, but it \
15231523
resolves to `{normalized_ty}`"
15241524
))
1525-
} else if Some(trait_def_id) == self.tcx.get_diagnostic_item(sym::Iterator) {
1525+
} else if Some(trait_def_id) == self.tcx.lang_items().iterator_trait() {
15261526
Some(format!(
15271527
"expected `{self_ty}` to be an iterator that yields `{expected_ty}`, but it \
15281528
yields `{normalized_ty}`"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
6969
message = "`{Self}` is not an iterator"
7070
)]
7171
#[doc(notable_trait)]
72-
#[rustc_diagnostic_item = "Iterator"]
72+
#[cfg_attr(not(bootstrap), lang = "iterator")]
7373
#[must_use = "iterators are lazy and do nothing unless consumed"]
7474
pub trait Iterator {
7575
/// The type of the elements being iterated over.

src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
118118
if let Some(parent) = get_parent_expr(cx, e);
119119
if let ExprKind::MethodCall(_, self_arg, _, _) = &parent.kind;
120120
let caller = cx.typeck_results().expr_ty(self_arg);
121-
if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
121+
if let Some(iter_id) = cx.tcx.lang_items().iterator_trait();
122122
if implements_trait(cx, caller, iter_id, &[]);
123123
then {
124124
return ControlFlow::Continue(Descend::No);

src/tools/clippy/clippy_lints/src/copy_iterator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyIterator {
4646
let ty = cx.tcx.type_of(item.owner_id).instantiate_identity();
4747
if is_copy(cx, ty);
4848
if let Some(trait_id) = trait_ref.trait_def_id();
49-
if cx.tcx.is_diagnostic_item(sym::Iterator, trait_id);
49+
if cx.tcx.lang_items().iterator_trait() == (trait_id);
5050
then {
5151
span_lint_and_note(
5252
cx,

0 commit comments

Comments
 (0)