diff --git a/src/librustc_builtin_macros/deriving/generic/ty.rs b/src/librustc_builtin_macros/deriving/generic/ty.rs index d83c98572a272..23980a2db8d42 100644 --- a/src/librustc_builtin_macros/deriving/generic/ty.rs +++ b/src/librustc_builtin_macros/deriving/generic/ty.rs @@ -98,7 +98,7 @@ pub enum Ty<'a> { Self_, /// &/Box/ Ty Ptr(Box>, PtrTy), - /// mod::mod::Type<[lifetime], [Params...]>, including a plain type + /// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type /// parameter, and things like `i32` Literal(Path<'a>), /// includes unit diff --git a/src/librustc_builtin_macros/test_harness.rs b/src/librustc_builtin_macros/test_harness.rs index 160a5204eaf70..fa5993471c44a 100644 --- a/src/librustc_builtin_macros/test_harness.rs +++ b/src/librustc_builtin_macros/test_harness.rs @@ -233,6 +233,7 @@ fn generate_test_harness( /// /// By default this expands to /// +/// ``` /// #[main] /// pub fn main() { /// extern crate test; @@ -242,6 +243,7 @@ fn generate_test_harness( /// &test_const3, /// ]); /// } +/// ``` /// /// Most of the Ident have the usual def-site hygiene for the AST pass. The /// exception is the `test_const`s. These have a syntax context that has two diff --git a/src/librustc_codegen_llvm/back/lto.rs b/src/librustc_codegen_llvm/back/lto.rs index e65bdbe171b26..d3e3441b087c2 100644 --- a/src/librustc_codegen_llvm/back/lto.rs +++ b/src/librustc_codegen_llvm/back/lto.rs @@ -17,7 +17,7 @@ use rustc_middle::bug; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_session::cgu_reuse_tracker::CguReuse; -use rustc_session::config::{self, Lto}; +use rustc_session::config::{self, CrateType, Lto}; use std::ffi::{CStr, CString}; use std::fs::File; @@ -33,13 +33,10 @@ use std::sync::Arc; /// compilation session. pub const THIN_LTO_IMPORTS_INCR_COMP_FILE_NAME: &str = "thin-lto-past-imports.bin"; -pub fn crate_type_allows_lto(crate_type: config::CrateType) -> bool { +pub fn crate_type_allows_lto(crate_type: CrateType) -> bool { match crate_type { - config::CrateType::Executable - | config::CrateType::Staticlib - | config::CrateType::Cdylib => true, - - config::CrateType::Dylib | config::CrateType::Rlib | config::CrateType::ProcMacro => false, + CrateType::Executable | CrateType::Staticlib | CrateType::Cdylib => true, + CrateType::Dylib | CrateType::Rlib | CrateType::ProcMacro => false, } } diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index f868385ee869a..01f90cae7a5fc 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -16,7 +16,7 @@ use rustc_middle::bug; use rustc_middle::mir::mono::CodegenUnit; use rustc_middle::ty::layout::{HasParamEnv, LayoutError, TyAndLayout}; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; -use rustc_session::config::{self, CFGuard, DebugInfo}; +use rustc_session::config::{CFGuard, CrateType, DebugInfo}; use rustc_session::Session; use rustc_span::source_map::{Span, DUMMY_SP}; use rustc_span::symbol::Symbol; @@ -49,12 +49,13 @@ pub struct CodegenCx<'ll, 'tcx> { pub const_cstr_cache: RefCell>, /// Reverse-direction for const ptrs cast from globals. - /// Key is a Value holding a *T, - /// Val is a Value holding a *[T]. + /// + /// Key is a Value holding a `*T`, + /// Val is a Value holding a `*[T]`. /// /// Needed because LLVM loses pointer->pointee association /// when we ptrcast, and we have to ptrcast during codegen - /// of a [T] const because we form a slice, a (*T,usize) pair, not + /// of a `[T]` const because we form a slice, a `(*T,usize)` pair, not /// a pointer to an LLVM array type. Similar for trait objects. pub const_unsized: RefCell>, @@ -101,9 +102,10 @@ fn to_llvm_tls_model(tls_model: TlsModel) -> llvm::ThreadLocalMode { /// If the list of crate types is not yet known we conservatively return `false`. pub fn all_outputs_are_pic_executables(sess: &Session) -> bool { sess.relocation_model() == RelocModel::Pic - && sess.crate_types.try_get().map_or(false, |crate_types| { - crate_types.iter().all(|ty| *ty == config::CrateType::Executable) - }) + && sess + .crate_types + .try_get() + .map_or(false, |crate_types| crate_types.iter().all(|ty| *ty == CrateType::Executable)) } fn strip_function_ptr_alignment(data_layout: String) -> String { diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 12cd58924aec6..7a0e1e2c63887 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -3,9 +3,8 @@ use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLibrary, NativeLibraryKind}; use rustc_middle::middle::dependency_format::Linkage; -use rustc_session::config::{ - self, CFGuard, DebugInfo, OutputFilenames, OutputType, PrintRequest, Sanitizer, -}; +use rustc_session::config::{self, CFGuard, CrateType, DebugInfo}; +use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, Sanitizer}; use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename}; use rustc_session::search_paths::PathKind; /// For all the linkers we support, and information they might @@ -55,7 +54,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( // Ignore executable crates if we have -Z no-codegen, as they will error. if (sess.opts.debugging_opts.no_codegen || !sess.opts.output_types.should_codegen()) && !output_metadata - && crate_type == config::CrateType::Executable + && crate_type == CrateType::Executable { continue; } @@ -82,7 +81,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( if outputs.outputs.should_codegen() { let out_filename = out_filename(sess, crate_type, outputs, crate_name); match crate_type { - config::CrateType::Rlib => { + CrateType::Rlib => { let _timer = sess.timer("link_rlib"); link_rlib::( sess, @@ -93,7 +92,7 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>( ) .build(); } - config::CrateType::Staticlib => { + CrateType::Staticlib => { link_staticlib::(sess, codegen_results, &out_filename, &tmpdir); } _ => { @@ -236,10 +235,10 @@ pub fn each_linked_rlib( let mut fmts = None; for (ty, list) in info.dependency_formats.iter() { match ty { - config::CrateType::Executable - | config::CrateType::Staticlib - | config::CrateType::Cdylib - | config::CrateType::ProcMacro => { + CrateType::Executable + | CrateType::Staticlib + | CrateType::Cdylib + | CrateType::ProcMacro => { fmts = Some(list); break; } @@ -461,7 +460,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>( // links to all upstream files as well. fn link_natively<'a, B: ArchiveBuilder<'a>>( sess: &'a Session, - crate_type: config::CrateType, + crate_type: CrateType, out_filename: &Path, codegen_results: &CodegenResults, tmpdir: &Path, @@ -664,13 +663,13 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>( } } -fn link_sanitizer_runtime(sess: &Session, crate_type: config::CrateType, linker: &mut dyn Linker) { +fn link_sanitizer_runtime(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) { let sanitizer = match &sess.opts.debugging_opts.sanitizer { Some(s) => s, None => return, }; - if crate_type != config::CrateType::Executable { + if crate_type != CrateType::Executable { return; } @@ -826,7 +825,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool { .crate_types .borrow() .iter() - .any(|&x| x != config::CrateType::Rlib && x != config::CrateType::Staticlib); + .any(|&x| x != CrateType::Rlib && x != CrateType::Staticlib); if !output_linked { return false; } @@ -1132,8 +1131,8 @@ fn exec_linker( } /// Add begin object files defined by the target spec. -fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config::CrateType) { - let pre_link_objects = if crate_type == config::CrateType::Executable { +fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: CrateType) { + let pre_link_objects = if crate_type == CrateType::Executable { &sess.target.target.options.pre_link_objects_exe } else { &sess.target.target.options.pre_link_objects_dll @@ -1142,7 +1141,7 @@ fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config cmd.add_object(&get_object_file_path(sess, obj)); } - if crate_type == config::CrateType::Executable && sess.crt_static(Some(crate_type)) { + if crate_type == CrateType::Executable && sess.crt_static(Some(crate_type)) { for obj in &sess.target.target.options.pre_link_objects_exe_crt { cmd.add_object(&get_object_file_path(sess, obj)); } @@ -1150,7 +1149,7 @@ fn add_pre_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config } /// Add end object files defined by the target spec. -fn add_post_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: config::CrateType) { +fn add_post_link_objects(cmd: &mut dyn Linker, sess: &Session, crate_type: CrateType) { for obj in &sess.target.target.options.post_link_objects { cmd.add_object(&get_object_file_path(sess, obj)); } @@ -1167,7 +1166,7 @@ fn add_pre_link_args( cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor, - crate_type: config::CrateType, + crate_type: CrateType, ) { if let Some(args) = sess.target.target.options.pre_link_args.get(&flavor) { cmd.args(args); @@ -1197,13 +1196,13 @@ fn add_late_link_args( cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor, - crate_type: config::CrateType, + crate_type: CrateType, codegen_results: &CodegenResults, ) { if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) { cmd.args(args); } - let any_dynamic_crate = crate_type == config::CrateType::Dylib + let any_dynamic_crate = crate_type == CrateType::Dylib || codegen_results.crate_info.dependency_formats.iter().any(|(ty, list)| { *ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic) }); @@ -1243,13 +1242,13 @@ fn add_local_crate_allocator_objects(cmd: &mut dyn Linker, codegen_results: &Cod /// Add object files containing metadata for the current crate. fn add_local_crate_metadata_objects( cmd: &mut dyn Linker, - crate_type: config::CrateType, + crate_type: CrateType, codegen_results: &CodegenResults, ) { // When linking a dynamic library, we put the metadata into a section of the // executable. This metadata is in a separate object file from the main // object file, so we link that in here. - if crate_type == config::CrateType::Dylib || crate_type == config::CrateType::ProcMacro { + if crate_type == CrateType::Dylib || crate_type == CrateType::ProcMacro { if let Some(obj) = codegen_results.metadata_module.as_ref().and_then(|m| m.object.as_ref()) { cmd.add_object(obj); @@ -1263,7 +1262,7 @@ fn add_local_crate_metadata_objects( fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'a>>( cmd: &mut dyn Linker, sess: &'a Session, - crate_type: config::CrateType, + crate_type: CrateType, codegen_results: &CodegenResults, tmpdir: &Path, ) { @@ -1326,10 +1325,10 @@ fn add_position_independent_executable_args( cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor, - crate_type: config::CrateType, + crate_type: CrateType, codegen_results: &CodegenResults, ) { - if crate_type != config::CrateType::Executable { + if crate_type != CrateType::Executable { return; } @@ -1407,7 +1406,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( path: &Path, flavor: LinkerFlavor, sess: &'a Session, - crate_type: config::CrateType, + crate_type: CrateType, tmpdir: &Path, out_filename: &Path, codegen_results: &CodegenResults, @@ -1463,7 +1462,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( cmd.output_filename(out_filename); // OBJECT-FILES-NO, AUDIT-ORDER - if crate_type == config::CrateType::Executable && sess.target.target.options.is_like_windows { + if crate_type == CrateType::Executable && sess.target.target.options.is_like_windows { if let Some(ref s) = codegen_results.windows_subsystem { cmd.subsystem(s); } @@ -1486,7 +1485,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // Try to strip as much out of the generated object by removing unused // sections if possible. See more comments in linker.rs if !sess.opts.cg.link_dead_code { - let keep_metadata = crate_type == config::CrateType::Dylib; + let keep_metadata = crate_type == CrateType::Dylib; cmd.gc_sections(keep_metadata); } @@ -1522,10 +1521,10 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( // NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER // Tell the linker what we're doing. - if crate_type != config::CrateType::Executable { + if crate_type != CrateType::Executable { cmd.build_dylib(out_filename); } - if crate_type == config::CrateType::Executable && sess.crt_static(Some(crate_type)) { + if crate_type == CrateType::Executable && sess.crt_static(Some(crate_type)) { cmd.build_static_executable(); } @@ -1619,7 +1618,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( cmd: &mut dyn Linker, sess: &'a Session, codegen_results: &CodegenResults, - crate_type: config::CrateType, + crate_type: CrateType, tmpdir: &Path, ) { // All of the heavy lifting has previously been accomplished by the @@ -1780,7 +1779,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( sess: &'a Session, codegen_results: &CodegenResults, tmpdir: &Path, - crate_type: config::CrateType, + crate_type: CrateType, cnum: CrateNum, ) { let src = &codegen_results.crate_info.used_crate_source[&cnum]; @@ -1796,7 +1795,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( if (!are_upstream_rust_objects_already_included(sess) || ignored_for_lto(sess, &codegen_results.crate_info, cnum)) - && crate_type != config::CrateType::Dylib + && crate_type != CrateType::Dylib && !skip_native { cmd.link_rlib(&fix_windows_verbatim_for_gcc(cratepath)); @@ -1857,7 +1856,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( // Note, though, that we don't want to include the whole of a // compiler-builtins crate (e.g., compiler-rt) because it'll get // repeatedly linked anyway. - if crate_type == config::CrateType::Dylib + if crate_type == CrateType::Dylib && codegen_results.crate_info.compiler_builtins != Some(cnum) { cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&dst)); @@ -1905,7 +1904,7 @@ fn add_upstream_native_libraries( cmd: &mut dyn Linker, sess: &Session, codegen_results: &CodegenResults, - crate_type: config::CrateType, + crate_type: CrateType, ) { // Be sure to use a topological sorting of crates because there may be // interdependencies between native libraries. When passing -nodefaultlibs, diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 338211ca11f3c..c0272e1cd2d6b 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -15,23 +15,22 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::subst::{GenericArgKind, SubstsRef}; use rustc_middle::ty::Instance; use rustc_middle::ty::{SymbolName, TyCtxt}; -use rustc_session::config::{self, Sanitizer}; +use rustc_session::config::{CrateType, Sanitizer}; pub fn threshold(tcx: TyCtxt<'_>) -> SymbolExportLevel { crates_export_threshold(&tcx.sess.crate_types.borrow()) } -fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel { +fn crate_export_threshold(crate_type: CrateType) -> SymbolExportLevel { match crate_type { - config::CrateType::Executable - | config::CrateType::Staticlib - | config::CrateType::ProcMacro - | config::CrateType::Cdylib => SymbolExportLevel::C, - config::CrateType::Rlib | config::CrateType::Dylib => SymbolExportLevel::Rust, + CrateType::Executable | CrateType::Staticlib | CrateType::ProcMacro | CrateType::Cdylib => { + SymbolExportLevel::C + } + CrateType::Rlib | CrateType::Dylib => SymbolExportLevel::Rust, } } -pub fn crates_export_threshold(crate_types: &[config::CrateType]) -> SymbolExportLevel { +pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel { if crate_types .iter() .any(|&crate_type| crate_export_threshold(crate_type) == SymbolExportLevel::Rust) @@ -213,7 +212,7 @@ fn exported_symbols_provider_local( })); } - if tcx.sess.crate_types.borrow().contains(&config::CrateType::Dylib) { + if tcx.sess.crate_types.borrow().contains(&CrateType::Dylib) { let symbol_name = metadata_symbol_name(tcx); let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(&symbol_name)); diff --git a/src/librustc_codegen_ssa/back/write.rs b/src/librustc_codegen_ssa/back/write.rs index 31bf064ad9179..c53fc5551fdfb 100644 --- a/src/librustc_codegen_ssa/back/write.rs +++ b/src/librustc_codegen_ssa/back/write.rs @@ -28,9 +28,8 @@ use rustc_middle::middle::cstore::EncodedMetadata; use rustc_middle::middle::exported_symbols::SymbolExportLevel; use rustc_middle::ty::TyCtxt; use rustc_session::cgu_reuse_tracker::CguReuseTracker; -use rustc_session::config::{ - self, Lto, OutputFilenames, OutputType, Passes, Sanitizer, SwitchWithOptPath, -}; +use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType}; +use rustc_session::config::{Passes, Sanitizer, SwitchWithOptPath}; use rustc_session::Session; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::SourceMap; @@ -288,7 +287,7 @@ pub struct CodegenContext { pub fewer_names: bool, pub exported_symbols: Option>, pub opts: Arc, - pub crate_types: Vec, + pub crate_types: Vec, pub each_linked_rlib_for_lto: Vec<(CrateNum, PathBuf)>, pub output_filenames: Arc, pub regular_module_config: Arc, @@ -375,7 +374,7 @@ pub struct CompiledModules { fn need_crate_bitcode_for_rlib(sess: &Session) -> bool { sess.opts.cg.embed_bitcode - && sess.crate_types.borrow().contains(&config::CrateType::Rlib) + && sess.crate_types.borrow().contains(&CrateType::Rlib) && sess.opts.output_types.contains_key(&OutputType::Exe) } @@ -760,7 +759,7 @@ fn execute_optimize_work_item( // require LTO so the request for LTO is always unconditionally // passed down to the backend, but we don't actually want to do // anything about it yet until we've got a final product. - let is_rlib = cgcx.crate_types.len() == 1 && cgcx.crate_types[0] == config::CrateType::Rlib; + let is_rlib = cgcx.crate_types.len() == 1 && cgcx.crate_types[0] == CrateType::Rlib; // Metadata modules never participate in LTO regardless of the lto // settings. @@ -1813,7 +1812,7 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool { ); tcx.sess.target.target.options.is_like_msvc && - tcx.sess.crate_types.borrow().iter().any(|ct| *ct == config::CrateType::Rlib) && + tcx.sess.crate_types.borrow().iter().any(|ct| *ct == CrateType::Rlib) && // ThinLTO can't handle this workaround in all cases, so we don't // emit the `__imp_` symbols. Instead we make them unnecessary by disallowing // dynamic linking when linker plugin LTO is enabled. diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index fc6b547c5e70c..c5b95905ea012 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -539,7 +539,7 @@ pub fn codegen_crate( // unnecessarily. if tcx.dep_graph.is_fully_enabled() { for cgu in codegen_units { - tcx.codegen_unit(cgu.name()); + tcx.ensure().codegen_unit(cgu.name()); } } diff --git a/src/librustc_codegen_ssa/traits/declare.rs b/src/librustc_codegen_ssa/traits/declare.rs index de63ef7961387..690aacd20566b 100644 --- a/src/librustc_codegen_ssa/traits/declare.rs +++ b/src/librustc_codegen_ssa/traits/declare.rs @@ -31,7 +31,7 @@ pub trait DeclareMethods<'tcx>: BackendTypes { /// Use this function when you intend to define a global. This function will /// return `None` if the name already has a definition associated with it. In that /// case an error should be reported to the user, because it usually happens due - /// to user’s fault (e.g., misuse of #[no_mangle] or #[export_name] attributes). + /// to user’s fault (e.g., misuse of `#[no_mangle]` or `#[export_name]` attributes). fn define_global(&self, name: &str, ty: Self::Type) -> Option; /// Declare a private global diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 6711a49b2b7c1..197169b7036e0 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -173,7 +173,7 @@ struct Node { /// must all be in a non-pending state. dependents: Vec, - /// If true, dependents[0] points to a "parent" node, which requires + /// If true, `dependents[0]` points to a "parent" node, which requires /// special treatment upon error but is otherwise treated the same. /// (It would be more idiomatic to store the parent node in a separate /// `Option` field, but that slows down the common case of diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index 16f2e740104ca..de503fe8228aa 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -289,7 +289,7 @@ impl TransitiveRelation { /// /// - A != B /// - A R B is true - /// - for each i, j: B[i] R B[j] does not hold + /// - for each i, j: `B[i]` R `B[j]` does not hold /// /// The intuition is that this moves "one step up" through a lattice /// (where the relation is encoding the `<=` relation for the lattice). diff --git a/src/librustc_hir/arena.rs b/src/librustc_hir/arena.rs index b8a691dd9813e..a0b19f61906ed 100644 --- a/src/librustc_hir/arena.rs +++ b/src/librustc_hir/arena.rs @@ -5,8 +5,8 @@ /// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is /// faster and more memory efficient if there is lots of allocations. /// -/// Specifying the `decode` modifier will add decode impls for &T and &[T] where T is the type -/// listed. These impls will appear in the implement_ty_decoder! macro. +/// Specifying the `decode` modifier will add decode impls for `&T` and `&[T]`, +/// where `T` is the type listed. These impls will appear in the implement_ty_decoder! macro. #[macro_export] macro_rules! arena_types { ($macro:path, $args:tt, $tcx:lifetime) => ( diff --git a/src/librustc_infer/infer/error_reporting/mod.rs b/src/librustc_infer/infer/error_reporting/mod.rs index 9de7dcc845f1d..50e97c8fb7a02 100644 --- a/src/librustc_infer/infer/error_reporting/mod.rs +++ b/src/librustc_infer/infer/error_reporting/mod.rs @@ -843,7 +843,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { /// /// For the following code: /// - /// ```norun + /// ```no_run /// let x: Foo> = foo::>(); /// ``` /// diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 267f1e7e2dc89..54f80e8f38812 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -1482,7 +1482,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { self.tcx.replace_bound_vars(value, fld_r, fld_t, fld_c) } - /// See the [`region_constraints::verify_generic_bound`] method. + /// See the [`region_constraints::RegionConstraintCollector::verify_generic_bound`] method. pub fn verify_generic_bound( &self, origin: SubregionOrigin<'tcx>, diff --git a/src/librustc_infer/infer/region_constraints/mod.rs b/src/librustc_infer/infer/region_constraints/mod.rs index 1292e96ff98e7..2be6ec4481c6b 100644 --- a/src/librustc_infer/infer/region_constraints/mod.rs +++ b/src/librustc_infer/infer/region_constraints/mod.rs @@ -810,7 +810,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> { ) } - /// See [`RegionInference::region_constraints_added_in_snapshot`]. + /// See `InferCtxt::region_constraints_added_in_snapshot`. pub fn region_constraints_added_in_snapshot(&self, mark: &RegionSnapshot) -> Option { self.undo_log[mark.length..] .iter() diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 7b96d8df12da1..801c8e9329b24 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -27,9 +27,7 @@ use rustc_parse::{parse_crate_from_file, parse_crate_from_source_str}; use rustc_passes::{self, hir_stats, layout_test}; use rustc_plugin_impl as plugin; use rustc_resolve::{Resolver, ResolverArenas}; -use rustc_session::config::{ - self, CrateType, Input, OutputFilenames, OutputType, PpMode, PpSourceMode, -}; +use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType, PpMode, PpSourceMode}; use rustc_session::lint; use rustc_session::output::{filename_for_input, filename_for_metadata}; use rustc_session::search_paths::PathKind; @@ -361,7 +359,7 @@ fn configure_and_expand_inner<'a>( }); let crate_types = sess.crate_types.borrow(); - let is_proc_macro_crate = crate_types.contains(&config::CrateType::ProcMacro); + let is_proc_macro_crate = crate_types.contains(&CrateType::ProcMacro); // For backwards compatibility, we don't try to run proc macro injection // if rustdoc is run on a proc macro crate without '--crate-type proc-macro' being diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 72c25270a5d69..c5a4d28d151b3 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -16,11 +16,12 @@ use rustc_metadata::dynamic_lib::DynamicLibrary; use rustc_middle::ty; use rustc_resolve::{self, Resolver}; use rustc_session as session; +use rustc_session::config::{self, CrateType}; use rustc_session::config::{ErrorOutputType, Input, OutputFilenames}; use rustc_session::lint::{self, BuiltinLintDiagnostics, LintBuffer}; use rustc_session::parse::CrateConfig; use rustc_session::CrateDisambiguator; -use rustc_session::{config, early_error, filesearch, output, DiagnosticOutput, Session}; +use rustc_session::{early_error, filesearch, output, DiagnosticOutput, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::{FileLoader, SourceMap}; use rustc_span::symbol::{sym, Symbol}; @@ -409,7 +410,7 @@ pub(crate) fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguat // Also incorporate crate type, so that we don't get symbol conflicts when // linking against a library of the same name, if this is an executable. - let is_exe = session.crate_types.borrow().contains(&config::CrateType::Executable); + let is_exe = session.crate_types.borrow().contains(&CrateType::Executable); hasher.write(if is_exe { b"exe" } else { b"lib" }); CrateDisambiguator::from(hasher.finish::()) @@ -457,23 +458,23 @@ pub(crate) fn check_attr_crate_type(attrs: &[ast::Attribute], lint_buffer: &mut } } -const CRATE_TYPES: &[(Symbol, config::CrateType)] = &[ - (sym::rlib, config::CrateType::Rlib), - (sym::dylib, config::CrateType::Dylib), - (sym::cdylib, config::CrateType::Cdylib), +const CRATE_TYPES: &[(Symbol, CrateType)] = &[ + (sym::rlib, CrateType::Rlib), + (sym::dylib, CrateType::Dylib), + (sym::cdylib, CrateType::Cdylib), (sym::lib, config::default_lib_output()), - (sym::staticlib, config::CrateType::Staticlib), - (sym::proc_dash_macro, config::CrateType::ProcMacro), - (sym::bin, config::CrateType::Executable), + (sym::staticlib, CrateType::Staticlib), + (sym::proc_dash_macro, CrateType::ProcMacro), + (sym::bin, CrateType::Executable), ]; -fn categorize_crate_type(s: Symbol) -> Option { +fn categorize_crate_type(s: Symbol) -> Option { Some(CRATE_TYPES.iter().find(|(key, _)| *key == s)?.1) } -pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec { +pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec { // Unconditionally collect crate types from attributes to make them used - let attr_types: Vec = attrs + let attr_types: Vec = attrs .iter() .filter_map(|a| { if a.check_name(sym::crate_type) { @@ -490,7 +491,7 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec LintLevelsBuilder<'s> { /// * It'll validate all lint-related attributes in `attrs` /// * It'll mark all lint-related attributes as used /// * Lint levels will be updated based on the attributes provided - /// * Lint attributes are validated, e.g., a #[forbid] can't be switched to - /// #[allow] + /// * Lint attributes are validated, e.g., a `#[forbid]` can't be switched to + /// `#[allow]` /// /// Don't forget to call `pop`! pub fn push(&mut self, attrs: &[ast::Attribute], store: &LintStore) -> BuilderPush { diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 6168f6e1e5c88..a9e7a9f35dc36 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -17,7 +17,7 @@ use rustc_middle::middle::cstore::{ CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn, }; use rustc_middle::ty::TyCtxt; -use rustc_session::config; +use rustc_session::config::{self, CrateType}; use rustc_session::output::validate_crate_name; use rustc_session::search_paths::PathKind; use rustc_session::{CrateDisambiguator, Session}; @@ -615,8 +615,7 @@ impl<'a> CrateLoader<'a> { fn inject_panic_runtime(&mut self, krate: &ast::Crate) { // If we're only compiling an rlib, then there's no need to select a // panic runtime, so we just skip this section entirely. - let any_non_rlib = - self.sess.crate_types.borrow().iter().any(|ct| *ct != config::CrateType::Rlib); + let any_non_rlib = self.sess.crate_types.borrow().iter().any(|ct| *ct != CrateType::Rlib); if !any_non_rlib { info!("panic runtime injection skipped, only generating rlib"); return; @@ -736,7 +735,7 @@ impl<'a> CrateLoader<'a> { // if our compilation session actually needs an allocator based on what // we're emitting. let all_rlib = self.sess.crate_types.borrow().iter().all(|ct| match *ct { - config::CrateType::Rlib => true, + CrateType::Rlib => true, _ => false, }); if all_rlib { diff --git a/src/librustc_metadata/dependency_format.rs b/src/librustc_metadata/dependency_format.rs index 91654067f0815..0876cd1e63835 100644 --- a/src/librustc_metadata/dependency_format.rs +++ b/src/librustc_metadata/dependency_format.rs @@ -59,7 +59,7 @@ use rustc_middle::middle::cstore::LinkagePreference::{self, RequireDynamic, Requ use rustc_middle::middle::cstore::{self, DepKind}; use rustc_middle::middle::dependency_format::{Dependencies, DependencyList, Linkage}; use rustc_middle::ty::TyCtxt; -use rustc_session::config; +use rustc_session::config::CrateType; use rustc_target::spec::PanicStrategy; crate fn calculate(tcx: TyCtxt<'_>) -> Dependencies { @@ -75,7 +75,7 @@ crate fn calculate(tcx: TyCtxt<'_>) -> Dependencies { .collect::>() } -fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { +fn calculate_type(tcx: TyCtxt<'_>, ty: CrateType) -> DependencyList { let sess = &tcx.sess; if !sess.opts.output_types.should_codegen() { @@ -90,29 +90,25 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { // Treat cdylibs similarly. If `-C prefer-dynamic` is set, the caller may // be code-size conscious, but without it, it makes sense to statically // link a cdylib. - config::CrateType::Dylib | config::CrateType::Cdylib if !sess.opts.cg.prefer_dynamic => { - Linkage::Static - } - config::CrateType::Dylib | config::CrateType::Cdylib => Linkage::Dynamic, + CrateType::Dylib | CrateType::Cdylib if !sess.opts.cg.prefer_dynamic => Linkage::Static, + CrateType::Dylib | CrateType::Cdylib => Linkage::Dynamic, // If the global prefer_dynamic switch is turned off, or the final // executable will be statically linked, prefer static crate linkage. - config::CrateType::Executable - if !sess.opts.cg.prefer_dynamic || sess.crt_static(Some(ty)) => - { + CrateType::Executable if !sess.opts.cg.prefer_dynamic || sess.crt_static(Some(ty)) => { Linkage::Static } - config::CrateType::Executable => Linkage::Dynamic, + CrateType::Executable => Linkage::Dynamic, // proc-macro crates are mostly cdylibs, but we also need metadata. - config::CrateType::ProcMacro => Linkage::Static, + CrateType::ProcMacro => Linkage::Static, // No linkage happens with rlibs, we just needed the metadata (which we // got long ago), so don't bother with anything. - config::CrateType::Rlib => Linkage::NotLinked, + CrateType::Rlib => Linkage::NotLinked, // staticlibs must have all static dependencies. - config::CrateType::Staticlib => Linkage::Static, + CrateType::Staticlib => Linkage::Static, }; if preferred_linkage == Linkage::NotLinked { @@ -129,8 +125,8 @@ fn calculate_type(tcx: TyCtxt<'_>, ty: config::CrateType) -> DependencyList { // Staticlibs and static executables must have all static dependencies. // If any are not found, generate some nice pretty errors. - if ty == config::CrateType::Staticlib - || (ty == config::CrateType::Executable + if ty == CrateType::Staticlib + || (ty == CrateType::Executable && sess.crt_static(Some(ty)) && !sess.target.target.options.crt_static_allows_dylibs) { diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index fc63cfd143eb3..f78f3c5d8d40f 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -220,9 +220,10 @@ use rustc_data_structures::svh::Svh; use rustc_data_structures::sync::MetadataRef; use rustc_errors::{struct_span_err, DiagnosticBuilder}; use rustc_middle::middle::cstore::{CrateSource, MetadataLoader}; +use rustc_session::config::{self, CrateType}; use rustc_session::filesearch::{FileDoesntMatch, FileMatches, FileSearch}; use rustc_session::search_paths::PathKind; -use rustc_session::{config, CrateDisambiguator, Session}; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::symbol::{sym, Symbol}; use rustc_span::Span; use rustc_target::spec::{Target, TargetTriple}; @@ -669,7 +670,7 @@ impl<'a> CrateLocator<'a> { // The all loop is because `--crate-type=rlib --crate-type=rlib` is // legal and produces both inside this type. - let is_rlib = self.sess.crate_types.borrow().iter().all(|c| *c == config::CrateType::Rlib); + let is_rlib = self.sess.crate_types.borrow().iter().all(|c| *c == CrateType::Rlib); let needs_object_code = self.sess.opts.output_types.should_codegen(); // If we're producing an rlib, then we don't need object code. // Or, if we're not producing object code, then we don't need it either diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index da1dd1e589b00..4ac2092bb069a 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -30,7 +30,7 @@ use rustc_middle::traits::specialization_graph; use rustc_middle::ty::codec::{self as ty_codec, TyEncoder}; use rustc_middle::ty::{self, SymbolName, Ty, TyCtxt}; use rustc_serialize::{opaque, Encodable, Encoder, SpecializedEncoder}; -use rustc_session::config::{self, CrateType}; +use rustc_session::config::CrateType; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::{self, ExternalSource, FileName, SourceFile, Span}; @@ -1499,7 +1499,7 @@ impl EncodeContext<'tcx> { fn encode_dylib_dependency_formats(&mut self) -> Lazy<[Option]> { let formats = self.tcx.dependency_formats(LOCAL_CRATE); for (ty, arr) in formats.iter() { - if *ty != config::CrateType::Dylib { + if *ty != CrateType::Dylib { continue; } return self.lazy(arr.iter().map(|slot| match *slot { @@ -1729,8 +1729,8 @@ struct PrefetchVisitor<'tcx> { impl<'tcx> PrefetchVisitor<'tcx> { fn prefetch_mir(&self, def_id: LocalDefId) { if self.mir_keys.contains(&def_id) { - self.tcx.optimized_mir(def_id); - self.tcx.promoted_mir(def_id); + self.tcx.ensure().optimized_mir(def_id); + self.tcx.ensure().promoted_mir(def_id); } } } diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index bbeacbfc5382e..96ef4b3741200 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -5,7 +5,7 @@ /// Leaving `few` out will cause the type to get its own dedicated `TypedArena` which is /// faster and more memory efficient if there is lots of allocations. /// -/// Specifying the `decode` modifier will add decode impls for &T and &[T] where T is the type +/// Specifying the `decode` modifier will add decode impls for `&T` and `&[T]` where `T` is the type /// listed. These impls will appear in the implement_ty_decoder! macro. #[macro_export] macro_rules! arena_types { diff --git a/src/librustc_middle/middle/dependency_format.rs b/src/librustc_middle/middle/dependency_format.rs index ee5f822d3134c..16ce315368a05 100644 --- a/src/librustc_middle/middle/dependency_format.rs +++ b/src/librustc_middle/middle/dependency_format.rs @@ -4,7 +4,7 @@ //! For all the gory details, see the provider of the `dependency_formats` //! query. -use rustc_session::config; +use rustc_session::config::CrateType; /// A list of dependencies for a certain crate type. /// @@ -17,7 +17,7 @@ pub type DependencyList = Vec; /// A mapping of all required dependencies for a particular flavor of output. /// /// This is local to the tcx, and is generally relevant to one session. -pub type Dependencies = Vec<(config::CrateType, DependencyList)>; +pub type Dependencies = Vec<(CrateType, DependencyList)>; #[derive(Copy, Clone, PartialEq, Debug, HashStable, RustcEncodable, RustcDecodable)] pub enum Linkage { diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index 4d7104531753c..8d416536155ac 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -158,10 +158,10 @@ pub struct Body<'tcx> { /// We hold in this field all the constants we are not able to evaluate yet. pub required_consts: Vec>, - /// The user may be writing e.g. &[(SOME_CELL, 42)][i].1 and this would get promoted, because + /// The user may be writing e.g. `&[(SOME_CELL, 42)][i].1` and this would get promoted, because /// we'd statically know that no thing with interior mutability will ever be available to the /// user without some serious unsafe code. Now this means that our promoted is actually - /// &[(SOME_CELL, 42)] and the MIR using it will do the &promoted[i].1 projection because the + /// `&[(SOME_CELL, 42)]` and the MIR using it will do the `&promoted[i].1` projection because the /// index may be a runtime value. Such a promoted value is illegal because it has reachable /// interior mutability. This flag just makes this situation very obvious where the previous /// implementation without the flag hid this situation silently. @@ -2124,7 +2124,7 @@ pub enum Rvalue<'tcx> { /// or when casting a reference to a raw pointer. AddressOf(Mutability, Place<'tcx>), - /// length of a [X] or [X;n] value + /// length of a `[X]` or `[X;n]` value Len(Place<'tcx>), Cast(CastKind, Operand<'tcx>, Ty<'tcx>), diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 95a28df99aad0..63b8d8c8da782 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -167,7 +167,7 @@ pub struct ClosureOutlivesRequirement<'tcx> { /// are interesting (for error reporting). Order of variants indicates sort /// order of the category, thereby influencing diagnostic output. /// -/// See also [rustc_mir::borrow_check::nll::constraints]. +/// See also `rustc_mir::borrow_check::constraints`. #[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] #[derive(RustcEncodable, RustcDecodable, HashStable)] pub enum ConstraintCategory { diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index 1999a32b3c65b..e43eb01ad96f7 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -54,8 +54,7 @@ use rustc_hir::{HirId, Node, TraitCandidate}; use rustc_hir::{ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet}; use rustc_index::vec::{Idx, IndexVec}; use rustc_macros::HashStable; -use rustc_session::config::CrateType; -use rustc_session::config::{BorrowckMode, OutputFilenames}; +use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames}; use rustc_session::lint::{Level, Lint}; use rustc_session::Session; use rustc_span::source_map::MultiSpan; diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 6b7672a57f055..4cdcd5320e761 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -70,8 +70,8 @@ impl IntegerExt for Integer { } /// Finds the appropriate Integer type and signedness for the given - /// signed discriminant range and #[repr] attribute. - /// N.B.: u128 values above i128::MAX will be treated as signed, but + /// signed discriminant range and `#[repr]` attribute. + /// N.B.: `u128` values above `i128::MAX` will be treated as signed, but /// that shouldn't affect anything, other than maybe debuginfo. fn repr_discr<'tcx>( tcx: TyCtxt<'tcx>, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index bef74289fd850..7064b24240ef6 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2696,7 +2696,7 @@ impl<'tcx> TyCtxt<'tcx> { } /// Returns `true` if the impls are the same polarity and the trait either - /// has no items or is annotated #[marker] and prevents item overrides. + /// has no items or is annotated `#[marker]` and prevents item overrides. pub fn impls_are_allowed_to_overlap( self, def_id1: DefId, diff --git a/src/librustc_middle/ty/query/plumbing.rs b/src/librustc_middle/ty/query/plumbing.rs index d6d4335e9388d..82ee8ca29fa02 100644 --- a/src/librustc_middle/ty/query/plumbing.rs +++ b/src/librustc_middle/ty/query/plumbing.rs @@ -424,6 +424,7 @@ macro_rules! define_queries_inner { $($(#[$attr])* #[inline(always)] + #[must_use] pub fn $name(self, key: query_helper_param_ty!($($K)*)) -> as QueryConfig>>::Stored { diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 7492654583025..5bc9f6df889c7 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -582,8 +582,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { /// /// This is used when creating error messages like below: /// - /// > cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as - /// > mutable (via `a.u.s.b`) [E0502] + /// ```text + /// cannot borrow `a.u` (via `a.u.z.c`) as immutable because it is also borrowed as + /// mutable (via `a.u.s.b`) [E0502] + /// ``` pub(in crate::borrow_check) fn describe_place_for_conflicting_borrow( &self, first_borrowed_place: Place<'tcx>, diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index a015dc603520b..a8487be77def3 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -641,7 +641,7 @@ pub fn check_unsafety(tcx: TyCtxt<'_>, def_id: DefId) { } UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { - tcx.unsafe_derive_on_repr_packed(impl_def_id); + tcx.ensure().unsafe_derive_on_repr_packed(impl_def_id); } else { tcx.struct_span_lint_hir( SAFE_PACKED_BORROWS, diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index a3880d691b2d1..e80da4f756c64 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -7,13 +7,15 @@ //! //! The `CleanFakeReadsAndBorrows` "pass" is actually implemented as two //! traversals (aka visits) of the input MIR. The first traversal, -//! [`DeleteAndRecordFakeReads`], deletes the fake reads and finds the -//! temporaries read by [`ForMatchGuard`] reads, and [`DeleteFakeBorrows`] +//! `DeleteAndRecordFakeReads`, deletes the fake reads and finds the +//! temporaries read by [`ForMatchGuard`] reads, and `DeleteFakeBorrows` //! deletes the initialization of those temporaries. //! //! [`AscribeUserType`]: rustc_middle::mir::StatementKind::AscribeUserType //! [`Shallow`]: rustc_middle::mir::BorrowKind::Shallow //! [`FakeRead`]: rustc_middle::mir::StatementKind::FakeRead +//! [`Assign`]: rustc_middle::mir::StatementKind::Assign +//! [`ForMatchGuard`]: rustc_middle::mir::FakeReadCause::ForMatchGuard //! [`Nop`]: rustc_middle::mir::StatementKind::Nop use crate::transform::{MirPass, MirSource}; diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/hair/pattern/_match.rs index 51ba84416d64d..de3ae2e961f42 100644 --- a/src/librustc_mir_build/hair/pattern/_match.rs +++ b/src/librustc_mir_build/hair/pattern/_match.rs @@ -513,6 +513,8 @@ impl<'p, 'tcx> Matrix<'p, 'tcx> { } /// Pretty-printer for matrices of patterns, example: +/// +/// ```text /// +++++++++++++++++++++++++++++ /// + _ + [] + /// +++++++++++++++++++++++++++++ diff --git a/src/librustc_passes/check_attr.rs b/src/librustc_passes/check_attr.rs index 0fb715f450477..b54731d8881d1 100644 --- a/src/librustc_passes/check_attr.rs +++ b/src/librustc_passes/check_attr.rs @@ -77,7 +77,7 @@ impl CheckAttrVisitor<'tcx> { } if matches!(target, Target::Fn | Target::Method(_) | Target::ForeignFn) { - self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); + self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id)); } self.check_repr(attrs, span, target, item, hir_id); @@ -390,7 +390,7 @@ impl CheckAttrVisitor<'tcx> { } } if target == Target::Closure { - self.tcx.codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id)); + self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(expr.hir_id)); } } diff --git a/src/librustc_passes/entry.rs b/src/librustc_passes/entry.rs index 6a6d031660907..d2f1d11256bf2 100644 --- a/src/librustc_passes/entry.rs +++ b/src/librustc_passes/entry.rs @@ -7,8 +7,8 @@ use rustc_hir::{HirId, ImplItem, Item, ItemKind, TraitItem}; use rustc_middle::hir::map::Map; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; -use rustc_session::config::EntryFnType; -use rustc_session::{config, Session}; +use rustc_session::config::{CrateType, EntryFnType}; +use rustc_session::Session; use rustc_span::symbol::sym; use rustc_span::{Span, DUMMY_SP}; @@ -51,8 +51,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for EntryContext<'a, 'tcx> { fn entry_fn(tcx: TyCtxt<'_>, cnum: CrateNum) -> Option<(LocalDefId, EntryFnType)> { assert_eq!(cnum, LOCAL_CRATE); - let any_exe = - tcx.sess.crate_types.borrow().iter().any(|ty| *ty == config::CrateType::Executable); + let any_exe = tcx.sess.crate_types.borrow().iter().any(|ty| *ty == CrateType::Executable); if !any_exe { // No need to find a main function. return None; diff --git a/src/librustc_passes/reachable.rs b/src/librustc_passes/reachable.rs index 1a86babbc46cf..7c169d6813282 100644 --- a/src/librustc_passes/reachable.rs +++ b/src/librustc_passes/reachable.rs @@ -17,7 +17,7 @@ use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs} use rustc_middle::middle::privacy; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, TyCtxt}; -use rustc_session::config; +use rustc_session::config::CrateType; use rustc_target::spec::abi::Abi; // Returns true if the given item must be inlined because it may be @@ -375,11 +375,10 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> &'tcx HirIdSet let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE); - let any_library = tcx.sess.crate_types.borrow().iter().any(|ty| { - *ty == config::CrateType::Rlib - || *ty == config::CrateType::Dylib - || *ty == config::CrateType::ProcMacro - }); + let any_library = + tcx.sess.crate_types.borrow().iter().any(|ty| { + *ty == CrateType::Rlib || *ty == CrateType::Dylib || *ty == CrateType::ProcMacro + }); let mut reachable_context = ReachableContext { tcx, tables: &ty::TypeckTables::empty(None), diff --git a/src/librustc_passes/weak_lang_items.rs b/src/librustc_passes/weak_lang_items.rs index 8e56ef0da5237..8a581626862a2 100644 --- a/src/librustc_passes/weak_lang_items.rs +++ b/src/librustc_passes/weak_lang_items.rs @@ -8,7 +8,7 @@ use rustc_hir::lang_items; use rustc_hir::weak_lang_items::WEAK_ITEMS_REFS; use rustc_middle::middle::lang_items::whitelisted; use rustc_middle::ty::TyCtxt; -use rustc_session::config; +use rustc_session::config::CrateType; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -38,12 +38,12 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { // We only need to check for the presence of weak lang items if we're // emitting something that's not an rlib. let needs_check = tcx.sess.crate_types.borrow().iter().any(|kind| match *kind { - config::CrateType::Dylib - | config::CrateType::ProcMacro - | config::CrateType::Cdylib - | config::CrateType::Executable - | config::CrateType::Staticlib => true, - config::CrateType::Rlib => false, + CrateType::Dylib + | CrateType::ProcMacro + | CrateType::Cdylib + | CrateType::Executable + | CrateType::Staticlib => true, + CrateType::Rlib => false, }); if !needs_check { return; diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 88ec4585b0059..450293b991bde 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1051,7 +1051,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { /// Suggests a missing `crate::` if that resolves to an correct module. /// - /// ``` + /// ```text /// | /// LL | use foo::Bar; /// | ^^^ did you mean `crate::foo`? @@ -1147,7 +1147,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> { /// Suggests importing a macro from the root of the crate rather than a module within /// the crate. /// - /// ``` + /// ```text /// help: a macro with this name exists at the root of the crate /// | /// LL | use issue_59764::makro; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d84edbe3ad77b..d33eaf5a827db 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2669,7 +2669,7 @@ impl<'a> Resolver<'a> { /// This function adds a suggestion to change the binding name of a new import that conflicts /// with an existing import. /// - /// ```ignore (diagnostic) + /// ```text,ignore (diagnostic) /// help: you can use `as` to change the binding name of the import /// | /// LL | use foo::bar as other_bar; diff --git a/src/librustc_session/output.rs b/src/librustc_session/output.rs index ba3d08cfc7c14..52216188397d7 100644 --- a/src/librustc_session/output.rs +++ b/src/librustc_session/output.rs @@ -1,5 +1,5 @@ //! Related to out filenames of compilation (e.g. save analysis, binaries). -use crate::config::{self, Input, OutputFilenames, OutputType}; +use crate::config::{CrateType, Input, OutputFilenames, OutputType}; use crate::Session; use rustc_ast::{ast, attr}; use rustc_span::symbol::sym; @@ -8,7 +8,7 @@ use std::path::{Path, PathBuf}; pub fn out_filename( sess: &Session, - crate_type: config::CrateType, + crate_type: CrateType, outputs: &OutputFilenames, crate_name: &str, ) -> PathBuf { @@ -146,27 +146,27 @@ pub fn filename_for_metadata( pub fn filename_for_input( sess: &Session, - crate_type: config::CrateType, + crate_type: CrateType, crate_name: &str, outputs: &OutputFilenames, ) -> PathBuf { let libname = format!("{}{}", crate_name, sess.opts.cg.extra_filename); match crate_type { - config::CrateType::Rlib => outputs.out_directory.join(&format!("lib{}.rlib", libname)), - config::CrateType::Cdylib | config::CrateType::ProcMacro | config::CrateType::Dylib => { + CrateType::Rlib => outputs.out_directory.join(&format!("lib{}.rlib", libname)), + CrateType::Cdylib | CrateType::ProcMacro | CrateType::Dylib => { let (prefix, suffix) = (&sess.target.target.options.dll_prefix, &sess.target.target.options.dll_suffix); outputs.out_directory.join(&format!("{}{}{}", prefix, libname, suffix)) } - config::CrateType::Staticlib => { + CrateType::Staticlib => { let (prefix, suffix) = ( &sess.target.target.options.staticlib_prefix, &sess.target.target.options.staticlib_suffix, ); outputs.out_directory.join(&format!("{}{}{}", prefix, libname, suffix)) } - config::CrateType::Executable => { + CrateType::Executable => { let suffix = &sess.target.target.options.exe_suffix; let out_filename = outputs.path(OutputType::Exe); if suffix.is_empty() { out_filename } else { out_filename.with_extension(&suffix[1..]) } @@ -183,18 +183,18 @@ pub fn filename_for_input( /// way to run iOS binaries anyway without jailbreaking and /// interaction with Rust code through static library is the only /// option for now -pub fn default_output_for_target(sess: &Session) -> config::CrateType { +pub fn default_output_for_target(sess: &Session) -> CrateType { if !sess.target.target.options.executables { - config::CrateType::Staticlib + CrateType::Staticlib } else { - config::CrateType::Executable + CrateType::Executable } } /// Checks if target supports crate_type as output -pub fn invalid_output_for_target(sess: &Session, crate_type: config::CrateType) -> bool { +pub fn invalid_output_for_target(sess: &Session, crate_type: CrateType) -> bool { match crate_type { - config::CrateType::Cdylib | config::CrateType::Dylib | config::CrateType::ProcMacro => { + CrateType::Cdylib | CrateType::Dylib | CrateType::ProcMacro => { if !sess.target.target.options.dynamic_linking { return true; } @@ -208,12 +208,12 @@ pub fn invalid_output_for_target(sess: &Session, crate_type: config::CrateType) } if sess.target.target.options.only_cdylib { match crate_type { - config::CrateType::ProcMacro | config::CrateType::Dylib => return true, + CrateType::ProcMacro | CrateType::Dylib => return true, _ => {} } } if !sess.target.target.options.executables { - if crate_type == config::CrateType::Executable { + if crate_type == CrateType::Executable { return true; } } diff --git a/src/librustc_session/session.rs b/src/librustc_session/session.rs index 3b7c2f268ce5d..69e1b46de4df7 100644 --- a/src/librustc_session/session.rs +++ b/src/librustc_session/session.rs @@ -1,7 +1,7 @@ use crate::cgu_reuse_tracker::CguReuseTracker; use crate::code_stats::CodeStats; pub use crate::code_stats::{DataTypeKind, FieldInfo, SizeKind, VariantInfo}; -use crate::config::{self, OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; +use crate::config::{self, CrateType, OutputType, PrintRequest, Sanitizer, SwitchWithOptPath}; use crate::filesearch; use crate::lint; use crate::parse::ParseSess; @@ -73,7 +73,7 @@ pub struct Session { /// (sub)diagnostics that have been set once, but should not be set again, /// in order to avoid redundantly verbose output (Issue #24690, #44953). pub one_time_diagnostics: Lock, String)>>, - pub crate_types: Once>, + pub crate_types: Once>, /// The `crate_disambiguator` is constructed out of all the `-C metadata` /// arguments passed to the compiler. Its value together with the crate-name /// forms a unique global identifier for the crate. It is used to allow @@ -552,7 +552,7 @@ impl Session { } /// Check whether this compile session and crate type use static crt. - pub fn crt_static(&self, crate_type: Option) -> bool { + pub fn crt_static(&self, crate_type: Option) -> bool { // If the target does not opt in to crt-static support, use its default. if self.target.target.options.crt_static_respected { self.crt_static_feature(crate_type) @@ -562,15 +562,15 @@ impl Session { } /// Check whether this compile session and crate type use `crt-static` feature. - pub fn crt_static_feature(&self, crate_type: Option) -> bool { + pub fn crt_static_feature(&self, crate_type: Option) -> bool { let requested_features = self.opts.cg.target_feature.split(','); let found_negative = requested_features.clone().any(|r| r == "-crt-static"); let found_positive = requested_features.clone().any(|r| r == "+crt-static"); if found_positive || found_negative { found_positive - } else if crate_type == Some(config::CrateType::ProcMacro) - || crate_type == None && self.opts.crate_types.contains(&config::CrateType::ProcMacro) + } else if crate_type == Some(CrateType::ProcMacro) + || crate_type == None && self.opts.crate_types.contains(&CrateType::ProcMacro) { // FIXME: When crate_type is not available, // we use compiler options to determine the crate_type. diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index 0afa2333e0615..23c3dccb130f6 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -661,7 +661,7 @@ pub struct ExpnData { /// The span of the macro definition (possibly dummy). /// This span serves only informational purpose and is not used for resolution. pub def_site: Span, - /// List of #[unstable]/feature-gated features that the macro is allowed to use + /// List of `#[unstable]`/feature-gated features that the macro is allowed to use /// internally without forcing the whole crate to opt-in /// to them. pub allow_internal_unstable: Option>, diff --git a/src/librustc_trait_selection/traits/coherence.rs b/src/librustc_trait_selection/traits/coherence.rs index f1311382c5447..f9ff772900bbd 100644 --- a/src/librustc_trait_selection/traits/coherence.rs +++ b/src/librustc_trait_selection/traits/coherence.rs @@ -327,12 +327,12 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe /// try to implement this trait-ref. To check for this, we use InCrate::Remote /// mode. That is sound because we already know all the impls from known crates. /// -/// 3. For non-#[fundamental] traits, they guarantee that parent crates can +/// 3. For non-`#[fundamental]` traits, they guarantee that parent crates can /// add "non-blanket" impls without breaking negative reasoning in dependent /// crates. This is the "rebalancing coherence" (RFC 1023) restriction. /// /// For that, we only a allow crate to perform negative reasoning on -/// non-local-non-#[fundamental] only if there's a local key parameter as per (2). +/// non-local-non-`#[fundamental]` only if there's a local key parameter as per (2). /// /// Because we never perform negative reasoning generically (coherence does /// not involve type parameters), this can be interpreted as doing the full diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index b65f1cd6fac4e..c5ead053a7f89 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -307,7 +307,7 @@ fn instance_def_size_estimate<'tcx>( /// If `def_id` is an issue 33140 hack impl, returns its self type; otherwise, returns `None`. /// -/// See [`ImplOverlapKind::Issue33140`] for more details. +/// See [`ty::ImplOverlapKind::Issue33140`] for more details. fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option> { debug!("issue33140_self_ty({:?})", def_id); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index adbab3d4cb620..c431745198822 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1748,11 +1748,11 @@ pub fn check_item_type<'tcx>(tcx: TyCtxt<'tcx>, it: &'tcx hir::Item<'tcx>) { // Consts can play a role in type-checking, so they are included here. hir::ItemKind::Static(..) => { let def_id = tcx.hir().local_def_id(it.hir_id); - tcx.typeck_tables_of(def_id); + tcx.ensure().typeck_tables_of(def_id); maybe_check_static_with_link_section(tcx, def_id, it.span); } hir::ItemKind::Const(..) => { - tcx.typeck_tables_of(tcx.hir().local_def_id(it.hir_id)); + tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(it.hir_id)); } hir::ItemKind::Enum(ref enum_definition, _) => { check_enum(tcx, it.span, &enum_definition.variants, it.hir_id); @@ -2670,7 +2670,7 @@ pub fn check_enum<'tcx>( for v in vs { if let Some(ref e) = v.disr_expr { - tcx.typeck_tables_of(tcx.hir().local_def_id(e.hir_id)); + tcx.ensure().typeck_tables_of(tcx.hir().local_def_id(e.hir_id)); } } diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 53d6ec96bd251..049f4767247c5 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -1105,19 +1105,21 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { /// itself the referent of a borrowed pointer. Let me give an /// example fragment of code to make clear(er) the situation: /// - /// let r: &'a mut T = ...; // the original reference "r" has lifetime 'a - /// ... - /// &'z *r // the reborrow has lifetime 'z + /// ```ignore (incomplete Rust code) + /// let r: &'a mut T = ...; // the original reference "r" has lifetime 'a + /// ... + /// &'z *r // the reborrow has lifetime 'z + /// ``` /// /// Now, in this case, our primary job is to add the inference /// constraint that `'z <= 'a`. Given this setup, let's clarify the /// parameters in (roughly) terms of the example: /// /// ```plain,ignore (pseudo-Rust) - /// A borrow of: `& 'z bk * r` where `r` has type `& 'a bk T` - /// borrow_region ^~ ref_region ^~ - /// borrow_kind ^~ ref_kind ^~ - /// ref_cmt ^ + /// A borrow of: `& 'z bk * r` where `r` has type `& 'a bk T` + /// borrow_region ^~ ref_region ^~ + /// borrow_kind ^~ ref_kind ^~ + /// ref_cmt ^ /// ``` /// /// Here `bk` stands for some borrow-kind (e.g., `mut`, `uniq`, etc). @@ -1193,7 +1195,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx> { /// a `FnMut` or `Fn` closure. /// /// This function links the lifetimes of those references to the lifetime - /// of the borrow that's provided. See [link_reborrowed_region] for some + /// of the borrow that's provided. See [RegionCtxt::link_reborrowed_region] for some /// more explanation of this in the general case. /// /// We also supply a *cause*, and in this case we set the cause to diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index d8ffb9f6b4c07..05d5a81217ce1 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -156,7 +156,7 @@ pub fn provide(providers: &mut Providers<'_>) { fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) { // Trigger building the specialization graph for the trait. This will detect and report any // overlap errors. - tcx.specialization_graph_of(def_id); + tcx.ensure().specialization_graph_of(def_id); let impls = tcx.hir().trait_impls(def_id); for &hir_id in impls { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index b6ad763ec395d..f7318e3b9fe2f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -207,12 +207,12 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Type { default: Some(_), .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); - self.tcx.type_of(def_id); + self.tcx.ensure().type_of(def_id); } hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Const { .. } => { let def_id = self.tcx.hir().local_def_id(param.hir_id); - self.tcx.type_of(def_id); + self.tcx.ensure().type_of(def_id); } } } @@ -222,8 +222,8 @@ impl Visitor<'tcx> for CollectItemTypesVisitor<'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) { if let hir::ExprKind::Closure(..) = expr.kind { let def_id = self.tcx.hir().local_def_id(expr.hir_id); - self.tcx.generics_of(def_id); - self.tcx.type_of(def_id); + self.tcx.ensure().generics_of(def_id); + self.tcx.ensure().type_of(def_id); } intravisit::walk_expr(self, expr); } @@ -635,47 +635,47 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { hir::ItemKind::ForeignMod(ref foreign_mod) => { for item in foreign_mod.items { let def_id = tcx.hir().local_def_id(item.hir_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); if let hir::ForeignItemKind::Fn(..) = item.kind { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } } } hir::ItemKind::Enum(ref enum_definition, _) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); convert_enum_variant_types(tcx, def_id.to_def_id(), &enum_definition.variants); } hir::ItemKind::Impl { .. } => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.impl_trait_ref(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().impl_trait_ref(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::Trait(..) => { - tcx.generics_of(def_id); - tcx.trait_def(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().trait_def(def_id); tcx.at(it.span).super_predicates_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::TraitAlias(..) => { - tcx.generics_of(def_id); + tcx.ensure().generics_of(def_id); tcx.at(it.span).super_predicates_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } hir::ItemKind::Struct(ref struct_def, _) | hir::ItemKind::Union(ref struct_def, _) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); for f in struct_def.fields() { let def_id = tcx.hir().local_def_id(f.hir_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } if let Some(ctor_hir_id) = struct_def.ctor_hir_id() { @@ -691,11 +691,11 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { | hir::ItemKind::Static(..) | hir::ItemKind::Const(..) | hir::ItemKind::Fn(..) => { - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); if let hir::ItemKind::Fn(..) = it.kind { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } } } @@ -704,20 +704,20 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) { fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { let trait_item = tcx.hir().expect_trait_item(trait_item_id); let def_id = tcx.hir().local_def_id(trait_item.hir_id); - tcx.generics_of(def_id); + tcx.ensure().generics_of(def_id); match trait_item.kind { hir::TraitItemKind::Fn(..) => { - tcx.type_of(def_id); - tcx.fn_sig(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().fn_sig(def_id); } hir::TraitItemKind::Const(.., Some(_)) => { - tcx.type_of(def_id); + tcx.ensure().type_of(def_id); } hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(_, Some(_)) => { - tcx.type_of(def_id); + tcx.ensure().type_of(def_id); // Account for `const C: _;` and `type T = _;`. let mut visitor = PlaceholderHirTyCollector::default(); visitor.visit_trait_item(trait_item); @@ -727,18 +727,18 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) { hir::TraitItemKind::Type(_, None) => {} }; - tcx.predicates_of(def_id); + tcx.ensure().predicates_of(def_id); } fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) { let def_id = tcx.hir().local_def_id(impl_item_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); let impl_item = tcx.hir().expect_impl_item(impl_item_id); match impl_item.kind { hir::ImplItemKind::Fn(..) => { - tcx.fn_sig(def_id); + tcx.ensure().fn_sig(def_id); } hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => { // Account for `type T = _;` @@ -752,9 +752,9 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) { fn convert_variant_ctor(tcx: TyCtxt<'_>, ctor_id: hir::HirId) { let def_id = tcx.hir().local_def_id(ctor_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId, variants: &[hir::Variant<'_>]) { @@ -790,9 +790,9 @@ fn convert_enum_variant_types(tcx: TyCtxt<'_>, def_id: DefId, variants: &[hir::V for f in variant.data.fields() { let def_id = tcx.hir().local_def_id(f.hir_id); - tcx.generics_of(def_id); - tcx.type_of(def_id); - tcx.predicates_of(def_id); + tcx.ensure().generics_of(def_id); + tcx.ensure().type_of(def_id); + tcx.ensure().predicates_of(def_id); } // Convert the ctor, if any. This also registers the variant as diff --git a/src/librustc_typeck/mem_categorization.rs b/src/librustc_typeck/mem_categorization.rs index f6edb6b754534..ffe9f1c7d7a71 100644 --- a/src/librustc_typeck/mem_categorization.rs +++ b/src/librustc_typeck/mem_categorization.rs @@ -30,7 +30,7 @@ //! - `ty`: the type of data found at the address `A`. //! //! The resulting categorization tree differs somewhat from the expressions -//! themselves. For example, auto-derefs are explicit. Also, an index a[b] is +//! themselves. For example, auto-derefs are explicit. Also, an index `a[b]` is //! decomposed into two operations: a dereference to reach the array data and //! then an index to jump forward to the relevant item. //! diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 91e60f81cec53..03d1dc21816c3 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -1,6 +1,7 @@ use rustc_ast::ast::CRATE_NODE_ID; use rustc_attr as attr; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; +use rustc_data_structures::sync::{self, Lrc}; use rustc_driver::abort_on_err; use rustc_errors::emitter::{Emitter, EmitterWriter}; use rustc_errors::json::JsonEmitter; @@ -13,15 +14,14 @@ use rustc_middle::middle::cstore::CrateStore; use rustc_middle::middle::privacy::AccessLevels; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_resolve as resolve; -use rustc_session::config::ErrorOutputType; +use rustc_session::config::{self, CrateType, ErrorOutputType}; use rustc_session::lint; use rustc_session::DiagnosticOutput; -use rustc_session::{config, Session}; +use rustc_session::Session; use rustc_span::source_map; use rustc_span::symbol::sym; use rustc_span::DUMMY_SP; -use rustc_data_structures::sync::{self, Lrc}; use std::cell::RefCell; use std::mem; use std::rc::Rc; @@ -30,7 +30,6 @@ use crate::clean; use crate::clean::{AttributesExt, MAX_DEF_ID}; use crate::config::{Options as RustdocOptions, RenderOptions}; use crate::html::render::RenderInfo; - use crate::passes::{self, Condition::*, ConditionalPass}; pub use rustc_session::config::{CodegenOptions, DebuggingOptions, Input, Options}; @@ -301,11 +300,8 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt }) .collect(); - let crate_types = if proc_macro_crate { - vec![config::CrateType::ProcMacro] - } else { - vec![config::CrateType::Rlib] - }; + let crate_types = + if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; // plays with error output here! let sessopts = config::Options { maybe_sysroot, diff --git a/src/librustdoc/html/toc.rs b/src/librustdoc/html/toc.rs index 3754029577475..721988e29a678 100644 --- a/src/librustdoc/html/toc.rs +++ b/src/librustdoc/html/toc.rs @@ -5,7 +5,7 @@ pub struct Toc { /// The levels are strictly decreasing, i.e. /// - /// entries[0].level >= entries[1].level >= ... + /// `entries[0].level >= entries[1].level >= ...` /// /// Normally they are equal, but can differ in cases like A and B, /// both of which end up in the same `Toc` as they have the same @@ -39,8 +39,8 @@ pub struct TocEntry { pub struct TocBuilder { top_level: Toc, /// The current hierarchy of parent headings, the levels are - /// strictly increasing (i.e., chain[0].level < chain[1].level < - /// ...) with each entry being the most recent occurrence of a + /// strictly increasing (i.e., `chain[0].level < chain[1].level < + /// ...`) with each entry being the most recent occurrence of a /// heading with that level (it doesn't include the most recent /// occurrences of every level, just, if it *is* in `chain` then /// it is the most recent one). diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index e2940efd49c0d..5028bb46b0066 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -9,12 +9,15 @@ use rustc_hir::{HirId, CRATE_HIR_ID}; use rustc_interface::interface; use rustc_middle::hir::map::Map; use rustc_middle::ty::TyCtxt; -use rustc_session::{self, config, lint, DiagnosticOutput, Session}; +use rustc_session::config::{self, CrateType}; +use rustc_session::{lint, DiagnosticOutput, Session}; use rustc_span::edition::Edition; use rustc_span::source_map::SourceMap; use rustc_span::symbol::sym; use rustc_span::{BytePos, FileName, Pos, Span, DUMMY_SP}; use rustc_target::spec::TargetTriple; +use tempfile::Builder as TempFileBuilder; + use std::collections::HashMap; use std::env; use std::io::{self, Write}; @@ -22,7 +25,6 @@ use std::panic; use std::path::PathBuf; use std::process::{self, Command, Stdio}; use std::str; -use tempfile::Builder as TempFileBuilder; use crate::clean::Attributes; use crate::config::Options; @@ -82,11 +84,8 @@ pub fn run(options: Options) -> i32 { }) .collect(); - let crate_types = if options.proc_macro_crate { - vec![config::CrateType::ProcMacro] - } else { - vec![config::CrateType::Rlib] - }; + let crate_types = + if options.proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] }; let sessopts = config::Options { maybe_sysroot: options.maybe_sysroot.clone(), diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 7565bdeb4096e..8f46649048aa9 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -1417,16 +1417,18 @@ enum ParserState { /// A Stack represents the current position of the parser in the logical /// structure of the JSON stream. -/// For example foo.bar[3].x +/// +/// An example is `foo.bar[3].x`. pub struct Stack { stack: Vec, str_buffer: Vec, } /// StackElements compose a Stack. -/// For example, StackElement::Key("foo"), StackElement::Key("bar"), -/// StackElement::Index(3) and StackElement::Key("x") are the -/// StackElements compositing the stack that represents foo.bar[3].x +/// +/// As an example, `StackElement::Key("foo")`, `StackElement::Key("bar")`, +/// `StackElement::Index(3)`, and `StackElement::Key("x")` are the +/// StackElements composing the stack that represents `foo.bar[3].x`. #[derive(PartialEq, Clone, Debug)] pub enum StackElement<'l> { Index(u32), diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 6aad082a97f9a..97c20ca9459ef 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -567,7 +567,7 @@ impl Error for JoinPathsError { #[rustc_deprecated( since = "1.29.0", reason = "This function's behavior is unexpected and probably not what you want. \ - Consider using the home_dir function from https://crates.io/crates/dirs instead." + Consider using a crate from crates.io instead." )] #[stable(feature = "env", since = "1.0.0")] pub fn home_dir() -> Option { diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 134f508dfab09..6115d652b0cea 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -216,7 +216,6 @@ pub const SOCK_STREAM: c_int = 1; pub const SOL_SOCKET: c_int = 0xffff; pub const SO_RCVTIMEO: c_int = 0x1006; pub const SO_SNDTIMEO: c_int = 0x1005; -pub const SO_REUSEADDR: c_int = 0x0004; pub const IPPROTO_IP: c_int = 0; pub const IPPROTO_TCP: c_int = 6; pub const IPPROTO_IPV6: c_int = 41; diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index a9b6079de7564..1c03bc9234448 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -368,12 +368,15 @@ impl TcpListener { let sock = Socket::new(addr, c::SOCK_STREAM)?; - // On platforms with Berkeley-derived sockets, this allows - // to quickly rebind a socket, without needing to wait for - // the OS to clean up the previous one. - if !cfg!(windows) { - setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1 as c_int)?; - } + // On platforms with Berkeley-derived sockets, this allows to quickly + // rebind a socket, without needing to wait for the OS to clean up the + // previous one. + // + // On Windows, this allows rebinding sockets which are actively in use, + // which allows “socket hijacking”, so we explicitly don't set it here. + // https://docs.microsoft.com/en-us/windows/win32/winsock/using-so-reuseaddr-and-so-exclusiveaddruse + #[cfg(not(windows))] + setsockopt(&sock, c::SOL_SOCKET, c::SO_REUSEADDR, 1 as c_int)?; // Bind our new socket let (addrp, len) = addr.into_inner();