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 15 pull requests #73470

Closed
wants to merge 44 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
591584e
Add tests for 'impl Default for [T; N]'
MikailBag May 26, 2020
3313bf6
Skip leak test on targets without panic=unwind
MikailBag May 28, 2020
1bc4e45
Only highlight results via mouseover if mouse has moved
carols10cents Jun 2, 2020
bbb3321
Ensure std benchmarks get tested.
ehuss Jun 8, 2020
724dfba
Clean up some weird command strings
GuillaumeGomez Jun 13, 2020
e32db84
Add rust features to print target features
aszenz Jun 14, 2020
d3ca6fd
Enable static-pie for the x86_64-unknown-linux-musl target
haraldh Jun 15, 2020
9e51008
Complete the std::time documentation to warn about the inconsistencie…
poliorcetics Jun 15, 2020
96f5584
Expand "recursive opaque type" diagnostic
estebank Apr 19, 2020
8f12485
review comments
estebank Jun 15, 2020
268decb
make all uses of ty::Error or ConstKind::Error delay a span bug
mark-i-m May 6, 2020
e855b90
track caller for delay_span_bug
mark-i-m May 26, 2020
5fbef22
warn against 'specialization' feature
RalfJung May 17, 2020
991dfe7
bless all
RalfJung Jun 16, 2020
d1265e7
libcore tests: use min_specialization
RalfJung Jun 16, 2020
1990f97
Disallow loading crates with non-ascii identifier name.
crlf0710 Jun 13, 2020
cfdbbb5
format derives
mark-i-m Jun 16, 2020
4506a35
add header for rust specific feature
aszenz Jun 16, 2020
9f50f84
break long line for formatting
aszenz Jun 16, 2020
457acbd
trim whitespace
aszenz Jun 16, 2020
15cd51a
Mention functions pointers in the documentation
poliorcetics Jun 16, 2020
9f2e8ad
Fix typo in librustc_ast docs
pierwill Jun 17, 2020
e75fa89
Don't imply function pointers are references
poliorcetics Jun 17, 2020
caffb28
add blank line bw sections
aszenz Jun 17, 2020
c9dc73d
Make novel structural match violations a warning
ecstatic-morse Jun 17, 2020
38e921b
Add regression test for #73431
ecstatic-morse Jun 17, 2020
3a1207f
Add issue number to novel violation warning
ecstatic-morse Jun 17, 2020
2da9ca7
Remove duplicate sentence fragment from mem::zeroed doc
dtolnay Jun 18, 2020
4e77214
Improve document for `Result::as_deref(_mut)`
tesuji Jun 18, 2020
09427f6
Rollup merge of #70551 - mark-i-m:ty-err-2, r=varkor
RalfJung Jun 18, 2020
9dfc614
Rollup merge of #70740 - haraldh:static-pie, r=petrochenkov
RalfJung Jun 18, 2020
e9995fe
Rollup merge of #71338 - estebank:recursive-impl-trait, r=nikomatsakis
RalfJung Jun 18, 2020
582b8eb
Rollup merge of #71420 - RalfJung:specialization-incomplete, r=matthe…
RalfJung Jun 18, 2020
594f58e
Rollup merge of #72628 - MikailBag:array-default-tests, r=shepmaster
RalfJung Jun 18, 2020
1a763ea
Rollup merge of #72836 - poliorcetics:std-time-os-specificities, r=sh…
RalfJung Jun 18, 2020
6ca9dce
Rollup merge of #72968 - integer32llc:docs-arrow-keys, r=GuillaumeGomez
RalfJung Jun 18, 2020
d67e993
Rollup merge of #73142 - ehuss:std-benches, r=dtolnay
RalfJung Jun 18, 2020
f8ae9a3
Rollup merge of #73305 - crlf0710:disallow_loading_monsters, r=petroc…
RalfJung Jun 18, 2020
3ff4fac
Rollup merge of #73315 - GuillaumeGomez:clean-up-config-strs, r=kinnison
RalfJung Jun 18, 2020
c51d0ac
Rollup merge of #73346 - aszenz:patch-1, r=cuviper
RalfJung Jun 18, 2020
b87d4a4
Rollup merge of #73425 - poliorcetics:zeroed-functions-pointers, r=dt…
RalfJung Jun 18, 2020
80c2238
Rollup merge of #73428 - pierwill:patch-1, r=jonas-schievink
RalfJung Jun 18, 2020
b3a7b40
Rollup merge of #73446 - ecstatic-morse:issue-73431, r=pnkfelix
RalfJung Jun 18, 2020
e96f154
Rollup merge of #73447 - lzutao:stabilize-result_as_deref, r=dtolnay
RalfJung Jun 18, 2020
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
1 change: 1 addition & 0 deletions src/liballoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ path = "../liballoc/tests/lib.rs"
[[bench]]
name = "collectionsbenches"
path = "../liballoc/benches/lib.rs"
test = true

