Skip to content

Commit 6e12110

Browse files
committed
Auto merge of #89449 - Manishearth:rollup-3alb61f, r=Manishearth
Rollup of 7 pull requests Successful merges: - #85223 (rustdoc: Clarified the attribute which prompts the warning) - #88847 (platform-support.md: correct ARMv7+MUSL platform triple notes) - #88963 (Coerce const FnDefs to implement const Fn traits ) - #89376 (Fix use after drop in self-profile with llvm events) - #89422 (Replace whitespaces in doctests' name with dashes) - #89440 (Clarify a sentence in the documentation of Vec (#84488)) - #89441 (Normalize after substituting via `field.ty()`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c02371c + 5ab1245 commit 6e12110

File tree

21 files changed

+157
-71
lines changed

21 files changed

+157
-71
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,13 +406,15 @@ pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(
406406
None
407407
};
408408

409-
let llvm_selfprofiler = if cgcx.prof.llvm_recording_enabled() {
410-
let mut llvm_profiler = LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap());
411-
&mut llvm_profiler as *mut _ as *mut c_void
409+
let mut llvm_profiler = if cgcx.prof.llvm_recording_enabled() {
410+
Some(LlvmSelfProfiler::new(cgcx.prof.get_self_profiler().unwrap()))
412411
} else {
413-
std::ptr::null_mut()
412+
None
414413
};
415414

415+
let llvm_selfprofiler =
416+
llvm_profiler.as_mut().map(|s| s as *mut _ as *mut c_void).unwrap_or(std::ptr::null_mut());
417+
416418
let extra_passes = config.passes.join(",");
417419

418420
// FIXME: NewPM doesn't provide a facility to pass custom InlineParams.

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ use rustc_middle::ty::TyCtxt;
66
use rustc_span::symbol::Symbol;
77
use rustc_target::spec::abi::Abi;
88

