about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-04-09 05:07:38 +0000
committerbors <bors@rust-lang.org>2024-04-09 05:07:38 +0000
commit86b603cd792b3f6172ba4f676d7b586c1af7630a (patch)
tree570bd620ca9c25b27f3992649864340f5d525d79 /src
parentbd12986fd6659a3091cff7694b8225374f4a26fe (diff)
parent9ea1063a12866d8e1d8247b1d0f677fa89e7bdbf (diff)
downloadrust-86b603cd792b3f6172ba4f676d7b586c1af7630a.tar.gz
rust-86b603cd792b3f6172ba4f676d7b586c1af7630a.zip
Auto merge of #123663 - matthiaskrgr:rollup-1qnj9j3, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #122768 (Use the more informative generic type inference failure error on method calls on raw pointers)
 - #123620 (sanitizers: Create the rustc_sanitizers crate)
 - #123624 ([rustdoc] [GUI tests] Make theme switching closer to reality)
 - #123636 (Update books)
 - #123647 (rustdoc: slightly clean up the synthesis of blanket impls)
 - #123648 (Avoid ICEing without the pattern_types feature gate)
 - #123649 (KCFI: Use legal charset in shim encoding)
 - #123652 (Fix UI tests with dist-vendored dependencies)
 - #123655 (Remove unimplemented!() from BinOp::ty() function)

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src')
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile22
-rw-r--r--src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version2
m---------src/doc/book0
m---------src/doc/edition-guide0
m---------src/doc/embedded-book0
m---------src/doc/nomicon0
m---------src/doc/reference0
m---------src/doc/rust-by-example0
m---------src/doc/rustc-dev-guide0
-rw-r--r--src/librustdoc/clean/blanket_impl.rs229
-rw-r--r--src/librustdoc/clean/mod.rs6
-rw-r--r--src/librustdoc/clean/utils.rs9
-rw-r--r--src/librustdoc/passes/collect_trait_impls.rs8
-rw-r--r--src/tools/compiletest/src/runtest.rs5
-rw-r--r--src/tools/tidy/src/error_codes.rs45
15 files changed, 168 insertions, 158 deletions
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile b/src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
index 6f720569898..a3e8f6176a3 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/Dockerfile
@@ -78,16 +78,6 @@ ENV PATH="$NODE_FOLDER:${PATH}"
 
 COPY host-x86_64/x86_64-gnu-tools/browser-ui-test.version /tmp/
 
-# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
-# to create a new folder. For reference:
-# https://github.com/puppeteer/puppeteer/issues/375
-#
-# We also specify the version in case we need to update it to go around cache limitations.
-#
-# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
-# the local version of the package is different than the one used by the CI.
-RUN npm install -g browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true
-
 ENV RUST_CONFIGURE_ARGS \
   --build=x86_64-unknown-linux-gnu \
   --save-toolstates=/tmp/toolstate/toolstates.json \
@@ -100,6 +90,14 @@ COPY host-x86_64/dist-x86_64-linux/build-gccjit.sh /scripts/
 
 RUN /scripts/build-gccjit.sh /scripts
 
+# For now, we need to use `--unsafe-perm=true` to go around an issue when npm tries
+# to create a new folder. For reference:
+# https://github.com/puppeteer/puppeteer/issues/375
+#
+# We also specify the version in case we need to update it to go around cache limitations.
+#
+# The `browser-ui-test.version` file is also used by bootstrap to emit warnings in case
+# the local version of the package is different than the one used by the CI.
 ENV SCRIPT /tmp/checktools.sh ../x.py && \
