Skip to content

Commit 7dd3864

Browse files
committed
Auto merge of #47998 - kennytm:rollup, r=kennytm
Rollup of 10 pull requests - Successful merges: #47862, #47877, #47896, #47912, #47947, #47958, #47978, #47996, #47999, #47892 - Failed merges:
2 parents 0c6091f + e17ebdf commit 7dd3864

39 files changed

+417
-204
lines changed

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ static HOST_COMPILETESTS: &[Test] = &[
610610
mode: "incremental",
611611
suite: "incremental-fulldeps",
612612
},
613-
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
614613
Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },
615614

616615
Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
@@ -619,6 +618,7 @@ static HOST_COMPILETESTS: &[Test] = &[
619618
Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
620619
Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
621620
Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
621+
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
622622
];
623623

624624
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

src/doc/unstable-book/src/language-features/match-beginning-vert.md

-23
This file was deleted.

src/libcore/any.rs

+27
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,36 @@ impl TypeId {
367367
/// }
368368
/// ```
369369
#[stable(feature = "rust1", since = "1.0.0")]
370+
#[cfg(stage0)]
370371
pub fn of<T: ?Sized + 'static>() -> TypeId {
371372
TypeId {
372373
t: unsafe { intrinsics::type_id::<T>() },
373374
}
374375
}
376+
377+
/// Returns the `TypeId` of the type this generic function has been
378+
/// instantiated with.
379+
///
380+
/// # Examples
381+
///
382+
/// ```
383+
/// use std::any::{Any, TypeId};
384+
///
385+
/// fn is_string<T: ?Sized + Any>(_s: &T) -> bool {
386+
/// TypeId::of::<String>() == TypeId::of::<T>()
387+
/// }
388+
///
389+
/// fn main() {
390+
/// assert_eq!(is_string(&0), false);
391+
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
392+
/// }
393+
/// ```
394+
#[stable(feature = "rust1", since = "1.0.0")]
395+
#[rustc_const_unstable(feature="const_type_id")]
396+
#[cfg(not(stage0))]
397+
pub const fn of<T: ?Sized + 'static>() -> TypeId {
398+
TypeId {
399+
t: unsafe { intrinsics::type_id::<T>() },
400+
}
401+
}
375402
}

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#![feature(untagged_unions)]
9292
#![feature(unwind_attributes)]
9393
#![feature(doc_spotlight)]
94+
#![feature(rustc_const_unstable)]
9495

9596
#[prelude_import]
9697
#[allow(unused)]

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ pub struct Location {
18251825
/// the location is within this block
18261826
pub block: BasicBlock,
18271827

1828-
/// the location is the start of the this statement; or, if `statement_index`
1828+
/// the location is the start of the statement; or, if `statement_index`
18291829
/// == num-statements, then the start of the terminator.
18301830
pub statement_index: usize,
18311831
}

src/librustc_const_eval/eval.rs

+4
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,10 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
327327
return Ok(mk_const(Integral(Usize(ConstUsize::new(align,
328328
tcx.sess.target.usize_ty).unwrap()))));
329329
}
330+
"type_id" => {
331+
let type_id = tcx.type_id_hash(substs.type_at(0));
332+
return Ok(mk_const(Integral(U64(type_id))));
333+
}
330334
_ => signal!(e, TypeckError)
331335
}
332336
}

src/librustc_lint/unused.rs

