Skip to content

Commit

Permalink
Auto merge of rust-lang#75383 - Dylan-DPC:rollup-6hi36zn, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 10 pull requests

Successful merges:

 - rust-lang#75098 (Clippy pointer cast lint experiment)
 - rust-lang#75249 (Only add a border for the rust logo)
 - rust-lang#75315 (Avoid deleting temporary files on error)
 - rust-lang#75316 (Don't try to use wasm intrinsics on vectors)
 - rust-lang#75337 (instance: only polymorphize upvar substs)
 - rust-lang#75339 (evaluate required_consts when pushing stack frame in Miri engine)
 - rust-lang#75363 (Use existing `infcx` when emitting trait impl diagnostic)
 - rust-lang#75366 (Add help button)
 - rust-lang#75369 (Move to intra-doc links in /library/core/src/borrow.rs)
 - rust-lang#75379 (Use intra-doc links in /library/core/src/cmp.rs)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Aug 11, 2020
2 parents 3bb5a86 + 0a738d4 commit 7189ca6
Show file tree
Hide file tree
Showing 46 changed files with 926 additions and 407 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3367,6 +3367,7 @@ dependencies = [
"smallvec 1.4.0",
"stable_deref_trait",
"stacker",
"tempfile",
"tracing",
"winapi 0.3.8",
]
Expand Down
11 changes: 4 additions & 7 deletions library/core/src/borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@
/// provide a reference to related type `T`, it is often better to use
/// [`AsRef<T>`] as more types can safely implement it.
///
/// [`AsRef<T>`]: ../../std/convert/trait.AsRef.html
/// [`BorrowMut<T>`]: trait.BorrowMut.html
/// [`BorrowMut<T>`]: BorrowMut
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
/// [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
/// [`Rc<T>`]: ../../std/rc/struct.Rc.html
/// [`str`]: ../../std/primitive.str.html
/// [`String`]: ../../std/string/struct.String.html
/// [`borrow`]: #tymethod.borrow
/// [`borrow`]: Borrow::borrow
///
/// # Examples
///
Expand Down Expand Up @@ -152,10 +150,9 @@
/// If it wants to allow others access to the underlying `str`, it can do
/// that via `AsRef<str>` which doesn’t carry any extra requirements.
///
/// [`Hash`]: ../../std/hash/trait.Hash.html
/// [`Hash`]: crate::hash::Hash
/// [`HashMap<K, V>`]: ../../std/collections/struct.HashMap.html
/// [`String`]: ../../std/string/struct.String.html
/// [`str`]: ../../std/primitive.str.html
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Borrow<Borrowed: ?Sized> {
/// Immutably borrows from an owned value.
Expand Down Expand Up @@ -187,7 +184,7 @@ pub trait Borrow<Borrowed: ?Sized> {
/// an underlying type by providing a mutable reference. See [`Borrow<T>`]
/// for more information on borrowing as another type.
///
/// [`Borrow<T>`]: trait.Borrow.html
/// [`Borrow<T>`]: Borrow
#[stable(feature = "rust1", since = "1.0.0")]
pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
/// Mutably borrows from an owned value.
Expand Down
10 changes: 2 additions & 8 deletions library/core/src/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@
//!
//! For more details, see the respective documentation of each item in the list.
//!
//! [`Eq`]: trait.Eq.html
//! [`PartialEq`]: trait.PartialEq.html
//! [`Ord`]: trait.Ord.html
//! [`PartialOrd`]: trait.PartialOrd.html
//! [`Ordering`]: enum.Ordering.html
//! [`Reverse`]: struct.Reverse.html
//! [`max`]: fn.max.html
//! [`min`]: fn.min.html
//! [`max`]: Ord::max
//! [`min`]: Ord::min
#![stable(feature = "rust1", since = "1.0.0")]

Expand Down
55 changes: 31 additions & 24 deletions src/librustc_codegen_llvm/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -728,20 +728,25 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
// codegen. Note that this has a semantic difference in that the
// intrinsic can trap whereas `fptoui` never traps. That difference,
// however, is handled by `fptosui_may_trap` above.
//
// Note that we skip the wasm intrinsics for vector types where `fptoui`
// must be used instead.
if self.wasm_and_missing_nontrapping_fptoint() {
let src_ty = self.cx.val_ty(val);
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.unsigned.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.unsigned.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.unsigned.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.unsigned.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return self.call(intrinsic, &[val], None);
if self.cx.type_kind(src_ty) != TypeKind::Vector {
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.unsigned.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.unsigned.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.unsigned.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.unsigned.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return self.call(intrinsic, &[val], None);
}
}
}
unsafe { llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, UNNAMED) }
Expand All @@ -750,18 +755,20 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
fn fptosi(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
if self.wasm_and_missing_nontrapping_fptoint() {
let src_ty = self.cx.val_ty(val);
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.signed.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.signed.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.signed.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.signed.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return self.call(intrinsic, &[val], None);
if self.cx.type_kind(src_ty) != TypeKind::Vector {
let float_width = self.cx.float_width(src_ty);
let int_width = self.cx.int_width(dest_ty);
let name = match (int_width, float_width) {
(32, 32) => Some("llvm.wasm.trunc.signed.i32.f32"),
(32, 64) => Some("llvm.wasm.trunc.signed.i32.f64"),
(64, 32) => Some("llvm.wasm.trunc.signed.i64.f32"),
(64, 64) => Some("llvm.wasm.trunc.signed.i64.f64"),
_ => None,
};
if let Some(name) = name {
let intrinsic = self.get_intrinsic(name);
return self.call(intrinsic, &[val], None);
}
}
}
unsafe { llvm::LLVMBuildFPToSI(self.llbuilder, val, dest_ty, UNNAMED) }
Expand Down
39 changes: 15 additions & 24 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_fs_util::fix_windows_verbatim_for_gcc;
use rustc_hir::def_id::CrateNum;
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLib};
Expand All @@ -23,7 +24,7 @@ use super::rpath::{self, RPathConfig};
use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME};

