Skip to content

Commit 6e12110

Browse files
committed
Auto merge of rust-lang#89449 - Manishearth:rollup-3alb61f, r=Manishearth
Rollup of 7 pull requests Successful merges: - rust-lang#85223 (rustdoc: Clarified the attribute which prompts the warning) - rust-lang#88847 (platform-support.md: correct ARMv7+MUSL platform triple notes) - rust-lang#88963 (Coerce const FnDefs to implement const Fn traits ) - rust-lang#89376 (Fix use after drop in self-profile with llvm events) - rust-lang#89422 (Replace whitespaces in doctests' name with dashes) - rust-lang#89440 (Clarify a sentence in the documentation of Vec (rust-lang#84488)) - rust-lang#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

+6-4
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

+1-18
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

+2-5
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

+3-1
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

+23
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

+2-2
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

+3-1
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

+1-2
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

+4-2
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

+1-1
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
}

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
11121112
// generator, this will raise error in other places
11131113
// or ignore error with const_async_blocks feature
11141114
GeneratorCandidate => {}
1115+
// FnDef where the function is const
1116+
FnPointerCandidate { is_const: true } => {}
11151117
ConstDropCandidate => {}
11161118
_ => {
11171119
// reject all other types of candidates
@@ -1539,6 +1541,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15391541
}
15401542
}
15411543

1544+
// Drop otherwise equivalent non-const fn pointer candidates
1545+
(FnPointerCandidate { .. }, FnPointerCandidate { is_const: false }) => true,
1546+
15421547
// Global bounds from the where clause should be ignored
15431548
// here (see issue #50825). Otherwise, we have a where
15441549
// clause so don't go around looking for impls.
@@ -1549,7 +1554,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15491554
ImplCandidate(..)
15501555
| ClosureCandidate
15511556
| GeneratorCandidate
1552-
| FnPointerCandidate
1557+
| FnPointerCandidate { .. }
15531558
| BuiltinObjectCandidate
15541559
| BuiltinUnsizeCandidate
15551560
| TraitUpcastingUnsizeCandidate(_)
@@ -1567,7 +1572,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15671572
ImplCandidate(_)
15681573
| ClosureCandidate
15691574
| GeneratorCandidate
1570-
| FnPointerCandidate
1575+
| FnPointerCandidate { .. }
15711576
| BuiltinObjectCandidate
15721577
| BuiltinUnsizeCandidate
15731578
| TraitUpcastingUnsizeCandidate(_)
@@ -1597,7 +1602,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
15971602
ImplCandidate(..)
15981603
| ClosureCandidate
15991604
| GeneratorCandidate
1600-
| FnPointerCandidate
1605+
| FnPointerCandidate { .. }
16011606
| BuiltinObjectCandidate
16021607
| BuiltinUnsizeCandidate
16031608
| TraitUpcastingUnsizeCandidate(_)
@@ -1609,7 +1614,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16091614
ImplCandidate(..)
16101615
| ClosureCandidate
16111616
| GeneratorCandidate
1612-
| FnPointerCandidate
1617+
| FnPointerCandidate { .. }
16131618
| BuiltinObjectCandidate
16141619
| BuiltinUnsizeCandidate
16151620
| TraitUpcastingUnsizeCandidate(_)
@@ -1690,7 +1695,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16901695
ImplCandidate(_)
16911696
| ClosureCandidate
16921697
| GeneratorCandidate
1693-
| FnPointerCandidate
1698+
| FnPointerCandidate { .. }
16941699
| BuiltinObjectCandidate
16951700
| BuiltinUnsizeCandidate
16961701
| TraitUpcastingUnsizeCandidate(_)
@@ -1699,7 +1704,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16991704
ImplCandidate(_)
17001705
| ClosureCandidate
17011706
| GeneratorCandidate
1702-
| FnPointerCandidate
1707+
| FnPointerCandidate { .. }
17031708
| BuiltinObjectCandidate
17041709
| BuiltinUnsizeCandidate
17051710
| TraitUpcastingUnsizeCandidate(_)

library/alloc/src/vec/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ mod spec_extend;
369369
/// scratch space that it may use however it wants. It will generally just do
370370
/// whatever is most efficient or otherwise easy to implement. Do not rely on
371371
/// removed data to be erased for security purposes. Even if you drop a `Vec`, its
372-
/// buffer may simply be reused by another `Vec`. Even if you zero a `Vec`'s memory
372+
/// buffer may simply be reused by another allocation. Even if you zero a `Vec`'s memory
373373
/// first, that might not actually happen because the optimizer does not consider
374374
/// this a side-effect that must be preserved. There is one case which we will
375375
/// not break, however: using `unsafe` code to write to the excess capacity,

