Skip to content

Commit a5584a8

Browse files
committed
Auto merge of #142181 - GuillaumeGomez:rollup-pn2p1lu, r=GuillaumeGomez
Rollup of 9 pull requests Successful merges: - #140560 (Allow `#![doc(test(attr(..)))]` everywhere) - #141447 (Document representation of `Option<unsafe fn()>`) - #141661 (Make the `dangerous_implicit_autorefs` lint deny-by-default) - #142065 (Stabilize `const_eq_ignore_ascii_case`) - #142116 (Fix bootstrap tracing imports) - #142126 (Treat normalizing consts like normalizing types in deeply normalize) - #142140 (compiler: Sort and doc ExternAbi variants) - #142148 (compiler: Treat ForceWarning as a Warning for diagnostic level) - #142154 (get rid of spurious cfg(bootstrap)) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cdd545b + aa94060 commit a5584a8

File tree

44 files changed

+976
-332
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

+976
-332
lines changed

compiler/rustc_abi/src/extern_abi.rs

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -12,66 +12,93 @@ use crate::AbiFromStrErr;
1212
#[cfg(test)]
1313
mod tests;
1414

15-
use ExternAbi as Abi;
16-
15+
/// ABI we expect to see within `extern "{abi}"`
1716
#[derive(Clone, Copy, Debug)]
1817
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable))]
1918
pub enum ExternAbi {
20-
// Some of the ABIs come first because every time we add a new ABI, we have to re-bless all the
21-
// hashing tests. These are used in many places, so giving them stable values reduces test
22-
// churn. The specific values are meaningless.
23-
Rust,
19+
/* universal */
20+
/// presumed C ABI for the platform
2421
C {
2522
unwind: bool,
2623
},
27-
Cdecl {
24+
/// ABI of the "system" interface, e.g. the Win32 API, always "aliasing"
25+
System {
2826
unwind: bool,
2927
},
30-
Stdcall {
28+
29+
/// that's us!
30+
Rust,
31+
/// the mostly-unused `unboxed_closures` ABI, effectively now an impl detail unless someone
32+
/// puts in the work to make it viable again... but would we need a special ABI?
33+
RustCall,
34+
/// For things unlikely to be called, where reducing register pressure in
35+
/// `extern "Rust"` callers is worth paying extra cost in the callee.
36+
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
37+
RustCold,
38+
39+
/// Unstable impl detail that directly uses Rust types to describe the ABI to LLVM.
40+
/// Even normally-compatible Rust types can become ABI-incompatible with this ABI!
41+
Unadjusted,
42+
43+
/// UEFI ABI, usually an alias of C, but sometimes an arch-specific alias
44+
/// and only valid on platforms that have a UEFI standard
45+
EfiApi,
46+
47+
/* arm */
48+
/// Arm Architecture Procedure Call Standard, sometimes `ExternAbi::C` is an alias for this
49+
Aapcs {
3150
unwind: bool,
3251
},
33-
Fastcall {
52+
/// extremely constrained barely-C ABI for TrustZone
53+
CCmseNonSecureCall,
54+
/// extremely constrained barely-C ABI for TrustZone
55+
CCmseNonSecureEntry,
56+
57+
/* gpu */
58+
/// An entry-point function called by the GPU's host
59+
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
60+
GpuKernel,
61+
/// An entry-point function called by the GPU's host
62+
// FIXME: why do we have two of these?
63+
PtxKernel,
64+
65+
/* interrupt */
66+
AvrInterrupt,
67+
AvrNonBlockingInterrupt,
68+
Msp430Interrupt,
69+
RiscvInterruptM,
70+
RiscvInterruptS,
71+
X86Interrupt,
72+
73+
/* x86 */
74+
/// `ExternAbi::C` but spelled funny because x86
75+
Cdecl {
3476
unwind: bool,
3577
},
36-
Vectorcall {
78+
/// gnu-stdcall on "unix" and win-stdcall on "windows"
79+
Stdcall {
3780
unwind: bool,
3881
},
39-
Thiscall {
82+
/// gnu-fastcall on "unix" and win-fastcall on "windows"
83+
Fastcall {
4084
unwind: bool,
4185
},
42-
Aapcs {
86+
/// windows C++ ABI
87+
Thiscall {
4388
unwind: bool,
4489
},
45-
Win64 {
90+
/// uses AVX and stuff
91+
Vectorcall {
4692
unwind: bool,
4793
},
94+
95+
/* x86_64 */
4896
SysV64 {
4997
unwind: bool,
5098
},
51-
PtxKernel,
52-
Msp430Interrupt,
53-
X86Interrupt,
54-
/// An entry-point function called by the GPU's host
55-
// FIXME: should not be callable from Rust on GPU targets, is for host's use only
56-
GpuKernel,
57-
EfiApi,
58-
AvrInterrupt,
59-
AvrNonBlockingInterrupt,
60-
CCmseNonSecureCall,
61-
CCmseNonSecureEntry,
62-
System {
99+
Win64 {
63100
unwind: bool,
64101
},
65-
RustCall,
66-
/// *Not* a stable ABI, just directly use the Rust types to describe the ABI for LLVM. Even
67-
/// normally ABI-compatible Rust types can become ABI-incompatible with this ABI!
68-
Unadjusted,
69-
/// For things unlikely to be called, where reducing register pressure in
70-
/// `extern "Rust"` callers is worth paying extra cost in the callee.
71-
/// Stronger than just `#[cold]` because `fn` pointers might be incompatible.
72-
RustCold,
73-
RiscvInterruptM,
74-
RiscvInterruptS,
75102
}
76103

77104
macro_rules! abi_impls {
@@ -224,7 +251,7 @@ pub fn all_names() -> Vec<&'static str> {
224251

225252
impl ExternAbi {
226253
/// Default ABI chosen for `extern fn` declarations without an explicit ABI.
227-
pub const FALLBACK: Abi = Abi::C { unwind: false };
254+
pub const FALLBACK: ExternAbi = ExternAbi::C { unwind: false };
228255

229256
pub fn name(self) -> &'static str {
230257
self.as_str()

compiler/rustc_errors/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ impl DiagCtxtInner {
15291529
// Future breakages aren't emitted if they're `Level::Allow` or
15301530
// `Level::Expect`, but they still need to be constructed and
15311531
// stashed below, so they'll trigger the must_produce_diag check.
1532-
assert_matches!(diagnostic.level, Error | Warning | Allow | Expect);
1532+
assert_matches!(diagnostic.level, Error | ForceWarning | Warning | Allow | Expect);
15331533
self.future_breakage_diagnostics.push(diagnostic.clone());
15341534
}
15351535

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,13 @@ impl<'tcx> InferCtxt<'tcx> {
823823
ty::Region::new_var(self.tcx, region_var)
824824
}
825825

826+
pub fn next_term_var_of_kind(&self, term: ty::Term<'tcx>, span: Span) -> ty::Term<'tcx> {
827+
match term.kind() {
828+
ty::TermKind::Ty(_) => self.next_ty_var(span).into(),
829+
ty::TermKind::Const(_) => self.next_const_var(span).into(),
830+
}
831+
}
832+
826833
/// Return the universe that the region `r` was created in. For
827834
/// most regions (e.g., `'static`, named regions from the user,
828835
/// etc) this is the root universe U0. For inference variables or

compiler/rustc_lint/src/autorefs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare_lint! {
1616
///
1717
/// ### Example
1818
///
19-
/// ```rust
19+
/// ```rust,compile_fail
2020
/// unsafe fn fun(ptr: *mut [u8]) -> *mut [u8] {
2121
/// unsafe { &raw mut (*ptr)[..16] }
2222
/// // ^^^^^^ this calls `IndexMut::index_mut(&mut ..., ..16)`,
@@ -51,7 +51,7 @@ declare_lint! {
5151
/// }
5252
/// ```
5353
pub DANGEROUS_IMPLICIT_AUTOREFS,
54-
Warn,
54+
Deny,
5555
"implicit reference to a dereference of a raw pointer",
5656
report_in_external_macro
5757
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,13 +1266,17 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12661266
true
12671267
}
12681268

1269-
/// Checks that `doc(test(...))` attribute contains only valid attributes. Returns `true` if
1270-
/// valid.
1271-
fn check_test_attr(&self, meta: &MetaItemInner, hir_id: HirId) {
1269+
/// Checks that `doc(test(...))` attribute contains only valid attributes and are at the right place.
1270+
fn check_test_attr(&self, attr: &Attribute, meta: &MetaItemInner, hir_id: HirId) {
12721271
if let Some(metas) = meta.meta_item_list() {
12731272
for i_meta in metas {
12741273
match (i_meta.name(), i_meta.meta_item()) {
1275-
(Some(sym::attr | sym::no_crate_inject), _) => {}
1274+
(Some(sym::attr), _) => {
1275+
// Allowed everywhere like `#[doc]`
1276+
}
1277+
(Some(sym::no_crate_inject), _) => {
1278+
self.check_attr_crate_level(attr, meta, hir_id);
1279+
}
12761280
(_, Some(m)) => {
12771281
self.tcx.emit_node_span_lint(
12781282
INVALID_DOC_ATTRIBUTES,
@@ -1359,9 +1363,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
13591363
}
13601364

13611365
Some(sym::test) => {
1362-
if self.check_attr_crate_level(attr, meta, hir_id) {
1363-
self.check_test_attr(meta, hir_id);
1364-
}
1366+
self.check_test_attr(attr, meta, hir_id);
13651367
}
13661368

13671369
Some(

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
231231
let infcx = self.goal.infcx;
232232
match goal.predicate.kind().no_bound_vars() {
233233
Some(ty::PredicateKind::NormalizesTo(ty::NormalizesTo { alias, term })) => {
234-
let unconstrained_term = match term.kind() {
235-
ty::TermKind::Ty(_) => infcx.next_ty_var(span).into(),
236-
ty::TermKind::Const(_) => infcx.next_const_var(span).into(),
237-
};
234+
let unconstrained_term = infcx.next_term_var_of_kind(term, span);
238235
let goal =
239236
goal.with(infcx.tcx, ty::NormalizesTo { alias, term: unconstrained_term });
240237
// We have to use a `probe` here as evaluating a `NormalizesTo` can constrain the

compiler/rustc_trait_selection/src/solve/normalize.rs

Lines changed: 25 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::assert_matches::assert_matches;
21
use std::fmt::Debug;
32

43
use rustc_data_structures::stack::ensure_sufficient_stack;
@@ -16,7 +15,6 @@ use tracing::instrument;
1615
use super::{FulfillmentCtxt, NextSolverError};
1716
use crate::error_reporting::InferCtxtErrorExt;
1817
use crate::error_reporting::traits::OverflowCause;
19-
use crate::traits::query::evaluate_obligation::InferCtxtExt;
2018
use crate::traits::{BoundVarReplacer, PlaceholderReplacer, ScrubbedTraitError};
2119

2220
/// Deeply normalize all aliases in `value`. This does not handle inference and expects
@@ -97,19 +95,18 @@ impl<'tcx, E> NormalizationFolder<'_, 'tcx, E>
9795
where
9896
E: FromSolverError<'tcx, NextSolverError<'tcx>>,
9997
{
100-
fn normalize_alias_ty(&mut self, alias_ty: Ty<'tcx>) -> Result<Ty<'tcx>, Vec<E>> {
101-
assert_matches!(alias_ty.kind(), ty::Alias(..));
102-
98+
fn normalize_alias_term(
99+
&mut self,
100+
alias_term: ty::Term<'tcx>,
101+
) -> Result<ty::Term<'tcx>, Vec<E>> {
103102
let infcx = self.at.infcx;
104103
let tcx = infcx.tcx;
105104
let recursion_limit = tcx.recursion_limit();
106105
if !recursion_limit.value_within_limit(self.depth) {
107-
let ty::Alias(_, data) = *alias_ty.kind() else {
108-
unreachable!();
109-
};
106+
let term = alias_term.to_alias_term().unwrap();
110107

111108
self.at.infcx.err_ctxt().report_overflow_error(
112-
OverflowCause::DeeplyNormalize(data.into()),
109+
OverflowCause::DeeplyNormalize(term),
113110
self.at.cause.span,
114111
true,
115112
|_| {},
@@ -118,14 +115,14 @@ where
118115

119116
self.depth += 1;
120117

121-
let new_infer_ty = infcx.next_ty_var(self.at.cause.span);
118+
let infer_term = infcx.next_term_var_of_kind(alias_term, self.at.cause.span);
122119
let obligation = Obligation::new(
123120
tcx,
124121
self.at.cause.clone(),
125122
self.at.param_env,
126123
ty::PredicateKind::AliasRelate(
127-
alias_ty.into(),
128-
new_infer_ty.into(),
124+
alias_term.into(),
125+
infer_term.into(),
129126
ty::AliasRelationDirection::Equate,
130127
),
131128
);
@@ -135,50 +132,13 @@ where
135132

136133
// Alias is guaranteed to be fully structurally resolved,
137134
// so we can super fold here.
138-
let ty = infcx.resolve_vars_if_possible(new_infer_ty);
139-
let result = ty.try_super_fold_with(self)?;
140-
self.depth -= 1;
141-
Ok(result)
142-
}
143-
144-
fn normalize_unevaluated_const(
145-
&mut self,
146-
uv: ty::UnevaluatedConst<'tcx>,
147-
) -> Result<ty::Const<'tcx>, Vec<E>> {
148-
let infcx = self.at.infcx;
149-
let tcx = infcx.tcx;
150-
let recursion_limit = tcx.recursion_limit();
151-
if !recursion_limit.value_within_limit(self.depth) {
152-
self.at.infcx.err_ctxt().report_overflow_error(
153-
OverflowCause::DeeplyNormalize(uv.into()),
154-
self.at.cause.span,
155-
true,
156-
|_| {},
157-
);
158-
}
159-
160-
self.depth += 1;
161-
162-
let new_infer_ct = infcx.next_const_var(self.at.cause.span);
163-
let obligation = Obligation::new(
164-
tcx,
165-
self.at.cause.clone(),
166-
self.at.param_env,
167-
ty::NormalizesTo { alias: uv.into(), term: new_infer_ct.into() },
168-
);
169-
170-
let result = if infcx.predicate_may_hold(&obligation) {
171-
self.fulfill_cx.register_predicate_obligation(infcx, obligation);
172-
let errors = self.fulfill_cx.select_where_possible(infcx);
173-
if !errors.is_empty() {
174-
return Err(errors);
175-
}
176-
let ct = infcx.resolve_vars_if_possible(new_infer_ct);
177-
ct.try_fold_with(self)?
178-
} else {
179-
ty::Const::new_unevaluated(tcx, uv).try_super_fold_with(self)?
135+
let term = infcx.resolve_vars_if_possible(infer_term);
136+
// super-folding the `term` will directly fold the `Ty` or `Const` so
137+
// we have to match on the term and super-fold them manually.
138+
let result = match term.kind() {
139+
ty::TermKind::Ty(ty) => ty.try_super_fold_with(self)?.into(),
140+
ty::TermKind::Const(ct) => ct.try_super_fold_with(self)?.into(),
180141
};
181-
182142
self.depth -= 1;
183143
Ok(result)
184144
}
@@ -238,7 +198,8 @@ where
238198
if ty.has_escaping_bound_vars() {
239199
let (ty, mapped_regions, mapped_types, mapped_consts) =
240200
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, ty);
241-
let result = ensure_sufficient_stack(|| self.normalize_alias_ty(ty))?;
201+
let result =
202+
ensure_sufficient_stack(|| self.normalize_alias_term(ty.into()))?.expect_type();
242203
Ok(PlaceholderReplacer::replace_placeholders(
243204
infcx,
244205
mapped_regions,
@@ -248,7 +209,7 @@ where
248209
result,
249210
))
250211
} else {
251-
ensure_sufficient_stack(|| self.normalize_alias_ty(ty))
212+
Ok(ensure_sufficient_stack(|| self.normalize_alias_term(ty.into()))?.expect_type())
252213
}
253214
}
254215

@@ -260,15 +221,13 @@ where
260221
return Ok(ct);
261222
}
262223

263-
let uv = match ct.kind() {
264-
ty::ConstKind::Unevaluated(ct) => ct,
265-
_ => return ct.try_super_fold_with(self),
266-
};
224+
let ty::ConstKind::Unevaluated(..) = ct.kind() else { return ct.try_super_fold_with(self) };
267225

268-
if uv.has_escaping_bound_vars() {
269-
let (uv, mapped_regions, mapped_types, mapped_consts) =
270-
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, uv);
271-
let result = ensure_sufficient_stack(|| self.normalize_unevaluated_const(uv))?;
226+
if ct.has_escaping_bound_vars() {
227+
let (ct, mapped_regions, mapped_types, mapped_consts) =
228+
BoundVarReplacer::replace_bound_vars(infcx, &mut self.universes, ct);
229+
let result =
230+
ensure_sufficient_stack(|| self.normalize_alias_term(ct.into()))?.expect_const();
272231
Ok(PlaceholderReplacer::replace_placeholders(
273232
infcx,
274233
mapped_regions,
@@ -278,7 +237,7 @@ where
278237
result,
279238
))
280239
} else {
281-
ensure_sufficient_stack(|| self.normalize_unevaluated_const(uv))
240+
Ok(ensure_sufficient_stack(|| self.normalize_alias_term(ct.into()))?.expect_const())
282241
}
283242
}
284243
}

compiler/rustc_trait_selection/src/traits/structural_normalize.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ impl<'tcx> At<'_, 'tcx> {
3939
return Ok(term);
4040
}
4141

42-
let new_infer = match term.kind() {
43-
ty::TermKind::Ty(_) => self.infcx.next_ty_var(self.cause.span).into(),
44-
ty::TermKind::Const(_) => self.infcx.next_const_var(self.cause.span).into(),
45-
};
42+
let new_infer = self.infcx.next_term_var_of_kind(term, self.cause.span);
4643

4744
// We simply emit an `alias-eq` goal here, since that will take care of
4845
// normalizing the LHS of the projection until it is a rigid projection

0 commit comments

Comments
 (0)