Skip to content

Commit 3b1c08c

Browse files
committed
Auto merge of rust-lang#73635 - Dylan-DPC:rollup-b4wbp42, r=Dylan-DPC
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
2 parents dcd470f + e979392 commit 3b1c08c

File tree

37 files changed

+176
-114
lines changed

37 files changed

+176
-114
lines changed

src/librustc_codegen_ssa/mir/block.rs

+2
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
200200
targets: &Vec<mir::BasicBlock>,
201201
) {
202202
let discr = self.codegen_operand(&mut bx, &discr);
203+
// `switch_ty` is redundant, sanity-check that.
204+
assert_eq!(discr.layout.ty, switch_ty);
203205
if targets.len() == 2 {
204206
// If there are two targets, emit br instead of switch
205207
let lltrue = helper.llblock(self, targets[0]);

src/librustc_codegen_ssa/traits/type_.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub trait DerivedTypeMethods<'tcx>: BaseTypeMethods<'tcx> + MiscMethods<'tcx> {
7474
}
7575

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

8080
fn type_has_metadata(&self, ty: Ty<'tcx>) -> bool {

src/librustc_error_codes/error_codes/E0081.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
A discrimant value is present more than once.
1+
A discriminant value is present more than once.
22

33
Erroneous code example:
44

src/librustc_error_codes/error_codes/E0699.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
A method was called on a raw pointer whose inner type wasn't completely known.
22

3-
For example, you may have done something like:
3+
Erroneous code example:
44

5-
```compile_fail
5+
```compile_fail,edition2018,E0699
66
# #![deny(warnings)]
7+
# fn main() {
78
let foo = &1;
89
let bar = foo as *const _;
910
if bar.is_null() {
1011
// ...
1112
}
13+
# }
1214
```
1315

1416
Here, the type of `bar` isn't known; it could be a pointer to anything. Instead,

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingCopyImplementations {
562562
return;
563563
}
564564
let param_env = ty::ParamEnv::empty();
565-
if ty.is_copy_modulo_regions(cx.tcx, param_env, item.span) {
565+
if ty.is_copy_modulo_regions(cx.tcx.at(item.span), param_env) {
566566
return;
567567
}
568568
if can_type_implement_copy(cx.tcx, param_env, ty).is_ok() {

src/librustc_middle/mir/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,8 @@ pub enum TerminatorKind<'tcx> {
10751075
discr: Operand<'tcx>,
10761076

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

10801082
/// Possible values. The locations to branch to in each case

src/librustc_middle/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2159,7 +2159,7 @@ where
21592159

21602160
ty::Ref(_, ty, mt) if offset.bytes() == 0 => {
21612161
let tcx = cx.tcx();
2162-
let is_freeze = ty.is_freeze(tcx, cx.param_env(), DUMMY_SP);
2162+
let is_freeze = ty.is_freeze(tcx.at(DUMMY_SP), cx.param_env());
21632163
let kind = match mt {
21642164
hir::Mutability::Not => {
21652165
if is_freeze {

src/librustc_middle/ty/util.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,10 @@ impl<'tcx> ty::TyS<'tcx> {
681681
/// winds up being reported as an error during NLL borrow check.
682682
pub fn is_copy_modulo_regions(
683683
&'tcx self,
684-
tcx: TyCtxt<'tcx>,
684+
tcx_at: TyCtxtAt<'tcx>,
685685
param_env: ty::ParamEnv<'tcx>,
686-
span: Span,
687686
) -> bool {
688-
tcx.at(span).is_copy_raw(param_env.and(self))
687+
tcx_at.is_copy_raw(param_env.and(self))
689688
}
690689

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

718712
/// Fast path helper for testing if a type is `Freeze`.

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
138138

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

141-
if span == move_span {
141+
if location == move_out.source {
142142
err.span_label(
143143
span,
144144
format!("value moved{} here, in previous iteration of loop", move_msg),

src/librustc_mir/dataflow/impls/borrowed_locals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl MutBorrow<'mir, 'tcx> {
233233
///
234234
/// [rust-lang/unsafe-code-guidelines#134]: https://github.com/rust-lang/unsafe-code-guidelines/issues/134
235235
fn shared_borrow_allows_mutation(&self, place: Place<'tcx>) -> bool {
236-
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx, self.param_env, DUMMY_SP)
236+
!place.ty(self.body, self.tcx).ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env)
237237
}
238238
}
239239

src/librustc_mir/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
391391

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

397397
pub fn load_mir(

src/librustc_mir/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
111111
if let InternMode::Static(mutability) = mode {
112112
// For this, we need to take into account `UnsafeCell`. When `ty` is `None`, we assume
113113
// no interior mutability.
114-
let frozen = ty.map_or(true, |ty| ty.is_freeze(*ecx.tcx, ecx.param_env, ecx.tcx.span));
114+
let frozen = ty.map_or(true, |ty| ty.is_freeze(ecx.tcx, ecx.param_env));
115115
// For statics, allocation mutability is the combination of the place mutability and
116116
// the type mutability.
117117
// The entire allocation needs to be mutable if it contains an `UnsafeCell` anywhere.

src/librustc_mir/interpret/terminator.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2424

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

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

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

53-
Call {
54-
ref func,
55-
ref args,
56-
destination,
57-
ref cleanup,
58-
from_hir_call: _from_hir_call,
59-
fn_span: _,
60-
} => {
54+
Call { ref func, ref args, destination, ref cleanup, from_hir_call: _, fn_span: _ } => {
6155
let old_stack = self.frame_idx();
6256
let old_loc = self.frame().loc;
6357
let func = self.eval_operand(func, None)?;

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -
327327
let param_env = tcx.param_env(def_id);
328328

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

332332
let dest = Place::return_place();
333333
let src = tcx.mk_place_deref(Place::from(Local::new(1 + 0)));

src/librustc_mir/transform/check_consts/qualifs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl Qualif for HasMutInterior {
7777
}
7878

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

8383
fn in_adt_inherently(cx: &ConstCx<'_, 'tcx>, adt: &'tcx AdtDef, _: SubstsRef<'tcx>) -> bool {

src/librustc_mir/transform/check_unsafety.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,8 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
282282
),
283283
};
284284
if !elem_ty.is_copy_modulo_regions(
285-
self.tcx,
285+
self.tcx.at(self.source_info.span),
286286
self.param_env,
287-
self.source_info.span,
288287
) {
289288
self.require_unsafe(
290289
"assignment to non-`Copy` union field",
@@ -459,11 +458,11 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> {
459458

460459
// Check `is_freeze` as late as possible to avoid cycle errors
461460
// with opaque types.
462-
} else if !place.ty(self.body, self.tcx).ty.is_freeze(
463-
self.tcx,
464-
self.param_env,
465-
self.source_info.span,
466-
) {
461+
} else if !place
462+
.ty(self.body, self.tcx)
463+
.ty
464+
.is_freeze(self.tcx.at(self.source_info.span), self.param_env)
465+
{
467466
(
468467
"borrow of layout constrained field with interior \
469468
mutability",

src/librustc_mir/transform/promote_consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<'tcx> Validator<'_, 'tcx> {
341341
Place::ty_from(place.local, proj_base, self.body, self.tcx)
342342
.projection_ty(self.tcx, elem)
343343
.ty;
344-
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
344+
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
345345
has_mut_interior = false;
346346
break;
347347
}
@@ -678,7 +678,7 @@ impl<'tcx> Validator<'_, 'tcx> {
678678
let ty = Place::ty_from(place.local, proj_base, self.body, self.tcx)
679679
.projection_ty(self.tcx, elem)
680680
.ty;
681-
if ty.is_freeze(self.tcx, self.param_env, DUMMY_SP) {
681+
if ty.is_freeze(self.tcx.at(DUMMY_SP), self.param_env) {
682682
has_mut_interior = false;
683683
break;
684684
}

src/librustc_mir/transform/validate.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
9090
let ty = place.ty(&self.body.local_decls, self.tcx).ty;
9191
let span = self.body.source_info(location).span;
9292

93-
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, span) {
93+
if !ty.is_copy_modulo_regions(self.tcx.at(span), self.param_env) {
9494
self.fail(location, format!("`Operand::Copy` with non-`Copy` type {}", ty));
9595
}
9696
}
@@ -121,7 +121,17 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
121121
TerminatorKind::Goto { target } => {
122122
self.check_edge(location, *target, EdgeKind::Normal);
123123
}
124-
TerminatorKind::SwitchInt { targets, values, .. } => {
124+
TerminatorKind::SwitchInt { targets, values, switch_ty, discr } => {
125+
let ty = discr.ty(&self.body.local_decls, self.tcx);
126+
if ty != *switch_ty {
127+
self.fail(
128+
location,
129+
format!(
130+
"encountered `SwitchInt` terminator with type mismatch: {:?} != {:?}",
131+
ty, switch_ty,
132+
),
133+
);
134+
}
125135
if targets.len() != values.len() + 1 {
126136
self.fail(
127137
location,

src/librustc_mir_build/build/expr/as_operand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
172172

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

177177
// As described above, detect the case where we are passing a value of unsized
178178
// type, and that value is coming from the deref of a box.

src/librustc_mir_build/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,7 @@ fn maybe_point_at_variant(ty: Ty<'_>, patterns: &[super::Pat<'_>]) -> Vec<Span>
579579

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

585585
/// Check the legality of legality of by-move bindings.

src/librustc_passes/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl ExprVisitor<'tcx> {
214214

215215
// Check that the type implements Copy. The only case where this can
216216
// possibly fail is for SIMD types which don't #[derive(Copy)].
217-
if !ty.is_copy_modulo_regions(self.tcx, self.param_env, DUMMY_SP) {
217+
if !ty.is_copy_modulo_regions(self.tcx.at(DUMMY_SP), self.param_env) {
218218
let msg = "arguments for inline assembly must be copyable";
219219
let mut err = self.tcx.sess.struct_span_err(expr.span, msg);
220220
err.note(&format!("`{}` does not implement the Copy trait", ty));

src/librustc_trait_selection/infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
4444
let ty = self.resolve_vars_if_possible(&ty);
4545

4646
if !(param_env, ty).needs_infer() {
47-
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
47+
return ty.is_copy_modulo_regions(self.tcx.at(span), param_env);
4848
}
4949

5050
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);

src/librustc_ty/needs_drop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where
9191

9292
for component in components {
9393
match component.kind {
94-
_ if component.is_copy_modulo_regions(tcx, self.param_env, DUMMY_SP) => (),
94+
_ if component.is_copy_modulo_regions(tcx.at(DUMMY_SP), self.param_env) => (),
9595

9696
ty::Closure(_, substs) => {
9797
for upvar_ty in substs.as_closure().upvar_tys() {

src/libstd/io/error.rs

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ pub enum ErrorKind {
160160
#[stable(feature = "rust1", since = "1.0.0")]
161161
Interrupted,
162162
/// Any I/O error not part of this list.
163+
///
164+
/// Errors that are `Other` now may move to a different or a new
165+
/// [`ErrorKind`] variant in the future. It is not recommended to match
166+
/// an error against `Other` and to expect any additional characteristics,
167+
/// e.g., a specific [`Error::raw_os_error`] return value.
163168
#[stable(feature = "rust1", since = "1.0.0")]
164169
Other,
165170

0 commit comments

Comments
 (0)