[[bench]]
name = "vec_deque_append_bench"
Expand Down
1 change: 1 addition & 0 deletions src/libcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ path = "../libcore/tests/lib.rs"
[[bench]]
name = "corebenches"
path = "../libcore/benches/lib.rs"
test = true

[dev-dependencies]
rand = "0.7"
Expand Down
12 changes: 7 additions & 5 deletions src/libcore/mem/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,11 +581,12 @@ pub const fn needs_drop<T>() -> bool {
/// This means that, for example, the padding byte in `(u8, u16)` is not
/// necessarily zeroed.
///
/// There is no guarantee that an all-zero byte-pattern represents a valid value of
/// some type `T`. For example, the all-zero byte-pattern is not a valid value
/// for reference types (`&T` and `&mut T`). Using `zeroed` on such types
/// causes immediate [undefined behavior][ub] because [the Rust compiler assumes][inv]
/// that there always is a valid value in a variable it considers initialized.
/// There is no guarantee that an all-zero byte-pattern represents a valid value
/// of some type `T`. For example, the all-zero byte-pattern is not a valid value
/// for reference types (`&T`, `&mut T`) and functions pointers. Using `zeroed`
/// on such types causes immediate [undefined behavior][ub] because [the Rust
/// compiler assumes][inv] that there always is a valid value in a variable it
/// considers initialized.
///
/// This has the same effect as [`MaybeUninit::zeroed().assume_init()`][zeroed].
/// It is useful for FFI sometimes, but should generally be avoided.
Expand All @@ -612,6 +613,7 @@ pub const fn needs_drop<T>() -> bool {
/// use std::mem;
///
/// let _x: &i32 = unsafe { mem::zeroed() }; // Undefined behavior!
/// let _y: fn() = unsafe { mem::zeroed() }; // And again!
/// ```
#[inline(always)]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
56 changes: 40 additions & 16 deletions src/libcore/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1145,45 +1145,69 @@ impl<T, E: Into<!>> Result<T, E> {
}
}

#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
#[unstable(feature = "inner_deref", issue = "50264")]
impl<T: Deref, E> Result<T, E> {
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&T::Target, &E>`.
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&<T as Deref>::Target, &E>`.
///
/// Leaves the original `Result` in-place, creating a new one containing a reference to the
/// `Ok` type's `Deref::Target` type.
/// Coerces the [`Ok`] variant of the original [`Result`] via [`Deref`](crate::ops::Deref)
/// and returns the new [`Result`].
///
/// # Examples
///
/// ```
/// let x: Result<String, u32> = Ok("hello".to_string());
/// let y: Result<&str, &u32> = Ok("hello");
/// assert_eq!(x.as_deref(), y);
///
/// let x: Result<String, u32> = Err(42);
/// let y: Result<&str, &u32> = Err(&42);
/// assert_eq!(x.as_deref(), y);
/// ```
pub fn as_deref(&self) -> Result<&T::Target, &E> {
self.as_ref().map(|t| t.deref())
}
}

#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
#[unstable(feature = "inner_deref", issue = "50264")]
impl<T, E: Deref> Result<T, E> {
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&T, &E::Target>`.
/// Converts from `Result<T, E>` (or `&Result<T, E>`) to `Result<&T, &<E as Deref>::Target>`.
///
/// Leaves the original `Result` in-place, creating a new one containing a reference to the
/// `Err` type's `Deref::Target` type.
/// Coerces the [`Err`] variant of the original [`Result`] via [`Deref`](crate::ops::Deref)
/// and returns the new [`Result`].
pub fn as_deref_err(&self) -> Result<&T, &E::Target> {
self.as_ref().map_err(|e| e.deref())
}
}

#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
#[unstable(feature = "inner_deref", issue = "50264")]
impl<T: DerefMut, E> Result<T, E> {
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T::Target, &mut E>`.
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut <T as DerefMut>::Target, &mut E>`.
///
/// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
/// the `Ok` type's `Deref::Target` type.
/// Coerces the [`Ok`] variant of the original [`Result`] via [`DerefMut`](crate::ops::DerefMut)
/// and returns the new [`Result`].
///
/// # Examples
///
/// ```
/// let mut x: Result<String, u32> = Ok("hello".to_string());
/// let y: Result<&mut str, &mut u32> = Ok("HELLO");
/// assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
///
/// let mut x: Result<String, u32> = Err(42);
/// let y: Result<&mut str, &mut u32> = Err(&42);
/// assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
/// ```
pub fn as_deref_mut(&mut self) -> Result<&mut T::Target, &mut E> {
self.as_mut().map(|t| t.deref_mut())
}
}

#[unstable(feature = "inner_deref", reason = "newly added", issue = "50264")]
#[unstable(feature = "inner_deref", issue = "50264")]
impl<T, E: DerefMut> Result<T, E> {
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T, &mut E::Target>`.
/// Converts from `Result<T, E>` (or `&mut Result<T, E>`) to `Result<&mut T, &mut <E as DerefMut>::Target>`.
///
/// Leaves the original `Result` in-place, creating a new one containing a mutable reference to
/// the `Err` type's `Deref::Target` type.
/// Coerces the [`Err`] variant of the original [`Result`] via [`DerefMut`](crate::ops::DerefMut)
/// and returns the new [`Result`].
pub fn as_deref_mut_err(&mut self) -> Result<&mut T, &mut E::Target> {
self.as_mut().map_err(|e| e.deref_mut())
}
Expand Down
49 changes: 49 additions & 0 deletions src/libcore/tests/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,52 @@ fn iterator_drops() {
}
assert_eq!(i.get(), 5);
}

// This test does not work on targets without panic=unwind support.
// To work around this problem, test is marked is should_panic, so it will
// be automagically skipped on unsuitable targets, such as
// wasm32-unknown-unkown.
//
// It means that we use panic for indicating success.
#[test]
#[should_panic(expected = "test succeeded")]
fn array_default_impl_avoids_leaks_on_panic() {
use core::sync::atomic::{AtomicUsize, Ordering::Relaxed};
static COUNTER: AtomicUsize = AtomicUsize::new(0);
#[derive(Debug)]
struct Bomb(usize);

impl Default for Bomb {
fn default() -> Bomb {
if COUNTER.load(Relaxed) == 3 {
panic!("bomb limit exceeded");
}

COUNTER.fetch_add(1, Relaxed);
Bomb(COUNTER.load(Relaxed))
}
}

impl Drop for Bomb {
fn drop(&mut self) {
COUNTER.fetch_sub(1, Relaxed);
}
}

let res = std::panic::catch_unwind(|| <[Bomb; 5]>::default());
let panic_msg = match res {
Ok(_) => unreachable!(),
Err(p) => p.downcast::<&'static str>().unwrap(),
};
assert_eq!(*panic_msg, "bomb limit exceeded");
// check that all bombs are successfully dropped
assert_eq!(COUNTER.load(Relaxed), 0);
panic!("test succeeded")
}

#[test]
fn empty_array_is_always_default() {
struct DoesNotImplDefault;

let _arr = <[DoesNotImplDefault; 0]>::default();
}
2 changes: 1 addition & 1 deletion src/libcore/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#![feature(raw)]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(specialization)]
#![feature(min_specialization)]
#![feature(step_trait)]
#![feature(step_trait_ext)]
#![feature(str_internals)]
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! additional metadata), and [`ItemKind`] (which represents a concrete type and contains
//! information specific to the type of the item).
//!
//! Other module items that worth mentioning:
//! Other module items worth mentioning:
//! - [`Ty`] and [`TyKind`]: A parsed Rust type.
//! - [`Expr`] and [`ExprKind`]: A parsed Rust expression.
//! - [`Pat`] and [`PatKind`]: A parsed Rust pattern. Patterns are often dual to expressions.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn push_debuginfo_type_name<'tcx>(
tcx.def_key(def_id).disambiguated_data.disambiguator
));
}
ty::Error
ty::Error(_)
| ty::Infer(_)
| ty::Placeholder(..)
| ty::Projection(..)
Expand Down
4 changes: 4 additions & 0 deletions src/librustc_errors/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
#![feature(crate_visibility_modifier)]
#![feature(nll)]
#![feature(track_caller)]

pub use emitter::ColorConfig;

Expand Down Expand Up @@ -621,6 +622,7 @@ impl Handler {
self.inner.borrow_mut().span_bug(span, msg)
}

#[track_caller]
pub fn delay_span_bug(&self, span: impl Into<MultiSpan>, msg: &str) {
self.inner.borrow_mut().delay_span_bug(span, msg)
}
Expand Down Expand Up @@ -873,6 +875,7 @@ impl HandlerInner {
self.emit_diagnostic(diag.set_span(sp));
}

#[track_caller]
fn delay_span_bug(&mut self, sp: impl Into<MultiSpan>, msg: &str) {
// This is technically `self.treat_err_as_bug()` but `delay_span_bug` is called before
// incrementing `err_count` by one, so we need to +1 the comparing.
Expand All @@ -883,6 +886,7 @@ impl HandlerInner {
}
let mut diagnostic = Diagnostic::new(Level::Bug, msg);
diagnostic.set_span(sp.into());
diagnostic.note(&format!("delayed at {}", std::panic::Location::caller()));
self.delay_as_bug(diagnostic)
}

Expand Down
1 change: 1 addition & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
sym::specialization,
];
12 changes: 12 additions & 0 deletions src/librustc_hir/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2726,6 +2726,18 @@ impl Node<'_> {
}
}

pub fn body_id(&self) -> Option<BodyId> {
match self {
Node::TraitItem(TraitItem {
kind: TraitItemKind::Fn(_, TraitFn::Provided(body_id)),
..
})
| Node::ImplItem(ImplItem { kind: ImplItemKind::Fn(_, body_id), .. })
| Node::Item(Item { kind: ItemKind::Fn(.., body_id), .. }) => Some(*body_id),
_ => None,
}
}

pub fn generics(&self) -> Option<&Generics<'_>> {
match self {
Node::TraitItem(TraitItem { generics, .. })
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
| ty::Float(..)
| ty::Adt(..)
| ty::Str
| ty::Error
| ty::Error(_)
| ty::Array(..)
| ty::Slice(..)
| ty::RawPtr(..)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
self.tcx
.mk_const(ty::Const {
val: ty::ConstKind::Placeholder(placeholder_mapped),
ty: self.tcx.types.err, // FIXME(const_generics)
ty: self.tcx.ty_error(), // FIXME(const_generics)
})
.into()
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
| ty::Float(..)
| ty::Adt(..)
| ty::Str
| ty::Error
| ty::Error(_)
| ty::Array(..)
| ty::Slice(..)
| ty::RawPtr(..)
Expand Down Expand Up @@ -250,7 +250,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
ty::ConstKind::Param(_)
| ty::ConstKind::Value(_)
| ty::ConstKind::Unevaluated(..)
| ty::ConstKind::Error => {}
| ty::ConstKind::Error(_) => {}
}

ct.super_fold_with(self)
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_infer/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1751,9 +1751,10 @@ impl<'tcx> TypeTrace<'tcx> {
}

pub fn dummy(tcx: TyCtxt<'tcx>) -> TypeTrace<'tcx> {
let err = tcx.ty_error();
TypeTrace {
cause: ObligationCause::dummy(),
values: Types(ExpectedFound { expected: tcx.types.err, found: tcx.types.err }),
values: Types(ExpectedFound { expected: err, found: err }),
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_infer/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
match t.kind {
ty::Infer(ty::TyVar(vid)) => {
self.err = Some(FixupError::UnresolvedTy(vid));
self.tcx().types.err
self.tcx().ty_error()
}
ty::Infer(ty::IntVar(vid)) => {
self.err = Some(FixupError::UnresolvedIntTy(vid));
self.tcx().types.err
self.tcx().ty_error()
}
ty::Infer(ty::FloatVar(vid)) => {
self.err = Some(FixupError::UnresolvedFloatTy(vid));
self.tcx().types.err
self.tcx().ty_error()
}
ty::Infer(_) => {
bug!("Unexpected type in full type resolver: {:?}", t);
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for FullTypeResolver<'a, 'tcx> {
match c.val {
ty::ConstKind::Infer(InferConst::Var(vid)) => {
self.err = Some(FixupError::UnresolvedConst(vid));
return self.tcx().mk_const(ty::Const { val: ty::ConstKind::Error, ty: c.ty });
return self.tcx().const_error(c.ty);
}
ty::ConstKind::Infer(InferConst::Fresh(_)) => {
bug!("Unexpected const in full const resolver: {:?}", c);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_infer/infer/sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
Ok(a)
}

(&ty::Error, _) | (_, &ty::Error) => {
(&ty::Error(_), _) | (_, &ty::Error(_)) => {
infcx.set_tainted_by_errors();
Ok(self.tcx().types.err)
Ok(self.tcx().ty_error())
}

_ => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
ty::Param(..)
| ty::Infer(..)
| ty::Bound(..)
| ty::Error
| ty::Error(_)
| ty::Closure(..)
| ty::Generator(..)
| ty::GeneratorWitness(..)
Expand Down
8 changes: 8 additions & 0 deletions src/librustc_metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,14 @@ impl<'a> CrateLoader<'a> {
if dep.is_none() {
self.used_extern_options.insert(name);
}
if !name.as_str().is_ascii() {
self.sess
.struct_span_err(
span,
&format!("cannot load a crate with a non-ascii name `{}`", name,),
)
.emit();
}
self.maybe_resolve_crate(name, span, dep_kind, dep).unwrap_or_else(|err| err.report())
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
| ty::Ref(..)
| ty::Str
| ty::Foreign(..)
| ty::Error => true,
| ty::Error(_) => true,

// [T; N] and [T] have same properties as T.
ty::Array(ty, _) | ty::Slice(ty) => trivial_dropck_outlives(tcx, ty),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl TypeRelation<'tcx> for Match<'tcx> {
Err(TypeError::Sorts(relate::expected_found(self, &a, &b)))
}

(&ty::Error, _) | (_, &ty::Error) => Ok(self.tcx().types.err),
(&ty::Error(_), _) | (_, &ty::Error(_)) => Ok(self.tcx().ty_error()),

_ => relate::super_relate_tys(self, a, b),
}
Expand Down
Loading