Skip to content

Rollup of 11 pull requests #79686

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Dec 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b787d72
Fix SGX CI
Dec 1, 2020
4eb76fc
Use more std:: instead of core:: in docs for consistency, add more in…
poliorcetics Dec 1, 2020
88c6cf8
Pass around Symbols instead of Idents in doctree
jyn514 Dec 2, 2020
5009798
Update cargo
ehuss Dec 2, 2020
67a67d8
disable a ptr equality test on Miri
RalfJung Dec 2, 2020
7e74b72
break formatting so rustfmt is happy
RalfJung Dec 2, 2020
4e7a2dc
Use `item_name` instead of pretty printing
jyn514 Dec 2, 2020
908bf5a
rustc_metadata: Remove some dead code
petrochenkov Dec 2, 2020
56c64f8
Add lint pass for doc keyword
GuillaumeGomez Nov 29, 2020
0105e4a
Add test for EXISTING_DOC_KEYWORD internal lint
GuillaumeGomez Dec 3, 2020
50eb3a8
Only deny doc_keyword in std and set it as "allow" by default
GuillaumeGomez Dec 3, 2020
ff0ebd2
move interpret::MemoryKind::Heap to const eval
vn-ki Dec 3, 2020
0ad3dce
Fix some clippy lints
jyn514 Dec 3, 2020
5d4a712
Render Markdown in search results
camelid Oct 5, 2020
e178030
Use `createElement` and `innerHTML` instead of `DOMParser`
camelid Nov 17, 2020
07e9426
Make `length_limit` a `usize`
camelid Nov 24, 2020
b903519
Add rustdoc-js test
camelid Nov 24, 2020
f0cf5a9
Add more rustdoc-js test cases
camelid Nov 24, 2020
376507f
Add missing feature flag
camelid Dec 3, 2020
6f2fbc1
Rollup merge of #77686 - camelid:rustdoc-render-search-results, r=Gui…
Dylan-DPC Dec 4, 2020
f406052
Rollup merge of #79541 - GuillaumeGomez:doc-keyword-lint-pass, r=lcnr
Dylan-DPC Dec 4, 2020
6b42900
Rollup merge of #79602 - jethrogb:sgx-fix-79038, r=Mark-Simulacrum
Dylan-DPC Dec 4, 2020
88f0c72
Rollup merge of #79611 - poliorcetics:use-std-in-docs, r=jyn514
Dylan-DPC Dec 4, 2020
14895ea
Rollup merge of #79623 - jyn514:ident, r=GuillaumeGomez
Dylan-DPC Dec 4, 2020
aef5edd
Rollup merge of #79627 - ehuss:update-cargo, r=ehuss
Dylan-DPC Dec 4, 2020
0a52b43
Rollup merge of #79631 - RalfJung:miri-const_str_ptr, r=oli-obk
Dylan-DPC Dec 4, 2020
5495bb9
Rollup merge of #79638 - jyn514:intra-link-self-raw, r=Manishearth
Dylan-DPC Dec 4, 2020
0fbbe94
Rollup merge of #79646 - petrochenkov:inclean, r=davidtwco
Dylan-DPC Dec 4, 2020
a2aa3d6
Rollup merge of #79664 - vn-ki:move-memkind-heap, r=oli-obk
Dylan-DPC Dec 4, 2020
5cebbaa
Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkor
Dylan-DPC Dec 4, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,10 @@ impl Annotatable {
pub fn derive_allowed(&self) -> bool {
match *self {
Annotatable::Stmt(ref stmt) => match stmt.kind {
ast::StmtKind::Item(ref item) => match item.kind {
ast::ItemKind::Struct(..)
| ast::ItemKind::Enum(..)
| ast::ItemKind::Union(..) => true,
_ => false,
},
ast::StmtKind::Item(ref item) => matches!(
item.kind,
ast::ItemKind::Struct(..) | ast::ItemKind::Enum(..) | ast::ItemKind::Union(..)
),
_ => false,
},
Annotatable::Item(ref item) => match item.kind {
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1134,7 +1134,9 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
// Collect the invoc regardless of whether or not attributes are permitted here
// expansion will eat the attribute so it won't error later.
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}

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

if let Some(attr) = self.take_first_attr_no_derive(&mut expr) {
attr.0.as_ref().map(|attr| self.cfg.maybe_emit_expr_attr_err(attr));
if let Some(attr) = attr.0.as_ref() {
self.cfg.maybe_emit_expr_attr_err(attr)
}

return self
.collect_attr(attr, Annotatable::Expr(P(expr)), AstFragmentKind::OptExpr)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ impl StructField<'_> {
// Still necessary in couple of places
pub fn is_positional(&self) -> bool {
let first = self.ident.as_str().as_bytes()[0];
first >= b'0' && first <= b'9'
(b'0'..=b'9').contains(&first)
}
}

Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_lexer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,8 @@ pub fn is_whitespace(c: char) -> bool {
pub fn is_id_start(c: char) -> bool {
// This is XID_Start OR '_' (which formally is not a XID_Start).
// We also add fast-path for ascii idents
('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
('a'..='z').contains(&c)
|| ('A'..='Z').contains(&c)
|| c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_start(c))
}
Expand All @@ -279,9 +279,9 @@ pub fn is_id_start(c: char) -> bool {
pub fn is_id_continue(c: char) -> bool {
// This is exactly XID_Continue.
// We also add fast-path for ascii idents
('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9')
('a'..='z').contains(&c)
|| ('A'..='Z').contains(&c)
|| ('0'..='9').contains(&c)
|| c == '_'
|| (c > '\x7f' && unicode_xid::UnicodeXID::is_xid_continue(c))
}
Expand Down
46 changes: 45 additions & 1 deletion compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath,
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_span::hygiene::{ExpnKind, MacroKind};
use rustc_span::symbol::{sym, Ident, Symbol};
use rustc_span::symbol::{kw, sym, Ident, Symbol};

declare_tool_lint! {
pub rustc::DEFAULT_HASH_TYPES,
Expand Down Expand Up @@ -267,3 +267,47 @@ impl EarlyLintPass for LintPassImpl {
}
}
}

declare_tool_lint! {
pub rustc::EXISTING_DOC_KEYWORD,
Allow,
"Check that documented keywords in std and core actually exist",
report_in_external_macro: true
}

declare_lint_pass!(ExistingDocKeyword => [EXISTING_DOC_KEYWORD]);

fn is_doc_keyword(s: Symbol) -> bool {
s <= kw::Union
}

impl<'tcx> LateLintPass<'tcx> for ExistingDocKeyword {
fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) {
for attr in item.attrs {
if !attr.has_name(sym::doc) {
continue;
}
if let Some(list) = attr.meta_item_list() {
for nested in list {
if nested.has_name(sym::keyword) {
let v = nested
.value_str()
.expect("#[doc(keyword = \"...\")] expected a value!");
if is_doc_keyword(v) {
return;
}
cx.struct_span_lint(EXISTING_DOC_KEYWORD, attr.span, |lint| {
lint.build(&format!(
"Found non-existing keyword `{}` used in \
`#[doc(keyword = \"...\")]`",
v,
))
.help("only existing keywords are allowed in core/std")
.emit();
});
}
}
}
}
}
}
3 changes: 3 additions & 0 deletions compiler/rustc_lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ fn register_internals(store: &mut LintStore) {
store.register_early_pass(|| box DefaultHashTypes::new());
store.register_lints(&LintPassImpl::get_lints());
store.register_early_pass(|| box LintPassImpl);
store.register_lints(&ExistingDocKeyword::get_lints());
store.register_late_pass(|| box ExistingDocKeyword);
store.register_lints(&TyTyKind::get_lints());
store.register_late_pass(|| box TyTyKind);
store.register_group(
Expand All @@ -475,6 +477,7 @@ fn register_internals(store: &mut LintStore) {
LintId::of(LINT_PASS_IMPL_WITHOUT_MACRO),
LintId::of(TY_PASS_BY_REFERENCE),
LintId::of(USAGE_OF_QUALIFIED_TY),
LintId::of(EXISTING_DOC_KEYWORD),
],
);
}
17 changes: 0 additions & 17 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1592,23 +1592,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
self.def_path_hash_unlocked(index, &mut def_path_hashes)
}

fn all_def_path_hashes_and_def_ids(&self) -> Vec<(DefPathHash, DefId)> {
let mut def_path_hashes = self.def_path_hash_cache.lock();
let mut def_index_to_data = |index| {
(self.def_path_hash_unlocked(index, &mut def_path_hashes), self.local_def_id(index))
};
if let Some(data) = &self.root.proc_macro_data {
std::iter::once(CRATE_DEF_INDEX)
.chain(data.macros.decode(self))
.map(def_index_to_data)
.collect()
} else {
(0..self.num_def_ids())
.map(|index| def_index_to_data(DefIndex::from_usize(index)))
.collect()
}
}

/// Get the `DepNodeIndex` corresponding this crate. The result of this
/// method is cached in the `dep_node_index` field.
fn get_crate_dep_node_index(&self, tcx: TyCtxt<'tcx>) -> DepNodeIndex {
Expand Down
12 changes: 4 additions & 8 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,10 @@ impl CStore {
pub fn module_expansion_untracked(&self, def_id: DefId, sess: &Session) -> ExpnId {
self.get_crate_data(def_id.krate).module_expansion(def_id.index, sess)
}

pub fn num_def_ids(&self, cnum: CrateNum) -> usize {
self.get_crate_data(cnum).num_def_ids()
}
}

impl CrateStore for CStore {
Expand Down Expand Up @@ -498,14 +502,6 @@ impl CrateStore for CStore {
self.get_crate_data(def.krate).def_path_hash(def.index)
}

fn all_def_path_hashes_and_def_ids(&self, cnum: CrateNum) -> Vec<(DefPathHash, DefId)> {
self.get_crate_data(cnum).all_def_path_hashes_and_def_ids()
}

fn num_def_ids(&self, cnum: CrateNum) -> usize {
self.get_crate_data(cnum).num_def_ids()
}

// See `CrateMetadataRef::def_path_hash_to_def_id` for more details
fn def_path_hash_to_def_id(
&self,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/middle/cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ pub trait CrateStore {
fn def_kind(&self, def: DefId) -> DefKind;
fn def_path(&self, def: DefId) -> DefPath;
fn def_path_hash(&self, def: DefId) -> DefPathHash;
fn all_def_path_hashes_and_def_ids(&self, cnum: CrateNum) -> Vec<(DefPathHash, DefId)>;
fn num_def_ids(&self, cnum: CrateNum) -> usize;
fn def_path_hash_to_def_id(
&self,
cnum: CrateNum,
Expand Down
27 changes: 26 additions & 1 deletion compiler/rustc_mir/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::collections::hash_map::Entry;
use std::hash::Hash;

use rustc_data_structures::fx::FxHashMap;
use std::fmt;

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

#[derive(Debug, PartialEq, Eq, Copy, Clone)]
pub enum MemoryKind {
Heap,
}

impl fmt::Display for MemoryKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MemoryKind::Heap => write!(f, "heap allocation"),
}
}
}

impl interpret::MayLeak for MemoryKind {
#[inline(always)]
fn may_leak(self) -> bool {
match self {
MemoryKind::Heap => false,
}
}
}

impl interpret::MayLeak for ! {
#[inline(always)]
fn may_leak(self) -> bool {
Expand Down Expand Up @@ -222,6 +245,8 @@ impl<'mir, 'tcx: 'mir> CompileTimeEvalContext<'mir, 'tcx> {
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
compile_time_machine!(<'mir, 'tcx>);

type MemoryKind = MemoryKind;

type MemoryExtra = MemoryExtra;

fn find_mir_or_eval_fn(
Expand Down Expand Up @@ -317,7 +342,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
let ptr = ecx.memory.allocate(
Size::from_bytes(size as u64),
align,
interpret::MemoryKind::ConstHeap,
interpret::MemoryKind::Machine(MemoryKind::Heap),
);
ecx.write_scalar(Scalar::Ptr(ptr), dest)?;
}
Expand Down
27 changes: 16 additions & 11 deletions compiler/rustc_mir/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ use rustc_target::abi::Size;
use rustc_ast::Mutability;

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

pub trait CompileTimeMachine<'mir, 'tcx> = Machine<
pub trait CompileTimeMachine<'mir, 'tcx, T> = Machine<
'mir,
'tcx,
MemoryKind = !,
MemoryKind = T,
PointerTag = (),
ExtraFnVal = !,
FrameExtra = (),
AllocExtra = (),
MemoryMap = FxHashMap<AllocId, (MemoryKind<!>, Allocation)>,
MemoryMap = FxHashMap<AllocId, (MemoryKind<T>, Allocation)>,
>;

struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> {
struct InternVisitor<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>> {
/// The ectx from which we intern.
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
/// Previously encountered safe references.
Expand Down Expand Up @@ -74,7 +75,7 @@ struct IsStaticOrFn;
/// `immutable` things might become mutable if `ty` is not frozen.
/// `ty` can be `None` if there is no potential interior mutability
/// to account for (e.g. for vtables).
fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>(
ecx: &'rt mut InterpCx<'mir, 'tcx, M>,
leftover_allocations: &'rt mut FxHashSet<AllocId>,
alloc_id: AllocId,
Expand Down Expand Up @@ -105,7 +106,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
// changes in this function.
match kind {
MemoryKind::Stack
| MemoryKind::ConstHeap
| MemoryKind::Machine(const_eval::MemoryKind::Heap)
| MemoryKind::Vtable
| MemoryKind::CallerLocation => {}
}
Expand Down Expand Up @@ -141,7 +142,9 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
None
}

impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir, 'tcx, M> {
impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>
InternVisitor<'rt, 'mir, 'tcx, M>
{
fn intern_shallow(
&mut self,
alloc_id: AllocId,
Expand All @@ -152,8 +155,8 @@ impl<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>> InternVisitor<'rt, 'mir
}
}

impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx>> ValueVisitor<'mir, 'tcx, M>
for InternVisitor<'rt, 'mir, 'tcx, M>
impl<'rt, 'mir, 'tcx: 'mir, M: CompileTimeMachine<'mir, 'tcx, const_eval::MemoryKind>>
ValueVisitor<'mir, 'tcx, M> for InternVisitor<'rt, 'mir, 'tcx, M>
{
type V = MPlaceTy<'tcx>;

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

impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>>
InterpCx<'mir, 'tcx, M>
{
/// A helper function that allocates memory for the layout given and gives you access to mutate
/// it. Once your own mutation code is done, the backing `Allocation` is removed from the
/// current `Memory` and returned.
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
type PointerTag = ();
type ExtraFnVal = !;

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

type AllocExtra = ();
type FrameExtra = ();
Expand Down Expand Up @@ -407,7 +407,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
_memory_extra: &Self::MemoryExtra,
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<!>>,
_kind: Option<MemoryKind<Self::MemoryKind>>,
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
// We do not use a tag so we can just cheaply forward the allocation
(alloc, ())
Expand Down
5 changes: 0 additions & 5 deletions compiler/rustc_mir/src/interpret/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ use crate::util::pretty;
pub enum MemoryKind<T> {
/// Stack memory. Error if deallocated except during a stack pop.
Stack,
/// Heap memory.
/// FIXME: this variant should be in const_eval
ConstHeap,
/// Memory backing vtables. Error if ever deallocated.
Vtable,
/// Memory allocated by `caller_location` intrinsic. Error if ever deallocated.
Expand All @@ -43,7 +40,6 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
fn may_leak(self) -> bool {
match self {
MemoryKind::Stack => false,
MemoryKind::ConstHeap => false,
MemoryKind::Vtable => true,
MemoryKind::CallerLocation => true,
MemoryKind::Machine(k) => k.may_leak(),
Expand All @@ -55,7 +51,6 @@ impl<T: fmt::Display> fmt::Display for MemoryKind<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MemoryKind::Stack => write!(f, "stack variable"),
MemoryKind::ConstHeap => write!(f, "heap allocation"),
MemoryKind::Vtable => write!(f, "vtable"),
MemoryKind::CallerLocation => write!(f, "caller location"),
MemoryKind::Machine(m) => write!(f, "{}", m),
Expand Down
Loading