Skip to content

Commit 1c03f0d

Browse files
committed
Auto merge of rust-lang#89037 - JohnTitor:rollup-rd9btbs, r=JohnTitor
Rollup of 10 pull requests Successful merges: - rust-lang#86382 (Make diagnostics clearer for `?` operators) - rust-lang#87529 (Fix ICE in `improper_ctypes_definitions` lint with all-ZST transparent types) - rust-lang#88339 (Add TcpListener::into_incoming and IntoIncoming) - rust-lang#88735 (Don't lint about missing code examples in derived traits) - rust-lang#88751 (Couple of changes to FileSearch and SearchPath) - rust-lang#88883 (Move some tests to more reasonable directories - 7) - rust-lang#88887 (Const Deref) - rust-lang#88911 (Improve error message for type mismatch in generator arguments) - rust-lang#89014 (PassWrapper: handle separate Module*SanitizerPass) - rust-lang#89033 (Set the library path in sysroot-crates-are-unstable) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 38e5764 + 4d5bcbe commit 1c03f0d

File tree

81 files changed

+283
-111
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+283
-111
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ fn link_dwarf_object<'a>(sess: &'a Session, executable_out_filename: &Path) {
637637
cmd.arg("-o");
638638
cmd.arg(&dwp_out_filename);
639639

640-
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
640+
let mut new_path = sess.get_tools_search_paths(false);
641641
if let Some(path) = env::var_os("PATH") {
642642
new_path.extend(env::split_paths(&path));
643643
}
@@ -2555,8 +2555,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
25552555
match ld_impl {
25562556
LdImpl::Lld => {
25572557
if sess.target.lld_flavor == LldFlavor::Ld64 {
2558-
let tools_path =
2559-
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2558+
let tools_path = sess.get_tools_search_paths(false);
25602559
let ld64_exe = tools_path
25612560
.into_iter()
25622561
.map(|p| p.join("gcc-ld"))
@@ -2571,8 +2570,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
25712570
arg
25722571
});
25732572
} else {
2574-
let tools_path =
2575-
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
2573+
let tools_path = sess.get_tools_search_paths(false);
25762574
let lld_path = tools_path
25772575
.into_iter()
25782576
.map(|p| p.join("gcc-ld"))

compiler/rustc_codegen_ssa/src/back/linker.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::middle::dependency_format::Linkage;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_serialize::{json, Encoder};
1717
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
18-
use rustc_session::search_paths::PathKind;
1918
use rustc_session::Session;
2019
use rustc_span::symbol::Symbol;
2120
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
@@ -101,7 +100,7 @@ pub fn get_linker<'a>(
101100

102101
// The compiler's sysroot often has some bundled tools, so add it to the
103102
// PATH for the child.
104-
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained);
103+
let mut new_path = sess.get_tools_search_paths(self_contained);
105104
let mut msvc_changed_path = false;
106105
if sess.target.is_like_msvc {
107106
if let Some(ref tool) = msvc_tool {

compiler/rustc_driver/src/lib.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -677,10 +677,7 @@ impl RustcDefaultCalls {
677677
println!("{}", targets.join("\n"));
678678
}
679679
Sysroot => println!("{}", sess.sysroot.display()),
680-
TargetLibdir => println!(
681-
"{}",
682-
sess.target_tlib_path.as_ref().unwrap_or(&sess.host_tlib_path).dir.display()
683-
),
680+
TargetLibdir => println!("{}", sess.target_tlib_path.dir.display()),
684681
TargetSpec => println!("{}", sess.target.to_json().pretty()),
685682
FileNames | CrateName => {
686683
let input = input.unwrap_or_else(|| {

compiler/rustc_errors/src/diagnostic.rs

+12
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ impl DiagnosticStyledString {
7474
pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString {
7575
DiagnosticStyledString(vec![StringPart::Highlighted(t.into())])
7676
}
77+
78+
pub fn content(&self) -> String {
79+
self.0.iter().map(|x| x.content()).collect::<String>()
80+
}
7781
}
7882

7983
#[derive(Debug, PartialEq, Eq)]
@@ -82,6 +86,14 @@ pub enum StringPart {
8286
Highlighted(String),
8387
}
8488

89+
impl StringPart {
90+
pub fn content(&self) -> &str {
91+
match self {
92+
&StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
93+
}
94+
}
95+
}
96+
8597
impl Diagnostic {
8698
pub fn new(level: Level, message: &str) -> Self {
8799
Diagnostic::new_with_code(level, None, message)

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
19711971
trace: TypeTrace<'tcx>,
19721972
terr: &TypeError<'tcx>,
19731973
) -> DiagnosticBuilder<'tcx> {
1974+
use crate::traits::ObligationCauseCode::MatchExpressionArm;
1975+
19741976
debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);
19751977

19761978
let span = trace.cause.span(self.tcx);
@@ -2013,6 +2015,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
20132015
_ => {}
20142016
}
20152017
}
2018+
if let MatchExpressionArm(box MatchExpressionArmCause { source, .. }) =
2019+
trace.cause.code
2020+
{
2021+
if let hir::MatchSource::TryDesugar = source {
2022+
if let Some((expected_ty, found_ty)) = self.values_str(trace.values) {
2023+
err.note(&format!(
2024+
"`?` operator cannot convert from `{}` to `{}`",
2025+
found_ty.content(),
2026+
expected_ty.content(),
2027+
));
2028+
}
2029+
}
2030+
}
20162031
err
20172032
}
20182033
FailureCode::Error0644(failure_str) => {
@@ -2585,9 +2600,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
25852600
CompareImplTypeObligation { .. } => Error0308("type not compatible with trait"),
25862601
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => {
25872602
Error0308(match source {
2588-
hir::MatchSource::TryDesugar => {
2589-
"try expression alternatives have incompatible types"
2590-
}
2603+
hir::MatchSource::TryDesugar => "`?` operator has incompatible types",
25912604
_ => "`match` arms have incompatible types",
25922605
})
25932606
}

compiler/rustc_lint/src/types.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -851,12 +851,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
851851
use FfiResult::*;
852852

853853
if def.repr.transparent() {
854-
// Can assume that only one field is not a ZST, so only check
854+
// Can assume that at most one field is not a ZST, so only check
855855
// that field's type for FFI-safety.
856856
if let Some(field) = transparent_newtype_field(self.cx.tcx, variant) {
857857
self.check_field_type_for_ffi(cache, field, substs)
858858
} else {
859-
bug!("malformed transparent type");
859+
// All fields are ZSTs; this means that the type should behave
860+
// like (), which is FFI-unsafe
861+
FfiUnsafe {
862+
ty,
863+
reason: "this struct contains only zero-sized fields".into(),
864+
help: None,
865+
}
860866
}
861867
} else {
862868
// We can't completely trust repr(C) markings; make sure the fields are

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,11 @@ LLVMRustOptimizeWithNewPassManager(
875875
#if LLVM_VERSION_GE(11, 0)
876876
OptimizerLastEPCallbacks.push_back(
877877
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
878+
#if LLVM_VERSION_GE(14, 0)
879+
MPM.addPass(ModuleMemorySanitizerPass(Options));
880+
#else
878881
MPM.addPass(MemorySanitizerPass(Options));
882+
#endif
879883
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
880884
}
881885
);
@@ -897,7 +901,11 @@ LLVMRustOptimizeWithNewPassManager(
897901
#if LLVM_VERSION_GE(11, 0)
898902
OptimizerLastEPCallbacks.push_back(
899903
[](ModulePassManager &MPM, OptimizationLevel Level) {
904+
#if LLVM_VERSION_GE(14, 0)
905+
MPM.addPass(ModuleThreadSanitizerPass());
906+
#else
900907
MPM.addPass(ThreadSanitizerPass());
908+
#endif
901909
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
902910
}
903911
);

compiler/rustc_session/src/filesearch.rs

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! A module for searching for libraries
2+
13
pub use self::FileMatch::*;
24

35
use std::env;
@@ -14,8 +16,6 @@ pub enum FileMatch {
1416
FileDoesntMatch,
1517
}
1618

17-
// A module for searching for libraries
18-
1919
#[derive(Clone)]
2020
pub struct FileSearch<'a> {
2121
sysroot: &'a Path,
@@ -83,22 +83,10 @@ impl<'a> FileSearch<'a> {
8383
FileSearch { sysroot, triple, search_paths, tlib_path, kind }
8484
}
8585

86-
// Returns just the directories within the search paths.
86+
/// Returns just the directories within the search paths.
8787
pub fn search_path_dirs(&self) -> Vec<PathBuf> {
8888
self.search_paths().map(|sp| sp.dir.to_path_buf()).collect()
8989
}
90-
91-
// Returns a list of directories where target-specific tool binaries are located.
92-
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
93-
let rustlib_path = rustc_target::target_rustlib_path(self.sysroot, &self.triple);
94-
let p = std::array::IntoIter::new([
95-
Path::new(&self.sysroot),
96-
Path::new(&rustlib_path),
97-
Path::new("bin"),
98-
])
99-
.collect::<PathBuf>();
100-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
101-
}
10290
}
10391

10492
pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
@@ -107,8 +95,8 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf {
10795
.collect::<PathBuf>()
10896
}
10997

110-
// This function checks if sysroot is found using env::args().next(), and if it
111-
// is not found, uses env::current_exe() to imply sysroot.
98+
/// This function checks if sysroot is found using env::args().next(), and if it
99+
/// is not found, uses env::current_exe() to imply sysroot.
112100
pub fn get_or_default_sysroot() -> PathBuf {
113101
// Follow symlinks. If the resolved path is relative, make it absolute.
114102
fn canonicalize(path: PathBuf) -> PathBuf {

compiler/rustc_session/src/search_paths.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ pub struct SearchPath {
99
pub files: Vec<SearchPathFile>,
1010
}
1111

12-
// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
13-
// it is searched repeatedly by `find_library_crate`, and the searches involve
14-
// checking the prefix and suffix of the filename of each `PathBuf`. This is
15-
// doable, but very slow, because it involves calls to `file_name` and
16-
// `extension` that are themselves slow.
17-
//
18-
// This type augments the `PathBuf` with an `Option<String>` containing the
19-
// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
20-
// `Option<String>` than the `PathBuf`. (It's an `Option` because
21-
// `Path::file_name` can fail; if that happens then all subsequent checking
22-
// will also fail, which is fine.)
12+
/// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
13+
/// it is searched repeatedly by `find_library_crate`, and the searches involve
14+
/// checking the prefix and suffix of the filename of each `PathBuf`. This is
15+
/// doable, but very slow, because it involves calls to `file_name` and
16+
/// `extension` that are themselves slow.
17+
///
18+
/// This type augments the `PathBuf` with an `Option<String>` containing the
19+
/// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
20+
/// `Option<String>` than the `PathBuf`. (It's an `Option` because
21+
/// `Path::file_name` can fail; if that happens then all subsequent checking
22+
/// will also fail, which is fine.)
2323
#[derive(Clone, Debug)]
2424
pub struct SearchPathFile {
2525
pub path: PathBuf,

compiler/rustc_session/src/session.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use std::fmt;
3636
use std::io::Write;
3737
use std::num::NonZeroU32;
3838
use std::ops::{Div, Mul};
39-
use std::path::PathBuf;
39+
use std::path::{Path, PathBuf};
4040
use std::str::FromStr;
4141
use std::sync::Arc;
4242
use std::time::Duration;
@@ -131,9 +131,8 @@ pub struct Session {
131131
pub target: Target,
132132
pub host: Target,
133133
pub opts: config::Options,
134-
pub host_tlib_path: SearchPath,
135-
/// `None` if the host and target are the same.
136-
pub target_tlib_path: Option<SearchPath>,
134+
pub host_tlib_path: Lrc<SearchPath>,
135+
pub target_tlib_path: Lrc<SearchPath>,
137136
pub parse_sess: ParseSess,
138137
pub sysroot: PathBuf,
139138
/// The name of the root source file of the crate, in the local file system.
@@ -787,8 +786,7 @@ impl Session {
787786
&self.sysroot,
788787
self.opts.target_triple.triple(),
789788
&self.opts.search_paths,
790-
// `target_tlib_path == None` means it's the same as `host_tlib_path`.
791-
self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path),
789+
&self.target_tlib_path,
792790
kind,
793791
)
794792
}
@@ -802,6 +800,18 @@ impl Session {
802800
)
803801
}
804802

803+
/// Returns a list of directories where target-specific tool binaries are located.
804+
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
805+
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple());
806+
let p = std::array::IntoIter::new([
807+
Path::new(&self.sysroot),
808+
Path::new(&rustlib_path),
809+
Path::new("bin"),
810+
])
811+
.collect::<PathBuf>();
812+
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
813+
}
814+
805815
pub fn init_incr_comp_session(
806816
&self,
807817
session_dir: PathBuf,
@@ -1245,11 +1255,13 @@ pub fn build_session(
12451255

12461256
let host_triple = config::host_triple();
12471257
let target_triple = sopts.target_triple.triple();
1248-
let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple);
1258+
let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple));
12491259
let target_tlib_path = if host_triple == target_triple {
1250-
None
1260+
// Use the same `SearchPath` if host and target triple are identical to avoid unnecessary
1261+
// rescanning of the target lib path and an unnecessary allocation.
1262+
host_tlib_path.clone()
12511263
} else {
1252-
Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
1264+
Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
12531265
};
12541266

12551267
let file_path_mapping = sopts.file_path_mapping();

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
722722
};
723723

724724
let found_did = match *found_trait_ty.kind() {
725-
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
725+
ty::Closure(did, _)
726+
| ty::Foreign(did)
727+
| ty::FnDef(did, _)
728+
| ty::Generator(did, ..) => Some(did),
726729
ty::Adt(def, _) => Some(def.did),
727730
_ => None,
728731
};

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -1256,33 +1256,40 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
12561256
trait_ref: ty::PolyTraitRef<'tcx>,
12571257
) -> String {
12581258
let inputs = trait_ref.skip_binder().substs.type_at(1);
1259-
let sig = if let ty::Tuple(inputs) = inputs.kind() {
1260-
tcx.mk_fn_sig(
1261-
inputs.iter().map(|k| k.expect_ty()),
1262-
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
1263-
false,
1264-
hir::Unsafety::Normal,
1265-
abi::Abi::Rust,
1266-
)
1267-
} else {
1268-
tcx.mk_fn_sig(
1259+
let sig = match inputs.kind() {
1260+
ty::Tuple(inputs)
1261+
if tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some() =>
1262+
{
1263+
tcx.mk_fn_sig(
1264+
inputs.iter().map(|k| k.expect_ty()),
1265+
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
1266+
false,
1267+
hir::Unsafety::Normal,
1268+
abi::Abi::Rust,
1269+
)
1270+
}
1271+
_ => tcx.mk_fn_sig(
12691272
std::iter::once(inputs),
12701273
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
12711274
false,
12721275
hir::Unsafety::Normal,
12731276
abi::Abi::Rust,
1274-
)
1277+
),
12751278
};
12761279
trait_ref.rebind(sig).to_string()
12771280
}
12781281

1279-
let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
1282+
let argument_kind = match expected_ref.skip_binder().substs.type_at(0) {
1283+
t if t.is_closure() => "closure",
1284+
t if t.is_generator() => "generator",
1285+
_ => "function",
1286+
};
12801287
let mut err = struct_span_err!(
12811288
self.tcx.sess,
12821289
span,
12831290
E0631,
12841291
"type mismatch in {} arguments",
1285-
if argument_is_closure { "closure" } else { "function" }
1292+
argument_kind
12861293
);
12871294

12881295
let found_str = format!("expected signature of `{}`", build_fn_sig_string(self.tcx, found));

library/alloc/src/borrow.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
330330
}
331331

332332
#[stable(feature = "rust1", since = "1.0.0")]
333-
impl<B: ?Sized + ToOwned> Deref for Cow<'_, B> {
333+
#[rustc_const_unstable(feature = "const_deref", issue = "88955")]
334+
impl<B: ?Sized + ToOwned> const Deref for Cow<'_, B>
335+
where
336+
B::Owned: ~const Borrow<B>,
337+
{
334338
type Target = B;
335339

336340
fn deref(&self) -> &B {

0 commit comments

Comments
 (0)