Skip to content

Commit e9dd18c

Browse files
committed
Auto merge of #79686 - Dylan-DPC:rollup-leama5f, r=Dylan-DPC
Rollup of 11 pull requests Successful merges: - #77686 (Render Markdown in search results) - #79541 (Doc keyword lint pass) - #79602 (Fix SGX CI) - #79611 (Use more std:: instead of core:: in docs for consistency) - #79623 (Pass around Symbols instead of Idents in doctree) - #79627 (Update cargo) - #79631 (disable a ptr equality test on Miri) - #79638 (Use `item_name` instead of pretty printing for resolving `Self` on intra-doc links) - #79646 (rustc_metadata: Remove some dead code) - #79664 (move interpret::MemoryKind::Heap to const eval) - #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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 6 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 45 additions & 1 deletion
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 0 additions & 17 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 26 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)