Skip to content

Commit

Permalink
Auto merge of rust-lang#73635 - Dylan-DPC:rollup-b4wbp42, r=Dylan-DPC
Browse files Browse the repository at this point in the history
Rollup of 7 pull requests

Successful merges:

 - rust-lang#71756 (add Windows system error codes that should map to io::ErrorKind::TimedOut)
 - rust-lang#73495 (Converted all platform-specific stdin/stdout/stderr implementations to use io:: traits)
 - rust-lang#73575 (Fix typo in error_codes doc)
 - rust-lang#73578 (Make is_freeze and is_copy_modulo_regions take TyCtxtAt)
 - rust-lang#73586 (switch_ty is redundant)
 - rust-lang#73600 (Fix spurious 'value moved here in previous iteration of loop' messages)
 - rust-lang#73610 (Clean up E0699 explanation)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Jun 23, 2020
2 parents dcd470f + e979392 commit 3b1c08c
Show file tree
Hide file tree
Showing 37 changed files with 176 additions and 114 deletions.
2 changes: 2 additions & 0 deletions src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
targets: &Vec<mir::BasicBlock>,
) {
let discr = self.codegen_operand(&mut bx, &discr);
// `switch_ty` is redundant, sanity-check that.
assert_eq!(discr.layout.ty, switch_ty);
if targets.len() == 2 {
// If there are two targets, emit br instead of switch
let lltrue = helper.llblock(self, targets[0]);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/traits/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
}

fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(self.tcx(), ty::ParamEnv::reveal_all(), DUMMY_SP)
ty.is_freeze(self.tcx().at(DUMMY_SP), ty::ParamEnv::reveal_all())
}

fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_error_codes/error_codes/E0081.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
A discrimant value is present more than once.
A discriminant value is present more than once.

Erroneous code example:

Expand Down
6 changes: 4 additions & 2 deletions src/librustc_error_codes/error_codes/E0699.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
A method was called on a raw pointer whose inner type wasn't completely known.

For example, you may have done something like:
Erroneous code example:

