Skip to content

Commit e9dd18c

Browse files
committed
Auto merge of rust-lang#79686 - Dylan-DPC:rollup-leama5f, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - rust-lang#77686 (Render Markdown in search results) - rust-lang#79541 (Doc keyword lint pass) - rust-lang#79602 (Fix SGX CI) - rust-lang#79611 (Use more std:: instead of core:: in docs for consistency) - rust-lang#79623 (Pass around Symbols instead of Idents in doctree) - rust-lang#79627 (Update cargo) - rust-lang#79631 (disable a ptr equality test on Miri) - rust-lang#79638 (Use `item_name` instead of pretty printing for resolving `Self` on intra-doc links) - rust-lang#79646 (rustc_metadata: Remove some dead code) - rust-lang#79664 (move interpret::MemoryKind::Heap to const eval) - rust-lang#79678 (Fix some clippy lints) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6513f50 + 5cebbaa commit e9dd18c

File tree

49 files changed

+430
-180
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+430
-180
lines changed

compiler/rustc_expand/src/base.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,10 @@ impl Annotatable {
235235
pub fn derive_allowed(&self) -> bool {
236236
match *self {
237237
Annotatable::Stmt(ref stmt) => match stmt.kind {
238-
ast::StmtKind::Item(ref item) => match item.kind {
239-
ast::ItemKind::Struct(..)
240-
| ast::ItemKind::Enum(..)
241-
| ast::ItemKind::Union(..) => true,
242-
_ => false,
243-
},
238+
ast::StmtKind::Item(ref item) => matches!(
239+
item.kind,
240+
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
241+
),
244242
_ => false,
245243
},
246244
Annotatable::Item(ref item) => match item.kind {

compiler/rustc_expand/src/expand.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11341134
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
11351135
// Collect the invoc regardless of whether or not attributes are permitted here
11361136
// expansion will eat the attribute so it won't error later.
1137-
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
1137+
if let Some(attr) = attr.0.as_ref() {
1138+
self.cfg.maybe_emit_expr_attr_err(attr)
1139+
}
11381140

11391141
// AstFragmentKind::Expr requires the macro to emit an expression.
11401142
return self
@@ -1231,7 +1233,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
12311233
self.cfg.configure_expr_kind(&mut expr.kind);
12321234

12331235
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
1234-
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
1236+
if let Some(attr) = attr.0.as_ref() {
1237+
self.cfg.maybe_emit_expr_attr_err(attr)
1238+
}
12351239

12361240
return self
12371241
.collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr)

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2401,7 +2401,7 @@ impl StructField<'_> {
24012401
// Still necessary in couple of places
24022402
pub fn is_positional(&self) -> bool {
24032403
let first = self.ident.as_str().as_bytes()[0];
2404-
first >= b'0' && first <= b'9'
2404+
(b'0'..=b'9').contains(&first)
24052405
}
24062406
}
24072407

compiler/rustc_lexer/src/lib.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ pub fn is_whitespace(c: char) -> bool {
267267
pub fn is_id_start(c: char) -> bool {
268268
// This is XID_Start OR '_' (which formally is not a XID_Start).
269269
// We also add fast-path for ascii idents
270-
('a' <= c && c <= 'z')
271-
|| ('A' <= c && c <= 'Z')
270+
('a'..='z').contains(&c)
271+
|| ('A'..='Z').contains(&c)
272272
|| c == '_'
273273
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c))
274274
}
@@ -279,9 +279,9 @@ pub fn is_id_start(c: char) -> bool {
279279
pub fn is_id_continue(c: char) -> bool {
280280
// This is exactly XID_Continue.
281281
// We also add fast-path for ascii idents
282-
('a' <= c && c <= 'z')
283-
|| ('A' <= c && c <= 'Z')
284-
|| ('0' <= c && c <= '9')
282+
('a'..='z').contains(&c)
283+
|| ('A'..='Z').contains(&c)
284+
|| ('0'..='9').contains(&c)
285285
|| c == '_'
286286
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
287287
}

compiler/rustc_lint/src/internal.rs

+45-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath,
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1212
use rustc_span::hygiene::{ExpnKind, MacroKind};
13-
use rustc_span::symbol::{sym, Ident, Symbol};
13+
use rustc_span::symbol::{kw, sym, Ident, Symbol};
1414

1515
declare_tool_lint! {
1616
pub rustc::DEFAULT_HASH_TYPES,
@@ -267,3 +267,47 @@ impl EarlyLintPass for LintPassImpl {
267267
}
268268
}
269269
}
270+
271+
declare_tool_lint! {
272+
pub rustc::EXISTING_DOC_KEYWORD,
273+
Allow,
274+
"Check that documented keywords in std and core actually exist",
275+
report_in_external_macro: true
276+
}
277+
278+
declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);
279+
280+
fn is_doc_keyword(s: Symbol) -> bool {
281+
s <= kw::Union
282+
}
283+
284+
impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
285+
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
286+
for attr in item.attrs {
287+
if !attr.has_name(sym::doc) {
288+
continue;
289+
}
290+
if let Some(list) = attr.meta_item_list() {
291+
for nested in list {
292+
if nested.has_name(sym::keyword) {
293+
let v = nested
294+
.value_str()
295+
.expect("#[doc(keyword = \"...\")] expected a value!");
296+
if is_doc_keyword(v) {
297+
return;
298+
}
299+
cx.struct_span_lint(EXISTING_DOC_KEYWORD, attr.span, |lint| {
300+
lint.build(&format!(
301+
"Found non-existing keyword `{}` used in \
302+
`#[doc(keyword = \"...\")]`",
303+
v,
304+
))
305+
.help("only existing keywords are allowed in core/std")
306+
.emit();
307+
});
308+
}
309+
}
310+
}
311+
}
312+
}
313+
}

