Skip to content

Commit

Permalink
Auto merge of rust-lang#89037 - JohnTitor:rollup-rd9btbs, r=JohnTitor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Sep 17, 2021
2 parents 38e5764 + 4d5bcbe commit 1c03f0d
Show file tree
Hide file tree
Showing 81 changed files with 283 additions and 111 deletions.
8 changes: 3 additions & 5 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ fn link_dwarf_object<'a>(sess: &'a Session, executable_out_filename: &Path) {
cmd.arg("-o");
cmd.arg(&dwp_out_filename);

let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let mut new_path = sess.get_tools_search_paths(false);
if let Some(path) = env::var_os("PATH") {
new_path.extend(env::split_paths(&path));
}
Expand Down Expand Up @@ -2555,8 +2555,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
match ld_impl {
LdImpl::Lld => {
if sess.target.lld_flavor == LldFlavor::Ld64 {
let tools_path =
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let tools_path = sess.get_tools_search_paths(false);
let ld64_exe = tools_path
.into_iter()
.map(|p| p.join("gcc-ld"))
Expand All @@ -2571,8 +2570,7 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
arg
});
} else {
let tools_path =
sess.host_filesearch(PathKind::All).get_tools_search_paths(false);
let tools_path = sess.get_tools_search_paths(false);
let lld_path = tools_path
.into_iter()
.map(|p| p.join("gcc-ld"))
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_codegen_ssa/src/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use rustc_middle::middle::dependency_format::Linkage;
use rustc_middle::ty::TyCtxt;
use rustc_serialize::{json, Encoder};
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
use rustc_session::search_paths::PathKind;
use rustc_session::Session;
use rustc_span::symbol::Symbol;
use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
Expand Down Expand Up @@ -101,7 +100,7 @@ pub fn get_linker<'a>(

// The compiler's sysroot often has some bundled tools, so add it to the
// PATH for the child.
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained);
let mut new_path = sess.get_tools_search_paths(self_contained);
let mut msvc_changed_path = false;
if sess.target.is_like_msvc {
if let Some(ref tool) = msvc_tool {
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,10 +677,7 @@ impl RustcDefaultCalls {
println!("{}", targets.join("\n"));
}
Sysroot => println!("{}", sess.sysroot.display()),
TargetLibdir => println!(
"{}",
sess.target_tlib_path.as_ref().unwrap_or(&sess.host_tlib_path).dir.display()
),
TargetLibdir => println!("{}", sess.target_tlib_path.dir.display()),
TargetSpec => println!("{}", sess.target.to_json().pretty()),
FileNames | CrateName => {
let input = input.unwrap_or_else(|| {
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ impl DiagnosticStyledString {
pub fn highlighted<S: Into<String>>(t: S) -> DiagnosticStyledString {
DiagnosticStyledString(vec![StringPart::Highlighted(t.into())])
}

pub fn content(&self) -> String {
self.0.iter().map(|x| x.content()).collect::<String>()
}
}

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

impl StringPart {
pub fn content(&self) -> &str {
match self {
&StringPart::Normal(ref s) | &StringPart::Highlighted(ref s) => s,
}
}
}

impl Diagnostic {
pub fn new(level: Level, message: &str) -> Self {
Diagnostic::new_with_code(level, None, message)
Expand Down
19 changes: 16 additions & 3 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1971,6 +1971,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
trace: TypeTrace<'tcx>,
terr: &TypeError<'tcx>,
) -> DiagnosticBuilder<'tcx> {
use crate::traits::ObligationCauseCode::MatchExpressionArm;

debug!("report_and_explain_type_error(trace={:?}, terr={:?})", trace, terr);

let span = trace.cause.span(self.tcx);
Expand Down Expand Up @@ -2013,6 +2015,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
_ => {}
}
}
if let MatchExpressionArm(box MatchExpressionArmCause { source, .. }) =
trace.cause.code
{
if let hir::MatchSource::TryDesugar = source {
if let Some((expected_ty, found_ty)) = self.values_str(trace.values) {
err.note(&format!(
"`?` operator cannot convert from `{}` to `{}`",
found_ty.content(),
expected_ty.content(),
));
}
}
}
err
}
FailureCode::Error0644(failure_str) => {
Expand Down Expand Up @@ -2585,9 +2600,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
CompareImplTypeObligation { .. } => Error0308("type not compatible with trait"),
MatchExpressionArm(box MatchExpressionArmCause { source, .. }) => {
Error0308(match source {
hir::MatchSource::TryDesugar => {
"try expression alternatives have incompatible types"
}
hir::MatchSource::TryDesugar => "`?` operator has incompatible types",
_ => "`match` arms have incompatible types",
})
}
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_lint/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,12 +851,18 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
use FfiResult::*;

if def.repr.transparent() {
// Can assume that only one field is not a ZST, so only check
// Can assume that at most one field is not a ZST, so only check
// that field's type for FFI-safety.
if let Some(field) = transparent_newtype_field(self.cx.tcx, variant) {
self.check_field_type_for_ffi(cache, field, substs)
} else {
bug!("malformed transparent type");
// All fields are ZSTs; this means that the type should behave
// like (), which is FFI-unsafe
FfiUnsafe {
ty,
reason: "this struct contains only zero-sized fields".into(),
help: None,
}
}
} else {
// We can't completely trust repr(C) markings; make sure the fields are
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,11 @@ LLVMRustOptimizeWithNewPassManager(
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_GE(14, 0)
MPM.addPass(ModuleMemorySanitizerPass(Options));
#else
MPM.addPass(MemorySanitizerPass(Options));
#endif
MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options)));
}
);
Expand All @@ -897,7 +901,11 @@ LLVMRustOptimizeWithNewPassManager(
#if LLVM_VERSION_GE(11, 0)
OptimizerLastEPCallbacks.push_back(
[](ModulePassManager &MPM, OptimizationLevel Level) {
#if LLVM_VERSION_GE(14, 0)
MPM.addPass(ModuleThreadSanitizerPass());
#else
MPM.addPass(ThreadSanitizerPass());
#endif
MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
}
);
Expand Down
22 changes: 5 additions & 17 deletions compiler/rustc_session/src/filesearch.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! A module for searching for libraries

pub use self::FileMatch::*;

use std::env;
Expand All @@ -14,8 +16,6 @@ pub enum FileMatch {
FileDoesntMatch,
}

// A module for searching for libraries

#[derive(Clone)]
pub struct FileSearch<'a> {
sysroot: &'a Path,
Expand Down Expand Up @@ -83,22 +83,10 @@ impl<'a> FileSearch<'a> {
FileSearch { sysroot, triple, search_paths, tlib_path, kind }
}

// Returns just the directories within the search paths.
/// Returns just the directories within the search paths.
pub fn search_path_dirs(&self) -> Vec<PathBuf> {
self.search_paths().map(|sp| sp.dir.to_path_buf()).collect()
}

// Returns a list of directories where target-specific tool binaries are located.
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
let rustlib_path = rustc_target::target_rustlib_path(self.sysroot, &self.triple);
let p = std::array::IntoIter::new([
Path::new(&self.sysroot),
Path::new(&rustlib_path),
Path::new("bin"),
])
.collect::<PathBuf>();
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
}
}

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

// This function checks if sysroot is found using env::args().next(), and if it
// is not found, uses env::current_exe() to imply sysroot.
/// This function checks if sysroot is found using env::args().next(), and if it
/// is not found, uses env::current_exe() to imply sysroot.
pub fn get_or_default_sysroot() -> PathBuf {
// Follow symlinks. If the resolved path is relative, make it absolute.
fn canonicalize(path: PathBuf) -> PathBuf {
Expand Down
22 changes: 11 additions & 11 deletions compiler/rustc_session/src/search_paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ pub struct SearchPath {
pub files: Vec<SearchPathFile>,
}

// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
// it is searched repeatedly by `find_library_crate`, and the searches involve
// checking the prefix and suffix of the filename of each `PathBuf`. This is
// doable, but very slow, because it involves calls to `file_name` and
// `extension` that are themselves slow.
//
// This type augments the `PathBuf` with an `Option<String>` containing the
// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
// `Option<String>` than the `PathBuf`. (It's an `Option` because
// `Path::file_name` can fail; if that happens then all subsequent checking
// will also fail, which is fine.)
/// The obvious implementation of `SearchPath::files` is a `Vec<PathBuf>`. But
/// it is searched repeatedly by `find_library_crate`, and the searches involve
/// checking the prefix and suffix of the filename of each `PathBuf`. This is
/// doable, but very slow, because it involves calls to `file_name` and
/// `extension` that are themselves slow.
///
/// This type augments the `PathBuf` with an `Option<String>` containing the
/// `PathBuf`'s filename. The prefix and suffix checking is much faster on the
/// `Option<String>` than the `PathBuf`. (It's an `Option` because
/// `Path::file_name` can fail; if that happens then all subsequent checking
/// will also fail, which is fine.)
#[derive(Clone, Debug)]
pub struct SearchPathFile {
pub path: PathBuf,
Expand Down
30 changes: 21 additions & 9 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use std::fmt;
use std::io::Write;
use std::num::NonZeroU32;
use std::ops::{Div, Mul};
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;
Expand Down Expand Up @@ -131,9 +131,8 @@ pub struct Session {
pub target: Target,
pub host: Target,
pub opts: config::Options,
pub host_tlib_path: SearchPath,
/// `None` if the host and target are the same.
pub target_tlib_path: Option<SearchPath>,
pub host_tlib_path: Lrc<SearchPath>,
pub target_tlib_path: Lrc<SearchPath>,
pub parse_sess: ParseSess,
pub sysroot: PathBuf,
/// The name of the root source file of the crate, in the local file system.
Expand Down Expand Up @@ -787,8 +786,7 @@ impl Session {
&self.sysroot,
self.opts.target_triple.triple(),
&self.opts.search_paths,
// `target_tlib_path == None` means it's the same as `host_tlib_path`.
self.target_tlib_path.as_ref().unwrap_or(&self.host_tlib_path),
&self.target_tlib_path,
kind,
)
}
Expand All @@ -802,6 +800,18 @@ impl Session {
)
}

/// Returns a list of directories where target-specific tool binaries are located.
pub fn get_tools_search_paths(&self, self_contained: bool) -> Vec<PathBuf> {
let rustlib_path = rustc_target::target_rustlib_path(&self.sysroot, &config::host_triple());
let p = std::array::IntoIter::new([
Path::new(&self.sysroot),
Path::new(&rustlib_path),
Path::new("bin"),
])
.collect::<PathBuf>();
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
}

pub fn init_incr_comp_session(
&self,
session_dir: PathBuf,
Expand Down Expand Up @@ -1245,11 +1255,13 @@ pub fn build_session(

let host_triple = config::host_triple();
let target_triple = sopts.target_triple.triple();
let host_tlib_path = SearchPath::from_sysroot_and_triple(&sysroot, host_triple);
let host_tlib_path = Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, host_triple));
let target_tlib_path = if host_triple == target_triple {
None
// Use the same `SearchPath` if host and target triple are identical to avoid unnecessary
// rescanning of the target lib path and an unnecessary allocation.
host_tlib_path.clone()
} else {
Some(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
Lrc::new(SearchPath::from_sysroot_and_triple(&sysroot, target_triple))
};

let file_path_mapping = sopts.file_path_mapping();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
};

let found_did = match *found_trait_ty.kind() {
ty::Closure(did, _) | ty::Foreign(did) | ty::FnDef(did, _) => Some(did),
ty::Closure(did, _)
| ty::Foreign(did)
| ty::FnDef(did, _)
| ty::Generator(did, ..) => Some(did),
ty::Adt(def, _) => Some(def.did),
_ => None,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1256,33 +1256,40 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
trait_ref: ty::PolyTraitRef<'tcx>,
) -> String {
let inputs = trait_ref.skip_binder().substs.type_at(1);
let sig = if let ty::Tuple(inputs) = inputs.kind() {
tcx.mk_fn_sig(
inputs.iter().map(|k| k.expect_ty()),
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
false,
hir::Unsafety::Normal,
abi::Abi::Rust,
)
} else {
tcx.mk_fn_sig(
let sig = match inputs.kind() {
ty::Tuple(inputs)
if tcx.fn_trait_kind_from_lang_item(trait_ref.def_id()).is_some() =>
{
tcx.mk_fn_sig(
inputs.iter().map(|k| k.expect_ty()),
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
false,
hir::Unsafety::Normal,
abi::Abi::Rust,
)
}
_ => tcx.mk_fn_sig(
std::iter::once(inputs),
tcx.mk_ty_infer(ty::TyVar(ty::TyVid::from_u32(0))),
false,
hir::Unsafety::Normal,
abi::Abi::Rust,
)
),
};
trait_ref.rebind(sig).to_string()
}

let argument_is_closure = expected_ref.skip_binder().substs.type_at(0).is_closure();
let argument_kind = match expected_ref.skip_binder().substs.type_at(0) {
t if t.is_closure() => "closure",
t if t.is_generator() => "generator",
_ => "function",
};
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0631,
"type mismatch in {} arguments",
if argument_is_closure { "closure" } else { "function" }
argument_kind
);

let found_str = format!("expected signature of `{}`", build_fn_sig_string(self.tcx, found));
Expand Down
6 changes: 5 additions & 1 deletion library/alloc/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ impl<B: ?Sized + ToOwned> Cow<'_, B> {
}

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

fn deref(&self) -> &B {
Expand Down
Loading

0 comments on commit 1c03f0d

Please sign in to comment.