Skip to content

Commit 7189ca6

Browse files
committed
Auto merge of rust-lang#75383 - Dylan-DPC:rollup-6hi36zn, r=Dylan-DPC
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
2 parents 3bb5a86 + 0a738d4 commit 7189ca6

Some content is hidden

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

46 files changed

+926
-407
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3367,6 +3367,7 @@ dependencies = [
33673367
"smallvec 1.4.0",
33683368
"stable_deref_trait",
33693369
"stacker",
3370+
"tempfile",
33703371
"tracing",
33713372
"winapi 0.3.8",
33723373
]

library/core/src/borrow.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
/// provide a reference to related type `T`, it is often better to use
4141
/// [`AsRef<T>`] as more types can safely implement it.
4242
///
43-
/// [`AsRef<T>`]: ../../std/convert/trait.AsRef.html
44-
/// [`BorrowMut<T>`]: trait.BorrowMut.html
43+
/// [`BorrowMut<T>`]: BorrowMut
4544
/// [`Box<T>`]: ../../std/boxed/struct.Box.html
4645
/// [`Mutex<T>`]: ../../std/sync/struct.Mutex.html
4746
/// [`Rc<T>`]: ../../std/rc/struct.Rc.html
48-
/// [`str`]: ../../std/primitive.str.html
4947
/// [`String`]: ../../std/string/struct.String.html
50-
/// [`borrow`]: #tymethod.borrow
48+
/// [`borrow`]: Borrow::borrow
5149
///
5250
/// # Examples
5351
///
@@ -152,10 +150,9 @@
152150
/// If it wants to allow others access to the underlying `str`, it can do
153151
/// that via `AsRef<str>` which doesn’t carry any extra requirements.
154152
///
155-
/// [`Hash`]: ../../std/hash/trait.Hash.html
153+
/// [`Hash`]: crate::hash::Hash
156154
/// [`HashMap<K, V>`]: ../../std/collections/struct.HashMap.html
157155
/// [`String`]: ../../std/string/struct.String.html
158-
/// [`str`]: ../../std/primitive.str.html
159156
#[stable(feature = "rust1", since = "1.0.0")]
160157
pub trait Borrow<Borrowed: ?Sized> {
161158
/// Immutably borrows from an owned value.
@@ -187,7 +184,7 @@ pub trait Borrow<Borrowed: ?Sized> {
187184
/// an underlying type by providing a mutable reference. See [`Borrow<T>`]
188185
/// for more information on borrowing as another type.
189186
///
190-
/// [`Borrow<T>`]: trait.Borrow.html
187+
/// [`Borrow<T>`]: Borrow
191188
#[stable(feature = "rust1", since = "1.0.0")]
192189
pub trait BorrowMut<Borrowed: ?Sized>: Borrow<Borrowed> {
193190
/// Mutably borrows from an owned value.

library/core/src/cmp.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,8 @@
1717
//!
1818
//! For more details, see the respective documentation of each item in the list.
1919
//!
20-
//! [`Eq`]: trait.Eq.html
21-
//! [`PartialEq`]: trait.PartialEq.html
22-
//! [`Ord`]: trait.Ord.html
23-
//! [`PartialOrd`]: trait.PartialOrd.html
24-
//! [`Ordering`]: enum.Ordering.html
25-
//! [`Reverse`]: struct.Reverse.html
26-
//! [`max`]: fn.max.html
27-
//! [`min`]: fn.min.html
20+
//! [`max`]: Ord::max
21+
//! [`min`]: Ord::min
2822
2923
#![stable(feature = "rust1", since = "1.0.0")]
3024

src/librustc_codegen_llvm/builder.rs

+31-24
Original file line numberDiff line numberDiff line change
@@ -728,20 +728,25 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
728728
// codegen. Note that this has a semantic difference in that the
729729
// intrinsic can trap whereas `fptoui` never traps. That difference,
730730
// however, is handled by `fptosui_may_trap` above.
731+
//
732+
// Note that we skip the wasm intrinsics for vector types where `fptoui`
733+
// must be used instead.
731734
if self.wasm_and_missing_nontrapping_fptoint() {
732735
let src_ty = self.cx.val_ty(val);
733-
let float_width = self.cx.float_width(src_ty);
734-
let int_width = self.cx.int_width(dest_ty);
735-
let name = match (int_width, float_width) {
736-
(32, 32) => Some("llvm.wasm.trunc.unsigned.i32.f32"),
737-
(32, 64) => Some("llvm.wasm.trunc.unsigned.i32.f64"),
738-
(64, 32) => Some("llvm.wasm.trunc.unsigned.i64.f32"),
739-
(64, 64) => Some("llvm.wasm.trunc.unsigned.i64.f64"),
740-
_ => None,
741-
};
742-
if let Some(name) = name {
743-
let intrinsic = self.get_intrinsic(name);
744-
return self.call(intrinsic, &[val], None);
736+
if self.cx.type_kind(src_ty) != TypeKind::Vector {
737+
let float_width = self.cx.float_width(src_ty);
738+
let int_width = self.cx.int_width(dest_ty);
739+
let name = match (int_width, float_width) {
740+
(32, 32) => Some("llvm.wasm.trunc.unsigned.i32.f32"),
741+
(32, 64) => Some("llvm.wasm.trunc.unsigned.i32.f64"),
742+
(64, 32) => Some("llvm.wasm.trunc.unsigned.i64.f32"),
743+
(64, 64) => Some("llvm.wasm.trunc.unsigned.i64.f64"),
744+
_ => None,
745+
};
746+
if let Some(name) = name {
747+
let intrinsic = self.get_intrinsic(name);
748+
return self.call(intrinsic, &[val], None);
749+
}
745750
}
746751
}
747752
unsafe { llvm::LLVMBuildFPToUI(self.llbuilder, val, dest_ty, UNNAMED) }
@@ -750,18 +755,20 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
750755
fn fptosi(&mut self, val: &'ll Value, dest_ty: &'ll Type) -> &'ll Value {
751756
if self.wasm_and_missing_nontrapping_fptoint() {
752757
let src_ty = self.cx.val_ty(val);
753-
let float_width = self.cx.float_width(src_ty);
754-
let int_width = self.cx.int_width(dest_ty);
755-
let name = match (int_width, float_width) {
756-
(32, 32) => Some("llvm.wasm.trunc.signed.i32.f32"),
757-
(32, 64) => Some("llvm.wasm.trunc.signed.i32.f64"),
758-
(64, 32) => Some("llvm.wasm.trunc.signed.i64.f32"),
759-
(64, 64) => Some("llvm.wasm.trunc.signed.i64.f64"),
760-
_ => None,
761-
};
762-
if let Some(name) = name {
763-
let intrinsic = self.get_intrinsic(name);
764-
return self.call(intrinsic, &[val], None);
758+
if self.cx.type_kind(src_ty) != TypeKind::Vector {
759+
let float_width = self.cx.float_width(src_ty);
760+
let int_width = self.cx.int_width(dest_ty);
761+
let name = match (int_width, float_width) {
762+
(32, 32) => Some("llvm.wasm.trunc.signed.i32.f32"),
763+
(32, 64) => Some("llvm.wasm.trunc.signed.i32.f64"),
764+
(64, 32) => Some("llvm.wasm.trunc.signed.i64.f32"),
765+
(64, 64) => Some("llvm.wasm.trunc.signed.i64.f64"),
766+
_ => None,
767+
};
768+
if let Some(name) = name {
769+
let intrinsic = self.get_intrinsic(name);
770+
return self.call(intrinsic, &[val], None);
771+
}
765772
}
766773
}
767774
unsafe { llvm::LLVMBuildFPToSI(self.llbuilder, val, dest_ty, UNNAMED) }

src/librustc_codegen_ssa/back/link.rs

+15-24
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_data_structures::fx::FxHashSet;
2+
use rustc_data_structures::temp_dir::MaybeTempDir;
23
use rustc_fs_util::fix_windows_verbatim_for_gcc;
34
use rustc_hir::def_id::CrateNum;
45
use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLib};
@@ -23,7 +24,7 @@ use super::rpath::{self, RPathConfig};
2324
use crate::{looks_like_rust_object_file, CodegenResults, CrateInfo, METADATA_FILENAME};
2425

2526
use cc::windows_registry;
26-
use tempfile::{Builder as TempFileBuilder, TempDir};
27+
use tempfile::Builder as TempFileBuilder;
2728

2829
use std::ffi::OsString;
2930
use std::path::{Path, PathBuf};
@@ -70,35 +71,29 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
7071
}
7172
});
7273

73-
let tmpdir = TempFileBuilder::new()
74-
.prefix("rustc")
75-
.tempdir()
76-
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
77-
7874
if outputs.outputs.should_codegen() {
75+
let tmpdir = TempFileBuilder::new()
76+
.prefix("rustc")
77+
.tempdir()
78+
.unwrap_or_else(|err| sess.fatal(&format!("couldn't create a temp dir: {}", err)));
79+
let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps);
7980
let out_filename = out_filename(sess, crate_type, outputs, crate_name);
8081
match crate_type {
8182
CrateType::Rlib => {
8283
let _timer = sess.timer("link_rlib");
83-
link_rlib::<B>(
84-
sess,
85-
codegen_results,
86-
RlibFlavor::Normal,
87-
&out_filename,
88-
&tmpdir,
89-
)
90-
.build();
84+
link_rlib::<B>(sess, codegen_results, RlibFlavor::Normal, &out_filename, &path)
85+
.build();
9186
}
9287
CrateType::Staticlib => {
93-
link_staticlib::<B>(sess, codegen_results, &out_filename, &tmpdir);
88+
link_staticlib::<B>(sess, codegen_results, &out_filename, &path);
9489
}
9590
_ => {
9691
link_natively::<B>(
9792
sess,
9893
crate_type,
9994
&out_filename,
10095
codegen_results,
101-
tmpdir.path(),
96+
path.as_ref(),
10297
target_cpu,
10398
);
10499
}
@@ -107,10 +102,6 @@ pub fn link_binary<'a, B: ArchiveBuilder<'a>>(
107102
sess.parse_sess.span_diagnostic.emit_artifact_notification(&out_filename, "link");
108103
}
109104
}
110-
111-
if sess.opts.cg.save_temps {
112-
let _ = tmpdir.into_path();
113-
}
114105
}
115106

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