src/doc/rustc/src/platform-support.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ target | std | notes
133133
`armv5te-unknown-linux-musleabi` | ✓ | ARMv5TE Linux with MUSL
134134
`armv7-linux-androideabi` | ✓ | ARMv7a Android
135135
`armv7-unknown-linux-gnueabi` | ✓ |ARMv7 Linux (kernel 4.15, glibc 2.27)
136-
`armv7-unknown-linux-musleabi` | ✓ |ARMv7 Linux, MUSL
137-
`armv7-unknown-linux-musleabihf` | ✓ | ARMv7 Linux with MUSL
136+
`armv7-unknown-linux-musleabi` | ✓ |ARMv7 Linux with MUSL
137+
`armv7-unknown-linux-musleabihf` | ✓ | ARMv7 Linux with MUSL, hardfloat
138138
`armv7a-none-eabi` | * | Bare ARMv7-A
139139
`armv7r-none-eabi` | * | Bare ARMv7-R
140140
`armv7r-none-eabihf` | * | Bare ARMv7-R, hardfloat

src/doc/rustdoc/src/lints.md

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ This lint **warns by default**. This lint detects when [intra-doc links] from pu
7070
For example:
7171

7272
```rust
73+
#![warn(rustdoc::private_intra_doc_links)] // note: unecessary - warns by default.
74+
7375
/// [private]
7476
pub fn public() {}
7577
fn private() {}
@@ -227,6 +229,8 @@ This lint **warns by default**. It detects code block attributes in
227229
documentation examples that have potentially mis-typed values. For example:
228230

229231
```rust
232+
#![warn(rustdoc::invalid_codeblock_attributes)] // note: unecessary - warns by default.
233+
230234
/// Example.
231235
///
232236
/// ```should-panic
@@ -344,6 +348,8 @@ This lint is **warn-by-default**. It detects URLs which are not links.
344348
For example:
345349

346350
```rust
351+
#![warn(rustdoc::bare_urls)] // note: unecessary - warns by default.
352+
347353
/// http://example.org
348354
/// [http://example.net]
349355
pub fn foo() {}

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ crate mod utils;
1111

1212
use rustc_ast as ast;
1313
use rustc_attr as attr;
14-
use rustc_const_eval::const_eval::{is_const_fn, is_unstable_const_fn};
14+
use rustc_const_eval::const_eval::is_unstable_const_fn;
1515
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1616
use rustc_hir as hir;
1717
use rustc_hir::def::{CtorKind, DefKind, Res};
@@ -787,7 +787,7 @@ fn clean_fn_or_proc_macro(
787787
let mut func = (sig, generics, body_id).clean(cx);
788788
let def_id = item.def_id.to_def_id();
789789
func.header.constness =
790-
if is_const_fn(cx.tcx, def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() {
790+
if cx.tcx.is_const_fn(def_id) && is_unstable_const_fn(cx.tcx, def_id).is_none() {
791791
hir::Constness::Const
792792
} else {
793793
hir::Constness::NotConst

src/librustdoc/doctest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,7 @@ impl Collector {
853853

854854
fn generate_name(&self, line: usize, filename: &FileName) -> String {
855855
let mut item_path = self.names.join("::");
856+
item_path.retain(|c| c != ' ');
856857
if !item_path.is_empty() {
857858
item_path.push(' ');
858859
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// check-pass
2+
3+
// From https://github.com/rust-lang/rust/issues/72476
4+
// and https://github.com/rust-lang/rust/issues/89393
5+
6+
trait Trait {
7+
type Projection;
8+
}
9+
10+
struct A;
11+
impl Trait for A {
12+
type Projection = bool;
13+
}
14+
15+
struct B;
16+
impl Trait for B {
17+
type Projection = (u32, u32);
18+
}
19+
20+
struct Next<T: Trait>(T::Projection);
21+
22+
fn foo1(item: Next<A>) {
23+
match item {
24+
Next(true) => {}
25+
Next(false) => {}
26+
}
27+
}
28+
29+
fn foo2(x: <A as Trait>::Projection) {
30+
match x {
31+
true => {}
32+
false => {}
33+
}
34+
}
35+
36+
fn foo3(x: Next<B>) {
37+
let Next((_, _)) = x;
38+
match x {
39+
Next((_, _)) => {}
40+
}
41+
}
42+
43+
fn foo4(x: <B as Trait>::Projection) {
44+
let (_, _) = x;
45+
match x {
46+
(_, _) => {}
47+
}
48+
}
49+
50+
fn foo5<T: Trait>(x: <T as Trait>::Projection) {
51+
match x {
52+
_ => {}
53+
}
54+
}
55+
56+
fn main() {}

0 commit comments

Comments
 (0)