-  NODE_PATH=`npm root -g` python3 ../x.py test tests/rustdoc-gui --stage 2 \
-    --test-args "'--no-sandbox --jobs 1'"
+  npm install browser-ui-test@$(head -n 1 /tmp/browser-ui-test.version) --unsafe-perm=true && \
+  python3 ../x.py test tests/rustdoc-gui --stage 2 --test-args "'--no-sandbox --jobs 1'"
diff --git a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
index 14a8c245756..50c2e5e29f0 100644
--- a/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
+++ b/src/ci/docker/host-x86_64/x86_64-gnu-tools/browser-ui-test.version
@@ -1 +1 @@
-0.17.1
\ No newline at end of file
+0.17.2
\ No newline at end of file
diff --git a/src/doc/book b/src/doc/book
-Subproject 19c40bfd2d57641d962f3119a1c343355f1b3c5
+Subproject 3131aa4642c627a24f523c82566b94a7d920f68
diff --git a/src/doc/edition-guide b/src/doc/edition-guide
-Subproject 98b33e9a441457b0a491fe1be90e7de64eafc3e
+Subproject eb3eb80e106d03250c1fb7c5666b1c8c5967286
diff --git a/src/doc/embedded-book b/src/doc/embedded-book
-Subproject 2e95fc2fd31d669947e993aa07ef10dc9828bee
+Subproject aa7d4b0b4653ddb47cb1de2036d090ec2ba9dab
diff --git a/src/doc/nomicon b/src/doc/nomicon
-Subproject 6bc2415218d4dd0cb01433d8320f5ccf79c343a
+Subproject 0d5f88475fe285affa6dbbc806e9e44d730797c
diff --git a/src/doc/reference b/src/doc/reference
-Subproject 984b36eca4b9293df04d5ba4eb5c4f77db0f51d
+Subproject 55694913b1301cc809f9bf4a1ad1b3d6920efbd
diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example
-Subproject 7601e0c5ad29d5bd3b518700ea63fddfff5915a
+Subproject 60d34b5fd33db1346f9aabfc0c9d0bda6c8e42b
diff --git a/src/doc/rustc-dev-guide b/src/doc/rustc-dev-guide
-Subproject ffa246b7fd95a96e1cd54883e613aed42c32547
+Subproject b77a34bd46399687b4ce6a17198e9f316c98879
diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs
index 72d4cc7c465..8ed6ee014f3 100644
--- a/src/librustdoc/clean/blanket_impl.rs
+++ b/src/librustdoc/clean/blanket_impl.rs
@@ -1,141 +1,130 @@
-use crate::rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
 use rustc_hir as hir;
 use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TyCtxtInferExt};
 use rustc_infer::traits;
-use rustc_middle::ty::ToPredicate;
+use rustc_middle::ty::{self, ToPredicate};
+use rustc_span::def_id::DefId;
 use rustc_span::DUMMY_SP;
+use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
 
-use super::*;
+use thin_vec::ThinVec;
 