compiler/rustc_lint/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,8 @@ fn register_internals(store: &mut LintStore) {
463463
store.register_early_pass(|| box DefaultHashTypes::new());
464464
store.register_lints(&LintPassImpl::get_lints());
465465
store.register_early_pass(|| box LintPassImpl);
466+
store.register_lints(&ExistingDocKeyword::get_lints());
467+
store.register_late_pass(|| box ExistingDocKeyword);
466468
store.register_lints(&TyTyKind::get_lints());
467469
store.register_late_pass(|| box TyTyKind);
468470
store.register_group(
@@ -475,6 +477,7 @@ fn register_internals(store: &mut LintStore) {
475477
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
476478
LintId::of(TY_PASS_BY_REFERENCE),
477479
LintId::of(USAGE_OF_QUALIFIED_TY),
480+
LintId::of(EXISTING_DOC_KEYWORD),
478481
],
479482
);
480483
}

compiler/rustc_metadata/src/rmeta/decoder.rs

-17
Original file line numberDiff line numberDiff line change
@@ -1592,23 +1592,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15921592
self.def_path_hash_unlocked(index, &mut def_path_hashes)
15931593
}
15941594

1595-
fn all_def_path_hashes_and_def_ids(&self) -> Vec<(DefPathHash, DefId)> {
1596-
let mut def_path_hashes = self.def_path_hash_cache.lock();
1597-
let mut def_index_to_data = |index| {
1598-
(self.def_path_hash_unlocked(index, &mut def_path_hashes), self.local_def_id(index))
1599-
};
1600-
if let Some(data) = &self.root.proc_macro_data {
1601-
std::iter::once(CRATE_DEF_INDEX)
1602-
.chain(data.macros.decode(self))
1603-
.map(def_index_to_data)
1604-
.collect()
1605-
} else {
1606-
(0..self.num_def_ids())
1607-
.map(|index| def_index_to_data(DefIndex::from_usize(index)))
1608-
.collect()
1609-
}
1610-
}
1611-
16121595
/// Get the `DepNodeIndex` corresponding this crate. The result of this
16131596
/// method is cached in the `dep_node_index` field.
16141597
fn get_crate_dep_node_index(&self, tcx: TyCtxt<'tcx>) -> DepNodeIndex {

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

+4-8
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ impl CStore {
456456
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
457457
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
458458
}
459+
460+
pub fn num_def_ids(&self, cnum: CrateNum) -> usize {
461+
self.get_crate_data(cnum).num_def_ids()
462+
}
459463
}
460464

