Skip to content

Commit 534d79a

Browse files
committed
Auto merge of #136481 - jieyouxu:rollup-w0lnnqb, r=jieyouxu
Rollup of 8 pull requests Successful merges: - #136356 (Docs for f16 and f128: correct a typo and add details) - #136404 (Remove a footgun-y feature / relic of the past from the compiletest DSL) - #136432 (LTA: Actually check where-clauses for well-formedness at the def site) - #136438 (miri: improve error when offset_from preconditions are violated) - #136441 ([`compiletest`-related cleanups 1/7] Cleanup `is_rustdoc` logic and remove a useless path join in rustdoc-json runtest logic) - #136455 (Remove some `Clone` bounds and derives.) - #136464 (Remove hook calling via `TyCtxtAt`.) - #136467 (override default config profile on tarballs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f2c4ccd + f65c6af commit 534d79a

File tree

33 files changed

+251
-143
lines changed

33 files changed

+251
-143
lines changed

compiler/rustc_const_eval/messages.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ const_eval_nullary_intrinsic_fail =
280280
could not evaluate nullary intrinsic
281281
282282
const_eval_offset_from_different_allocations =
283-
`{$name}` called on pointers into different allocations
283+
`{$name}` called on two different pointers that are not both derived from the same allocation
284+
const_eval_offset_from_out_of_bounds =
285+
`{$name}` called on two different pointers where the memory range between them is not in-bounds of an allocation
284286
const_eval_offset_from_overflow =
285287
`{$name}` called when first pointer is too far ahead of second
286288
const_eval_offset_from_test =

compiler/rustc_const_eval/src/const_eval/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Not in interpret to make sure we do not use private implementation details
22

33
use rustc_abi::VariantIdx;
4-
use rustc_middle::query::{Key, TyCtxtAt};
4+
use rustc_middle::query::Key;
55
use rustc_middle::ty::layout::LayoutOf;
66
use rustc_middle::ty::{self, Ty, TyCtxt};
77
use rustc_middle::{bug, mir};
@@ -35,16 +35,17 @@ pub(crate) type ValTreeCreationResult<'tcx> = Result<ty::ValTree<'tcx>, ValTreeC
3535

3636
#[instrument(skip(tcx), level = "debug")]
3737
pub(crate) fn try_destructure_mir_constant_for_user_output<'tcx>(
38-
tcx: TyCtxtAt<'tcx>,
38+
tcx: TyCtxt<'tcx>,
3939
val: mir::ConstValue<'tcx>,
4040
ty: Ty<'tcx>,
4141
) -> Option<mir::DestructuredConstant<'tcx>> {
4242
let typing_env = ty::TypingEnv::fully_monomorphized();
43-
let (ecx, op) = mk_eval_cx_for_const_val(tcx, typing_env, val, ty)?;
43+
// FIXME: use a proper span here?
44+
let (ecx, op) = mk_eval_cx_for_const_val(tcx.at(rustc_span::DUMMY_SP), typing_env, val, ty)?;
4445