use cc::windows_registry;
use tempfile::{Builder as TempFileBuilder, TempDir};
use tempfile::Builder as TempFileBuilder;

use std::ffi::OsString;
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -70,35 +71,29 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
}
});

let tmpdir = TempFileBuilder::new()
.prefix("rustc")
.tempdir()
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));

if outputs.outputs.should_codegen() {
let tmpdir = TempFileBuilder::new()
.prefix("rustc")
.tempdir()
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps);
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
match crate_type {
CrateType::Rlib => {
let _timer = sess.timer("link_rlib");
link_rlib::<B>(
sess,
codegen_results,
RlibFlavor::Normal,
&out_filename,
&tmpdir,
)
.build();
link_rlib::<B>(sess, codegen_results, RlibFlavor::Normal, &out_filename, &path)
.build();
}
CrateType::Staticlib => {
link_staticlib::<B>(sess, codegen_results, &out_filename, &tmpdir);
link_staticlib::<B>(sess, codegen_results, &out_filename, &path);
}
_ => {
link_natively::<B>(
sess,
crate_type,
&out_filename,
codegen_results,
tmpdir.path(),
path.as_ref(),
target_cpu,
);
}
Expand All @@ -107,10 +102,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename, "link");
}
}

if sess.opts.cg.save_temps {
let _ = tmpdir.into_path();
}
}

