Skip to content

Commit b0521fe

Browse files
authored
Rollup merge of #117173 - oli-obk:gen_fn_split2, r=compiler-errors
Make `Iterator` a lang item r? `@compiler-errors` pulled out of #116447 We're doing this change on its own, because iterator was the one diagnostic item that was load bearing on us correctly emitting errors about `diagnostic_item` mis-uses. It was used in some diagnostics as an early abort, before the actual checks of the diagnostic, so effectively the compiler was *unconditionally* checking for the iterator diagnostic item, even if it didn't emit any diagnostics. Changing those uses to use the lang item, caused us not to invoke the `all_diagnostic_items` query anymore, which then caused us to miss some issues around diagnostic items until they were actually used. The reason we keep the diagnostic item around is that clippy uses it a lot and having `Iterator` be a lang item and a diagnostic item at the same time doesn't cost us anything, but makes clippy's internal code simpler
2 parents beba522 + 268ec72 commit b0521fe

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

compiler/rustc_hir/src/lang_items.rs

+1
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_interface/src/passes.rs

+5
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_span/src/symbol.rs

+1
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,

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

+1
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)