-pub(crate) struct BlanketImplFinder<'a, 'tcx> {
-    pub(crate) cx: &'a mut core::DocContext<'tcx>,
-}
+use crate::clean;
+use crate::clean::{
+    clean_middle_assoc_item, clean_middle_ty, clean_trait_ref_with_bindings, clean_ty_generics,
+};
+use crate::core::DocContext;
+
+#[instrument(level = "debug", skip(cx))]
+pub(crate) fn synthesize_blanket_impls(
+    cx: &mut DocContext<'_>,
+    item_def_id: DefId,
+) -> Vec<clean::Item> {
+    let tcx = cx.tcx;
+    let ty = tcx.type_of(item_def_id);
 
-impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
-    pub(crate) fn get_blanket_impls(&mut self, item_def_id: DefId) -> Vec<Item> {
-        let cx = &mut self.cx;
-        let ty = cx.tcx.type_of(item_def_id);
+    let mut blanket_impls = Vec::new();
+    for trait_def_id in tcx.all_traits() {
+        if !cx.cache.effective_visibilities.is_reachable(tcx, trait_def_id)
+            || cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
+        {
+            continue;
+        }
+        // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls
+        let trait_impls = tcx.trait_impls_of(trait_def_id);
+        'blanket_impls: for &impl_def_id in trait_impls.blanket_impls() {
+            trace!("considering impl `{impl_def_id:?}` for trait `{trait_def_id:?}`");
 
-        trace!("get_blanket_impls({ty:?})");
-        let mut impls = Vec::new();
-        for trait_def_id in cx.tcx.all_traits() {
-            if !cx.cache.effective_visibilities.is_reachable(cx.tcx, trait_def_id)
-                || cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
-            {
+            let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
+            if !matches!(trait_ref.skip_binder().self_ty().kind(), ty::Param(_)) {
                 continue;
             }
-            // NOTE: doesn't use `for_each_relevant_impl` to avoid looking at anything besides blanket impls
-            let trait_impls = cx.tcx.trait_impls_of(trait_def_id);
-            'blanket_impls: for &impl_def_id in trait_impls.blanket_impls() {
-                trace!(
-                    "get_blanket_impls: Considering impl for trait '{:?}' {:?}",
-                    trait_def_id,
-                    impl_def_id
-                );
-                let trait_ref = cx.tcx.impl_trait_ref(impl_def_id).unwrap();
-                if !matches!(trait_ref.skip_binder().self_ty().kind(), ty::Param(_)) {
-                    continue;
-                }
-                let infcx = cx.tcx.infer_ctxt().build();
-                let args = infcx.fresh_args_for_item(DUMMY_SP, item_def_id);
-                let impl_ty = ty.instantiate(infcx.tcx, args);
-                let param_env = ty::ParamEnv::empty();
+            let infcx = tcx.infer_ctxt().build();
+            let args = infcx.fresh_args_for_item(DUMMY_SP, item_def_id);
+            let impl_ty = ty.instantiate(tcx, args);
+            let param_env = ty::ParamEnv::empty();
 
-                let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
-                let impl_trait_ref = trait_ref.instantiate(infcx.tcx, impl_args);
+            let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
+            let impl_trait_ref = trait_ref.instantiate(tcx, impl_args);
 
-                // Require the type the impl is implemented on to match
-                // our type, and ignore the impl if there was a mismatch.
-                let Ok(eq_result) = infcx.at(&traits::ObligationCause::dummy(), param_env).eq(
-                    DefineOpaqueTypes::Yes,
-                    impl_trait_ref.self_ty(),
-                    impl_ty,
-                ) else {
-                    continue;
-                };
-                let InferOk { value: (), obligations } = eq_result;
-                // FIXME(eddyb) ignoring `obligations` might cause false positives.
-                drop(obligations);
+            // Require the type the impl is implemented on to match
+            // our type, and ignore the impl if there was a mismatch.
+            let Ok(eq_result) = infcx.at(&traits::ObligationCause::dummy(), param_env).eq(
+                DefineOpaqueTypes::Yes,
+                impl_trait_ref.self_ty(),
+                impl_ty,
+            ) else {
+                continue;
+            };
+            let InferOk { value: (), obligations } = eq_result;
+            // FIXME(eddyb) ignoring `obligations` might cause false positives.
+            drop(obligations);
 
-                trace!(
-                    "invoking predicate_may_hold: param_env={:?}, impl_trait_ref={:?}, impl_ty={:?}",
+            let predicates = tcx
+                .predicates_of(impl_def_id)
+                .instantiate(tcx, impl_args)
+                .predicates
+                .into_iter()
+                .chain(Some(ty::Binder::dummy(impl_trait_ref).to_predicate(tcx)));
+            for predicate in predicates {
+                let obligation = traits::Obligation::new(
+                    tcx,
+                    traits::ObligationCause::dummy(),
                     param_env,
-                    impl_trait_ref,
-                    impl_ty
+                    predicate,
                 );
-                let predicates = cx
-                    .tcx
-                    .predicates_of(impl_def_id)
-                    .instantiate(cx.tcx, impl_args)
-                    .predicates
-                    .into_iter()
-                    .chain(Some(ty::Binder::dummy(impl_trait_ref).to_predicate(infcx.tcx)));
-                for predicate in predicates {
-                    debug!("testing predicate {predicate:?}");
-                    let obligation = traits::Obligation::new(
-                        infcx.tcx,
-                        traits::ObligationCause::dummy(),
-                        param_env,
-                        predicate,
-                    );
-                    match infcx.evaluate_obligation(&obligation) {
-                        Ok(eval_result) if eval_result.may_apply() => {}
-                        Err(traits::OverflowError::Canonical) => {}
-                        _ => continue 'blanket_impls,
-                    }
+                match infcx.evaluate_obligation(&obligation) {
+                    Ok(eval_result) if eval_result.may_apply() => {}
+                    Err(traits::OverflowError::Canonical) => {}
+                    _ => continue 'blanket_impls,
                 }
-                debug!(
-                    "get_blanket_impls: found applicable impl for trait_ref={:?}, ty={:?}",
-                    trait_ref, ty
-                );
+            }
+            debug!("found applicable impl for trait ref {trait_ref:?}");
 
-                cx.generated_synthetics.insert((ty.skip_binder(), trait_def_id));
+            cx.generated_synthetics.insert((ty.skip_binder(), trait_def_id));
 
-                impls.push(Item {
-                    name: None,
-                    attrs: Default::default(),
-                    item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
-                    kind: Box::new(ImplItem(Box::new(Impl {
-                        unsafety: hir::Unsafety::Normal,
-                        generics: clean_ty_generics(
-                            cx,
-                            cx.tcx.generics_of(impl_def_id),
-                            cx.tcx.explicit_predicates_of(impl_def_id),
-                        ),
-                        // FIXME(eddyb) compute both `trait_` and `for_` from
-                        // the post-inference `trait_ref`, as it's more accurate.
-                        trait_: Some(clean_trait_ref_with_bindings(
-                            cx,
-                            ty::Binder::dummy(trait_ref.instantiate_identity()),
-                            ThinVec::new(),
-                        )),
-                        for_: clean_middle_ty(
-                            ty::Binder::dummy(ty.instantiate_identity()),
-                            cx,
-                            None,
-                            None,
-                        ),
-                        items: cx
-                            .tcx
-                            .associated_items(impl_def_id)
-                            .in_definition_order()
-                            .filter(|item| !item.is_impl_trait_in_trait())
-                            .map(|item| clean_middle_assoc_item(item, cx))
-                            .collect::<Vec<_>>(),
-                        polarity: ty::ImplPolarity::Positive,
-                        kind: ImplKind::Blanket(Box::new(clean_middle_ty(
-                            ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
-                            cx,
-                            None,
-                            None,
-                        ))),
-                    }))),
-                    cfg: None,
-                    inline_stmt_id: None,
-                });
-            }
+            blanket_impls.push(clean::Item {
+                name: None,
+                attrs: Default::default(),
+                item_id: clean::ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
+                kind: Box::new(clean::ImplItem(Box::new(clean::Impl {
+                    unsafety: hir::Unsafety::Normal,
+                    generics: clean_ty_generics(
+                        cx,
+                        tcx.generics_of(impl_def_id),
+                        tcx.explicit_predicates_of(impl_def_id),
+                    ),
+                    // FIXME(eddyb) compute both `trait_` and `for_` from
+                    // the post-inference `trait_ref`, as it's more accurate.
+                    trait_: Some(clean_trait_ref_with_bindings(
+                        cx,
+                        ty::Binder::dummy(trait_ref.instantiate_identity()),
+                        ThinVec::new(),
+                    )),
+                    for_: clean_middle_ty(
+                        ty::Binder::dummy(ty.instantiate_identity()),
+                        cx,
+                        None,
+                        None,
+                    ),
+                    items: tcx
+                        .associated_items(impl_def_id)
+                        .in_definition_order()
+                        .filter(|item| !item.is_impl_trait_in_trait())
+                        .map(|item| clean_middle_assoc_item(item, cx))
+                        .collect(),
+                    polarity: ty::ImplPolarity::Positive,
+                    kind: clean::ImplKind::Blanket(Box::new(clean_middle_ty(
+                        ty::Binder::dummy(trait_ref.instantiate_identity().self_ty()),
+                        cx,
+                        None,
+                        None,
+                    ))),
+                }))),
+                cfg: None,
+                inline_stmt_id: None,
+            });
         }
-
-        impls
     }
+
+    blanket_impls
 }
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs
index bbdfbbd0852..12f45fe4979 100644
--- a/src/librustdoc/clean/mod.rs
+++ b/src/librustdoc/clean/mod.rs
@@ -29,7 +29,7 @@ use rustc_middle::ty::{self, AdtKind, Ty, TyCtxt};
 use rustc_middle::{bug, span_bug};
 use rustc_span::hygiene::{AstPass, MacroKind};
 use rustc_span::symbol::{kw, sym, Ident, Symbol};
-use rustc_span::{self, ExpnKind};
+use rustc_span::ExpnKind;
 use rustc_trait_selection::traits::wf::object_region_bounds;
 
 use std::borrow::Cow;
@@ -37,14 +37,14 @@ use std::collections::BTreeMap;
 use std::mem;
 use thin_vec::ThinVec;
 
-use crate::core::{self, DocContext};
+use crate::core::DocContext;
 use crate::formats::item_type::ItemType;
 use crate::visit_ast::Module as DocModule;
 
 use utils::*;
 
 pub(crate) use self::types::*;
-pub(crate) use self::utils::{get_auto_trait_and_blanket_impls, krate, register_res};
+pub(crate) use self::utils::{krate, register_res, synthesize_auto_trait_and_blanket_impls};
 
 pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<'tcx>) -> Item {
     let mut items: Vec<Item> = vec![];
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index d5e0e83696f..dc62fbb5edb 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -1,5 +1,5 @@
 use crate::clean::auto_trait::synthesize_auto_trait_impls;
-use crate::clean::blanket_impl::BlanketImplFinder;
+use crate::clean::blanket_impl::synthesize_blanket_impls;
 use crate::clean::render_macro_matchers::render_macro_matcher;
 use crate::clean::{
     clean_doc_module, clean_middle_const, clean_middle_region, clean_middle_ty, inline, Crate,
@@ -477,8 +477,7 @@ pub(crate) fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
     }
 }
 
-// FIXME(fmease): Update the `get_*` terminology to the `synthesize_` one.
-pub(crate) fn get_auto_trait_and_blanket_impls(
+pub(crate) fn synthesize_auto_trait_and_blanket_impls(
     cx: &mut DocContext<'_>,
     item_def_id: DefId,
 ) -> impl Iterator<Item = Item> {
@@ -490,8 +489,8 @@ pub(crate) fn get_auto_trait_and_blanket_impls(
     let blanket_impls = cx
         .sess()
         .prof
-        .generic_activity("get_blanket_impls")
-        .run(|| BlanketImplFinder { cx }.get_blanket_impls(item_def_id));
+        .generic_activity("synthesize_blanket_impls")
+        .run(|| synthesize_blanket_impls(cx, item_def_id));
     auto_impls.into_iter().chain(blanket_impls)
 }
 
diff --git a/src/librustdoc/passes/collect_trait_impls.rs b/src/librustdoc/passes/collect_trait_impls.rs
index fbbb6152cfe..c92cf9d3e80 100644
--- a/src/librustdoc/passes/collect_trait_impls.rs
+++ b/src/librustdoc/passes/collect_trait_impls.rs
@@ -122,7 +122,7 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
                         _ => true,
                     }
                 }) {
-                    let impls = get_auto_trait_and_blanket_impls(cx, def_id);
+                    let impls = synthesize_auto_trait_and_blanket_impls(cx, def_id);
                     new_items_external.extend(impls.filter(|i| cx.inlined.insert(i.item_id)));
                 }
             }
