Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 53 additions & 86 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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;

0 commit comments

Comments
 (0)