286277
if let Err(e) = result {
@@ -301,7 +292,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
301292
codegen_results: &CodegenResults,
302293
flavor: RlibFlavor,
303294
out_filename: &Path,
304-
tmpdir: &TempDir,
295+
tmpdir: &MaybeTempDir,
305296
) -> B {
306297
info!("preparing rlib to {:?}", out_filename);
307298
let mut ab = <B as ArchiveBuilder>::new(sess, out_filename, None);
@@ -406,7 +397,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>(
406397
sess: &'a Session,
407398
codegen_results: &CodegenResults,
408399
out_filename: &Path,
409-
tempdir: &TempDir,
400+
tempdir: &MaybeTempDir,
410401
) {
411402
let mut ab =
412403
link_rlib::<B>(sess, codegen_results, RlibFlavor::StaticlibBase, out_filename, tempdir);

src/librustc_data_structures/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ bitflags = "1.2.1"
3030
measureme = "0.7.1"
3131
libc = "0.2"
3232
stacker = "0.1.9"
33+
tempfile = "3.0.5"
3334

3435
[dependencies.parking_lot]
3536
version = "0.10"

src/librustc_data_structures/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub mod vec_linked_list;
9595
pub mod work_queue;
9696
pub use atomic_ref::AtomicRef;
9797
pub mod frozen;
98+
pub mod temp_dir;
9899

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

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use std::mem::ManuallyDrop;
2+
use std::path::Path;
3+
use tempfile::TempDir;
4+
5+
/// This is used to avoid TempDir being dropped on error paths unintentionally.
6+
#[derive(Debug)]
7+
pub struct MaybeTempDir {
8+
dir: ManuallyDrop<TempDir>,
9+
// Whether the TempDir should be deleted on drop.
10+
keep: bool,
11+
}
12+
13+
impl Drop for MaybeTempDir {
14+
fn drop(&mut self) {
15+
// Safety: We are in the destructor, and no further access will
16+
// occur.
17+
let dir = unsafe { ManuallyDrop::take(&mut self.dir) };
18+
if self.keep {
19+
dir.into_path();
20+
}
21+
}
22+
}
23+
24+
impl AsRef<Path> for MaybeTempDir {
25+
fn as_ref(&self) -> &Path {
26+
self.dir.path()
27+
}
28+
}
29+
30+
impl MaybeTempDir {
31+
pub fn new(dir: TempDir, keep_on_drop: bool) -> MaybeTempDir {
32+
MaybeTempDir { dir: ManuallyDrop::new(dir), keep: keep_on_drop }
33+
}
34+
}

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
44
use crate::infer::lexical_region_resolve::RegionResolutionError;
5-
use crate::infer::{Subtype, TyCtxtInferExt, ValuePairs};
5+
use crate::infer::{Subtype, ValuePairs};
66
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
77
use rustc_errors::ErrorReported;
88
use rustc_hir as hir;
@@ -53,7 +53,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5353
}
5454

5555
fn emit_err(&self, sp: Span, expected: Ty<'tcx>, found: Ty<'tcx>, trait_def_id: DefId) {
56-
let tcx = self.tcx();
5756
let trait_sp = self.tcx().def_span(trait_def_id);
5857
let mut err = self
5958
.tcx()
@@ -85,9 +84,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8584
);
8685
}
8786