4546
// We go to `usize` as we cannot allocate anything bigger anyway.
4647
let (field_count, variant, down) = match ty.kind() {
47-
ty::Array(_, len) => (len.try_to_target_usize(tcx.tcx)? as usize, None, op),
48+
ty::Array(_, len) => (len.try_to_target_usize(tcx)? as usize, None, op),
4849
ty::Adt(def, _) if def.variants().is_empty() => {
4950
return None;
5051
}

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,25 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
319319

320320
// Check that the memory between them is dereferenceable at all, starting from the
321321
// origin pointer: `dist` is `a - b`, so it is based on `b`.
322-
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)?;
322+
self.check_ptr_access_signed(b, dist, CheckInAllocMsg::OffsetFromTest)
323+
.map_err_kind(|_| {
324+
// This could mean they point to different allocations, or they point to the same allocation
325+
// but not the entire range between the pointers is in-bounds.
326+
if let Ok((a_alloc_id, ..)) = self.ptr_try_get_alloc_id(a, 0)
327+
&& let Ok((b_alloc_id, ..)) = self.ptr_try_get_alloc_id(b, 0)
328+
&& a_alloc_id == b_alloc_id
329+
{
330+
err_ub_custom!(
331+
fluent::const_eval_offset_from_out_of_bounds,
332+
name = intrinsic_name,
333+
)
334+
} else {
335+
err_ub_custom!(
336+
fluent::const_eval_offset_from_different_allocations,
337+
name = intrinsic_name,
338+
)
339+
}
340+
})?;
323341
// Then check that this is also dereferenceable from `a`. This ensures that they are
324342
// derived from the same allocation.
325343
self.check_ptr_access_signed(

compiler/rustc_const_eval/src/util/caller_location.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_hir::LangItem;
2-
use rustc_middle::query::TyCtxtAt;
32
use rustc_middle::ty::layout::LayoutOf;
4-
use rustc_middle::ty::{self};
3+
use rustc_middle::ty::{self, TyCtxt};
54
use rustc_middle::{bug, mir};
65
use rustc_span::Symbol;
76
use tracing::trace;
@@ -48,15 +47,15 @@ fn alloc_caller_location<'tcx>(
4847
}
4948

