Skip to content

Commit c0941df

Browse files
committed
Auto merge of rust-lang#100847 - matthiaskrgr:rollup-0ga531s, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#100556 (Clamp Function for f32 and f64) - rust-lang#100663 (Make slice::reverse const) - rust-lang#100697 ( Minor syntax and formatting update to doc comment on `find_vtable_types_for_unsizing`) - rust-lang#100760 (update test for LLVM change) - rust-lang#100761 (some general mir typeck cleanup) - rust-lang#100775 (rustdoc: Merge source code pages HTML elements together v2) - rust-lang#100813 (Add `/build-rust-analyzer/` to .gitignore) - rust-lang#100821 (Make some docs nicer wrt pointer offsets) - rust-lang#100822 (Replace most uses of `pointer::offset` with `add` and `sub`) - rust-lang#100839 (Make doc for stdin field of process consistent) - rust-lang#100842 (Add diagnostics lints to `rustc_transmute` module (zero diags)) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 650bff8 + 5ba68df commit c0941df

File tree

44 files changed

+350
-300
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+350
-300
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ no_llvm_build
4242
/llvm/
4343
/mingw-build/
4444
/build/
45+
/build-rust-analyzer/
4546
/dist/
4647
/unicode-downloads
4748
/target

compiler/rustc_arena/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<T> TypedArena<T> {
219219
} else {
220220
let ptr = self.ptr.get();
221221
// Advance the pointer.
222-
self.ptr.set(self.ptr.get().offset(1));
222+
self.ptr.set(self.ptr.get().add(1));
223223
// Write into uninitialized memory.
224224
ptr::write(ptr, object);
225225
&mut *ptr

compiler/rustc_borrowck/src/type_check/canonical.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9090
locations: Locations,
9191
category: ConstraintCategory<'tcx>,
9292
) {
93-
self.prove_predicates(
94-
Some(ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
93+
self.prove_predicate(
94+
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
9595
trait_ref,
9696
constness: ty::BoundConstness::NotConst,
9797
polarity: ty::ImplPolarity::Positive,
98-
}))),
98+
}))
99+
.to_predicate(self.tcx()),
99100
locations,
100101
category,
101102
);

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl<'tcx> UniversalRegionRelationsBuilder<'_, 'tcx> {
268268
// }
269269
// impl Foo for () {
270270
// type Bar = ();
271-
// fn foo(&self) ->&() {}
271+
// fn foo(&self) -> &() {}
272272
// }
273273
// ```
274274
// Both &Self::Bar and &() are WF

compiler/rustc_borrowck/src/type_check/mod.rs

+53-86
Original file line numberDiff line numberDiff line change
@@ -178,97 +178,15 @@ pub(crate) fn type_check<'mir, 'tcx>(
178178
upvars,
179179
};
180180