+28-9
Original file line numberDiff line numberDiff line change
@@ -302,19 +302,38 @@ impl EarlyLintPass for UnusedParens {
302302
Assign(_, ref value) => (value, "assigned value", false),
303303
AssignOp(.., ref value) => (value, "assigned value", false),
304304
InPlace(_, ref value) => (value, "emplacement value", false),
305-
Call(_, ref args) => {
306-
for arg in args {
307-
self.check_unused_parens_core(cx, arg, "function argument", false)
305+
// either function/method call, or something this lint doesn't care about
306+
ref call_or_other => {
307+
let args_to_check;
308+
let call_kind;
309+
match *call_or_other {
310+
Call(_, ref args) => {
311+
call_kind = "function";
312+
args_to_check = &args[..];
313+
},
314+
MethodCall(_, ref args) => {
315+
call_kind = "method";
316+
// first "argument" is self (which sometimes needs parens)
317+
args_to_check = &args[1..];
318+
}
319+
// actual catch-all arm
320+
_ => { return; }
308321
}
309-
return;
310-
},
311-
MethodCall(_, ref args) => {
312-
for arg in &args[1..] { // first "argument" is self (which sometimes needs parens)
313-
self.check_unused_parens_core(cx, arg, "method argument", false)
322+
// Don't lint if this is a nested macro expansion: otherwise, the lint could
323+
// trigger in situations that macro authors shouldn't have to care about, e.g.,
324+
// when a parenthesized token tree matched in one macro expansion is matched as
325+
// an expression in another and used as a fn/method argument (Issue #47775)
326+
if e.span.ctxt().outer().expn_info()
327+
.map_or(false, |info| info.call_site.ctxt().outer()
328+
.expn_info().is_some()) {
329+
return;
330+
}
331+
let msg = format!("{} argument", call_kind);
332+
for arg in args_to_check {
333+
self.check_unused_parens_core(cx, arg, &msg, false);
314334
}
315335
return;
316336
}
317-
_ => return,
318337
};
319338
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
320339
}

src/librustc_mir/borrow_check/nll/type_check/mod.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -374,13 +374,20 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
374374
}
375375
};
376376
if let PlaceContext::Copy = context {
377-
let ty = place_ty.to_ty(self.tcx());
378-
if self.cx
379-
.infcx
380-
.type_moves_by_default(self.cx.param_env, ty, DUMMY_SP)
381-
{
382-
span_mirbug!(self, place, "attempted copy of non-Copy type ({:?})", ty);
383-
}
377+
let tcx = self.tcx();
378+
let trait_ref = ty::TraitRef {
379+
def_id: tcx.lang_items().copy_trait().unwrap(),
380+
substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
381+
};
382+
383+
// In order to have a Copy operand, the type T of the value must be Copy. Note that we
384+
// prove that T: Copy, rather than using the type_moves_by_default test. This is
385+
// important because type_moves_by_default ignores the resulting region obligations and
386+
// assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
387+
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
388+
// fully apply: in effect, the rule is that if a value of some type could implement
389+
// Copy, then it must.
390+
self.cx.prove_trait_ref(trait_ref, location);
384391
}
385392
place_ty
386393
}

src/librustc_mir/interpret/const_eval.rs

+6
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ impl<'tcx> super::Machine<'tcx> for CompileTimeEvaluator {
243243
ecx.write_primval(dest, PrimVal::from_u128(size), dest_layout.ty)?;
244244
}
245245

246+
"type_id" => {
247+
let ty = substs.type_at(0);
248+
let type_id = ecx.tcx.type_id_hash(ty) as u128;
249+
ecx.write_primval(dest, PrimVal::from_u128(type_id), dest_layout.ty)?;
250+
}
251+
246252
name => return Err(ConstEvalError::NeedsRfc(format!("calling intrinsic `{}`", name)).into()),
247253
}
248254