461465
impl CrateStore for CStore {
@@ -498,14 +502,6 @@ impl CrateStore for CStore {
498502
self.get_crate_data(def.krate).def_path_hash(def.index)
499503
}
500504

501-
fn all_def_path_hashes_and_def_ids(&self, cnum: CrateNum) -> Vec<(DefPathHash, DefId)> {
502-
self.get_crate_data(cnum).all_def_path_hashes_and_def_ids()
503-
}
504-
505-
fn num_def_ids(&self, cnum: CrateNum) -> usize {
506-
self.get_crate_data(cnum).num_def_ids()
507-
}
508-
509505
// See `CrateMetadataRef::def_path_hash_to_def_id` for more details
510506
fn def_path_hash_to_def_id(
511507
&self,

compiler/rustc_middle/src/middle/cstore.rs

-2
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ pub trait CrateStore {
189189
fn def_kind(&self, def: DefId) -> DefKind;
190190
fn def_path(&self, def: DefId) -> DefPath;
191191
fn def_path_hash(&self, def: DefId) -> DefPathHash;
192-
fn all_def_path_hashes_and_def_ids(&self, cnum: CrateNum) -> Vec<(DefPathHash, DefId)>;
193-
fn num_def_ids(&self, cnum: CrateNum) -> usize;
194192
fn def_path_hash_to_def_id(
195193
&self,
196194
cnum: CrateNum,

compiler/rustc_mir/src/const_eval/machine.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::collections::hash_map::Entry;
77
use std::hash::Hash;
88

99
use rustc_data_structures::fx::FxHashMap;
10+
use std::fmt;
1011

1112
use rustc_ast::Mutability;
1213
use rustc_hir::def_id::DefId;
@@ -179,6 +180,28 @@ impl<K: Hash + Eq, V> interpret::AllocMap<K, V> for FxHashMap<K, V> {
179180
crate type CompileTimeEvalContext<'mir, 'tcx> =
180181
InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>>;
181182

183+
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
184+
pub enum MemoryKind {
185+
Heap,
186+
}
187+
188+
impl fmt::Display for MemoryKind {
189+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
190+
match self {
191+
MemoryKind::Heap => write!(f, "heap allocation"),
192+
}
193+
}
194+
}
195+
196+
impl interpret::MayLeak for MemoryKind {
197+
#[inline(always)]
198+
fn may_leak(self) -> bool {
199+
match self {
200+
MemoryKind::Heap => false,
201+
}
202+
}
203+
}
204+
182205
impl interpret::MayLeak for ! {
183206
#[inline(always)]
184207
fn may_leak(self) -> bool {
@@ -222,6 +245,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
222245
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
223246
compile_time_machine!(<'mir, 'tcx>);
224247

248+
type MemoryKind = MemoryKind;
249+
225250
type MemoryExtra = MemoryExtra;
226251

227252
fn find_mir_or_eval_fn(
@@ -317,7 +342,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
317342
let ptr = ecx.memory.allocate(
318343
Size::from_bytes(size as u64),
319344
align,
320-
interpret::MemoryKind::ConstHeap,
345+
interpret::MemoryKind::Machine(MemoryKind::Heap),
321346
);
322347
ecx.write_scalar(Scalar::Ptr(ptr), dest)?;
323348
}

compiler/rustc_mir/src/interpret/intern.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ use rustc_target::abi::Size;
2525
use rustc_ast::Mutability;
2626

2727
use super::{AllocId, Allocation, InterpCx, MPlaceTy, Machine, MemoryKind, Scalar, ValueVisitor};
28+
use crate::const_eval;
2829

29-
pub trait CompileTimeMachine<'mir, 'tcx> = Machine<
30+
pub trait CompileTimeMachine<'mir, 'tcx, T> = Machine<
3031
'mir,
3132
'tcx,
32-
MemoryKind = !,
33+
MemoryKind = T,
3334
PointerTag = (),
3435
ExtraFnVal = !,
3536
FrameExtra = (),
3637
AllocExtra = (),
37-
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
38+
MemoryMap = FxHashMap<AllocId, (MemoryKind<T>, Allocation)>,
3839
>;
3940

40-
struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> {
41+
struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>> {
4142
/// The ectx from which we intern.
4243
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
4344
/// Previously encountered safe references.
@@ -74,7 +75,7 @@ struct IsStaticOrFn;
7475
/// `immutable` things might become mutable if `ty` is not frozen.
7576
/// `ty` can be `None` if there is no potential interior mutability
7677
/// to account for (e.g. for vtables).
77-
fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
78+
fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>(
7879
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
7980
leftover_allocations: &'rt mut FxHashSet<AllocId>,
8081
alloc_id: AllocId,
@@ -105,7 +106,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
105106
// changes in this function.
106107
match kind {
107108
MemoryKind::Stack
108-
| MemoryKind::ConstHeap
109+
| MemoryKind::Machine(const_eval::MemoryKind::Heap)
109110
| MemoryKind::Vtable
110111
| MemoryKind::CallerLocation => {}
111112
}
@@ -141,7 +142,9 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
141142
None
142143
}
143144

144-
impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir, 'tcx, M> {
145+
impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>
146+
InternVisitor<'rt, 'mir, 'tcx, M>
147+
{
145148
fn intern_shallow(
146149
&mut self,
147150
alloc_id: AllocId,
@@ -152,8 +155,8 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir
152155
}
153156
}
154157

155-
impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
156-
for InternVisitor<'rt, 'mir, 'tcx, M>
158+
impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>
159+
ValueVisitor<'mir, 'tcx, M> for InternVisitor<'rt, 'mir, 'tcx, M>
157160
{
158161
type V = MPlaceTy<'tcx>;
159162

@@ -290,7 +293,7 @@ pub enum InternKind {
290293
/// Any errors here would anyway be turned into `const_err` lints, whereas validation failures
291294
/// are hard errors.
292295
#[tracing::instrument(skip(ecx))]
293-
pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx>>(
296+
pub fn intern_const_alloc_recursive<M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>(
294297
ecx: &mut InterpCx<'mir, 'tcx, M>,
295298
intern_kind: InternKind,
296299
ret: MPlaceTy<'tcx>,
@@ -421,7 +424,9 @@ where
421424
Ok(())
422425
}
423426

424-
impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
427+
impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
428+
InterpCx<'mir, 'tcx, M>
429+
{
425430
/// A helper function that allocates memory for the layout given and gives you access to mutate
426431
/// it. Once your own mutation code is done, the backing `Allocation` is removed from the
427432
/// current `Memory` and returned.

compiler/rustc_mir/src/interpret/machine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
366366
type PointerTag = ();
367367
type ExtraFnVal = !;
368368

369-
type MemoryKind = !;
370-
type MemoryMap = rustc_data_structures::fx::FxHashMap<AllocId, (MemoryKind<!>, Allocation)>;
371-
const GLOBAL_KIND: Option<!> = None; // no copying of globals from `tcx` to machine memory
369+
type MemoryMap =
370+
rustc_data_structures::fx::FxHashMap<AllocId, (MemoryKind<Self::MemoryKind>, Allocation)>;
371+
const GLOBAL_KIND: Option<Self::MemoryKind> = None; // no copying of globals from `tcx` to machine memory
372372

373373
type AllocExtra = ();
374374
type FrameExtra = ();
@@ -407,7 +407,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
407407
_memory_extra: &Self::MemoryExtra,
408408
_id: AllocId,
409409
alloc: Cow<'b, Allocation>,
410-
_kind: Option<MemoryKind<!>>,
410+
_kind: Option<MemoryKind<Self::MemoryKind>>,
411411
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
412412
// We do not use a tag so we can just cheaply forward the allocation
413413
(alloc, ())

compiler/rustc_mir/src/interpret/memory.rs

-5
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@ use crate::util::pretty;
2727
pub enum MemoryKind<T> {
2828
/// Stack memory. Error if deallocated except during a stack pop.
2929
Stack,
30-
/// Heap memory.
31-
/// FIXME: this variant should be in const_eval
32-
ConstHeap,
3330
/// Memory backing vtables. Error if ever deallocated.
3431
Vtable,
3532
/// Memory allocated by `caller_location` intrinsic. Error if ever deallocated.
@@ -43,7 +40,6 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
4340
fn may_leak(self) -> bool {
4441
match self {
4542
MemoryKind::Stack => false,
46-
MemoryKind::ConstHeap => false,
4743
MemoryKind::Vtable => true,
4844
MemoryKind::CallerLocation => true,
4945
MemoryKind::Machine(k) => k.may_leak(),
@@ -55,7 +51,6 @@ impl<T: fmt::Display> fmt::Display for MemoryKind<T> {
5551
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5652
match self {
5753
MemoryKind::Stack => write!(f, "stack variable"),
58-
MemoryKind::ConstHeap => write!(f, "heap allocation"),
5954
MemoryKind::Vtable => write!(f, "vtable"),
6055
MemoryKind::CallerLocation => write!(f, "caller location"),
6156
MemoryKind::Machine(m) => write!(f, "{}", m),

0 commit comments

Comments
 (0)