Skip to content

Commit d903a9d

Browse files
committed
Auto merge of rust-lang#72134 - Dylan-DPC:rollup-h3shfz5, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#71737 (Miri: run liballoc tests with threads) - rust-lang#71928 (Add strikethrough support to rustdoc) - rust-lang#72048 (Visit move out of `_0` when visiting `return`) - rust-lang#72096 (Make MIR typeck use `LocalDefId` and fix docs) - rust-lang#72128 (strings do not have to be valid UTF-8 any more) Failed merges: r? @ghost
2 parents 09c817e + ceeb9bd commit d903a9d

File tree

17 files changed

+127
-80
lines changed

17 files changed

+127
-80
lines changed

Diff for: src/liballoc/alloc/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn allocate_zeroed() {
2323
}
2424

2525
#[bench]
26-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
26+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
2727
fn alloc_owned_small(b: &mut Bencher) {
2828
b.iter(|| {
2929
let _: Box<_> = box 10;

Diff for: src/liballoc/collections/linked_list/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ fn test_insert_prev() {
182182

183183
#[test]
184184
#[cfg_attr(target_os = "emscripten", ignore)]
185-
#[cfg_attr(miri, ignore)] // Miri does not support threads
186185
fn test_send() {
187186
let n = list_from(&[1, 2, 3]);
188187
thread::spawn(move || {

Diff for: src/liballoc/collections/vec_deque/tests.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::*;
33
use test;
44

55
#[bench]
6-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
6+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
77
fn bench_push_back_100(b: &mut test::Bencher) {
88
let mut deq = VecDeque::with_capacity(101);
99
b.iter(|| {
@@ -16,7 +16,7 @@ fn bench_push_back_100(b: &mut test::Bencher) {
1616
}
1717

1818
#[bench]
19-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
19+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
2020
fn bench_push_front_100(b: &mut test::Bencher) {
2121
let mut deq = VecDeque::with_capacity(101);
2222
b.iter(|| {
@@ -29,7 +29,7 @@ fn bench_push_front_100(b: &mut test::Bencher) {
2929
}
3030

3131
#[bench]
32-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
32+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
3333
fn bench_pop_back_100(b: &mut test::Bencher) {
3434
let mut deq = VecDeque::<i32>::with_capacity(101);
3535

@@ -43,7 +43,7 @@ fn bench_pop_back_100(b: &mut test::Bencher) {
4343
}
4444

4545
#[bench]
46-
#[cfg_attr(miri, ignore)] // Miri does not support benchmarks
46+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
4747
fn bench_pop_front_100(b: &mut test::Bencher) {
4848
let mut deq = VecDeque::<i32>::with_capacity(101);
4949

Diff for: src/liballoc/sync/tests.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ impl Drop for Canary {
3232

3333
#[test]
3434
#[cfg_attr(target_os = "emscripten", ignore)]
35-
#[cfg_attr(miri, ignore)] // Miri does not support threads
3635
fn manually_share_arc() {
3736
let v = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
3837
let arc_v = Arc::new(v);
@@ -337,12 +336,13 @@ fn test_ptr_eq() {
337336

338337
#[test]
339338
#[cfg_attr(target_os = "emscripten", ignore)]
340-
#[cfg_attr(miri, ignore)] // Miri does not support threads
341339
fn test_weak_count_locked() {
342340
let mut a = Arc::new(atomic::AtomicBool::new(false));
343341
let a2 = a.clone();
344342
let t = thread::spawn(move || {
345-
for _i in 0..1000000 {
343+
// Miri is too slow
344+
let count = if cfg!(miri) { 1000 } else { 1000000 };
345+
for _i in 0..count {
346346
Arc::get_mut(&mut a);
347347
}
348348
a.store(true, SeqCst);
@@ -351,6 +351,8 @@ fn test_weak_count_locked() {
351351
while !a2.load(SeqCst) {
352352
let n = Arc::weak_count(&a2);
353353
assert!(n < 2, "bad weak count: {}", n);
354+
#[cfg(miri)] // Miri's scheduler does not guarantee liveness, and thus needs this hint.
355+
atomic::spin_loop_hint();
354356
}
355357
t.join().unwrap();
356358
}

Diff for: src/librustc_middle/mir/visit.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -427,13 +427,29 @@ macro_rules! make_mir_visitor {
427427
TerminatorKind::Goto { .. } |
428428
TerminatorKind::Resume |
429429
TerminatorKind::Abort |
430-
TerminatorKind::Return |
431430
TerminatorKind::GeneratorDrop |
432431
TerminatorKind::Unreachable |
433432
TerminatorKind::FalseEdges { .. } |
434433
TerminatorKind::FalseUnwind { .. } => {
435434
}
436435

436+
TerminatorKind::Return => {
437+
// `return` logically moves from the return place `_0`. Note that the place
438+
// cannot be changed by any visitor, though.
439+
let $($mutability)? local = RETURN_PLACE;
440+
self.visit_local(
441+
& $($mutability)? local,
442+
PlaceContext::NonMutatingUse(NonMutatingUseContext::Move),
443+
source_location,
444+
);
445+
446+
assert_eq!(
447+
local,
448+
RETURN_PLACE,
449+
"`MutVisitor` tried to mutate return place of `return` terminator"
450+
);
451+
}
452+
437453
TerminatorKind::SwitchInt {
438454
discr,
439455
switch_ty,

Diff for: src/librustc_mir/borrow_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn do_mir_borrowck<'a, 'tcx>(
209209
nll_errors,
210210
} = nll::compute_regions(
211211
infcx,
212-
def_id.to_def_id(),
212+
def_id,
213213
free_regions,
214214
body,
215215
&promoted,

Diff for: src/librustc_mir/borrow_check/nll.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_errors::Diagnostic;
5-
use rustc_hir::def_id::DefId;
5+
use rustc_hir::def_id::{DefId, LocalDefId};
66
use rustc_index::vec::IndexVec;
77
use rustc_infer::infer::InferCtxt;
88
use rustc_middle::mir::{
@@ -157,7 +157,7 @@ fn populate_polonius_move_facts(
157157
/// This may result in errors being reported.
158158
pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
159159
infcx: &InferCtxt<'cx, 'tcx>,
160-
def_id: DefId,
160+
def_id: LocalDefId,
161161
universal_regions: UniversalRegions<'tcx>,
162162
body: &Body<'tcx>,
163163
promoted: &IndexVec<Promoted, Body<'tcx>>,
@@ -272,7 +272,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
272272
// Dump facts if requested.
273273
let polonius_output = all_facts.and_then(|all_facts| {
274274
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
275-
let def_path = infcx.tcx.def_path(def_id);
275+
let def_path = infcx.tcx.def_path(def_id.to_def_id());
276276
let dir_path =
277277
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
278278
all_facts.write_to_dir(dir_path, location_table).unwrap();
@@ -292,7 +292,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'tcx>(
292292

293293
// Solve the region constraints.
294294
let (closure_region_requirements, nll_errors) =
295-
regioncx.solve(infcx, &body, def_id, polonius_output.clone());
295+
regioncx.solve(infcx, &body, def_id.to_def_id(), polonius_output.clone());
296296

297297
if !nll_errors.is_empty() {
298298
// Suppress unhelpful extra errors in `infer_opaque_types`.

Diff for: src/librustc_mir/borrow_check/type_check/input_output.rs

+29-27
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,37 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
3333
//
3434
// e.g., `|x: FxHashMap<_, &'static u32>| ...`
3535
let user_provided_sig;
36-
if !self.tcx().is_closure(self.mir_def_id) {
36+
if !self.tcx().is_closure(self.mir_def_id.to_def_id()) {
3737
user_provided_sig = None;
3838
} else {
39-
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id.expect_local());
40-
user_provided_sig = match typeck_tables.user_provided_sigs.get(&self.mir_def_id) {
41-
None => None,
42-
Some(user_provided_poly_sig) => {
43-
// Instantiate the canonicalized variables from
44-
// user-provided signature (e.g., the `_` in the code
45-
// above) with fresh variables.
46-
let (poly_sig, _) = self.infcx.instantiate_canonical_with_fresh_inference_vars(
47-
body.span,
48-
&user_provided_poly_sig,
49-
);
50-
51-
// Replace the bound items in the fn sig with fresh
52-
// variables, so that they represent the view from
53-
// "inside" the closure.
54-
Some(
55-
self.infcx
56-
.replace_bound_vars_with_fresh_vars(
39+
let typeck_tables = self.tcx().typeck_tables_of(self.mir_def_id);
40+
user_provided_sig =
41+
match typeck_tables.user_provided_sigs.get(&self.mir_def_id.to_def_id()) {
42+
None => None,
43+
Some(user_provided_poly_sig) => {
44+
// Instantiate the canonicalized variables from
45+
// user-provided signature (e.g., the `_` in the code
46+
// above) with fresh variables.
47+
let (poly_sig, _) =
48+
self.infcx.instantiate_canonical_with_fresh_inference_vars(
5749
body.span,
58-
LateBoundRegionConversionTime::FnCall,
59-
&poly_sig,
60-
)
61-
.0,
62-
)
50+
&user_provided_poly_sig,
51+
);
52+
53+
// Replace the bound items in the fn sig with fresh
54+
// variables, so that they represent the view from
55+
// "inside" the closure.
56+
Some(
57+
self.infcx
58+
.replace_bound_vars_with_fresh_vars(
59+
body.span,
60+
LateBoundRegionConversionTime::FnCall,
61+
&poly_sig,
62+
)
63+
.0,
64+
)
65+
}
6366
}
64-
}
6567
};
6668

6769
debug!(
@@ -120,7 +122,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
120122
if let Err(terr) = self.eq_opaque_type_and_type(
121123
mir_output_ty,
122124
normalized_output_ty,
123-
self.mir_def_id,
125+
self.mir_def_id.to_def_id(),
124126
Locations::All(output_span),
125127
ConstraintCategory::BoringNoLocation,
126128
) {
@@ -143,7 +145,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
143145
if let Err(err) = self.eq_opaque_type_and_type(
144146
mir_output_ty,
145147
user_provided_output_ty,
146-
self.mir_def_id,
148+
self.mir_def_id.to_def_id(),
147149
Locations::All(output_span),
148150
ConstraintCategory::BoringNoLocation,
149151
) {

Diff for: src/librustc_mir/borrow_check/type_check/mod.rs

+16-22
Original file line numberDiff line numberDiff line change
@@ -108,26 +108,22 @@ mod relate_tys;
108108
///
109109
/// - `infcx` -- inference context to use
110110
/// - `param_env` -- parameter environment to use for trait solving
111-
/// - `mir` -- MIR to type-check
112-
/// - `mir_def_id` -- DefId from which the MIR is derived (must be local)
113-
/// - `region_bound_pairs` -- the implied outlives obligations between type parameters
114-
/// and lifetimes (e.g., `&'a T` implies `T: 'a`)
115-
/// - `implicit_region_bound` -- a region which all generic parameters are assumed
116-
/// to outlive; should represent the fn body
117-
/// - `input_tys` -- fully liberated, but **not** normalized, expected types of the arguments;
118-
/// the types of the input parameters found in the MIR itself will be equated with these
119-
/// - `output_ty` -- fully liberated, but **not** normalized, expected return type;
120-
/// the type for the RETURN_PLACE will be equated with this
121-
/// - `liveness` -- results of a liveness computation on the MIR; used to create liveness
122-
/// constraints for the regions in the types of variables
111+
/// - `body` -- MIR body to type-check
112+
/// - `promoted` -- map of promoted constants within `body`
113+
/// - `mir_def_id` -- `LocalDefId` from which the MIR is derived
114+
/// - `universal_regions` -- the universal regions from `body`s function signature
115+
/// - `location_table` -- MIR location map of `body`
116+
/// - `borrow_set` -- information about borrows occurring in `body`
117+
/// - `all_facts` -- when using Polonius, this is the generated set of Polonius facts
123118
/// - `flow_inits` -- results of a maybe-init dataflow analysis
124119
/// - `move_data` -- move-data constructed when performing the maybe-init dataflow analysis
120+
/// - `elements` -- MIR region map
125121
pub(crate) fn type_check<'mir, 'tcx>(
126122
infcx: &InferCtxt<'_, 'tcx>,
127123
param_env: ty::ParamEnv<'tcx>,
128124
body: &Body<'tcx>,
129125
promoted: &IndexVec<Promoted, Body<'tcx>>,
130-
mir_def_id: DefId,
126+
mir_def_id: LocalDefId,
131127
universal_regions: &Rc<UniversalRegions<'tcx>>,
132128
location_table: &LocationTable,
133129
borrow_set: &BorrowSet<'tcx>,
@@ -191,7 +187,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
191187

192188
fn type_check_internal<'a, 'tcx, R>(
193189
infcx: &'a InferCtxt<'a, 'tcx>,
194-
mir_def_id: DefId,
190+
mir_def_id: LocalDefId,
195191
param_env: ty::ParamEnv<'tcx>,
196192
body: &'a Body<'tcx>,
197193
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
@@ -271,7 +267,7 @@ struct TypeVerifier<'a, 'b, 'tcx> {
271267
body: &'b Body<'tcx>,
272268
promoted: &'b IndexVec<Promoted, Body<'tcx>>,
273269
last_span: Span,
274-
mir_def_id: DefId,
270+
mir_def_id: LocalDefId,
275271
errors_reported: bool,
276272
}
277273

@@ -815,7 +811,7 @@ struct TypeChecker<'a, 'tcx> {
815811
/// User type annotations are shared between the main MIR and the MIR of
816812
/// all of the promoted items.
817813
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
818-
mir_def_id: DefId,
814+
mir_def_id: LocalDefId,
819815
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
820816
implicit_region_bound: ty::Region<'tcx>,
821817
reported_errors: FxHashSet<(Ty<'tcx>, Span)>,
@@ -963,7 +959,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
963959
fn new(
964960
infcx: &'a InferCtxt<'a, 'tcx>,
965961
body: &'a Body<'tcx>,
966-
mir_def_id: DefId,
962+
mir_def_id: LocalDefId,
967963
param_env: ty::ParamEnv<'tcx>,
968964
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
969965
implicit_region_bound: ty::Region<'tcx>,
@@ -1142,7 +1138,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11421138
// When you have `let x: impl Foo = ...` in a closure,
11431139
// the resulting inferend values are stored with the
11441140
// def-id of the base function.
1145-
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id);
1141+
let parent_def_id = self.tcx().closure_base_def_id(self.mir_def_id.to_def_id());
11461142
return self.eq_opaque_type_and_type(sub, sup, parent_def_id, locations, category);
11471143
} else {
11481144
return Err(terr);
@@ -1994,7 +1990,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19941990
if !self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span) {
19951991
let ccx = ConstCx::new_with_param_env(
19961992
tcx,
1997-
self.mir_def_id.expect_local(),
1993+
self.mir_def_id,
19981994
body,
19991995
self.param_env,
20001996
);
@@ -2010,9 +2006,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20102006
&traits::Obligation::new(
20112007
ObligationCause::new(
20122008
span,
2013-
self.tcx()
2014-
.hir()
2015-
.local_def_id_to_hir_id(self.mir_def_id.expect_local()),
2009+
self.tcx().hir().local_def_id_to_hir_id(self.mir_def_id),
20162010
traits::ObligationCauseCode::RepeatVec(should_suggest),
20172011
),
20182012
self.param_env,

Diff for: src/librustc_mir/interpret/validity.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_middle::mir::interpret::{InterpError, InterpErrorInfo};
1515
use rustc_middle::ty;
1616
use rustc_middle::ty::layout::TyAndLayout;
1717
use rustc_span::symbol::{sym, Symbol};
18-
use rustc_target::abi::{Abi, LayoutOf, Scalar, VariantIdx, Variants};
18+
use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx, Variants};
1919

2020
use std::hash::Hash;
2121

@@ -744,10 +744,11 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
744744
match op.layout.ty.kind {
745745
ty::Str => {
746746
let mplace = op.assert_mem_place(self.ecx); // strings are never immediate
747+
let len = mplace.len(self.ecx)?;
747748
try_validation!(
748-
self.ecx.read_str(mplace),
749+
self.ecx.memory.read_bytes(mplace.ptr, Size::from_bytes(len)),
749750
self.path,
750-
err_ub!(InvalidStr(..)) => { "uninitialized or non-UTF-8 data in str" },
751+
err_ub!(InvalidUninitBytes(..)) => { "uninitialized data in `str`" },
751752
);
752753
}
753754
ty::Array(tys, ..) | ty::Slice(tys)

Diff for: src/librustc_mir/transform/copy_prop.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,12 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation {
7373
}
7474
// Conservatively gives up if the dest is an argument,
7575
// because there may be uses of the original argument value.
76-
if body.local_kind(dest_local) == LocalKind::Arg {
76+
// Also gives up on the return place, as we cannot propagate into its implicit
77+
// use by `return`.
78+
if matches!(
79+
body.local_kind(dest_local),
80+
LocalKind::Arg | LocalKind::ReturnPointer
81+
) {
7782
debug!(" Can't copy-propagate local: dest {:?} (argument)", dest_local);
7883
continue;
7984
}

Diff for: src/librustc_mir/transform/generator.rs

+10
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> {
9191
*local = self.to;
9292
}
9393
}
94+
95+
fn visit_terminator_kind(&mut self, kind: &mut TerminatorKind<'tcx>, location: Location) {
96+
match kind {
97+
TerminatorKind::Return => {
98+
// Do not replace the implicit `_0` access here, as that's not possible. The
99+
// transform already handles `return` correctly.
100+
}
101+
_ => self.super_terminator_kind(kind, location),
102+
}
103+
}
94104
}
95105

96106
struct DerefArgVisitor<'tcx> {

0 commit comments

Comments
 (0)