Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #47998

Merged
merged 21 commits into from
Feb 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b9f7564
Do not ignore lifetime bounds in Copy impls
spastorino Jan 30, 2018
a99b5db
stabilize match_beginning_vert
goodmanjonathan Jan 30, 2018
5985b0b
wherein the parens lint keeps its own counsel re args in nested macros
zackmdavis Jan 31, 2018
e2de8de
Enable stack-probe tests with system LLVM >= 5.0
cuviper Jan 31, 2018
55b54a9
Use a range to identify SIGSEGV in stack guards
cuviper Jan 31, 2018
196fad0
Turn `type_id` into a constant intrinsic
Badel2 Jan 30, 2018
cc68afb
ui tests: diff from old (expected) to new (actual) instead of backwards.
eddyb Feb 3, 2018
6b35d81
Fix const evaluation ICE in rustdoc
GuillaumeGomez Jan 29, 2018
d597da3
Clarify shared file handler behavior of File::try_clone.
frewsxcv Feb 2, 2018
32d5fbe
Run the `run-make` tests last, so more tests run on Windows when `mak…
Zoxc Feb 4, 2018
f168700
Remove 'the this' in doc comments.
jaystrictor Feb 4, 2018
6869863
Rollup merge of #47862 - GuillaumeGomez:const-evaluation-ice, r=eddyb
kennytm Feb 4, 2018
f3dc756
Rollup merge of #47877 - spastorino:lifetime-bounds-in-copy, r=nikoma…
kennytm Feb 4, 2018
349115e
Rollup merge of #47896 - zackmdavis:and_the_case_of_the_necessary_unn…
kennytm Feb 4, 2018
8b8c6ee
Rollup merge of #47912 - cuviper:glibc-stack-guard, r=alexcrichton
kennytm Feb 4, 2018
1439c2a
Rollup merge of #47947 - goodmanjonathan:stabilize_match_beginning_ve…
kennytm Feb 4, 2018
e58cff2
Rollup merge of #47958 - frewsxcv:frewsxcv-try-clone, r=aidanhs
kennytm Feb 4, 2018
393cd89
Rollup merge of #47978 - eddyb:iu, r=kennytm
kennytm Feb 4, 2018
adb5849
Rollup merge of #47996 - Zoxc:run-make-last, r=Mark-Simulacrum
kennytm Feb 4, 2018
66d6c85
Rollup merge of #47999 - jaystrictor:master, r=Mark-Simulacrum
kennytm Feb 4, 2018
e17ebdf
Rollup merge of #47892 - Badel2:const_type_id_of, r=oli-obk
kennytm Feb 4, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bootstrap/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,6 @@ static HOST_COMPILETESTS: &[Test] = &[
mode: "incremental",
suite: "incremental-fulldeps",
},
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
Test { path: "src/test/rustdoc", mode: "rustdoc", suite: "rustdoc" },

Test { path: "src/test/pretty", mode: "pretty", suite: "pretty" },
Expand All @@ -619,6 +618,7 @@ static HOST_COMPILETESTS: &[Test] = &[
Test { path: "src/test/run-pass-valgrind/pretty", mode: "pretty", suite: "run-pass-valgrind" },
Test { path: "src/test/run-pass-fulldeps/pretty", mode: "pretty", suite: "run-pass-fulldeps" },
Test { path: "src/test/run-fail-fulldeps/pretty", mode: "pretty", suite: "run-fail-fulldeps" },
Test { path: "src/test/run-make", mode: "run-make", suite: "run-make" },
];

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

This file was deleted.

27 changes: 27 additions & 0 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,36 @@ impl TypeId {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(stage0)]
pub fn of<T: ?Sized + 'static>() -> TypeId {
TypeId {
t: unsafe { intrinsics::type_id::<T>() },
}
}

/// Returns the `TypeId` of the type this generic function has been
/// instantiated with.
///
/// # Examples
///
/// ```
/// use std::any::{Any, TypeId};
///
/// fn is_string<T: ?Sized + Any>(_s: &T) -> bool {
/// TypeId::of::<String>() == TypeId::of::<T>()
/// }
///
/// fn main() {
/// assert_eq!(is_string(&0), false);
/// assert_eq!(is_string(&"cookie monster".to_string()), true);
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature="const_type_id")]
#[cfg(not(stage0))]
pub const fn of<T: ?Sized + 'static>() -> TypeId {
TypeId {
t: unsafe { intrinsics::type_id::<T>() },
}
}
}
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
#![feature(doc_spotlight)]
#![feature(rustc_const_unstable)]

#[prelude_import]
#[allow(unused)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ pub struct Location {
/// the location is within this block
pub block: BasicBlock,