@@ -230,8 +230,10 @@ impl<'a, 'tcx> DocVisitor for SyntheticImplCollector<'a, 'tcx> {
         if i.is_struct() || i.is_enum() || i.is_union() {
             // FIXME(eddyb) is this `doc(hidden)` check needed?
             if !self.cx.tcx.is_doc_hidden(i.item_id.expect_def_id()) {
-                self.impls
-                    .extend(get_auto_trait_and_blanket_impls(self.cx, i.item_id.expect_def_id()));
+                self.impls.extend(synthesize_auto_trait_and_blanket_impls(
+                    self.cx,
+                    i.item_id.expect_def_id(),
+                ));
             }
         }
 
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index bb8509fe413..770496289e2 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -2354,6 +2354,11 @@ impl<'test> TestCx<'test> {
             "ignore-directory-in-diagnostics-source-blocks={}",
             home::cargo_home().expect("failed to find cargo home").to_str().unwrap()
         ));
+        // Similarly, vendored sources shouldn't be shown when running from a dist tarball.
+        rustc.arg("-Z").arg(format!(
+            "ignore-directory-in-diagnostics-source-blocks={}",
+            self.config.find_rust_src_root().unwrap().join("vendor").display(),
+        ));
 
         // Optionally prevent default --sysroot if specified in test compile-flags.
         if !self.props.compile_flags.iter().any(|flag| flag.starts_with("--sysroot"))