src/librustc_mir/transform/qualify_consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
737737
Abi::PlatformIntrinsic => {
738738
assert!(!self.tcx.is_const_fn(def_id));
739739
match &self.tcx.item_name(def_id)[..] {
740-
"size_of" | "min_align_of" => is_const_fn = Some(def_id),
740+
"size_of" | "min_align_of" | "type_id" => is_const_fn = Some(def_id),
741741

742742
name if name.starts_with("simd_shuffle") => {
743743
is_shuffle = true;

src/librustc_trans/mir/constant.rs

+5
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
411411
self.cx.align_of(substs.type_at(0)).abi());
412412
Ok(Const::new(llval, tcx.types.usize))
413413
}
414+
"type_id" => {
415+
let llval = C_u64(self.cx,
416+
self.cx.tcx.type_id_hash(substs.type_at(0)));
417+
Ok(Const::new(llval, tcx.types.u64))
418+
}
414419
_ => span_bug!(span, "{:?} in constant", terminator.kind)
415420
}
416421
} else if let Some((op, is_checked)) = self.is_binop_lang_item(def_id) {

src/librustdoc/clean/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -2447,7 +2447,12 @@ impl Clean<Type> for hir::Ty {
24472447
let def_id = cx.tcx.hir.body_owner_def_id(n);
24482448
let param_env = cx.tcx.param_env(def_id);
24492449
let substs = Substs::identity_for_item(cx.tcx, def_id);
2450-
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap();
2450+
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap_or_else(|_| {
2451+
cx.tcx.mk_const(ty::Const {
2452+
val: ConstVal::Unevaluated(def_id, substs),
2453+
ty: cx.tcx.types.usize
2454+
})
2455+
});
24512456
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
24522457
n.to_string()
24532458
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
@@ -2577,7 +2582,9 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
25772582
let mut n = cx.tcx.lift(&n).unwrap();
25782583
if let ConstVal::Unevaluated(def_id, substs) = n.val {
25792584
let param_env = cx.tcx.param_env(def_id);
2580-
n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap()
2585+
if let Ok(new_n) = cx.tcx.const_eval(param_env.and((def_id, substs))) {
2586+
n = new_n;
2587+
}
25812588
};
25822589
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
25832590
n.to_string()

src/libstd/fs.rs

+30-8
Original file line numberDiff line numberDiff line change
@@ -482,20 +482,42 @@ impl File {
482482
self.inner.file_attr().map(Metadata)
483483
}
484484

485-
/// Creates a new independently owned handle to the underlying file.
486-
///
487-
/// The returned `File` is a reference to the same state that this object
488-
/// references. Both handles will read and write with the same cursor
489-
/// position.
485+
/// Create a new `File` instance that shares the same underlying file handle
486+
/// as the existing `File` instance. Reads, writes, and seeks will affect
487+
/// both `File` instances simultaneously.
490488
///
491489
/// # Examples
492490
///
491+
/// Create two handles for a file named `foo.txt`:
492+
///
493493
/// ```no_run
494494
/// use std::fs::File;
495495
///
496496
/// # fn foo() -> std::io::Result<()> {
497-
/// let mut f = File::open("foo.txt")?;
498-
/// let file_copy = f.try_clone()?;
497+
/// let mut file = File::open("foo.txt")?;
498+
/// let file_copy = file.try_clone()?;
499+
/// # Ok(())
500+
/// # }
501+
/// ```
502+
///
503+
/// Assuming there’s a file named `foo.txt` with contents `abcdef\n`, create
504+
/// two handles, seek one of them, and read the remaining bytes from the
505+
/// other handle:
506+
///
507+
/// ```no_run
508+
/// use std::fs::File;
509+
/// use std::io::SeekFrom;
510+
/// use std::io::prelude::*;
511+
///
512+
/// # fn foo() -> std::io::Result<()> {
513+
/// let mut file = File::open("foo.txt")?;
514+
/// let mut file_copy = file.try_clone()?;
515+
///
516+
/// file.seek(SeekFrom::Start(3))?;
517+
///
518+
/// let mut contents = vec![];
519+
/// file_copy.read_to_end(&mut contents)?;
520+
/// assert_eq!(contents, b"def\n");
499521
/// # Ok(())
500522
/// # }
501523
/// ```
@@ -1001,7 +1023,7 @@ impl Metadata {
10011023
self.0.accessed().map(FromInner::from_inner)
10021024
}
10031025

1004-
/// Returns the creation time listed in the this metadata.
1026+
/// Returns the creation time listed in this metadata.
10051027
///
10061028
/// The returned value corresponds to the `birthtime` field of `stat` on
10071029
/// Unix platforms and the `ftCreationTime` field on Windows platforms.

src/libstd/sys/cloudabi/thread.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,11 @@ impl Drop for Thread {
111111

112112
#[cfg_attr(test, allow(dead_code))]
113113
pub mod guard {
114-
pub unsafe fn current() -> Option<usize> {
114+
pub type Guard = !;
115+
pub unsafe fn current() -> Option<Guard> {
115116
None
116117
}
117-
pub unsafe fn init() -> Option<usize> {
118+
pub unsafe fn init() -> Option<Guard> {
118119
None
119120
}
120121
}

src/libstd/sys/redox/thread.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ impl Thread {
8888
}
8989

9090
pub mod guard {
91-
pub unsafe fn current() -> Option<usize> { None }
92-
pub unsafe fn init() -> Option<usize> { None }
91+
pub type Guard = !;
92+
pub unsafe fn current() -> Option<Guard> { None }
93+
pub unsafe fn init() -> Option<Guard> { None }
9394
}

src/libstd/sys/unix/stack_overflow.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ mod imp {
5757
use sys_common::thread_info;
5858

5959

60-
// This is initialized in init() and only read from after
61-
static mut PAGE_SIZE: usize = 0;
62-
6360
#[cfg(any(target_os = "linux", target_os = "android"))]
6461
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
6562
#[repr(C)]
@@ -102,12 +99,12 @@ mod imp {
10299
_data: *mut libc::c_void) {
103100
use sys_common::util::report_overflow;
104101

105-
let guard = thread_info::stack_guard().unwrap_or(0);
102+
let guard = thread_info::stack_guard().unwrap_or(0..0);
106103
let addr = siginfo_si_addr(info);
107104

108105
// If the faulting address is within the guard page, then we print a
109106
// message saying so and abort.
110-
if guard != 0 && guard - PAGE_SIZE <= addr && addr < guard {
107+
if guard.start <= addr && addr < guard.end {
111108
report_overflow();
112109
rtabort!("stack overflow");
113110
} else {
@@ -123,8 +120,6 @@ mod imp {
123120
static mut MAIN_ALTSTACK: *mut libc::c_void = ptr::null_mut();
124121

125122
pub unsafe fn init() {
126-
PAGE_SIZE = ::sys::os::page_size();
127-
128123
let mut action: sigaction = mem::zeroed();
129124
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
130125
action.sa_sigaction = signal_handler as sighandler_t;

0 commit comments

Comments
 (0)