/// the location is the start of the this statement; or, if `statement_index`
/// the location is the start of the statement; or, if `statement_index`
/// == num-statements, then the start of the terminator.
pub statement_index: usize,
}
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_const_eval/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,10 @@ fn eval_const_expr_partial<'a, 'tcx>(cx: &ConstContext<'a, 'tcx>,
return Ok(mk_const(Integral(Usize(ConstUsize::new(align,
tcx.sess.target.usize_ty).unwrap()))));
}
"type_id" => {
let type_id = tcx.type_id_hash(substs.type_at(0));
return Ok(mk_const(Integral(U64(type_id))));
}
_ => signal!(e, TypeckError)
}
}
Expand Down
37 changes: 28 additions & 9 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,19 +302,38 @@ impl EarlyLintPass for UnusedParens {
Assign(_, ref value) => (value, "assigned value", false),
AssignOp(.., ref value) => (value, "assigned value", false),
InPlace(_, ref value) => (value, "emplacement value", false),
Call(_, ref args) => {
for arg in args {
self.check_unused_parens_core(cx, arg, "function argument", false)
// either function/method call, or something this lint doesn't care about
ref call_or_other => {
let args_to_check;
let call_kind;
match *call_or_other {
Call(_, ref args) => {
call_kind = "function";
args_to_check = &args[..];
},
MethodCall(_, ref args) => {
call_kind = "method";
// first "argument" is self (which sometimes needs parens)
args_to_check = &args[1..];
}
// actual catch-all arm
_ => { return; }
}
return;
},
MethodCall(_, ref args) => {
for arg in &args[1..] { // first "argument" is self (which sometimes needs parens)
self.check_unused_parens_core(cx, arg, "method argument", false)
// Don't lint if this is a nested macro expansion: otherwise, the lint could
// trigger in situations that macro authors shouldn't have to care about, e.g.,
// when a parenthesized token tree matched in one macro expansion is matched as
// an expression in another and used as a fn/method argument (Issue #47775)
if e.span.ctxt().outer().expn_info()
.map_or(false, |info| info.call_site.ctxt().outer()
.expn_info().is_some()) {
return;
}
let msg = format!("{} argument", call_kind);
for arg in args_to_check {
self.check_unused_parens_core(cx, arg, &msg, false);
}
return;
}
_ => return,
};
self.check_unused_parens_core(cx, &value, msg, struct_lit_needs_parens);
}
Expand Down
21 changes: 14 additions & 7 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,13 +374,20 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
};
if let PlaceContext::Copy = context {
let ty = place_ty.to_ty(self.tcx());
if self.cx
.infcx
.type_moves_by_default(self.cx.param_env, ty, DUMMY_SP)
{
span_mirbug!(self, place, "attempted copy of non-Copy type ({:?})", ty);
}
let tcx = self.tcx();
let trait_ref = ty::TraitRef {
def_id: tcx.lang_items().copy_trait().unwrap(),
substs: tcx.mk_substs_trait(place_ty.to_ty(tcx), &[]),
};

// In order to have a Copy operand, the type T of the value must be Copy. Note that we
// prove that T: Copy, rather than using the type_moves_by_default test. This is
// important because type_moves_by_default ignores the resulting region obligations and
// assumes they pass. This can result in bounds from Copy impls being unsoundly ignored
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
// fully apply: in effect, the rule is that if a value of some type could implement
// Copy, then it must.
self.cx.prove_trait_ref(trait_ref, location);
}
place_ty
}
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_mir/interpret/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ impl<'tcx> super::Machine<'tcx> for CompileTimeEvaluator {
ecx.write_primval(dest, PrimVal::from_u128(size), dest_layout.ty)?;
}

"type_id" => {
let ty = substs.type_at(0);
let type_id = ecx.tcx.type_id_hash(ty) as u128;
ecx.write_primval(dest, PrimVal::from_u128(type_id), dest_layout.ty)?;
}