181-
let opaque_type_values = type_check_internal(
181+
let mut checker = TypeChecker::new(
182182
infcx,
183-
param_env,
184183
body,
185-
promoted,
184+
param_env,
186185
&region_bound_pairs,
187186
implicit_region_bound,
188187
&mut borrowck_context,
189-
|mut cx| {
190-
debug!("inside extra closure of type_check_internal");
191-
cx.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
192-
liveness::generate(
193-
&mut cx,
194-
body,
195-
elements,
196-
flow_inits,
197-
move_data,
198-
location_table,
199-
use_polonius,
200-
);
201-
202-
translate_outlives_facts(&mut cx);
203-
let opaque_type_values =
204-
infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
205-
206-
opaque_type_values
207-
.into_iter()
208-
.map(|(opaque_type_key, decl)| {
209-
cx.fully_perform_op(
210-
Locations::All(body.span),
211-
ConstraintCategory::OpaqueType,
212-
CustomTypeOp::new(
213-
|infcx| {
214-
infcx.register_member_constraints(
215-
param_env,
216-
opaque_type_key,
217-
decl.hidden_type.ty,
218-
decl.hidden_type.span,
219-
);
220-
Ok(InferOk { value: (), obligations: vec![] })
221-
},
222-
|| "opaque_type_map".to_string(),
223-
),
224-
)
225-
.unwrap();
226-
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
227-
trace!(
228-
"finalized opaque type {:?} to {:#?}",
229-
opaque_type_key,
230-
hidden_type.ty.kind()
231-
);
232-
if hidden_type.has_infer_types_or_consts() {
233-
infcx.tcx.sess.delay_span_bug(
234-
decl.hidden_type.span,
235-
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
236-
);
237-
hidden_type.ty = infcx.tcx.ty_error();
238-
}
239-
240-
(opaque_type_key, (hidden_type, decl.origin))
241-
})
242-
.collect()
243-
},
244188
);
245189

246-
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
247-
}
248-
249-
#[instrument(
250-
skip(infcx, body, promoted, region_bound_pairs, borrowck_context, extra),
251-
level = "debug"
252-
)]
253-
fn type_check_internal<'a, 'tcx, R>(
254-
infcx: &'a InferCtxt<'a, 'tcx>,
255-
param_env: ty::ParamEnv<'tcx>,
256-
body: &'a Body<'tcx>,
257-
promoted: &'a IndexVec<Promoted, Body<'tcx>>,
258-
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
259-
implicit_region_bound: ty::Region<'tcx>,
260-
borrowck_context: &'a mut BorrowCheckContext<'a, 'tcx>,
261-
extra: impl FnOnce(TypeChecker<'a, 'tcx>) -> R,
262-
) -> R {
263-
debug!("body: {:#?}", body);
264-
let mut checker = TypeChecker::new(
265-
infcx,
266-
body,
267-
param_env,
268-
region_bound_pairs,
269-
implicit_region_bound,
270-
borrowck_context,
271-
);
272190
let errors_reported = {
273191
let mut verifier = TypeVerifier::new(&mut checker, promoted);
274192
verifier.visit_body(&body);
@@ -280,7 +198,56 @@ fn type_check_internal<'a, 'tcx, R>(
280198
checker.typeck_mir(body);
281199
}
282200

283-
extra(checker)
201+
checker.equate_inputs_and_outputs(&body, universal_regions, &normalized_inputs_and_output);
202+
liveness::generate(
203+
&mut checker,
204+
body,
205+
elements,
206+
flow_inits,
207+
move_data,
208+
location_table,
209+
use_polonius,
210+
);
211+
212+
translate_outlives_facts(&mut checker);
213+
let opaque_type_values = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
214+
215+
let opaque_type_values = opaque_type_values
216+
.into_iter()
217+
.map(|(opaque_type_key, decl)| {
218+
checker
219+
.fully_perform_op(
220+
Locations::All(body.span),
221+
ConstraintCategory::OpaqueType,
222+
CustomTypeOp::new(
223+
|infcx| {
224+
infcx.register_member_constraints(
225+
param_env,
226+
opaque_type_key,
227+
decl.hidden_type.ty,
228+
decl.hidden_type.span,
229+
);
230+
Ok(InferOk { value: (), obligations: vec![] })
231+
},
232+
|| "opaque_type_map".to_string(),
233+
),
234+
)
235+
.unwrap();
236+
let mut hidden_type = infcx.resolve_vars_if_possible(decl.hidden_type);
237+
trace!("finalized opaque type {:?} to {:#?}", opaque_type_key, hidden_type.ty.kind());
238+
if hidden_type.has_infer_types_or_consts() {
239+
infcx.tcx.sess.delay_span_bug(
240+
decl.hidden_type.span,
241+
&format!("could not resolve {:#?}", hidden_type.ty.kind()),
242+
);
243+
hidden_type.ty = infcx.tcx.ty_error();
244+
}
245+
246+
(opaque_type_key, (hidden_type, decl.origin))
247+
})
248+
.collect();
249+
250+
MirTypeckResults { constraints, universal_region_relations, opaque_type_values }
284251
}
285252

286253
fn translate_outlives_facts(typeck: &mut TypeChecker<'_, '_>) {
@@ -1911,7 +1878,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
19111878
}
19121879
}
19131880

