From d96391047364d2c4c7eda92ce9c3681d59a5197a Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Sat, 16 Feb 2019 00:34:29 +0000 Subject: [PATCH 1/4] rustc: comments --- src/bootstrap/bin/rustc.rs | 2 +- src/bootstrap/builder.rs | 39 +- src/bootstrap/cache.rs | 3 +- src/bootstrap/compile.rs | 42 +- src/bootstrap/dist.rs | 4 +- src/bootstrap/doc.rs | 14 +- src/bootstrap/flags.rs | 6 +- src/bootstrap/native.rs | 4 +- src/bootstrap/sanity.rs | 6 +- src/bootstrap/test.rs | 14 +- src/libarena/lib.rs | 12 +- src/libcore/str/pattern.rs | 2 +- src/libfmt_macros/lib.rs | 2 +- src/libpanic_unwind/dwarf/eh.rs | 2 +- src/libpanic_unwind/gcc.rs | 20 +- src/librustc/cfg/construct.rs | 17 +- src/librustc/dep_graph/dep_node.rs | 14 +- src/librustc/dep_graph/graph.rs | 82 +-- src/librustc/diagnostics.rs | 2 +- src/librustc/hir/lowering.rs | 12 +- src/librustc/hir/map/definitions.rs | 100 +-- src/librustc/hir/map/hir_id_validator.rs | 7 +- src/librustc/hir/map/mod.rs | 89 +-- src/librustc/hir/mod.rs | 144 +++-- src/librustc/hir/print.rs | 12 +- src/librustc/ich/impls_hir.rs | 14 +- src/librustc/infer/canonical/mod.rs | 2 +- .../infer/canonical/query_response.rs | 2 +- src/librustc/infer/combine.rs | 81 ++- src/librustc/infer/error_reporting/mod.rs | 71 ++- .../nice_region_error/find_anon_type.rs | 2 +- .../error_reporting/nice_region_error/mod.rs | 3 +- .../nice_region_error/named_anon_conflict.rs | 12 +- .../nice_region_error/placeholder_error.rs | 4 +- .../error_reporting/nice_region_error/util.rs | 52 +- src/librustc/infer/error_reporting/note.rs | 2 +- src/librustc/infer/fudge.rs | 2 +- src/librustc/infer/glb.rs | 2 +- src/librustc/infer/higher_ranked/mod.rs | 6 +- src/librustc/infer/lattice.rs | 2 +- .../infer/lexical_region_resolve/mod.rs | 41 +- src/librustc/infer/lub.rs | 2 +- src/librustc/infer/mod.rs | 175 +++--- src/librustc/infer/nll_relate/mod.rs | 10 +- src/librustc/infer/opaque_types/mod.rs | 18 +- src/librustc/infer/outlives/obligations.rs | 2 +- src/librustc/infer/outlives/verify.rs | 2 +- src/librustc/infer/region_constraints/mod.rs | 6 +- src/librustc/infer/resolve.rs | 2 +- src/librustc/infer/sub.rs | 2 +- src/librustc/infer/type_variable.rs | 2 +- src/librustc/lint/builtin.rs | 4 +- src/librustc/lint/context.rs | 4 +- src/librustc/lint/levels.rs | 4 +- src/librustc/lint/mod.rs | 17 +- src/librustc/middle/dead.rs | 2 +- src/librustc/middle/expr_use_visitor.rs | 4 +- src/librustc/middle/liveness.rs | 101 ++- src/librustc/middle/mem_categorization.rs | 71 ++- src/librustc/middle/reachable.rs | 12 +- src/librustc/middle/region.rs | 10 +- src/librustc/middle/resolve_lifetime.rs | 178 +++--- src/librustc/middle/stability.rs | 2 +- src/librustc/mir/cache.rs | 4 +- src/librustc/mir/interpret/allocation.rs | 28 +- src/librustc/mir/interpret/error.rs | 9 +- src/librustc/mir/interpret/mod.rs | 2 +- src/librustc/mir/mod.rs | 30 +- src/librustc/session/config.rs | 6 +- src/librustc/session/filesearch.rs | 4 +- src/librustc/session/mod.rs | 30 +- src/librustc/traits/auto_trait.rs | 6 +- src/librustc/traits/codegen/mod.rs | 6 +- src/librustc/traits/coherence.rs | 26 +- src/librustc/traits/error_reporting.rs | 22 +- src/librustc/traits/fulfill.rs | 6 +- src/librustc/traits/mod.rs | 98 +-- src/librustc/traits/object_safety.rs | 98 +-- src/librustc/traits/project.rs | 33 +- src/librustc/traits/query/method_autoderef.rs | 2 +- .../query/type_op/implied_outlives_bounds.rs | 2 +- src/librustc/traits/query/type_op/mod.rs | 2 +- src/librustc/traits/query/type_op/outlives.rs | 2 +- src/librustc/traits/select.rs | 78 +-- src/librustc/traits/specialize/mod.rs | 26 +- src/librustc/traits/structural_impls.rs | 2 +- src/librustc/traits/util.rs | 6 +- src/librustc/ty/adjustment.rs | 8 +- src/librustc/ty/cast.rs | 14 +- src/librustc/ty/codec.rs | 4 +- src/librustc/ty/context.rs | 295 ++++----- src/librustc/ty/fast_reject.rs | 2 +- src/librustc/ty/fold.rs | 23 +- src/librustc/ty/instance.rs | 4 +- src/librustc/ty/item_path.rs | 12 +- src/librustc/ty/layout.rs | 6 +- src/librustc/ty/mod.rs | 60 +- src/librustc/ty/outlives.rs | 4 +- src/librustc/ty/query/job.rs | 91 +-- src/librustc/ty/query/mod.rs | 21 +- src/librustc/ty/query/on_disk_cache.rs | 10 +- src/librustc/ty/query/plumbing.rs | 125 ++-- src/librustc/ty/relate.rs | 10 +- src/librustc/ty/sty.rs | 8 +- src/librustc/ty/util.rs | 67 +- src/librustc/ty/wf.rs | 19 +- src/librustc/util/common.rs | 32 +- src/librustc/util/ppaux.rs | 22 +- src/librustc_apfloat/ieee.rs | 16 +- src/librustc_apfloat/lib.rs | 10 +- src/librustc_apfloat/ppc.rs | 12 +- src/librustc_apfloat/tests/ppc.rs | 2 +- src/librustc_borrowck/borrowck/check_loans.rs | 2 +- .../borrowck/gather_loans/mod.rs | 8 +- src/librustc_borrowck/borrowck/mod.rs | 4 +- src/librustc_borrowck/borrowck/move_data.rs | 2 +- src/librustc_borrowck/borrowck/unused.rs | 2 +- src/librustc_borrowck/dataflow.rs | 22 +- src/librustc_codegen_llvm/abi.rs | 6 +- src/librustc_codegen_llvm/asm.rs | 2 +- src/librustc_codegen_llvm/back/link.rs | 73 ++- src/librustc_codegen_llvm/back/lto.rs | 22 +- src/librustc_codegen_llvm/back/rpath.rs | 4 +- src/librustc_codegen_llvm/back/write.rs | 2 +- src/librustc_codegen_llvm/callee.rs | 4 +- src/librustc_codegen_llvm/consts.rs | 4 +- src/librustc_codegen_llvm/debuginfo/doc.rs | 2 - .../debuginfo/metadata.rs | 153 +++-- src/librustc_codegen_llvm/debuginfo/mod.rs | 4 +- .../debuginfo/source_loc.rs | 2 +- src/librustc_codegen_llvm/intrinsic.rs | 22 +- src/librustc_codegen_llvm/lib.rs | 2 +- src/librustc_codegen_llvm/llvm_util.rs | 2 +- src/librustc_codegen_llvm/type_of.rs | 12 +- src/librustc_codegen_ssa/back/link.rs | 4 +- src/librustc_codegen_ssa/back/linker.rs | 104 ++-- .../back/symbol_export.rs | 2 +- src/librustc_codegen_ssa/back/write.rs | 28 +- src/librustc_codegen_ssa/base.rs | 6 +- src/librustc_codegen_ssa/common.rs | 16 +- src/librustc_codegen_ssa/glue.rs | 2 +- src/librustc_codegen_ssa/lib.rs | 8 +- src/librustc_codegen_ssa/mir/block.rs | 69 +-- src/librustc_codegen_ssa/mir/mod.rs | 25 +- src/librustc_codegen_ssa/mir/operand.rs | 4 +- src/librustc_codegen_ssa/mir/place.rs | 50 +- src/librustc_codegen_ssa/mir/rvalue.rs | 18 +- src/librustc_codegen_ssa/traits/type_.rs | 4 +- src/librustc_codegen_utils/codegen_backend.rs | 9 +- src/librustc_codegen_utils/link.rs | 4 +- src/librustc_codegen_utils/symbol_names.rs | 2 +- src/librustc_data_structures/bit_set.rs | 6 +- src/librustc_data_structures/fingerprint.rs | 2 +- .../graph/dominators/mod.rs | 2 +- .../graph/scc/test.rs | 2 +- .../obligation_forest/mod.rs | 8 +- .../owning_ref/mod.rs | 14 +- .../snapshot_map/mod.rs | 2 +- src/librustc_data_structures/sync.rs | 6 +- .../transitive_relation.rs | 4 +- src/librustc_driver/driver.rs | 4 +- src/librustc_driver/lib.rs | 6 +- src/librustc_driver/pretty.rs | 8 +- src/librustc_driver/profile/mod.rs | 4 +- src/librustc_driver/test.rs | 14 +- src/librustc_errors/emitter.rs | 4 +- src/librustc_errors/lib.rs | 4 +- src/librustc_incremental/assert_dep_graph.rs | 4 +- .../persist/dirty_clean.rs | 76 +-- src/librustc_lint/builtin.rs | 63 +- src/librustc_lint/lib.rs | 2 +- src/librustc_lint/types.rs | 11 +- src/librustc_lint/unused.rs | 2 +- src/librustc_metadata/creader.rs | 10 +- src/librustc_metadata/cstore_impl.rs | 12 +- src/librustc_metadata/decoder.rs | 4 +- src/librustc_metadata/encoder.rs | 24 +- src/librustc_metadata/locator.rs | 14 +- src/librustc_metadata/schema.rs | 2 +- src/librustc_mir/borrow_check/borrow_set.rs | 18 +- .../borrow_check/error_reporting.rs | 12 +- src/librustc_mir/borrow_check/location.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 34 +- .../borrow_check/nll/constraints/mod.rs | 4 +- .../borrow_check/nll/invalidation.rs | 37 +- src/librustc_mir/borrow_check/nll/mod.rs | 2 +- .../nll/region_infer/error_reporting/mod.rs | 8 +- .../error_reporting/region_name.rs | 6 +- .../borrow_check/nll/region_infer/mod.rs | 10 +- .../borrow_check/nll/region_infer/values.rs | 4 +- .../nll/type_check/free_region_relations.rs | 4 +- .../nll/type_check/liveness/trace.rs | 16 +- .../borrow_check/nll/type_check/mod.rs | 30 +- .../borrow_check/nll/universal_regions.rs | 8 +- src/librustc_mir/borrow_check/path_utils.rs | 8 +- src/librustc_mir/borrow_check/place_ext.rs | 2 +- src/librustc_mir/borrow_check/used_muts.rs | 2 +- src/librustc_mir/build/expr/as_place.rs | 2 +- src/librustc_mir/build/expr/as_rvalue.rs | 2 +- src/librustc_mir/build/expr/category.rs | 3 +- src/librustc_mir/build/expr/stmt.rs | 6 +- src/librustc_mir/build/matches/mod.rs | 234 ++++--- src/librustc_mir/build/matches/simplify.rs | 29 +- src/librustc_mir/build/matches/test.rs | 108 ++-- src/librustc_mir/build/mod.rs | 30 +- src/librustc_mir/build/scope.rs | 2 +- src/librustc_mir/const_eval.rs | 94 +-- src/librustc_mir/dataflow/graphviz.rs | 22 +- .../dataflow/impls/borrowed_locals.rs | 8 +- src/librustc_mir/dataflow/impls/borrows.rs | 4 +- src/librustc_mir/dataflow/impls/mod.rs | 7 + src/librustc_mir/dataflow/move_paths/mod.rs | 46 +- src/librustc_mir/diagnostics.rs | 4 +- src/librustc_mir/hair/cx/expr.rs | 14 +- src/librustc_mir/hair/cx/mod.rs | 10 +- src/librustc_mir/hair/pattern/_match.rs | 6 +- src/librustc_mir/hair/pattern/check_match.rs | 2 +- src/librustc_mir/hair/pattern/mod.rs | 17 +- src/librustc_mir/interpret/eval_context.rs | 48 +- src/librustc_mir/interpret/memory.rs | 28 +- src/librustc_mir/interpret/operand.rs | 75 +-- src/librustc_mir/interpret/operator.rs | 32 +- src/librustc_mir/interpret/place.rs | 52 +- src/librustc_mir/interpret/snapshot.rs | 14 +- src/librustc_mir/interpret/terminator.rs | 12 +- src/librustc_mir/interpret/validity.rs | 26 +- src/librustc_mir/interpret/visitor.rs | 16 +- src/librustc_mir/lints.rs | 6 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/monomorphize/item.rs | 4 +- src/librustc_mir/monomorphize/mod.rs | 15 +- src/librustc_mir/monomorphize/partitioning.rs | 4 +- src/librustc_mir/shim.rs | 2 +- .../transform/add_moves_for_packed_drops.rs | 5 +- src/librustc_mir/transform/add_retag.rs | 36 +- src/librustc_mir/transform/check_unsafety.rs | 60 +- src/librustc_mir/transform/copy_prop.rs | 6 +- src/librustc_mir/transform/deaggregator.rs | 8 +- src/librustc_mir/transform/generator.rs | 12 +- src/librustc_mir/transform/inline.rs | 14 +- src/librustc_mir/transform/mod.rs | 2 +- src/librustc_mir/transform/promote_consts.rs | 2 +- src/librustc_mir/transform/qualify_consts.rs | 136 ++-- src/librustc_mir/transform/simplify.rs | 4 +- src/librustc_passes/ast_validation.rs | 44 +- src/librustc_passes/rvalue_promotion.rs | 2 +- src/librustc_privacy/lib.rs | 14 +- src/librustc_resolve/build_reduced_graph.rs | 47 +- src/librustc_resolve/check_unused.rs | 13 +- src/librustc_resolve/diagnostics.rs | 4 +- src/librustc_resolve/lib.rs | 242 ++++---- src/librustc_resolve/macros.rs | 22 +- src/librustc_resolve/resolve_imports.rs | 43 +- src/librustc_save_analysis/dump_visitor.rs | 22 +- src/librustc_save_analysis/lib.rs | 22 +- src/librustc_save_analysis/sig.rs | 40 +- src/librustc_save_analysis/span_utils.rs | 14 +- src/librustc_target/abi/call/mod.rs | 10 +- src/librustc_target/abi/call/powerpc64.rs | 11 +- src/librustc_target/abi/call/s390x.rs | 4 +- src/librustc_target/abi/call/sparc64.rs | 2 +- src/librustc_target/abi/call/x86_win64.rs | 2 +- src/librustc_target/abi/mod.rs | 10 +- src/librustc_target/spec/dragonfly_base.rs | 2 +- src/librustc_target/spec/freebsd_base.rs | 4 +- src/librustc_target/spec/mod.rs | 2 +- src/librustc_target/spec/netbsd_base.rs | 2 +- src/librustc_target/spec/openbsd_base.rs | 4 +- .../spec/s390x_unknown_linux_gnu.rs | 2 +- .../spec/sparcv9_sun_solaris.rs | 2 +- src/librustc_target/spec/thumb_base.rs | 4 +- .../spec/wasm32_unknown_emscripten.rs | 4 +- src/librustc_target/spec/windows_base.rs | 4 +- src/librustc_traits/chalk_context/mod.rs | 12 +- .../chalk_context/program_clauses.rs | 2 +- .../implied_outlives_bounds.rs | 4 +- src/librustc_traits/lowering/mod.rs | 24 +- src/librustc_traits/type_op.rs | 4 +- src/librustc_typeck/astconv.rs | 17 +- src/librustc_typeck/check/_match.rs | 16 +- src/librustc_typeck/check/autoderef.rs | 2 +- src/librustc_typeck/check/callee.rs | 24 +- src/librustc_typeck/check/closure.rs | 4 +- src/librustc_typeck/check/coercion.rs | 25 +- src/librustc_typeck/check/compare_method.rs | 30 +- src/librustc_typeck/check/demand.rs | 2 +- src/librustc_typeck/check/dropck.rs | 10 +- .../check/generator_interior.rs | 4 +- src/librustc_typeck/check/method/confirm.rs | 8 +- src/librustc_typeck/check/method/mod.rs | 2 +- src/librustc_typeck/check/method/probe.rs | 28 +- src/librustc_typeck/check/method/suggest.rs | 7 +- src/librustc_typeck/check/mod.rs | 197 +++--- src/librustc_typeck/check/op.rs | 4 +- src/librustc_typeck/check/regionck.rs | 37 +- src/librustc_typeck/check/upvar.rs | 6 +- src/librustc_typeck/check/wfcheck.rs | 28 +- src/librustc_typeck/check/writeback.rs | 38 +- src/librustc_typeck/check_unused.rs | 2 +- src/librustc_typeck/coherence/builtin.rs | 6 +- .../coherence/inherent_impls.rs | 6 +- src/librustc_typeck/coherence/mod.rs | 10 +- src/librustc_typeck/collect.rs | 52 +- src/librustc_typeck/diagnostics.rs | 22 +- src/librustc_typeck/lib.rs | 10 +- .../outlives/implicit_infer.rs | 28 +- src/librustc_typeck/outlives/mod.rs | 4 +- src/librustc_typeck/outlives/utils.rs | 12 +- src/librustc_typeck/variance/solve.rs | 2 +- src/librustc_typeck/variance/terms.rs | 2 +- src/librustdoc/clean/auto_trait.rs | 6 +- src/librustdoc/clean/blanket_impl.rs | 2 +- src/librustdoc/clean/cfg.rs | 2 +- src/librustdoc/clean/inline.rs | 4 +- src/librustdoc/clean/mod.rs | 15 +- src/librustdoc/clean/simplify.rs | 2 +- src/librustdoc/config.rs | 2 +- src/librustdoc/core.rs | 6 +- src/librustdoc/html/escape.rs | 2 +- src/librustdoc/html/format.rs | 2 +- src/librustdoc/html/highlight.rs | 3 +- src/librustdoc/html/markdown.rs | 12 +- src/librustdoc/html/render.rs | 10 +- src/librustdoc/passes/mod.rs | 2 +- src/libserialize/collection_impls.rs | 2 +- src/libserialize/json.rs | 223 ++++--- src/libsyntax/ast.rs | 2 +- src/libsyntax/attr/mod.rs | 2 +- src/libsyntax/config.rs | 24 +- src/libsyntax/ext/base.rs | 78 ++- src/libsyntax/ext/build.rs | 8 +- src/libsyntax/ext/expand.rs | 97 +-- src/libsyntax/ext/tt/macro_parser.rs | 14 +- src/libsyntax/ext/tt/macro_rules.rs | 162 ++--- src/libsyntax/ext/tt/quoted.rs | 18 +- src/libsyntax/ext/tt/transcribe.rs | 6 +- src/libsyntax/feature_gate.rs | 37 +- src/libsyntax/lib.rs | 6 +- src/libsyntax/parse/classify.rs | 4 +- src/libsyntax/parse/lexer/comments.rs | 6 +- src/libsyntax/parse/lexer/mod.rs | 6 +- src/libsyntax/parse/lexer/unicode_chars.rs | 4 +- src/libsyntax/parse/mod.rs | 23 +- src/libsyntax/parse/parser.rs | 579 ++++++++++-------- src/libsyntax/parse/token.rs | 12 +- src/libsyntax/print/pprust.rs | 14 +- src/libsyntax/ptr.rs | 13 +- src/libsyntax/source_map.rs | 8 +- src/libsyntax/std_inject.rs | 2 +- src/libsyntax/tokenstream.rs | 10 +- src/libsyntax/util/lev_distance.rs | 2 +- src/libsyntax/util/parser.rs | 2 +- src/libsyntax/visit.rs | 7 +- src/libsyntax_ext/deriving/generic/mod.rs | 20 +- src/libsyntax_ext/env.rs | 3 +- src/libsyntax_ext/format.rs | 132 ++-- src/libsyntax_ext/format_foreign.rs | 2 +- src/libsyntax_ext/proc_macro_server.rs | 6 +- src/libsyntax_ext/test.rs | 81 ++- src/libsyntax_pos/analyze_source_file.rs | 2 +- src/libsyntax_pos/hygiene.rs | 6 +- src/libsyntax_pos/symbol.rs | 2 +- src/libterm/terminfo/searcher.rs | 26 +- src/libterm/win.rs | 17 +- 364 files changed, 4321 insertions(+), 4193 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 7a765973e20f8..34edca4cdeda1 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -149,7 +149,7 @@ fn main() { // // `compiler_builtins` are unconditionally compiled with panic=abort to // workaround undefined references to `rust_eh_unwind_resume` generated - // otherwise, see issue https://github.com/rust-lang/rust/issues/43095. + // otherwise, see issue #43095. if crate_name == "panic_abort" || crate_name == "compiler_builtins" && stage != "0" { cmd.arg("-C").arg("panic=abort"); diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 9d037dad9ccbd..04c95b04e01ce 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -80,7 +80,7 @@ pub trait Step: 'static + Clone + Debug + PartialEq + Eq + Hash { // It is reasonable to not have an implementation of make_run for rules // who do not want to get called from the root context. This means that // they are likely dependencies (e.g., sysroot creation) or similar, and - // as such calling them from ./x.py isn't logical. + // as such calling them from `./x.py` isn't logical. unimplemented!() } } @@ -236,11 +236,11 @@ impl StepDescription { #[derive(Clone)] pub struct ShouldRun<'a> { pub builder: &'a Builder<'a>, - // use a BTreeSet to maintain sort order + // Use a `BTreeSet` to maintain sort order. paths: BTreeSet, // If this is a default rule, this is an additional constraint placed on - // its run. Generally something like compiler docs being enabled. + // its run (generally something like compiler docs being enabled). is_really_default: bool, } @@ -249,7 +249,8 @@ impl<'a> ShouldRun<'a> { ShouldRun { builder, paths: BTreeSet::new(), - is_really_default: true, // by default no additional conditions + // By default no additional conditions. + is_really_default: true, } } @@ -277,12 +278,12 @@ impl<'a> ShouldRun<'a> { self } - // single, non-aliased path + // Single, non-aliased path. pub fn path(self, path: &str) -> Self { self.paths(&[path]) } - // multiple aliases for the same job + // Multiple aliases for the same job. pub fn paths(mut self, paths: &[&str]) -> Self { self.paths .insert(PathSet::Set(paths.iter().map(PathBuf::from).collect())); @@ -301,7 +302,7 @@ impl<'a> ShouldRun<'a> { self } - // allows being more explicit about why should_run in Step returns the value passed to it + // Allows being more explicit about why `Step::should_run` returns the value passed to it. pub fn never(mut self) -> ShouldRun<'a> { self.paths.insert(PathSet::empty()); self @@ -677,7 +678,7 @@ impl<'a> Builder<'a> { let compiler = self.compiler(self.top_stage, host); cmd.env("RUSTC_STAGE", compiler.stage.to_string()) .env("RUSTC_SYSROOT", self.sysroot(compiler)) - // Note that this is *not* the sysroot_libdir because rustdoc must be linked + // Note that this is *not* the `sysroot_libdir` because rustdoc must be linked // equivalently to rustc. .env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler)) .env("CFG_RELEASE_CHANNEL", &self.config.channel) @@ -813,12 +814,12 @@ impl<'a> Builder<'a> { } cargo.arg("-j").arg(self.jobs().to_string()); - // Remove make-related flags to ensure Cargo can correctly set things up + // Remove make-related flags to ensure Cargo can correctly set things up. cargo.env_remove("MAKEFLAGS"); cargo.env_remove("MFLAGS"); - // FIXME: Temporary fix for https://github.com/rust-lang/cargo/issues/3005 - // Force cargo to output binaries with disambiguating hashes in the name + // FIXME: temporary fix for rust-lang/cargo#3005. + // Force cargo to output binaries with disambiguating hashes in the name. let metadata = if compiler.stage == 0 { // Treat stage0 like special channel, whether it's a normal prior- // release rustc or a local rebuild with the same version, so we @@ -863,7 +864,7 @@ impl<'a> Builder<'a> { // "raw" compiler in that it's the exact snapshot we download. Normally // the stage0 build means it uses libraries build by the stage0 // compiler, but for tools we just use the precompiled libraries that - // we've downloaded + // we've downloaded. let use_snapshot = mode == Mode::ToolBootstrap; assert!(!use_snapshot || stage == 0 || self.local_rebuild); @@ -920,7 +921,7 @@ impl<'a> Builder<'a> { if mode.is_tool() { // Tools like cargo and rls don't get debuginfo by default right now, but this can be - // enabled in the config. Adding debuginfo makes them several times larger. + // enabled in the config. Adding debuginfo makes them several times larger. if self.config.rust_debuginfo_tools { cargo.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string()); cargo.env( @@ -1028,7 +1029,7 @@ impl<'a> Builder<'a> { // Build scripts use either the `cc` crate or `configure/make` so we pass // the options through environment variables that are fetched and understood by both. // - // FIXME: the guard against msvc shouldn't need to be here + // FIXME: the guard against MSVC shouldn't need to be here. if target.contains("msvc") { if let Some(ref cl) = self.config.llvm_clang_cl { cargo.env("CC", cl).env("CXX", cl); @@ -1040,7 +1041,7 @@ impl<'a> Builder<'a> { Some(ref s) => s, None => return s.display().to_string(), }; - // FIXME: the cc-rs crate only recognizes the literal strings + // FIXME: the cc-rs crate only recognizes the literal strings. // `ccache` and `sccache` when doing caching compilations, so we // mirror that here. It should probably be fixed upstream to // accept a new env var or otherwise work with custom ccache @@ -1080,12 +1081,12 @@ impl<'a> Builder<'a> { cargo.env("RUSTC_SAVE_ANALYSIS", "api".to_string()); } - // For `cargo doc` invocations, make rustdoc print the Rust version into the docs + // For `cargo doc` invocations, make rustdoc print the Rust version into the docs. cargo.env("RUSTDOC_CRATE_VERSION", self.rust_version()); - // Environment variables *required* throughout the build + // Environment variables *required* throughout the build. // - // FIXME: should update code to not require this env var + // FIXME: should update code to not require this env var. cargo.env("CFG_COMPILER_HOST_TRIPLE", target); // Set this for all builds to make sure doc builds also get it. @@ -1476,7 +1477,7 @@ mod __test { #[test] fn dist_with_target_flag() { let mut config = configure(&["B"], &["C"]); - config.run_host_only = false; // as-if --target=C was passed + config.run_host_only = false; // as if `--target=C` were passed let build = Build::new(config); let mut builder = Builder::new(&build); builder.run_step_descriptions(&Builder::get_step_descriptions(Kind::Dist), &[]); diff --git a/src/bootstrap/cache.rs b/src/bootstrap/cache.rs index 5f84816789a68..ada8e871dfc14 100644 --- a/src/bootstrap/cache.rs +++ b/src/bootstrap/cache.rs @@ -235,7 +235,8 @@ lazy_static! { pub struct Cache( RefCell, // actually a HashMap> + // Actually a `HashMap>`. + Box, >> ); diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index 8fabb8c3fd08f..a75c0cc613751 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -165,12 +165,12 @@ pub fn std_cargo(builder: &Builder, let features = builder.std_features(); if compiler.stage != 0 && builder.config.sanitizers { - // This variable is used by the sanitizer runtime crates, e.g. - // rustc_lsan, to build the sanitizer runtime from C code + // This variable is used by the sanitizer runtime crates, e.g., + // `rustc_lsan`, to build the sanitizer runtime from C code // When this variable is missing, those crates won't compile the C code, // so we don't set this variable during stage0 where llvm-config is // missing - // We also only build the runtimes when --enable-sanitizers (or its + // We also only build the runtimes when `--enable-sanitizers` (or its // config.toml equivalent) is used let llvm_config = builder.ensure(native::Llvm { target: builder.config.build, @@ -895,7 +895,7 @@ impl Step for Assemble { run.never() } - /// Prepare a new compiler from the artifacts in `stage` + /// Prepares a new compiler from the artifacts in `stage` /// /// This will assemble a compiler in `build/$host/stage$stage`. The compiler /// must have been previously produced by the `stage - 1` builder.build @@ -921,17 +921,17 @@ impl Step for Assemble { // produce some other architecture compiler we need to start from // `build` to get there. // - // FIXME: Perhaps we should download those libraries? - // It would make builds faster... + // FIXME: perhaps we should download those libraries? + // It would certainly make builds faster. // - // FIXME: It may be faster if we build just a stage 1 compiler and then - // use that to bootstrap this compiler forward. + // FIXME: it may be faster if we build just a stage 1 compiler and then + // use that to bootstrap this compiler forward. let build_compiler = builder.compiler(target_compiler.stage - 1, builder.config.build); // Build the libraries for this compiler to link to (i.e., the libraries // it uses at runtime). NOTE: Crates the target compiler compiles don't - // link to these. (FIXME: Is that correct? It seems to be correct most + // link to these. (FIXME: is that correct? It seems to be correct most // of the time but I think we do link to these for stage2/bin compilers // when not performing a full bootstrap). builder.ensure(Rustc { @@ -958,7 +958,7 @@ impl Step for Assemble { let host = target_compiler.host; builder.info(&format!("Assembling stage{} compiler ({})", stage, host)); - // Link in all dylibs to the libdir + // Link in all dylibs to the libdir. let sysroot = builder.sysroot(target_compiler); let sysroot_libdir = sysroot.join(libdir(&*host)); t!(fs::create_dir_all(&sysroot_libdir)); @@ -979,7 +979,7 @@ impl Step for Assemble { dist::maybe_install_llvm_dylib(builder, target_compiler.host, &sysroot); - // Link the compiler binary itself into place + // Link the compiler binary itself into place. let out_dir = builder.cargo_out(build_compiler, Mode::Rustc, host); let rustc = out_dir.join(exe("rustc_binary", &*host)); let bindir = sysroot.join("bin"); @@ -992,7 +992,7 @@ impl Step for Assemble { } } -/// Link some files into a rustc sysroot. +/// Links some files into a rustc sysroot. /// /// For a particular stage this will link the file listed in `stamp` into the /// `sysroot_dst` provided. @@ -1013,16 +1013,16 @@ pub fn run_cargo(builder: &Builder, return Vec::new(); } - // `target_root_dir` looks like $dir/$target/release + // `target_root_dir` looks like `$dir/$target/release`. let target_root_dir = stamp.parent().unwrap(); - // `target_deps_dir` looks like $dir/$target/release/deps + // `target_deps_dir` looks like `$dir/$target/release/deps`. let target_deps_dir = target_root_dir.join("deps"); - // `host_root_dir` looks like $dir/release + // `host_root_dir` looks like `$dir/release`. let host_root_dir = target_root_dir.parent().unwrap() // chop off `release` .parent().unwrap() // chop off `$target` .join(target_root_dir.file_name().unwrap()); - // Spawn Cargo slurping up its JSON output. We'll start building up the + // Spawn Cargo, collecting its JSON output. We'll start building up the // `deps` array of all files it generated along with a `toplevel` array of // files we need to probe for later. let mut deps = Vec::new(); @@ -1033,7 +1033,7 @@ pub fn run_cargo(builder: &Builder, _ => return, }; for filename in filenames { - // Skip files like executables + // Skip files like executables. if !filename.ends_with(".rlib") && !filename.ends_with(".lib") && !is_dylib(&filename) && @@ -1056,7 +1056,7 @@ pub fn run_cargo(builder: &Builder, continue; } - // Otherwise this was a "top level artifact" which right now doesn't + // Otherwise, this was a "top level artifact" which right now doesn't // have a hash in the name, but there's a version of this file in // the `deps` folder which *does* have a hash in the name. That's // the one we'll want to we'll probe for it later. @@ -1080,7 +1080,7 @@ pub fn run_cargo(builder: &Builder, exit(1); } - // Ok now we need to actually find all the files listed in `toplevel`. We've + // Now we need to actually find all the files listed in `toplevel`. We've // got a list of prefix/extensions and we basically just need to find the // most recent file in the `deps` folder corresponding to each one. let contents = t!(target_deps_dir.read_dir()) @@ -1168,7 +1168,7 @@ pub fn stream_cargo( Err(e) => panic!("failed to execute command: {:?}\nerror: {}", cargo, e), }; - // Spawn Cargo slurping up its JSON output. We'll start building up the + // Spawn Cargo, collecting its JSON output. We'll start building up the // `deps` array of all files it generated along with a `toplevel` array of // files we need to probe for later. let stdout = BufReader::new(child.stdout.take().unwrap()); @@ -1176,7 +1176,7 @@ pub fn stream_cargo( let line = t!(line); match serde_json::from_str::(&line) { Ok(msg) => cb(msg), - // If this was informational, just print it out and continue + // If this was informational, just print it out and continue. Err(_) => println!("{}", line) } } diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index bc1fdad356be3..30cfbd61773c0 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -2222,8 +2222,8 @@ impl Step for Lldb { } } - // The lldb scripts might be installed in lib/python$version - // or in lib64/python$version. If lib64 exists, use it; + // The lldb scripts might be installed in `lib/python$version` + // or in `lib64/python$version`. If lib64 exists, use it; // otherwise lib. let libdir = builder.llvm_out(target).join("lib64"); let (libdir, libdir_name) = if libdir.exists() { diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d14b23e5988cb..dbfefe9c3e5f0 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -567,14 +567,14 @@ impl Step for Test { compiler }; - // Build libstd docs so that we generate relative links + // Build libstd docs so that we generate relative links. builder.ensure(Std { stage, target }); builder.ensure(compile::Test { compiler, target }); let out_dir = builder.stage_out(compiler, Mode::Test) .join(target).join("doc"); - // See docs in std above for why we symlink + // See docs in std above for why we symlink. let my_out = builder.crate_doc_out(target); t!(symlink_dir_force(&builder.config, &my_out, &out_dir)); @@ -633,14 +633,14 @@ impl Step for WhitelistedRustc { compiler }; - // Build libstd docs so that we generate relative links + // Build libstd docs so that we generate relative links. builder.ensure(Std { stage, target }); builder.ensure(compile::Rustc { compiler, target }); let out_dir = builder.stage_out(compiler, Mode::Rustc) .join(target).join("doc"); - // See docs in std above for why we symlink + // See docs in std above for why we symlink. let my_out = builder.crate_doc_out(target); t!(symlink_dir_force(&builder.config, &my_out, &out_dir)); @@ -737,7 +737,7 @@ impl Step for Rustc { for krate in &compiler_crates { // Create all crate output directories first to make sure rustdoc uses // relative links. - // FIXME: Cargo should probably do this itself. + // FIXME: cargo should probably do this itself. t!(fs::create_dir_all(out_dir.join(krate))); cargo.arg("-p").arg(krate); } @@ -879,7 +879,7 @@ impl Step for ErrorIndex { index.arg("html"); index.arg(out.join("error-index.html")); - // FIXME: shouldn't have to pass this env var + // FIXME: shouldn't have to pass this env var. index.env("CFG_BUILD", &builder.config.build) .env("RUSTC_ERROR_METADATA_DST", builder.extended_error_dir()); @@ -936,7 +936,7 @@ fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()> if m.file_type().is_dir() { fs::remove_dir_all(dst)?; } else { - // handle directory junctions on windows by falling back to + // Handle directory junctions on Windows by falling back to // `remove_dir`. fs::remove_file(dst).or_else(|_| { fs::remove_dir(dst) diff --git a/src/bootstrap/flags.rs b/src/bootstrap/flags.rs index 0f9a4271ac062..1cb2f44b4978d 100644 --- a/src/bootstrap/flags.rs +++ b/src/bootstrap/flags.rs @@ -33,7 +33,7 @@ pub struct Flags { pub rustc_error_format: Option, pub dry_run: bool, - // true => deny + // `true` => deny pub warnings: Option, } @@ -139,8 +139,8 @@ To learn more about a subcommand, run `./x.py -h`" // We can't use getopt to parse the options until we have completed specifying which // options are valid, but under the current implementation, some options are conditional on - // the subcommand. Therefore we must manually identify the subcommand first, so that we can - // complete the definition of the options. Then we can use the getopt::Matches object from + // the subcommand. Therefore, we must manually identify the subcommand first, so that we can + // complete the definition of the options. Then we can use the `getopt::Matches` object from // there on out. let subcommand = args.iter().find(|&s| { (s == "build") diff --git a/src/bootstrap/native.rs b/src/bootstrap/native.rs index f48f9ee752e93..53fccc066d48a 100644 --- a/src/bootstrap/native.rs +++ b/src/bootstrap/native.rs @@ -197,8 +197,8 @@ impl Step for Llvm { cfg.define("LLDB_CODESIGN_IDENTITY", ""); cfg.define("LLDB_NO_DEBUGSERVER", "ON"); } else { - // LLDB requires libxml2; but otherwise we want it to be disabled. - // See https://github.com/rust-lang/rust/pull/50104 + // LLDB requires libxml2, but otherwise we want it to be disabled. + // See PR #50104. cfg.define("LLVM_ENABLE_LIBXML2", "OFF"); } diff --git a/src/bootstrap/sanity.rs b/src/bootstrap/sanity.rs index ff4fb85bbfad3..eae408888625b 100644 --- a/src/bootstrap/sanity.rs +++ b/src/bootstrap/sanity.rs @@ -62,13 +62,13 @@ pub fn check(build: &mut Build) { // On Windows, quotes are invalid characters for filename paths, and if // one is present as part of the PATH then that can lead to the system // being unable to identify the files properly. See - // https://github.com/rust-lang/rust/issues/34959 for more details. + // issue #34959 for more details. if cfg!(windows) && path.to_string_lossy().contains('\"') { panic!("PATH contains invalid character '\"'"); } let mut cmd_finder = Finder::new(); - // If we've got a git directory we're gonna need git to update + // If we've got a Git directory we're gonna need git to update // submodules and learn about various other aspects. if build.rust_info.is_git() { cmd_finder.must_have("git"); @@ -122,7 +122,7 @@ pub fn check(build: &mut Build) { // We're gonna build some custom C code here and there, host triples // also build some C++ shims for LLVM so we need a C++ compiler. for target in &build.targets { - // On emscripten we don't actually need the C compiler to just + // On Emscripten we don't actually need the C compiler to just // build the target artifacts, only for testing. For the sake // of easier bot configuration, just skip detection. if target.contains("emscripten") { diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index a882550f734f4..f2e312ae828d2 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -47,7 +47,7 @@ impl From for TestKind { } impl TestKind { - // Return the cargo subcommand for this test kind + // Returns the cargo subcommand for this test kind. fn subcommand(self) -> &'static str { match self { TestKind::Test => "test", @@ -517,8 +517,8 @@ impl Step for Clippy { } fn path_for_cargo(builder: &Builder, compiler: Compiler) -> OsString { - // Configure PATH to find the right rustc. NB. we have to use PATH - // and not RUSTC because the Cargo test suite has tests that will + // Configure `PATH` to find the right rustc. N.B., we have to use PATH + // and not `RUSTC` because the Cargo test suite has tests that will // fail if rustc is not spelled `rustc`. let path = builder.sysroot(compiler).join("bin"); let old_path = env::var_os("PATH").unwrap_or_default(); @@ -951,7 +951,7 @@ impl Step for Compiletest { } if suite.ends_with("fulldeps") || - // FIXME: Does pretty need librustc compiled? Note that there are + // FIXME: does pretty need librustc compiled? Note that there are // fulldeps test suites with mode = pretty as well. mode == "pretty" { @@ -971,7 +971,7 @@ impl Step for Compiletest { builder.ensure(compile::Std { compiler, target: compiler.host }); } - // HACK(eddyb) ensure that `libproc_macro` is available on the host. + // HACK(eddyb): ensure that `libproc_macro` is available on the host. builder.ensure(compile::Test { compiler, target: compiler.host }); // Also provide `rust_test_helpers` for the host. builder.ensure(native::TestHelpers { target: compiler.host }); @@ -1976,8 +1976,8 @@ impl Step for Bootstrap { .env("RUSTC", &builder.initial_rustc); if let Some(flags) = option_env!("RUSTFLAGS") { // Use the same rustc flags for testing as for "normal" compilation, - // so that Cargo doesn’t recompile the entire dependency graph every time: - // https://github.com/rust-lang/rust/issues/49215 + // so that Cargo doesn’t recompile the entire dependency graph every time + // (issue #49215). cmd.env("RUSTFLAGS", flags); } if !builder.fail_fast { diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 8ae046c0796bc..aecfd387b3f19 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -413,7 +413,7 @@ impl DroplessArena { } #[derive(Default)] -// FIXME(@Zoxc): this type is entirely unused in rustc +// FIXME(Zoxc): this type is entirely unused in rustc. pub struct SyncTypedArena { lock: MTLock>, } @@ -421,7 +421,7 @@ pub struct SyncTypedArena { impl SyncTypedArena { #[inline(always)] pub fn alloc(&self, object: T) -> &mut T { - // Extend the lifetime of the result since it's limited to the lock guard + // Extend the lifetime of the result since it's limited to the lock guard. unsafe { &mut *(self.lock.lock().alloc(object) as *mut T) } } @@ -430,7 +430,7 @@ impl SyncTypedArena { where T: Copy, { - // Extend the lifetime of the result since it's limited to the lock guard + // Extend the lifetime of the result since it's limited to the lock guard. unsafe { &mut *(self.lock.lock().alloc_slice(slice) as *mut [T]) } } @@ -453,13 +453,13 @@ impl SyncDroplessArena { #[inline(always)] pub fn alloc_raw(&self, bytes: usize, align: usize) -> &mut [u8] { - // Extend the lifetime of the result since it's limited to the lock guard + // Extend the lifetime of the result since it's limited to the lock guard. unsafe { &mut *(self.lock.lock().alloc_raw(bytes, align) as *mut [u8]) } } #[inline(always)] pub fn alloc(&self, object: T) -> &mut T { - // Extend the lifetime of the result since it's limited to the lock guard + // Extend the lifetime of the result since it's limited to the lock guard. unsafe { &mut *(self.lock.lock().alloc(object) as *mut T) } } @@ -468,7 +468,7 @@ impl SyncDroplessArena { where T: Copy, { - // Extend the lifetime of the result since it's limited to the lock guard + // Extend the lifetime of the result since it's limited to the lock guard. unsafe { &mut *(self.lock.lock().alloc_slice(slice) as *mut [T]) } } } diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 2571780ad0bab..c325f00cfc746 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -625,7 +625,7 @@ macro_rules! searcher_methods { // Impl for &[char] ///////////////////////////////////////////////////////////////////////////// -// Todo: Change / Remove due to ambiguity in meaning. +// FIXME: change/remove due to ambiguity in meaning. /// Associated type for `<&[char] as Pattern<'a>>::Searcher`. #[derive(Clone, Debug)] diff --git a/src/libfmt_macros/lib.rs b/src/libfmt_macros/lib.rs index aacd6cec565a5..86ed4ad15fbc9 100644 --- a/src/libfmt_macros/lib.rs +++ b/src/libfmt_macros/lib.rs @@ -413,7 +413,7 @@ impl<'a> Parser<'a> { let pos = self.position(); let format = self.format(); - // Resolve position after parsing format spec. + // Resolves position after parsing format spec. let pos = match pos { Some(position) => position, None => { diff --git a/src/libpanic_unwind/dwarf/eh.rs b/src/libpanic_unwind/dwarf/eh.rs index 07fa2971847f6..4cee394a7a55e 100644 --- a/src/libpanic_unwind/dwarf/eh.rs +++ b/src/libpanic_unwind/dwarf/eh.rs @@ -100,7 +100,7 @@ pub unsafe fn find_eh_action(lsda: *const u8, context: &EHContext<'_>) } } } - // Ip is not present in the table. This should not happen... but it does: issue #35011. + // Ip is not present in the table. This should not happen... but it does: issue #35011. // So rather than returning EHAction::Terminate, we do this. Ok(EHAction::None) } else { diff --git a/src/libpanic_unwind/gcc.rs b/src/libpanic_unwind/gcc.rs index e2b743b379704..faf7f8ebf3b47 100644 --- a/src/libpanic_unwind/gcc.rs +++ b/src/libpanic_unwind/gcc.rs @@ -91,7 +91,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box { cause.unwrap() } -// Rust's exception class identifier. This is used by personality routines to +// Rust's exception class identifier. This is used by personality routines to // determine whether the exception was thrown by their own runtime. fn rust_exception_class() -> uw::_Unwind_Exception_Class { // M O Z \0 R U S T -- vendor, language @@ -99,11 +99,11 @@ fn rust_exception_class() -> uw::_Unwind_Exception_Class { } -// Register ids were lifted from LLVM's TargetLowering::getExceptionPointerRegister() -// and TargetLowering::getExceptionSelectorRegister() for each architecture, +// Register IDs were lifted from LLVM's `TargetLowering::getExceptionPointerRegister()` +// and `TargetLowering::getExceptionSelectorRegister()` for each architecture, // then mapped to DWARF register numbers via register definition tables -// (typically RegisterInfo.td, search for "DwarfRegNum"). -// See also http://llvm.org/docs/WritingAnLLVMBackend.html#defining-a-register. +// (typically `RegisterInfo.td`; search for "DwarfRegNum"). +// See also . #[cfg(target_arch = "x86")] const UNWIND_DATA_REG: (i32, i32) = (0, 2); // EAX, EDX @@ -126,12 +126,12 @@ const UNWIND_DATA_REG: (i32, i32) = (6, 7); // R6, R7 #[cfg(target_arch = "sparc64")] const UNWIND_DATA_REG: (i32, i32) = (24, 25); // I0, I1 -// The following code is based on GCC's C and C++ personality routines. For reference, see: +// The following code is based on GCC's C and C++ personality routines. For reference, see: // https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc // https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c // The personality routine for most of our targets, except ARM, which has a slightly different ABI -// (however, iOS goes here as it uses SjLj unwinding). Also, the 64-bit Windows implementation +// (however, iOS goes here as it uses SjLj unwinding). Also, the 64-bit Windows implementation // lives in seh64_gnu.rs #[cfg(all(any(target_os = "ios", target_os = "netbsd", not(target_arch = "arm"))))] #[lang = "eh_personality"] @@ -281,12 +281,12 @@ unsafe extern "C" fn rust_eh_unwind_resume(panic_ctx: *mut u8) -> ! { uw::_Unwind_Resume(panic_ctx as *mut uw::_Unwind_Exception); } -// Frame unwind info registration +// Frame unwind info registration. // // Each module's image contains a frame unwind info section (usually -// ".eh_frame"). When a module is loaded/unloaded into the process, the +// ".eh_frame"). When a module is loaded/unloaded into the process, the // unwinder must be informed about the location of this section in memory. The -// methods of achieving that vary by the platform. On some (e.g., Linux), the +// methods of achieving that vary by the platform. On some (e.g., Linux), the // unwinder can discover unwind info sections on its own (by dynamically // enumerating currently loaded modules via the dl_iterate_phdr() API and // finding their ".eh_frame" sections); Others, like Windows, require modules diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index f7ffbe8c65833..269f3118512ba 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -19,15 +19,20 @@ struct CFGBuilder<'a, 'tcx: 'a> { #[derive(Copy, Clone)] struct BlockScope { - block_expr_id: hir::ItemLocalId, // id of breakable block expr node - break_index: CFGIndex, // where to go on `break` + // ID of breakable block expr node. + block_expr_id: hir::ItemLocalId, + // Where to go on `break`. + break_index: CFGIndex, } #[derive(Copy, Clone)] struct LoopScope { - loop_id: hir::ItemLocalId, // id of loop/while node - continue_index: CFGIndex, // where to go on a `loop` - break_index: CFGIndex, // where to go on a `break` + // ID of `loop`/`while` node. + loop_id: hir::ItemLocalId, + // Where to go on a `loop`. + continue_index: CFGIndex, + // Where to go on `break`. + break_index: CFGIndex, } pub fn construct<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, @@ -475,7 +480,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { // #47295: We used to have very special case code // here for when a pair of arms are both formed // solely from constants, and if so, not add these - // edges. But this was not actually sound without + // edges. But this was not actually sound without // other constraints that we stopped enforcing at // some point. while let Some(prev) = prev_guards.pop() { diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 796739c872174..c926c42100b83 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -151,7 +151,7 @@ macro_rules! define_dep_nodes { } } - // FIXME: Make `is_anon`, `is_input`, `is_eval_always` and `has_params` properties + // FIXME: make `is_anon`, `is_input`, `is_eval_always` and `has_params` properties // of queries #[inline(always)] pub fn is_anon(&self) -> bool { @@ -428,23 +428,23 @@ define_dep_nodes!( <'tcx> [] Null, // Represents the `Krate` as a whole (the `hir::Krate` value) (as - // distinct from the krate module). This is basically a hash of + // distinct from the `krate` module). This is basically a hash of // the entire krate, so if you read from `Krate` (e.g., by calling // `tcx.hir().krate()`), we will have to assume that any change // means that you need to be recompiled. This is because the // `Krate` value gives you access to all other items. To avoid // this fate, do not call `tcx.hir().krate()`; instead, prefer - // wrappers like `tcx.visit_all_items_in_krate()`. If there is no + // wrappers like `tcx.visit_all_items_in_krate()`. If there is no // suitable wrapper, you can use `tcx.dep_graph.ignore()` to gain - // access to the krate, but you must remember to add suitable + // access to the crate, but you must remember to add suitable // edges yourself for the individual items that you read. [input] Krate, - // Represents the body of a function or method. The def-id is that of the + // Represents the body of a function or method. The `DefId` is that of the // function/method. [input] HirBody(DefId), - // Represents the HIR node with the given node-id + // Represents the HIR node with the given `NodeId`. [input] Hir(DefId), // Represents metadata from an extern crate. @@ -548,7 +548,7 @@ define_dep_nodes!( <'tcx> [] Environment(DefId), [] DescribeDef(DefId), - // FIXME(mw): DefSpans are not really inputs since they are derived from + // FIXME(mw): `DefSpan`s are not really inputs since they are derived from // HIR. But at the moment HIR hashing still contains some hacks that allow // to make type debuginfo to be source location independent. Declaring // DefSpan an input makes sure that changes to these are always detected diff --git a/src/librustc/dep_graph/graph.rs b/src/librustc/dep_graph/graph.rs index 8a2f79e6793c0..69786f63bd785 100644 --- a/src/librustc/dep_graph/graph.rs +++ b/src/librustc/dep_graph/graph.rs @@ -75,7 +75,7 @@ struct DepGraphData { dep_node_debug: Lock>, - // Used for testing, only populated when -Zquery-dep-graph is specified. + // Used for testing, only populated when the `-Zquery-dep-graph` compiler flag is specified. loaded_from_cache: Lock>, } @@ -162,7 +162,7 @@ impl DepGraph { } /// Starts a new dep-graph task. Dep-graph tasks are specified - /// using a free function (`task`) and **not** a closure -- this + /// using a free function (`task`) and *not* a closure -- this /// is intentional because we want to exercise tight control over /// what state they have access to. In particular, we want to /// prevent implicit 'leaks' of tracked state into the task (which @@ -256,8 +256,8 @@ impl DepGraph { // In incremental mode, hash the result of the task. We don't // do anything with the hash yet, but we are computing it // anyway so that - // - we make sure that the infrastructure works and - // - we can get an idea of the runtime cost. + // - we make sure that the infrastructure works and + // - we can get an idea of the runtime cost. let mut hcx = cx.get_stable_hashing_context(); if cfg!(debug_assertions) { @@ -294,7 +294,7 @@ impl DepGraph { let print_status = cfg!(debug_assertions) && hcx.sess().opts.debugging_opts.dep_tasks; - // Determine the color of the new DepNode. + // Determine the color of the new `DepNode`. if let Some(prev_index) = data.previous.node_to_index_opt(&key) { let prev_fingerprint = data.previous.fingerprint_by_index(prev_index); @@ -522,7 +522,7 @@ impl DepGraph { for (current_dep_node_index, edges) in current_dep_graph.data.iter_enumerated() .map(|(i, d)| (i, &d.edges)) { let start = edge_list_data.len() as u32; - // This should really just be a memcpy :/ + // FIXME: this should really just be a `memcpy`. edge_list_data.extend(edges.iter().map(|i| SerializedDepNodeIndex::new(i.index()))); let end = edge_list_data.len() as u32; @@ -578,17 +578,17 @@ impl DepGraph { ) -> Option<(SerializedDepNodeIndex, DepNodeIndex)> { debug_assert!(!dep_node.kind.is_input()); - // Return None if the dep graph is disabled + // Return `None` if the dep graph is disabled. let data = self.data.as_ref()?; - // Return None if the dep node didn't exist in the previous session + // Return `None` if the dep node didn't exist in the previous session. let prev_index = data.previous.node_to_index_opt(dep_node)?; match data.colors.get(prev_index) { Some(DepNodeColor::Green(dep_node_index)) => Some((prev_index, dep_node_index)), Some(DepNodeColor::Red) => None, None => { - // This DepNode and the corresponding query invocation existed + // This `DepNode` and the corresponding query invocation existed. // in the previous compilation session too, so we can try to // mark it as green by recursively marking all of its // dependencies green. @@ -620,7 +620,7 @@ impl DepGraph { debug_assert!(data.colors.get(prev_dep_node_index).is_none()); } - // We never try to mark inputs as green + // We never try to mark inputs as green. debug_assert!(!dep_node.kind.is_input()); debug_assert_eq!(data.previous.index_to_node(prev_dep_node_index), *dep_node); @@ -733,7 +733,7 @@ impl DepGraph { } } } else { - // The DepNode could not be forced. + // The `DepNode` could not be forced. debug!("try_mark_previous_green({:?}) - END - dependency {:?} \ could not be forced", dep_node, dep_dep_node); return None @@ -743,24 +743,24 @@ impl DepGraph { } // If we got here without hitting a `return` that means that all - // dependencies of this DepNode could be marked as green. Therefore we - // can also mark this DepNode as green. + // dependencies of this `DepNode` could be marked as green. Therefore, we + // can also mark this `DepNode` as green. - // There may be multiple threads trying to mark the same dep node green concurrently + // There may be multiple threads trying to mark the same dep node green concurrently. let (dep_node_index, did_allocation) = { let mut current = data.current.borrow_mut(); // Copy the fingerprint from the previous graph, - // so we don't have to recompute it + // so we don't have to recompute it. let fingerprint = data.previous.fingerprint_by_index(prev_dep_node_index); // We allocating an entry for the node in the current dependency graph and - // adding all the appropriate edges imported from the previous graph + // adding all the appropriate edges imported from the previous graph. current.intern_node(*dep_node, current_deps, fingerprint) }; - // ... emitting any stored diagnostic ... + // ... emitting any stored diagnostic, ... let diagnostics = tcx.queries.on_disk_cache .load_diagnostics(tcx, prev_dep_node_index); @@ -775,8 +775,8 @@ impl DepGraph { ); } - // ... and finally storing a "Green" entry in the color map. - // Multiple threads can all write the same color here + // ... and finally storing a "green" entry in the color map. + // Multiple threads can all write the same color here. #[cfg(not(parallel_compiler))] debug_assert!(data.colors.get(prev_dep_node_index).is_none(), "DepGraph::try_mark_previous_green() - Duplicate DepNodeColor \ @@ -801,7 +801,7 @@ impl DepGraph { diagnostics: Vec, ) { if did_allocation || !cfg!(parallel_compiler) { - // Only the thread which did the allocation emits the error messages + // Only the thread which did the allocation emits the error messages. let handle = tcx.sess.diagnostic(); // Promote the previous diagnostics to the current session. @@ -814,12 +814,12 @@ impl DepGraph { #[cfg(parallel_compiler)] { - // Mark the diagnostics and emitted and wake up waiters + // Mark the diagnostics and emitted and wake up waiters. data.emitted_diagnostics.lock().insert(dep_node_index); data.emitted_diagnostics_cond_var.notify_all(); } } else { - // The other threads will wait for the diagnostics to be emitted + // The other threads will wait for the diagnostics to be emitted. let mut emitted_diagnostics = data.emitted_diagnostics.lock(); loop { @@ -831,20 +831,20 @@ impl DepGraph { } } - // Returns true if the given node has been marked as green during the - // current compilation session. Used in various assertions + // Returns `true` if the given node has been marked as green during the + // current compilation session. Used in various assertions. pub fn is_green(&self, dep_node: &DepNode) -> bool { self.node_color(dep_node).map(|c| c.is_green()).unwrap_or(false) } - // This method loads all on-disk cacheable query results into memory, so - // they can be written out to the new cache file again. Most query results - // will already be in memory but in the case where we marked something as - // green but then did not need the value, that value will never have been - // loaded from disk. - // - // This method will only load queries that will end up in the disk cache. - // Other queries will not be executed. + /// Loads all on-disk cacheable query results into memory, so + /// they can be written out to the new cache file again. Most query results + /// will already be in memory but in the case where we marked something as + /// green but then did not need the value, that value will never have been + /// loaded from disk. + /// + /// This method will only load queries that will end up in the disk cache. + /// Other queries will not be executed. pub fn exec_cache_promotions<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) { let green_nodes: Vec = { let data = self.data.as_ref().unwrap(); @@ -1018,15 +1018,15 @@ impl CurrentDepGraph { fingerprint: Fingerprint ) -> DepNodeIndex { // If this is an input node, we expect that it either has no - // dependencies, or that it just depends on DepKind::CrateMetadata - // or DepKind::Krate. This happens for some "thin wrapper queries" + // dependencies, or that it just depends on `DepKind::CrateMetadata` + // or `DepKind::Krate`. This happens for some "thin wrapper queries" // like `crate_disambiguator` which sometimes have zero deps (for - // when called for LOCAL_CRATE) or they depend on a CrateMetadata + // when called for `LOCAL_CRATE`) or they depend on a `CrateMetadata` // node. if cfg!(debug_assertions) { if node.kind.is_input() && task_deps.reads.len() > 0 && - // FIXME(mw): Special case for DefSpan until Spans are handled - // better in general. + // FIXME(mw): special case for `DefSpan` until `Span`s are handled + // better in general. node.kind != DepKind::DefSpan && task_deps.reads.iter().any(|&i| { !(self.data[i].node.kind == DepKind::CrateMetadata || @@ -1053,8 +1053,8 @@ impl CurrentDepGraph { ::std::mem::discriminant(&read_dep_node.kind).hash(&mut hasher); - // Fingerprint::combine() is faster than sending Fingerprint - // through the StableHasher (at least as long as StableHasher + // `Fingerprint::combine()` is faster than sending `Fingerprint` + // through the `StableHasher` (at least as long as `StableHasher` // is so slow). fingerprint = fingerprint.combine(read_dep_node.hash); } @@ -1144,8 +1144,8 @@ pub struct TaskDeps { read_set: FxHashSet, } -// A data structure that stores Option values as a contiguous -// array, using one u32 per entry. +// A data structure that stores `Option` values as a contiguous +// array, using one `u32` per entry. struct DepNodeColorMap { values: IndexVec, } diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index f46ff6f6062c2..8f794e6df71ee 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -1793,7 +1793,7 @@ extern "C" { fn foo(x: S); } impl S { fn foo(self) { /* ... */ } } ``` -the type of `foo` is **not** `fn(S)`, as one might expect. +the type of `foo` is *not* `fn(S)`, as one might expect. Rather, it is a unique, zero-sized marker type written here as `typeof(foo)`. However, `typeof(foo)` can be _coerced_ to a function pointer `fn(S)`, so you rarely notice this: diff --git a/src/librustc/hir/lowering.rs b/src/librustc/hir/lowering.rs index 84487c40f8745..53947aa6e2805 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -74,7 +74,7 @@ const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; pub struct LoweringContext<'a> { crate_root: Option<&'static str>, - // Used to assign ids to HIR nodes that do not directly correspond to an AST node. + // Used to assign IDs to HIR nodes that do not directly correspond to an AST node. sess: &'a Session, cstore: &'a dyn CrateStore, @@ -1969,7 +1969,7 @@ impl<'a> LoweringContext<'a> { &mut self, data: &ParenthesizedArgs, ) -> (hir::GenericArgs, bool) { - // Switch to `PassThrough` mode for anonymous lifetimes: this + // Switch to `PassThrough` mode for anonymous lifetimes; this // means that we permit things like `&Ref`, where `Ref` has // a hidden lifetime parameter. This is needed for backwards // compatibility, even in contexts like an impl header where @@ -2331,7 +2331,7 @@ impl<'a> LoweringContext<'a> { } }; - // "" + // `` let LoweredNodeId { node_id, hir_id } = this.next_id(); let future_params = P(hir::GenericArgs { args: hir_vec![], @@ -3198,7 +3198,7 @@ impl<'a> LoweringContext<'a> { // // The first two are produced by recursively invoking // `lower_use_tree` (and indeed there may be things - // like `use foo::{a::{b, c}}` and so forth). They + // like `use foo::{a::{b, c}}` and so forth). They // wind up being directly added to // `self.items`. However, the structure of this // function also requires us to return one item, and @@ -3223,7 +3223,7 @@ impl<'a> LoweringContext<'a> { let mut ident = ident.clone(); let mut prefix = prefix.clone(); - // Give the segments new node-ids since they are being cloned. + // Give the segments new `NodeId`s since they are being cloned. for seg in &mut prefix.segments { seg.id = self.sess.next_node_id(); } @@ -3279,7 +3279,7 @@ impl<'a> LoweringContext<'a> { // because that affects rustdoc and also the lints // about `pub` items. But we can't *always* make it // private -- particularly not for restricted paths -- - // because it contains node-ids that would then be + // because it contains `NodeId`s that would then be // unused, failing the check that HirIds are "densely // assigned". match vis.node { diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index f454d691d4188..017f9cc86dda7 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -22,17 +22,17 @@ use syntax::symbol::{Symbol, InternedString}; use syntax_pos::{Span, DUMMY_SP}; use crate::util::nodemap::NodeMap; -/// The DefPathTable maps DefIndexes to DefKeys and vice versa. -/// Internally the DefPathTable holds a tree of DefKeys, where each DefKey -/// stores the DefIndex of its parent. -/// There is one DefPathTable for each crate. +/// Maps `DefIndex`es to `DefKey`s and vice versa. +/// Internally, holds a tree of `DefKey`s, where each `DefKey` +/// stores the `DefIndex` of its parent. +/// There is one `DefPathTable` for each crate. #[derive(Default)] pub struct DefPathTable { index_to_key: [Vec; 2], def_path_hashes: [Vec; 2], } -// Unfortunately we have to provide a manual impl of Clone because of the +// Unfortunately we have to provide a manual impl of `Clone` because of the // fixed-sized array field. impl Clone for DefPathTable { fn clone(&self) -> Self { @@ -107,14 +107,13 @@ impl DefPathTable { } } - impl Encodable for DefPathTable { fn encode(&self, s: &mut S) -> Result<(), S::Error> { - // Index to key + // Index to key. self.index_to_key[DefIndexAddressSpace::Low.index()].encode(s)?; self.index_to_key[DefIndexAddressSpace::High.index()].encode(s)?; - // DefPath hashes + // `DefPath` hashes. self.def_path_hashes[DefIndexAddressSpace::Low.index()].encode(s)?; self.def_path_hashes[DefIndexAddressSpace::High.index()].encode(s)?; @@ -174,7 +173,7 @@ impl DefKey { fn compute_stable_hash(&self, parent_hash: DefPathHash) -> DefPathHash { let mut hasher = StableHasher::new(); - // We hash a 0u8 here to disambiguate between regular DefPath hashes, + // We hash a `0u8` here to disambiguate between regular `DefPath` hashes // and the special "root_parent" below. 0u8.hash(&mut hasher); parent_hash.hash(&mut hasher); @@ -198,8 +197,8 @@ impl DefKey { crate_disambiguator: CrateDisambiguator) -> DefPathHash { let mut hasher = StableHasher::new(); - // Disambiguate this from a regular DefPath hash, - // see compute_stable_hash() above. + // Disambiguate this from a regular `DefPath` hash; + // see `compute_stable_hash()` above. 1u8.hash(&mut hasher); crate_name.hash(&mut hasher); crate_disambiguator.hash(&mut hasher); @@ -330,52 +329,59 @@ impl DefPath { pub enum DefPathData { // Root: these should only be used for the root nodes, because // they are treated specially by the `def_path` function. - /// The crate root (marker) + + /// The crate root (marker). CrateRoot, - // Catch-all for random DefId things like DUMMY_NODE_ID + // Catch-all for random `DefId` things like `DUMMY_NODE_ID`. Misc, - // Different kinds of items and item-like things: - /// An impl + + // Different kinds of items and item-like things. + + /// An impl. Impl, - /// A trait + /// A trait. Trait(InternedString), - /// An associated type **declaration** (i.e., in a trait) + /// An associated type **declaration** (i.e., in a trait). AssocTypeInTrait(InternedString), - /// An associated type **value** (i.e., in an impl) + /// An associated type **value** (i.e., in an impl). AssocTypeInImpl(InternedString), - /// An existential associated type **value** (i.e., in an impl) + /// An existential associated type **value** (i.e., in an impl). AssocExistentialInImpl(InternedString), - /// Something in the type NS + /// Something in the type namespace. TypeNs(InternedString), - /// Something in the value NS + /// Something in the value namespace. ValueNs(InternedString), - /// A module declaration + /// A module declaration. Module(InternedString), - /// A macro rule + /// A macro rule. MacroDef(InternedString), - /// A closure expression + /// A closure expression. ClosureExpr, - // Subportions of items - /// A type (generic) parameter + + // Subportions of items. + + /// A type (generic) parameter. TypeParam(InternedString), - /// A lifetime (generic) parameter + /// A lifetime (generic) parameter. LifetimeParam(InternedString), - /// A const (generic) parameter + /// A const (generic) parameter. ConstParam(InternedString), /// A variant of a enum EnumVariant(InternedString), - /// A struct field + /// A struct field. Field(InternedString), - /// Implicit ctor for a tuple-like struct + /// Implicit ctor for a tuple-like struct. StructCtor, - /// A constant expression (see {ast,hir}::AnonConst). + /// A constant expression (see `{ast,hir}::AnonConst`). AnonConst, - /// An `impl Trait` type node + /// An `impl Trait` type node. ImplTrait, - /// GlobalMetaData identifies a piece of crate metadata that is global to - /// a whole crate (as opposed to just one item). GlobalMetaData components + + /// Identifies a piece of crate metadata that is global to + /// a whole crate (as opposed to just one item). These components /// are only supposed to show up right below the crate root. GlobalMetaData(InternedString), + /// A trait alias. TraitAlias(InternedString), } @@ -469,7 +475,7 @@ impl Definitions { } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. #[inline] pub fn as_local_hir_id(&self, def_id: DefId) -> Option { if def_id.krate == LOCAL_CRATE { @@ -533,13 +539,13 @@ impl Definitions { self.def_index_to_node[address_space.index()].push(ast::CRATE_NODE_ID); self.node_to_def_index.insert(ast::CRATE_NODE_ID, root_index); - // Allocate some other DefIndices that always must exist. + // Allocate some other `DefIndex`es that always must exist. GlobalMetaDataKind::allocate_def_indices(self); root_index } - /// Add a definition with a parent definition. + /// Adds a definition with a parent definition. pub fn create_def_with_parent(&mut self, parent: DefIndex, node_id: ast::NodeId, @@ -557,7 +563,7 @@ impl Definitions { data, self.table.def_key(self.node_to_def_index[&node_id])); - // The root node must be created with create_root_def() + // The root node must be created with `create_root_def()`. assert!(data != DefPathData::CrateRoot); // Find the next free disambiguator for this key. @@ -586,9 +592,9 @@ impl Definitions { self.def_index_to_node[address_space.index()].len()); self.def_index_to_node[address_space.index()].push(node_id); - // Some things for which we allocate DefIndices don't correspond to - // anything in the AST, so they don't have a NodeId. For these cases - // we don't need a mapping from NodeId to DefIndex. + // Some things for which we allocate `DefIndex`es don't correspond to + // anything in the AST, so they don't have a `NodeId`. For these cases + // we don't need a mapping from NodeId to `DefIndex`. if node_id != ast::DUMMY_NODE_ID { debug!("create_def_with_parent: def_index_to_node[{:?} <-> {:?}", index, node_id); self.node_to_def_index.insert(node_id, index); @@ -598,7 +604,7 @@ impl Definitions { self.expansions_that_defined.insert(index, expansion); } - // The span is added if it isn't dummy + // The span is added if it isn't dummy. if !span.is_dummy() { self.def_index_to_span.insert(index, span); } @@ -678,7 +684,7 @@ impl DefPathData { GlobalMetaData(name) => { return name } - // note that this does not show up in user printouts + // Note that this does not show up in user print-outs. CrateRoot => "{{root}}", Impl => "{{impl}}", Misc => "{{?}}", @@ -701,9 +707,9 @@ macro_rules! count { ( $x:tt $($xs:tt)* ) => (1usize + count!($($xs)*)); } -// We define the GlobalMetaDataKind enum with this macro because we want to +// We define the `GlobalMetaDataKind` enum with this macro because we want to // make sure that we exhaustively iterate over all variants when registering -// the corresponding DefIndices in the DefTable. +// the corresponding `DefIndex`es in the `DefTable`. macro_rules! define_global_metadata_kind { (pub enum GlobalMetaDataKind { $($variant:ident),* @@ -729,7 +735,7 @@ macro_rules! define_global_metadata_kind { DUMMY_SP ); - // Make sure calling def_index does not crash. + // Make sure that calling `def_index` does not crash. instance.def_index(&definitions.table); })* } @@ -743,7 +749,7 @@ macro_rules! define_global_metadata_kind { } }; - // These DefKeys are all right after the root, + // These `DefKey`s are all right after the root, // so a linear search is fine. let index = def_path_table.index_to_key[GLOBAL_MD_ADDRESS_SPACE.index()] .iter() diff --git a/src/librustc/hir/map/hir_id_validator.rs b/src/librustc/hir/map/hir_id_validator.rs index 2c3ff4c9b5c05..aaf2ef60aef62 100644 --- a/src/librustc/hir/map/hir_id_validator.rs +++ b/src/librustc/hir/map/hir_id_validator.rs @@ -96,12 +96,12 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { .expect("owning item has no entry"); if max != self.hir_ids_seen.len() - 1 { - // Collect the missing ItemLocalIds + // Collect the missing `ItemLocalId`s. let missing: Vec<_> = (0 ..= max as u32) .filter(|&i| !self.hir_ids_seen.contains_key(&ItemLocalId::from_u32(i))) .collect(); - // Try to map those to something more useful + // Try to map those to something more useful. let mut missing_items = Vec::with_capacity(missing.len()); for local_id in missing { @@ -112,8 +112,7 @@ impl<'a, 'hir: 'a> HirIdValidator<'a, 'hir> { trace!("missing hir id {:#?}", hir_id); - // We are already in ICE mode here, so doing a linear search - // should be fine. + // We are already in ICE mode here, so doing a linear search should be fine. let (node_id, _) = self.hir_map .definitions() .node_to_hir_id diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index b6cf4c1b84d0c..b161e1bb2bbd0 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -208,7 +208,7 @@ impl<'hir> Map<'hir> { } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn read_by_hir_id(&self, hir_id: HirId) { let node_id = self.hir_to_node_id(hir_id); self.read(node_id); @@ -230,7 +230,7 @@ impl<'hir> Map<'hir> { }) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn def_path_from_hir_id(&self, id: HirId) -> DefPath { self.def_path(self.local_def_id_from_hir_id(id)) } @@ -248,7 +248,7 @@ impl<'hir> Map<'hir> { }) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. #[inline] pub fn local_def_id_from_hir_id(&self, hir_id: HirId) -> DefId { let node_id = self.hir_to_node_id(hir_id); @@ -258,7 +258,7 @@ impl<'hir> Map<'hir> { }) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. #[inline] pub fn opt_local_def_id_from_hir_id(&self, hir_id: HirId) -> Option { let node_id = self.hir_to_node_id(hir_id); @@ -275,7 +275,7 @@ impl<'hir> Map<'hir> { self.definitions.as_local_node_id(def_id) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. #[inline] pub fn as_local_hir_id(&self, def_id: DefId) -> Option { self.definitions.as_local_hir_id(def_id) @@ -603,7 +603,7 @@ impl<'hir> Map<'hir> { // Read the module so we'll be re-executed if new items // appear immediately under in the module. If some new item appears // in some nested item in the module, we'll be re-executed due to reads - // in the expect_* calls the loops below + // in the `expect_*` calls the loops below. self.read(node_id); let module = &self.forest.krate.modules[&node_id]; @@ -621,21 +621,22 @@ impl<'hir> Map<'hir> { } } - /// Retrieve the Node corresponding to `id`, panicking if it cannot + /// Retrieves the `Node` corresponding to `id`, panicking if it cannot /// be found. pub fn get(&self, id: NodeId) -> Node<'hir> { // read recorded by `find` self.find(id).unwrap_or_else(|| bug!("couldn't find node id {} in the AST map", id)) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn get_by_hir_id(&self, id: HirId) -> Node<'hir> { let node_id = self.hir_to_node_id(id); self.get(node_id) } pub fn get_if_local(&self, id: DefId) -> Option> { - self.as_local_node_id(id).map(|id| self.get(id)) // read recorded by `get` + // Read is recorded by `get`. + self.as_local_node_id(id).map(|id| self.get(id)) } pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics> { @@ -680,13 +681,13 @@ impl<'hir> Map<'hir> { result } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn find_by_hir_id(&self, hir_id: HirId) -> Option> { let node_id = self.hir_to_node_id(hir_id); self.find(node_id) } - /// Similar to `get_parent`; returns the parent node-id, or own `id` if there is + /// Similar to `get_parent`; returns the parent `NodeId`, or own `id` if there is /// no parent. Note that the parent may be `CRATE_NODE_ID`, which is not itself /// present in the map -- so passing the return value of get_parent_node to /// get may actually panic. @@ -706,14 +707,14 @@ impl<'hir> Map<'hir> { self.find_entry(id).and_then(|x| x.parent_node()).unwrap_or(id) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn get_parent_node_by_hir_id(&self, id: HirId) -> HirId { let node_id = self.hir_to_node_id(id); let parent_node_id = self.get_parent_node(node_id); self.node_to_hir_id(parent_node_id) } - /// Check if the node is an argument. An argument is a local variable whose + /// Checks if the node is an argument. An argument is a local variable whose /// immediate parent is an item or a closure. pub fn is_argument(&self, id: NodeId) -> bool { match self.find(id) { @@ -837,7 +838,7 @@ impl<'hir> Map<'hir> { } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn get_parent_item(&self, id: HirId) -> HirId { let node_id = self.hir_to_node_id(id); let parent_node_id = self.get_parent(node_id); @@ -869,9 +870,10 @@ impl<'hir> Map<'hir> { } /// Returns the nearest enclosing scope. A scope is an item or block. - /// FIXME: it is not clear to me that all items qualify as scopes -- statics - /// and associated types probably shouldn't, for example. Behavior in this - /// regard should be expected to be highly unstable. + // + // FIXME: it is not clear to me that all items qualify as scopes -- statics + // and associated types probably shouldn't, for example. Behavior in this + // regard should be expected to be highly unstable. pub fn get_enclosing_scope(&self, id: NodeId) -> Option { self.walk_parent_nodes(id, |node| match *node { Node::Item(_) | @@ -899,7 +901,8 @@ impl<'hir> Map<'hir> { if let Entry { node: Node::Item(Item { node: ItemKind::ForeignMod(ref nm), .. }), .. } = entry { - self.read(id); // reveals some of the content of a node + // Reveals some of the content of a node. + self.read(id); return nm.abi; } } @@ -913,13 +916,14 @@ impl<'hir> Map<'hir> { } pub fn expect_item(&self, id: NodeId) -> &'hir Item { - match self.find(id) { // read recorded by `find` + // Read recorded by `find` method. + match self.find(id) { Some(Node::Item(item)) => item, _ => bug!("expected item, found {}", self.node_to_string(id)) } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn expect_item_by_hir_id(&self, id: HirId) -> &'hir Item { let node_id = self.hir_to_node_id(id); self.expect_item(node_id) @@ -985,19 +989,20 @@ impl<'hir> Map<'hir> { } pub fn expect_expr(&self, id: NodeId) -> &'hir Expr { - match self.find(id) { // read recorded by find + // Read recorded by `find` method. + match self.find(id) { Some(Node::Expr(expr)) => expr, _ => bug!("expected expr, found {}", self.node_to_string(id)) } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn expect_expr_by_hir_id(&self, id: HirId) -> &'hir Expr { let node_id = self.hir_to_node_id(id); self.expect_expr(node_id) } - /// Returns the name associated with the given NodeId's AST. + /// Returns the name associated with the given `NodeId`'s AST. pub fn name(&self, id: NodeId) -> Name { match self.get(id) { Node::Item(i) => i.ident.name, @@ -1014,14 +1019,14 @@ impl<'hir> Map<'hir> { } } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn name_by_hir_id(&self, id: HirId) -> Name { let node_id = self.hir_to_node_id(id); self.name(node_id) } - /// Given a node ID, get a list of attributes associated with the AST - /// corresponding to the Node ID + /// Given a `NodeId`, get a list of attributes associated with the AST + /// corresponding to the `NodeId`. pub fn attrs(&self, id: NodeId) -> &'hir [ast::Attribute] { self.read(id); // reveals attributes on the node let attrs = match self.find(id) { @@ -1034,25 +1039,24 @@ impl<'hir> Map<'hir> { Some(Node::Expr(ref e)) => Some(&*e.attrs), Some(Node::Stmt(ref s)) => Some(s.node.attrs()), Some(Node::GenericParam(param)) => Some(¶m.attrs[..]), - // unit/tuple structs take the attributes straight from - // the struct definition. + // Unit/tuple structs take the attributes straight from the struct definition. Some(Node::StructCtor(_)) => return self.attrs(self.get_parent(id)), _ => None }; attrs.unwrap_or(&[]) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn attrs_by_hir_id(&self, id: HirId) -> &'hir [ast::Attribute] { let node_id = self.hir_to_node_id(id); self.attrs(node_id) } - /// Returns an iterator that yields the node id's with paths that - /// match `parts`. (Requires `parts` is non-empty.) + /// Returns an iterator that yields the `NodeId`'s with paths that + /// match `parts`. (Requires that `parts` is non-empty.) /// /// For example, if given `parts` equal to `["bar", "quux"]`, then - /// the iterator will produce node id's for items with paths + /// the iterator will produce `NodeId`'s for items with paths /// such as `foo::bar::quux`, `bar::quux`, `other::bar::quux`, and /// any other such items it can find in the map. pub fn nodes_matching_suffix<'a>(&'a self, parts: &'a [String]) @@ -1066,7 +1070,8 @@ impl<'hir> Map<'hir> { } pub fn span(&self, id: NodeId) -> Span { - self.read(id); // reveals span from node + // Reveals span from node. + self.read(id); match self.find_entry(id).map(|entry| entry.node) { Some(Node::Item(item)) => item.span, Some(Node::ForeignItem(foreign_item)) => foreign_item.span, @@ -1111,7 +1116,7 @@ impl<'hir> Map<'hir> { node_id_to_string(self, id, true) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn hir_to_string(&self, id: HirId) -> String { hir_id_to_string(self, id, true) } @@ -1120,7 +1125,7 @@ impl<'hir> Map<'hir> { node_id_to_string(self, id, false) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn hir_to_user_string(&self, id: HirId) -> String { hir_id_to_string(self, id, false) } @@ -1129,7 +1134,7 @@ impl<'hir> Map<'hir> { print::to_string(self, |s| s.print_node(self.get(id))) } - // FIXME(@ljedrz): replace the NodeId variant + // FIXME(ljedrz): replace the `NodeId` variant. pub fn hir_to_pretty_string(&self, id: HirId) -> String { print::to_string(self, |s| s.print_node(self.get_by_hir_id(id))) } @@ -1167,7 +1172,7 @@ impl<'a, 'hir> NodesMatchingSuffix<'a, 'hir> { // that mod's name. // // If `id` itself is a mod named `m` with parent `p`, then - // returns `Some(id, m, p)`. If `id` has no mod in its parent + // returns `Some(id, m, p)`. If `id` has no mod in its parent // chain, then returns `None`. fn find_first_mod_parent<'a>(map: &'a Map<'_>, mut id: NodeId) -> Option<(NodeId, Name)> { loop { @@ -1325,9 +1330,9 @@ impl<'a> print::State<'a> { Node::Block(a) => { use syntax::print::pprust::PrintState; - // containing cbox, will be closed by print-block at } + // Containing cbox -- will be closed by print-block at `}`. self.cbox(print::indent_unit)?; - // head-ibox, will be closed by print-block after { + // Head-ibox -- will be closed by print-block after `{`. self.ibox(0)?; self.print_block(&a) } @@ -1335,8 +1340,8 @@ impl<'a> print::State<'a> { Node::Visibility(a) => self.print_visibility(&a), Node::GenericParam(_) => bug!("cannot print Node::GenericParam"), Node::Field(_) => bug!("cannot print StructField"), - // these cases do not carry enough information in the - // hir_map to reconstruct their full structure for pretty + // These cases do not carry enough information in the + // `hir_map` to reconstruct their full structure for pretty // printing. Node::StructCtor(_) => bug!("cannot print isolated StructCtor"), Node::Local(a) => self.print_local_decl(&a), @@ -1476,7 +1481,7 @@ fn node_id_to_string(map: &Map<'_>, id: NodeId, include_id: bool) -> String { } } -// FIXME(@ljedrz): replace the NodeId variant +// FIXME(ljedrz): replace the `NodeId` variant. fn hir_id_to_string(map: &Map<'_>, id: HirId, include_id: bool) -> String { let node_id = map.hir_to_node_id(id); node_id_to_string(map, node_id, include_id) diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index d774359fa79ec..29d4f75dfd08a 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -1,4 +1,4 @@ -// HIR datatypes. See the [rustc guide] for more info. +// HIR data-types. See the [rustc guide] for more info. //! //! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html @@ -112,12 +112,12 @@ impl serialize::UseSpecializedDecodable for HirId { } } -// hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module +// HACK: ensure that we don't try to access the private parts of `ItemLocalId` in this module. mod item_local_id_inner { use rustc_data_structures::indexed_vec::Idx; /// An `ItemLocalId` uniquely identifies something within a given "item-like", - /// that is within a hir::Item, hir::TraitItem, or hir::ImplItem. There is no - /// guarantee that the numerical value of a given `ItemLocalId` corresponds to + /// that is within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is + /// no guarantee that the numerical value of a given `ItemLocalId` corresponds to /// the node's position within the owning item in any way, but there is a /// guarantee that the `LocalItemId`s within an owner occupy a dense range of /// integers starting at zero, so a mapping that maps all or most nodes within @@ -236,8 +236,8 @@ impl LifetimeName { LifetimeName::Implicit | LifetimeName::Underscore => true, // It might seem surprising that `Fresh(_)` counts as - // *not* elided -- but this is because, as far as the code - // in the compiler is concerned -- `Fresh(_)` variants act + // *not* elided, but this is because, as far as the code + // in the compiler is concerned, `Fresh(_)` variants act // equivalently to "some fresh name". They correspond to // early-bound regions on an impl, in other words. LifetimeName::Error | LifetimeName::Param(_) | LifetimeName::Static => false, @@ -375,8 +375,8 @@ impl PathSegment { } } - // FIXME: hack required because you can't create a static - // `GenericArgs`, so you can't just return a `&GenericArgs`. + // HACK: required because you can't create a static `GenericArgs`, + // so you can't just return a `&GenericArgs`. pub fn with_generic_args(&self, f: F) -> R where F: FnOnce(&GenericArgs) -> R { @@ -698,8 +698,8 @@ pub struct Crate { pub span: Span, pub exported_macros: HirVec, - // N.B., we use a BTreeMap here so that `visit_all_items` iterates - // over the ids in increasing order. In principle it should not + // N.B., we use a `BTreeMap` here so that `visit_all_items` iterates + // over the IDs in increasing order. In principle it should not // matter what order we visit things in, but in *practice* it // does, because it can affect the order in which errors are // detected, which in turn can make compile-fail tests yield @@ -833,7 +833,7 @@ impl fmt::Debug for Pat { } impl Pat { - // FIXME(#19596) this is a workaround, but there should be a better way + // FIXME(#19596): this is a workaround, but there should be a better way. fn walk_(&self, it: &mut G) -> bool where G: FnMut(&Pat) -> bool { @@ -1603,11 +1603,11 @@ impl fmt::Display for LoopIdError { #[derive(Clone, RustcEncodable, RustcDecodable, Debug, Copy)] pub struct Destination { - // This is `Some(_)` iff there is an explicit user-specified `label + // This is `Some(_)` iff there is an explicit user-specified label. pub label: Option