// Remove the temporary object file and metadata if we aren't saving temps
Expand Down Expand Up @@ -279,8 +270,8 @@ pub fn each_linked_rlib(
/// building an `.rlib` (stomping over one another), or writing an `.rmeta` into a
/// directory being searched for `extern crate` (observing an incomplete file).
/// The returned path is the temporary file containing the complete metadata.
pub fn emit_metadata(sess: &Session, metadata: &EncodedMetadata, tmpdir: &TempDir) -> PathBuf {
let out_filename = tmpdir.path().join(METADATA_FILENAME);
pub fn emit_metadata(sess: &Session, metadata: &EncodedMetadata, tmpdir: &MaybeTempDir) -> PathBuf {
let out_filename = tmpdir.as_ref().join(METADATA_FILENAME);
let result = fs::write(&out_filename, &metadata.raw_data);

if let Err(e) = result {
Expand All @@ -301,7 +292,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
codegen_results: &CodegenResults,
flavor: RlibFlavor,
out_filename: &Path,
tmpdir: &TempDir,
tmpdir: &MaybeTempDir,
) -> B {
info!("preparing rlib to {:?}", out_filename);
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename, None);
Expand Down Expand Up @@ -406,7 +397,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
sess: &'a Session,
codegen_results: &CodegenResults,
out_filename: &Path,
tempdir: &TempDir,
tempdir: &MaybeTempDir,
) {
let mut ab =
link_rlib::<B>(sess, codegen_results, RlibFlavor::StaticlibBase, out_filename, tempdir);
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ bitflags = "1.2.1"
measureme = "0.7.1"
libc = "0.2"
stacker = "0.1.9"
tempfile = "3.0.5"

[dependencies.parking_lot]
version = "0.10"
Expand Down
1 change: 1 addition & 0 deletions src/librustc_data_structures/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod frozen;
pub mod temp_dir;

pub struct OnDrop<F: Fn()>(pub F);

Expand Down
34 changes: 34 additions & 0 deletions src/librustc_data_structures/temp_dir.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::mem::ManuallyDrop;
use std::path::Path;
use tempfile::TempDir;

/// This is used to avoid TempDir being dropped on error paths unintentionally.
#[derive(Debug)]
pub struct MaybeTempDir {
dir: ManuallyDrop<TempDir>,
// Whether the TempDir should be deleted on drop.
keep: bool,
}

impl Drop for MaybeTempDir {
fn drop(&mut self) {
// Safety: We are in the destructor, and no further access will
// occur.
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
if self.keep {
dir.into_path();
}
}
}

impl AsRef<Path> for MaybeTempDir {
fn as_ref(&self) -> &Path {
self.dir.path()
}
}

impl MaybeTempDir {
pub fn new(dir: TempDir, keep_on_drop: bool) -> MaybeTempDir {
MaybeTempDir { dir: ManuallyDrop::new(dir), keep: keep_on_drop }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{Subtype, TyCtxtInferExt, ValuePairs};
use crate::infer::{Subtype, ValuePairs};
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
Expand Down Expand Up @@ -53,7 +53,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}

fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, trait_def_id: DefId) {
let tcx = self.tcx();
let trait_sp = self.tcx().def_span(trait_def_id);
let mut err = self
.tcx()
Expand Down Expand Up @@ -85,9 +84,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
);
}

if let Some((expected, found)) = tcx
.infer_ctxt()
.enter(|infcx| infcx.expected_found_str_ty(&ExpectedFound { expected, found }))
if let Some((expected, found)) =
self.infcx.expected_found_str_ty(&ExpectedFound { expected, found })
{
// Highlighted the differences when showing the "expected/found" note.
err.note_expected_found(&"", expected, &"", found);
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc_ast::{self, ast, visit};
use rustc_codegen_ssa::back::link::emit_metadata;
use rustc_codegen_ssa::traits::CodegenBackend;
use rustc_data_structures::sync::{par_iter, Lrc, OnceCell, ParallelIterator, WorkerLocal};
use rustc_data_structures::temp_dir::MaybeTempDir;
use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
use rustc_errors::{ErrorReported, PResult};
use rustc_expand::base::ExtCtxt;
Expand Down Expand Up @@ -974,6 +975,7 @@ fn encode_and_write_metadata(
.prefix("rmeta")
.tempdir_in(out_filename.parent().unwrap())
.unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err)));
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
let metadata_filename = emit_metadata(tcx.sess, &metadata, &metadata_tmpdir);
if let Err(e) = fs::rename(&metadata_filename, &out_filename) {
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));
Expand Down
Loading

0 comments on commit 7189ca6

Please sign in to comment.