88-
if let Some((expected, found)) = tcx
89-
.infer_ctxt()
90-
.enter(|infcx| infcx.expected_found_str_ty(&ExpectedFound { expected, found }))
87+
if let Some((expected, found)) =
88+
self.infcx.expected_found_str_ty(&ExpectedFound { expected, found })
9189
{
9290
// Highlighted the differences when showing the "expected/found" note.
9391
err.note_expected_found(&"", expected, &"", found);

src/librustc_interface/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_ast::{self, ast, visit};
99
use rustc_codegen_ssa::back::link::emit_metadata;
1010
use rustc_codegen_ssa::traits::CodegenBackend;
1111
use rustc_data_structures::sync::{par_iter, Lrc, OnceCell, ParallelIterator, WorkerLocal};
12+
use rustc_data_structures::temp_dir::MaybeTempDir;
1213
use rustc_data_structures::{box_region_allow_access, declare_box_region_type, parallel};
1314
use rustc_errors::{ErrorReported, PResult};
1415
use rustc_expand::base::ExtCtxt;
@@ -974,6 +975,7 @@ fn encode_and_write_metadata(
974975
.prefix("rmeta")
975976
.tempdir_in(out_filename.parent().unwrap())
976977
.unwrap_or_else(|err| tcx.sess.fatal(&format!("couldn't create a temp dir: {}", err)));
978+
let metadata_tmpdir = MaybeTempDir::new(metadata_tmpdir, tcx.sess.opts.cg.save_temps);
977979
let metadata_filename = emit_metadata(tcx.sess, &metadata, &metadata_tmpdir);
978980
if let Err(e) = fs::rename(&metadata_filename, &out_filename) {
979981
tcx.sess.fatal(&format!("failed to write {}: {}", out_filename.display(), e));

0 commit comments

Comments
 (0)