name => return Err(ConstEvalError::NeedsRfc(format!("calling intrinsic `{}`", name)).into()),
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
Abi::PlatformIntrinsic => {
assert!(!self.tcx.is_const_fn(def_id));
match &self.tcx.item_name(def_id)[..] {
"size_of" | "min_align_of" => is_const_fn = Some(def_id),
"size_of" | "min_align_of" | "type_id" => is_const_fn = Some(def_id),

name if name.starts_with("simd_shuffle") => {
is_shuffle = true;
Expand Down
5 changes: 5 additions & 0 deletions src/librustc_trans/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
self.cx.align_of(substs.type_at(0)).abi());
Ok(Const::new(llval, tcx.types.usize))
}
"type_id" => {
let llval = C_u64(self.cx,
self.cx.tcx.type_id_hash(substs.type_at(0)));
Ok(Const::new(llval, tcx.types.u64))
}
_ => span_bug!(span, "{:?} in constant", terminator.kind)
}
} else if let Some((op, is_checked)) = self.is_binop_lang_item(def_id) {
Expand Down
11 changes: 9 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2447,7 +2447,12 @@ impl Clean<Type> for hir::Ty {
let def_id = cx.tcx.hir.body_owner_def_id(n);
let param_env = cx.tcx.param_env(def_id);
let substs = Substs::identity_for_item(cx.tcx, def_id);
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap();
let n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap_or_else(|_| {
cx.tcx.mk_const(ty::Const {
val: ConstVal::Unevaluated(def_id, substs),
ty: cx.tcx.types.usize
})
});
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
n.to_string()
} else if let ConstVal::Unevaluated(def_id, _) = n.val {
Expand Down Expand Up @@ -2577,7 +2582,9 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
let mut n = cx.tcx.lift(&n).unwrap();
if let ConstVal::Unevaluated(def_id, substs) = n.val {
let param_env = cx.tcx.param_env(def_id);
n = cx.tcx.const_eval(param_env.and((def_id, substs))).unwrap()
if let Ok(new_n) = cx.tcx.const_eval(param_env.and((def_id, substs))) {
n = new_n;
}
};
let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
n.to_string()
Expand Down
38 changes: 30 additions & 8 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,42 @@ impl File {
self.inner.file_attr().map(Metadata)
}

/// Creates a new independently owned handle to the underlying file.
///
/// The returned `File` is a reference to the same state that this object
/// references. Both handles will read and write with the same cursor
/// position.
/// Create a new `File` instance that shares the same underlying file handle
/// as the existing `File` instance. Reads, writes, and seeks will affect
/// both `File` instances simultaneously.
///
/// # Examples
///
/// Create two handles for a file named `foo.txt`:
///
/// ```no_run
/// use std::fs::File;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut f = File::open("foo.txt")?;
/// let file_copy = f.try_clone()?;
/// let mut file = File::open("foo.txt")?;
/// let file_copy = file.try_clone()?;
/// # Ok(())
/// # }
/// ```
///
/// Assuming there’s a file named `foo.txt` with contents `abcdef\n`, create
/// two handles, seek one of them, and read the remaining bytes from the
/// other handle:
///
/// ```no_run
/// use std::fs::File;
/// use std::io::SeekFrom;
/// use std::io::prelude::*;
///
/// # fn foo() -> std::io::Result<()> {
/// let mut file = File::open("foo.txt")?;
/// let mut file_copy = file.try_clone()?;
///
/// file.seek(SeekFrom::Start(3))?;
///
/// let mut contents = vec![];
/// file_copy.read_to_end(&mut contents)?;
/// assert_eq!(contents, b"def\n");
/// # Ok(())
/// # }
/// ```
Expand Down Expand Up @@ -1001,7 +1023,7 @@ impl Metadata {
self.0.accessed().map(FromInner::from_inner)
}

/// Returns the creation time listed in the this metadata.
/// Returns the creation time listed in this metadata.
///
/// The returned value corresponds to the `birthtime` field of `stat` on
/// Unix platforms and the `ftCreationTime` field on Windows platforms.
Expand Down
5 changes: 3 additions & 2 deletions src/libstd/sys/cloudabi/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ impl Drop for Thread {

#[cfg_attr(test, allow(dead_code))]
pub mod guard {
pub unsafe fn current() -> Option<usize> {
pub type Guard = !;
pub unsafe fn current() -> Option<Guard> {
None
}
pub unsafe fn init() -> Option<usize> {
pub unsafe fn init() -> Option<Guard> {
None
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/libstd/sys/redox/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ impl Thread {
}

pub mod guard {
pub unsafe fn current() -> Option<usize> { None }
pub unsafe fn init() -> Option<usize> { None }
pub type Guard = !;
pub unsafe fn current() -> Option<Guard> { None }
pub unsafe fn init() -> Option<Guard> { None }
}
9 changes: 2 additions & 7 deletions src/libstd/sys/unix/stack_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ mod imp {
use sys_common::thread_info;


// This is initialized in init() and only read from after
static mut PAGE_SIZE: usize = 0;

#[cfg(any(target_os = "linux", target_os = "android"))]
unsafe fn siginfo_si_addr(info: *mut libc::siginfo_t) -> usize {
#[repr(C)]
Expand Down Expand Up @@ -102,12 +99,12 @@ mod imp {
_data: *mut libc::c_void) {
use sys_common::util::report_overflow;

let guard = thread_info::stack_guard().unwrap_or(0);
let guard = thread_info::stack_guard().unwrap_or(0..0);
let addr = siginfo_si_addr(info);

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

pub unsafe fn init() {
PAGE_SIZE = ::sys::os::page_size();

let mut action: sigaction = mem::zeroed();
action.sa_flags = SA_SIGINFO | SA_ONSTACK;
action.sa_sigaction = signal_handler as sighandler_t;
Expand Down
Loading