diff --git a/src/tools/tidy/src/error_codes.rs b/src/tools/tidy/src/error_codes.rs
index 6fc65e56901..39f7e70b693 100644
--- a/src/tools/tidy/src/error_codes.rs
+++ b/src/tools/tidy/src/error_codes.rs
@@ -71,10 +71,12 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
     let path = root_path.join(Path::new(ERROR_CODES_PATH));
     let file =
         fs::read_to_string(&path).unwrap_or_else(|e| panic!("failed to read `{path:?}`: {e}"));
+    let path = path.display();
 
     let mut error_codes = Vec::new();
 
-    for line in file.lines() {
+    for (line_index, line) in file.lines().enumerate() {
+        let line_index = line_index + 1;
         let line = line.trim();
 
         if line.starts_with('E') {
@@ -82,39 +84,54 @@ fn extract_error_codes(root_path: &Path, errors: &mut Vec<String>) -> Vec<String
 
             // Extract the error code from the line. Emit a fatal error if it is not in the correct
             // format.
-            let err_code = if let Some(err_code) = split_line {
-                err_code.0.to_owned()
-            } else {
+            let Some(split_line) = split_line else {
                 errors.push(format!(
-                    "Expected a line with the format `Eabcd: abcd, \
+                    "{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
                     but got \"{}\" without a `:` delimiter",
                     line,
                 ));
                 continue;
             };
 
+            let err_code = split_line.0.to_owned();
+
             // If this is a duplicate of another error code, emit a fatal error.
             if error_codes.contains(&err_code) {
-                errors.push(format!("Found duplicate error code: `{}`", err_code));
+                errors.push(format!(
+                    "{path}:{line_index}: Found duplicate error code: `{}`",
+                    err_code
+                ));
                 continue;
             }
 
             let mut chars = err_code.chars();
-            chars.next();
+            assert_eq!(chars.next(), Some('E'));
             let error_num_as_str = chars.as_str();
 
             // Ensure that the line references the correct markdown file.
-            let expected_filename = format!(" {},", error_num_as_str);
-            if expected_filename != split_line.unwrap().1 {
+            let rest = split_line.1.split_once(',');
+            let Some(rest) = rest else {
+                errors.push(format!(
+                    "{path}:{line_index}: Expected a line with the format `Eabcd: abcd, \
+                    but got \"{}\" without a `,` delimiter",
+                    line,
+                ));
+                continue;
+            };
+            if error_num_as_str != rest.0.trim() {
                 errors.push(format!(
-                    "`{}:` should be followed by `{}` but instead found `{}` in \
+                    "{path}:{line_index}: `{}:` should be followed by `{},` but instead found `{}` in \
                     `compiler/rustc_error_codes/src/lib.rs`",
                     err_code,
-                    expected_filename,
-                    split_line.unwrap().1,
+                    error_num_as_str,
+                    split_line.1,
                 ));
                 continue;
             }
+            if !rest.1.trim().is_empty() && !rest.1.trim().starts_with("//") {
+                errors.push(format!("{path}:{line_index}: should only have one error per line"));
+                continue;
+            }
 
             error_codes.push(err_code);
         }
@@ -146,14 +163,14 @@ fn check_error_codes_docs(
             return;
         }
 
-        // Make sure that the file is referenced in `error_codes.rs`
+        // Make sure that the file is referenced in `rustc_error_codes/src/lib.rs`
         let filename = path.file_name().unwrap().to_str().unwrap().split_once('.');
         let err_code = filename.unwrap().0; // `unwrap` is ok because we know the filename is in the correct format.
 
         if error_codes.iter().all(|e| e != err_code) {
             errors.push(format!(
                 "Found valid file `{}` in error code docs directory without corresponding \
-                entry in `error_code.rs`",
+                entry in `rustc_error_codes/src/lib.rs`",
                 path.display()
             ));
             return;