```compile_fail
```compile_fail,edition2018,E0699
# #![deny(warnings)]
# fn main() {
let foo = &1;
let bar = foo as *const _;
if bar.is_null() {
// ...
}
# }
```

Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
return;
}
let param_env = ty::ParamEnv::empty();
if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
if ty.is_copy_modulo_regions(cx.tcx.at(item.span), param_env) {
return;
}
if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,8 @@ pub enum TerminatorKind<'tcx> {
discr: Operand<'tcx>,

/// The type of value being tested.
/// This is always the same as the type of `discr`.
/// FIXME: remove this redundant information. Currently, it is relied on by pretty-printing.
switch_ty: Ty<'tcx>,

/// Possible values. The locations to branch to in each case
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2159,7 +2159,7 @@ where

ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
let tcx = cx.tcx();
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
let is_freeze = ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env());
let kind = match mt {
hir::Mutability::Not => {
if is_freeze {
Expand Down
14 changes: 4 additions & 10 deletions src/librustc_middle/ty/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,11 +681,10 @@ impl<'tcx> ty::TyS<'tcx> {
/// winds up being reported as an error during NLL borrow check.
pub fn is_copy_modulo_regions(
&'tcx self,
tcx: TyCtxt<'tcx>,
tcx_at: TyCtxtAt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span,
) -> bool {
tcx.at(span).is_copy_raw(param_env.and(self))
tcx_at.is_copy_raw(param_env.and(self))
}

/// Checks whether values of this type `T` have a size known at
Expand All @@ -706,13 +705,8 @@ impl<'tcx> ty::TyS<'tcx> {
/// that the `Freeze` trait is not exposed to end users and is
/// effectively an implementation detail.
// FIXME: use `TyCtxtAt` instead of separate `Span`.
pub fn is_freeze(
&'tcx self,
tcx: TyCtxt<'tcx>,
param_env: ty::ParamEnv<'tcx>,
span: Span,
) -> bool {
self.is_trivially_freeze() || tcx.at(span).is_freeze_raw(param_env.and(self))
pub fn is_freeze(&'tcx self, tcx_at: TyCtxtAt<'tcx>, param_env: ty::ParamEnv<'tcx>) -> bool {
self.is_trivially_freeze() || tcx_at.is_freeze_raw(param_env.and(self))
}

/// Fast path helper for testing if a type is `Freeze`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {

let move_msg = if move_spans.for_closure() { " into closure" } else { "" };

if span == move_span {
if location == move_out.source {
err.span_label(
span,
format!("value moved{} here, in previous iteration of loop", move_msg),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/impls/borrowed_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ impl MutBorrow<'mir, 'tcx> {
///
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
fn shared_borrow_allows_mutation(&self, place: Place<'tcx>) -> bool {
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx, self.param_env, DUMMY_SP)
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

#[inline]
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(*self.tcx, self.param_env, self.tcx.span)
ty.is_freeze(self.tcx, self.param_env)
}

pub fn load_mir(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
if let InternMode::Static(mutability) = mode {
// For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
// no interior mutability.
let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env, ecx.tcx.span));
let frozen = ty.map_or(true, |ty| ty.is_freeze(ecx.tcx, ecx.param_env));
// For statics, allocation mutability is the combination of the place mutability and
// the type mutability.
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.
Expand Down
12 changes: 3 additions & 9 deletions src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {

Goto { target } => self.go_to_block(target),

SwitchInt { ref discr, ref values, ref targets, .. } => {
SwitchInt { ref discr, ref values, ref targets, switch_ty } => {
let discr = self.read_immediate(self.eval_operand(discr, None)?)?;
trace!("SwitchInt({:?})", *discr);
assert_eq!(discr.layout.ty, switch_ty);

// Branch to the `otherwise` case by default, if no match is found.
assert!(!targets.is_empty());
Expand All @@ -50,14 +51,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.go_to_block(target_block);
}

Call {
ref func,
ref args,
destination,
ref cleanup,
from_hir_call: _from_hir_call,
fn_span: _,
} => {
Call { ref func, ref args, destination, ref cleanup, from_hir_call: _, fn_span: _ } => {
let old_stack = self.frame_idx();
let old_loc = self.frame().loc;
let func = self.eval_operand(func, None)?;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
let param_env = tcx.param_env(def_id);

let mut builder = CloneShimBuilder::new(tcx, def_id, self_ty);
let is_copy = self_ty.is_copy_modulo_regions(tcx, param_env, builder.span);
let is_copy = self_ty.is_copy_modulo_regions(tcx.at(builder.span), param_env);

let dest = Place::return_place();
let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/check_consts/qualifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl Qualif for HasMutInterior {
}

fn in_any_value_of_ty(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
!ty.is_freeze(cx.tcx, cx.param_env, DUMMY_SP)
!ty.is_freeze(cx.tcx.at(DUMMY_SP), cx.param_env)
}

fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {
Expand Down
13 changes: 6 additions & 7 deletions src/librustc_mir/transform/check_unsafety.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
),
};
if !elem_ty.is_copy_modulo_regions(
self.tcx,
self.tcx.at(self.source_info.span),
self.param_env,
self.source_info.span,
) {
self.require_unsafe(
"assignment to non-`Copy` union field",
Expand Down Expand Up @@ -459,11 +458,11 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {

// Check `is_freeze` as late as possible to avoid cycle errors
// with opaque types.
} else if !place.ty(self.body, self.tcx).ty.is_freeze(
self.tcx,
self.param_env,
self.source_info.span,
) {
} else if !place
.ty(self.body, self.tcx)
.ty
.is_freeze(self.tcx.at(self.source_info.span), self.param_env)
{
(
"borrow of layout constrained field with interior \
mutability",
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<'tcx> Validator<'_, 'tcx> {
Place::ty_from(place.local, proj_base, self.body, self.tcx)
.projection_ty(self.tcx, elem)
.ty;
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
has_mut_interior = false;
break;
}
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'tcx> Validator<'_, 'tcx> {
let ty = Place::ty_from(place.local, proj_base, self.body, self.tcx)
.projection_ty(self.tcx, elem)
.ty;
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
has_mut_interior = false;
break;
}
Expand Down
14 changes: 12 additions & 2 deletions src/librustc_mir/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
let span = self.body.source_info(location).span;

if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
}
}
Expand Down Expand Up @@ -121,7 +121,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
TerminatorKind::Goto { target } => {
self.check_edge(location, *target, EdgeKind::Normal);
}
TerminatorKind::SwitchInt { targets, values, .. } => {
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
let ty = discr.ty(&self.body.local_decls, self.tcx);
if ty != *switch_ty {
self.fail(
location,
format!(
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
ty, switch_ty,
),
);
}
if targets.len() != values.len() + 1 {
self.fail(
location,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/build/expr/as_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {

if !ty.is_sized(tcx.at(span), param_env) {
// !sized means !copy, so this is an unsized move
assert!(!ty.is_copy_modulo_regions(tcx, param_env, span));
assert!(!ty.is_copy_modulo_regions(tcx.at(span), param_env));

// As described above, detect the case where we are passing a value of unsized
// type, and that value is coming from the deref of a box.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/hair/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span>

/// Check if a by-value binding is by-value. That is, check if the binding's type is not `Copy`.
fn is_binding_by_move(cx: &MatchVisitor<'_, '_>, hir_id: HirId, span: Span) -> bool {
!cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx, cx.param_env, span)
!cx.tables.node_type(hir_id).is_copy_modulo_regions(cx.tcx.at(span), cx.param_env)
}

/// Check the legality of legality of by-move bindings.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_passes/intrinsicck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl ExprVisitor<'tcx> {

// Check that the type implements Copy. The only case where this can
// possibly fail is for SIMD types which don't #[derive(Copy)].
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
let msg = "arguments for inline assembly must be copyable";
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
err.note(&format!("`{}` does not implement the Copy trait", ty));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
let ty = self.resolve_vars_if_possible(&ty);

if !(param_env, ty).needs_infer() {
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
return ty.is_copy_modulo_regions(self.tcx.at(span), param_env);
}

let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ty/needs_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where

for component in components {
match component.kind {
_ if component.is_copy_modulo_regions(tcx, self.param_env, DUMMY_SP) => (),
_ if component.is_copy_modulo_regions(tcx.at(DUMMY_SP), self.param_env) => (),

ty::Closure(_, substs) => {
for upvar_ty in substs.as_closure().upvar_tys() {
Expand Down
5 changes: 5 additions & 0 deletions src/libstd/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ pub enum ErrorKind {
#[stable(feature = "rust1", since = "1.0.0")]
Interrupted,
/// Any I/O error not part of this list.
///
/// Errors that are `Other` now may move to a different or a new
/// [`ErrorKind`] variant in the future. It is not recommended to match
/// an error against `Other` and to expect any additional characteristics,
/// e.g., a specific [`Error::raw_os_error`] return value.
#[stable(feature = "rust1", since = "1.0.0")]
Other,

Expand Down
Loading

0 comments on commit 3b1c08c

Please sign in to comment.