5049
pub(crate) fn const_caller_location_provider(
51-
tcx: TyCtxtAt<'_>,
50+
tcx: TyCtxt<'_>,
5251
file: Symbol,
5352
line: u32,
5453
col: u32,
5554
) -> mir::ConstValue<'_> {
5655
trace!("const_caller_location: {}:{}:{}", file, line, col);
5756
let mut ecx = mk_eval_cx_to_read_const_val(
58-
tcx.tcx,
59-
tcx.span,
57+
tcx,
58+
rustc_span::DUMMY_SP, // FIXME: use a proper span here?
6059
ty::TypingEnv::fully_monomorphized(),
6160
CanAccessMutGlobal::No,
6261
);

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+13-11
Original file line numberDiff line numberDiff line change
@@ -328,16 +328,20 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
328328
hir::ItemKind::TraitAlias(..) => check_trait(tcx, item),
329329
// `ForeignItem`s are handled separately.
330330
hir::ItemKind::ForeignMod { .. } => Ok(()),
331-
hir::ItemKind::TyAlias(hir_ty, hir_generics) => {
332-
if tcx.type_alias_is_lazy(item.owner_id) {
333-
// Bounds of lazy type aliases and of eager ones that contain opaque types are respected.
334-
// E.g: `type X = impl Trait;`, `type X = (impl Trait, Y);`.
335-
let res = check_item_type(tcx, def_id, hir_ty.span, UnsizedHandling::Allow);
336-
check_variances_for_type_defn(tcx, item, hir_generics);
337-
res
338-
} else {
331+
hir::ItemKind::TyAlias(hir_ty, hir_generics) if tcx.type_alias_is_lazy(item.owner_id) => {
332+
let res = enter_wf_checking_ctxt(tcx, item.span, def_id, |wfcx| {
333+
let ty = tcx.type_of(def_id).instantiate_identity();
334+
let item_ty = wfcx.normalize(hir_ty.span, Some(WellFormedLoc::Ty(def_id)), ty);
335+
wfcx.register_wf_obligation(
336+
hir_ty.span,
337+
Some(WellFormedLoc::Ty(def_id)),
338+
item_ty.into(),
339+
);
340+
check_where_clauses(wfcx, item.span, def_id);
339341
Ok(())
340-
}
342+
});
343+
check_variances_for_type_defn(tcx, item, hir_generics);
344+
res
341345
}
342346
_ => Ok(()),
343347
};
@@ -1276,7 +1280,6 @@ fn check_item_fn(
12761280

12771281
enum UnsizedHandling {
12781282
Forbid,
1279-
Allow,
12801283
AllowIfForeignTail,
12811284
}
12821285

@@ -1294,7 +1297,6 @@ fn check_item_type(
12941297

12951298
let forbid_unsized = match unsized_handling {
12961299
UnsizedHandling::Forbid => true,
1297-
UnsizedHandling::Allow => false,
12981300
UnsizedHandling::AllowIfForeignTail => {
12991301
let tail =
13001302
tcx.struct_tail_for_codegen(item_ty, wfcx.infcx.typing_env(wfcx.param_env));

compiler/rustc_incremental/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::util::Providers;
2424
#[allow(missing_docs)]
2525
pub fn provide(providers: &mut Providers) {
2626
providers.hooks.save_dep_graph =
27-
|tcx| tcx.sess.time("serialize_dep_graph", || persist::save_dep_graph(tcx.tcx));
27+
|tcx| tcx.sess.time("serialize_dep_graph", || persist::save_dep_graph(tcx));
2828
}
2929

3030
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ fn provide_cstore_hooks(providers: &mut Providers) {
689689
providers.hooks.def_path_hash_to_def_id_extern = |tcx, hash, stable_crate_id| {
690690
// If this is a DefPathHash from an upstream crate, let the CrateStore map
691691
// it to a DefId.
692-
let cstore = CStore::from_tcx(tcx.tcx);
692+
let cstore = CStore::from_tcx(tcx);
693693
let cnum = *tcx
694694
.untracked()
695695
.stable_crate_ids
@@ -702,11 +702,11 @@ fn provide_cstore_hooks(providers: &mut Providers) {
702702
};
703703

704704
providers.hooks.expn_hash_to_expn_id = |tcx, cnum, index_guess, hash| {
705-
let cstore = CStore::from_tcx(tcx.tcx);
705+
let cstore = CStore::from_tcx(tcx);
706706
cstore.get_crate_data(cnum).expn_hash_to_expn_id(tcx.sess, index_guess, hash)
707707
};
708708
providers.hooks.import_source_files = |tcx, cnum| {
709-
let cstore = CStore::from_tcx(tcx.tcx);
709+
let cstore = CStore::from_tcx(tcx);
710710
let cdata = cstore.get_crate_data(cnum);
711711
for file_index in 0..cdata.root.source_map.size() {
712712
cdata.imported_source_file(file_index as u32, tcx.sess);

compiler/rustc_middle/src/hooks/mod.rs

+3-17
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
use rustc_hir::def_id::{DefId, DefPathHash};
77
use rustc_session::StableCrateId;
88
use rustc_span::def_id::{CrateNum, LocalDefId};
9-
use rustc_span::{DUMMY_SP, ExpnHash, ExpnId};
10-
use tracing::instrument;
9+
use rustc_span::{ExpnHash, ExpnId};
1110

1211
use crate::mir;
13-
use crate::query::TyCtxtAt;
1412
use crate::ty::{Ty, TyCtxt};
1513

1614
macro_rules! declare_hooks {
@@ -22,26 +20,14 @@ macro_rules! declare_hooks {
2220
#[inline(always)]
2321
pub fn $name(self, $($arg: $K,)*) -> $V
2422
{
25-
self.at(DUMMY_SP).$name($($arg,)*)
26-
}
27-
)*
28-
}
29-
30-
impl<'tcx> TyCtxtAt<'tcx> {
31-
$(
32-
$(#[$attr])*
33-
#[inline(always)]
34-
#[instrument(level = "debug", skip(self), ret)]
35-
pub fn $name(self, $($arg: $K,)*) -> $V
36-
{
37-
(self.tcx.hooks.$name)(self, $($arg,)*)
23+
(self.hooks.$name)(self, $($arg,)*)
3824
}
3925
)*
4026
}
4127

4228
pub struct Providers {
4329
$(pub $name: for<'tcx> fn(
44-
TyCtxtAt<'tcx>,
30+
TyCtxt<'tcx>,
4531
$($arg: $K,)*
4632
) -> $V,)*
4733
}

0 commit comments

Comments
 (0)