9-
/// Whether the `def_id` counts as const fn in your current crate, considering all active
10-
/// feature gates
11-
pub fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
12-
tcx.is_const_fn_raw(def_id)
13-
&& match is_unstable_const_fn(tcx, def_id) {
14-
Some(feature_name) => {
15-
// has a `rustc_const_unstable` attribute, check whether the user enabled the
16-
// corresponding feature gate.
17-
tcx.features().declared_lib_features.iter().any(|&(sym, _)| sym == feature_name)
18-
}
19-
// functions without const stability are either stable user written
20-
// const fn or the user is using feature gates and we thus don't
21-
// care what they do
22-
None => true,
23-
}
24-
}
25-
269
/// Whether the `def_id` is an unstable const fn and what feature gate is necessary to enable it
2710
pub fn is_unstable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Symbol> {
2811
if tcx.is_const_fn_raw(def_id) {
@@ -77,7 +60,7 @@ fn is_const_fn_raw(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
7760
}
7861

7962
fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
80-
is_const_fn(tcx, def_id)
63+
tcx.is_const_fn(def_id)
8164
&& match tcx.lookup_const_stability(def_id) {
8265
Some(stab) => {
8366
if cfg!(debug_assertions) && stab.promotable {

compiler/rustc_const_eval/src/transform/promote_consts.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ use rustc_index::vec::{Idx, IndexVec};
2626
use std::cell::Cell;
2727
use std::{cmp, iter, mem};
2828

29-
use crate::const_eval::{is_const_fn, is_unstable_const_fn};
3029
use crate::transform::check_consts::{is_lang_panic_fn, qualifs, ConstCx};
3130
use crate::transform::MirPass;
3231

@@ -658,9 +657,7 @@ impl<'tcx> Validator<'_, 'tcx> {
658657

659658
let is_const_fn = match *fn_ty.kind() {
660659
ty::FnDef(def_id, _) => {
661-
is_const_fn(self.tcx, def_id)
662-
|| is_unstable_const_fn(self.tcx, def_id).is_some()
663-
|| is_lang_panic_fn(self.tcx, def_id)
660+
self.tcx.is_const_fn_raw(def_id) || is_lang_panic_fn(self.tcx, def_id)
664661
}
665662
_ => false,
666663
};
@@ -1081,7 +1078,7 @@ pub fn is_const_fn_in_array_repeat_expression<'tcx>(
10811078
if let ty::FnDef(def_id, _) = *literal.ty().kind() {
10821079
if let Some((destination_place, _)) = destination {
10831080
if destination_place == place {
1084-
if is_const_fn(ccx.tcx, def_id) {
1081+
if ccx.tcx.is_const_fn(def_id) {
10851082
return true;
10861083
}
10871084
}

compiler/rustc_middle/src/traits/select.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ pub enum SelectionCandidate<'tcx> {
120120

121121
/// Implementation of a `Fn`-family trait by one of the anonymous
122122
/// types generated for a fn pointer type (e.g., `fn(int) -> int`)
123-
FnPointerCandidate,
123+
FnPointerCandidate {
124+
is_const: bool,
125+
},
124126

125127
/// Builtin implementation of `DiscriminantKind`.
126128
DiscriminantKindCandidate,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2701,6 +2701,29 @@ impl<'tcx> TyCtxt<'tcx> {
27012701
pub fn lifetime_scope(self, id: HirId) -> Option<LifetimeScopeForPath> {
27022702
self.lifetime_scope_map(id.owner).and_then(|mut map| map.remove(&id.local_id))
27032703
}
2704+
2705+
/// Whether the `def_id` counts as const fn in the current crate, considering all active
2706+
/// feature gates
2707+
pub fn is_const_fn(self, def_id: DefId) -> bool {
2708+
if self.is_const_fn_raw(def_id) {
2709+
match self.lookup_const_stability(def_id) {
2710+
Some(stability) if stability.level.is_unstable() => {
2711+
// has a `rustc_const_unstable` attribute, check whether the user enabled the
2712+
// corresponding feature gate.
2713+
self.features()
2714+
.declared_lib_features
2715+
.iter()
2716+
.any(|&(sym, _)| sym == stability.feature)
2717+
}
2718+
// functions without const stability are either stable user written
2719+
// const fn or the user is using feature gates and we thus don't
2720+
// care what they do
2721+
_ => true,
2722+
}
2723+
} else {
2724+
false
2725+
}
2726+
}
27042727
}
27052728

27062729
impl TyCtxtAt<'tcx> {

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,8 +1638,8 @@ impl ReprOptions {
16381638
}
16391639

16401640
impl<'tcx> FieldDef {
1641-
/// Returns the type of this field. The `subst` is typically obtained
1642-
/// via the second field of `TyKind::AdtDef`.
1641+
/// Returns the type of this field. The resulting type is not normalized. The `subst` is
1642+
/// typically obtained via the second field of `TyKind::AdtDef`.
16431643
pub fn ty(&self, tcx: TyCtxt<'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> {
16441644
tcx.type_of(self.did).subst(tcx, subst)
16451645
}

compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,8 @@ impl<'p, 'tcx> Fields<'p, 'tcx> {
11541154

11551155
variant.fields.iter().enumerate().filter_map(move |(i, field)| {
11561156
let ty = field.ty(cx.tcx, substs);
1157+
// `field.ty()` doesn't normalize after substituting.
1158+
let ty = cx.tcx.normalize_erasing_regions(cx.param_env, ty);
11571159
let is_visible = adt.is_enum() || field.vis.is_accessible_from(cx.module, cx.tcx);
11581160
let is_uninhabited = cx.is_uninhabited(ty);
11591161

@@ -1671,7 +1673,7 @@ impl<'p, 'tcx> fmt::Debug for DeconstructedPat<'p, 'tcx> {
16711673
write!(f, "{}", hi)
16721674
}
16731675
IntRange(range) => write!(f, "{:?}", range), // Best-effort, will render e.g. `false` as `0..=0`
1674-
Wildcard | Missing { .. } | NonExhaustive => write!(f, "_"),
1676+
Wildcard | Missing { .. } | NonExhaustive => write!(f, "_ : {:?}", self.ty),
16751677
Or => {
16761678
for pat in self.iter_fields() {
16771679
write!(f, "{}{:?}", start_or_continue(" | "), pat)?;

compiler/rustc_mir_build/src/thir/pattern/usefulness.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ fn is_useful<'p, 'tcx>(
781781

782782
assert!(rows.iter().all(|r| r.len() == v.len()));
783783

784-
// FIXME(Nadrieril): Hack to work around type normalization issues (see #72476).
785-
let ty = matrix.heads().next().map_or(v.head().ty(), |r| r.ty());
784+
let ty = v.head().ty();
786785
let is_non_exhaustive = cx.is_foreign_non_exhaustive_enum(ty);
787786
let pcx = PatCtxt { cx, ty, span: v.head().span(), is_top_level, is_non_exhaustive };
788787

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
476476
..
477477
} = self_ty.fn_sig(self.tcx()).skip_binder()
478478
{
479-
candidates.vec.push(FnPointerCandidate);
479+
candidates.vec.push(FnPointerCandidate { is_const: false });
480480
}
481481
}
482482
// Provide an impl for suitable functions, rejecting `#[target_feature]` functions (RFC 2396).
@@ -489,7 +489,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
489489
} = self_ty.fn_sig(self.tcx()).skip_binder()
490490
{
491491
if self.tcx().codegen_fn_attrs(def_id).target_features.is_empty() {
492-
candidates.vec.push(FnPointerCandidate);
492+
candidates
493+
.vec
494+
.push(FnPointerCandidate { is_const: self.tcx().is_const_fn(def_id) });
493495
}
494496
}
495497
}

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
9292
Ok(ImplSource::Generator(vtable_generator))
9393
}
9494

95-
FnPointerCandidate => {
95+
FnPointerCandidate { .. } => {
9696
let data = self.confirm_fn_pointer_candidate(obligation)?;
9797
Ok(ImplSource::FnPointer(data))
9898
}

0 commit comments

Comments
 (0)