1914-
&Rvalue::NullaryOp(_, ty) => {
1881+
&Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, ty) => {
19151882
let trait_ref = ty::TraitRef {
19161883
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
19171884
substs: tcx.mk_substs_trait(ty, &[]),

compiler/rustc_codegen_cranelift/example/alloc_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ mod platform {
9494
struct Header(*mut u8);
9595
const HEAP_ZERO_MEMORY: DWORD = 0x00000008;
9696
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
97-
&mut *(ptr as *mut Header).offset(-1)
97+
&mut *(ptr as *mut Header).sub(1)
9898
}
9999
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
100100
let aligned = ptr.add(align - (ptr as usize & (align - 1)));

compiler/rustc_codegen_gcc/example/alloc_system.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ mod platform {
156156
struct Header(*mut u8);
157157
const HEAP_ZERO_MEMORY: DWORD = 0x00000008;
158158
unsafe fn get_header<'a>(ptr: *mut u8) -> &'a mut Header {
159-
&mut *(ptr as *mut Header).offset(-1)
159+
&mut *(ptr as *mut Header).sub(1)
160160
}
161161
unsafe fn align_ptr(ptr: *mut u8, align: usize) -> *mut u8 {
162162
let aligned = ptr.add(align - (ptr as usize & (align - 1)));

compiler/rustc_monomorphize/src/collector.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
//! #### Unsizing Casts
129129
//! A subtle way of introducing neighbor edges is by casting to a trait object.
130130
//! Since the resulting fat-pointer contains a reference to a vtable, we need to
131-
//! instantiate all object-save methods of the trait, as we need to store
131+
//! instantiate all object-safe methods of the trait, as we need to store
132132
//! pointers to these functions even if they never get called anywhere. This can
133133
//! be seen as a special case of taking a function reference.
134134
//!
@@ -1044,10 +1044,12 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
10441044
/// them.
10451045
///
10461046
/// For example, the source type might be `&SomeStruct` and the target type
1047-
/// might be `&SomeTrait` in a cast like:
1047+
/// might be `&dyn SomeTrait` in a cast like:
10481048
///
1049+
/// ```rust,ignore (not real code)
10491050
/// let src: &SomeStruct = ...;
1050-
/// let target = src as &SomeTrait;
1051+
/// let target = src as &dyn SomeTrait;
1052+
/// ```
10511053
///
10521054
/// Then the output of this function would be (SomeStruct, SomeTrait) since for
10531055
/// constructing the `target` fat-pointer we need the vtable for that pair.
@@ -1068,8 +1070,10 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) ->
10681070
/// for the pair of `T` (which is a trait) and the concrete type that `T` was
10691071
/// originally coerced from:
10701072
///
1073+
/// ```rust,ignore (not real code)
10711074
/// let src: &ComplexStruct<SomeStruct> = ...;
1072-
/// let target = src as &ComplexStruct<SomeTrait>;
1075+
/// let target = src as &ComplexStruct<dyn SomeTrait>;
1076+
/// ```
10731077
///
10741078
/// Again, we want this `find_vtable_types_for_unsizing()` to provide the pair
10751079
/// `(SomeStruct, SomeTrait)`.

compiler/rustc_serialize/src/serialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl<D: Decoder, T: Decodable<D>> Decodable<D> for Vec<T> {
273273
unsafe {
274274
let ptr: *mut T = vec.as_mut_ptr();
275275
for i in 0..len {
276-
std::ptr::write(ptr.offset(i as isize), Decodable::decode(d));
276+
std::ptr::write(ptr.add(i), Decodable::decode(d));
277277
}
278278
vec.set_len(len);
279279
}

compiler/rustc_transmute/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
result_into_ok_or_err
88
)]
99
#![allow(dead_code, unused_variables)]
10+
#![deny(rustc::untranslatable_diagnostic)]
11+
#![deny(rustc::diagnostic_outside_of_impl)]
1012

1113
#[macro_use]
1214
extern crate tracing;

library/alloc/src/alloc/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn allocate_zeroed() {
1515
let end = i.add(layout.size());
1616
while i < end {
1717
assert_eq!(*i, 0);
18-
i = i.offset(1);
18+
i = i.add(1);
1919
}
2020
Global.deallocate(ptr.as_non_null_ptr(), layout);
2121
}

library/alloc/src/collections/vec_deque/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2447,8 +2447,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
24472447
let mut right_offset = 0;
24482448
for i in left_edge..right_edge {
24492449
right_offset = (i - left_edge) % (cap - right_edge);
2450-
let src: isize = (right_edge + right_offset) as isize;
2451-
ptr::swap(buf.add(i), buf.offset(src));
2450+
let src = right_edge + right_offset;
2451+
ptr::swap(buf.add(i), buf.add(src));
24522452
}
24532453
let n_ops = right_edge - left_edge;
24542454
left_edge += n_ops;

library/alloc/src/ffi/c_str.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ impl CString {
436436
///
437437
/// unsafe {
438438
/// assert_eq!(b'f', *ptr as u8);
439-
/// assert_eq!(b'o', *ptr.offset(1) as u8);
440-
/// assert_eq!(b'o', *ptr.offset(2) as u8);
441-
/// assert_eq!(b'\0', *ptr.offset(3) as u8);
439+
/// assert_eq!(b'o', *ptr.add(1) as u8);
440+
/// assert_eq!(b'o', *ptr.add(2) as u8);
441+
/// assert_eq!(b'\0', *ptr.add(3) as u8);
442442
///
443443
/// // retake pointer to free memory
444444
/// let _ = CString::from_raw(ptr);

library/alloc/src/slice.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ where
10241024
// Consume the greater side.
10251025
// If equal, prefer the right run to maintain stability.
10261026
unsafe {
1027-
let to_copy = if is_less(&*right.offset(-1), &*left.offset(-1)) {
1027+
let to_copy = if is_less(&*right.sub(1), &*left.sub(1)) {
10281028
decrement_and_get(left)
10291029
} else {
10301030
decrement_and_get(right)
@@ -1038,12 +1038,12 @@ where
10381038

10391039
unsafe fn get_and_increment<T>(ptr: &mut *mut T) -> *mut T {
10401040
let old = *ptr;
1041-
*ptr = unsafe { ptr.offset(1) };
1041+
*ptr = unsafe { ptr.add(1) };
10421042
old
10431043
}
10441044

10451045
unsafe fn decrement_and_get<T>(ptr: &mut *mut T) -> *mut T {
1046-
*ptr = unsafe { ptr.offset(-1) };
1046+
*ptr = unsafe { ptr.sub(1) };
10471047
*ptr
10481048
}
10491049

library/alloc/src/vec/in_place_collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ where
267267
// one slot in the underlying storage will have been freed up and we can immediately
268268
// write back the result.
269269
unsafe {
270-
let dst = dst_buf.offset(i as isize);
270+
let dst = dst_buf.add(i);
271271
debug_assert!(dst as *const _ <= end, "InPlaceIterable contract violation");
272272
ptr::write(dst, self.__iterator_get_unchecked(i));
273273
// Since this executes user code which can panic we have to bump the pointer

library/alloc/src/vec/into_iter.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<T, A: Allocator> Iterator for IntoIter<T, A> {
160160
Some(unsafe { mem::zeroed() })
161161
} else {
162162
let old = self.ptr;
163-
self.ptr = unsafe { self.ptr.offset(1) };
163+
self.ptr = unsafe { self.ptr.add(1) };
164164

165165
Some(unsafe { ptr::read(old) })
166166
}
@@ -272,7 +272,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
272272
// Make up a value of this ZST.
273273
Some(unsafe { mem::zeroed() })
274274
} else {
275-
self.end = unsafe { self.end.offset(-1) };
275+
self.end = unsafe { self.end.sub(1) };
276276

277277
Some(unsafe { ptr::read(self.end) })
278278
}
@@ -288,7 +288,7 @@ impl<T, A: Allocator> DoubleEndedIterator for IntoIter<T, A> {
288288
}
289289
} else {
290290
// SAFETY: same as for advance_by()
291-
self.end = unsafe { self.end.offset(step_size.wrapping_neg() as isize) };
291+
self.end = unsafe { self.end.sub(step_size) };
292292
}
293293
let to_drop = ptr::slice_from_raw_parts_mut(self.end as *mut T, step_size);
294294
// SAFETY: same as for advance_by()

0 commit comments

Comments
 (0)