Skip to content
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

Rollup of 7 pull requests #82688

Merged
merged 23 commits into from
Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
9f1abe8
Run some rustc passes in rustdoc
GuillaumeGomez Feb 27, 2021
25e030b
Add test for rustdoc new check pass
GuillaumeGomez Feb 27, 2021
5ab4d46
Update rustdoc test to make it work with newly added rustc passes
GuillaumeGomez Feb 27, 2021
2f8fa01
Use identifier's span in unused lint
SkiFire13 Feb 28, 2021
6214ef8
Bless some tests
SkiFire13 Feb 28, 2021
65f0b25
Always compile rustdoc with debug logging enabled when `download-rust…
jyn514 Dec 28, 2020
6dc9934
Remove deleted pass from rustdoc test suite
jyn514 Mar 1, 2021
4d7a648
Remove the dummy cache in `DocContext`
jyn514 Feb 12, 2021
163b01a
Remove unused `RenderInfo` struct
jyn514 Feb 12, 2021
be069a6
Remove `krate.version`; fix `crate_version` in JSON
jyn514 Feb 25, 2021
3c63f67
Add regression test
SkiFire13 Feb 28, 2021
5a33f53
check that first arg to `panic!()` in const is `&str`
abonander Jan 5, 2021
bd51dea
Change twice used large const table to static
dtolnay Mar 1, 2021
b0b330f
Validate meta items used in \#\[doc(...)\]
GuillaumeGomez Mar 1, 2021
f6de130
Add tests for doc attribute check
GuillaumeGomez Mar 1, 2021
d20fd62
Add missing stability attributes in libstd
GuillaumeGomez Feb 27, 2021
865cf0c
Rollup merge of #80734 - abonander:ab/issue-66693, r=oli-obk
GuillaumeGomez Mar 1, 2021
22ebb86
Rollup merge of #81932 - jyn514:rustdoc-logging, r=Mark-Simulacrum
GuillaumeGomez Mar 1, 2021
b51272e
Rollup merge of #82018 - jyn514:no-dummy-cache, r=camelid,GuillaumeGomez
GuillaumeGomez Mar 1, 2021
5a82251
Rollup merge of #82598 - GuillaumeGomez:rustdoc-rustc-pass, r=jyn514
GuillaumeGomez Mar 1, 2021
d259d1d
Rollup merge of #82655 - SkiFire13:fix-issue-81314, r=estebank
GuillaumeGomez Mar 1, 2021
0c6b69a
Rollup merge of #82662 - GuillaumeGomez:doc-attr-check, r=jyn514
GuillaumeGomez Mar 1, 2021
9a0ac7c
Rollup merge of #82676 - dtolnay:powers, r=Mark-Simulacrum
GuillaumeGomez Mar 1, 2021
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
3 changes: 3 additions & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4554,6 +4554,9 @@ dependencies = [
"serde_json",
"smallvec 1.6.1",
"tempfile",
"tracing",
"tracing-subscriber",
"tracing-tree",
]

[[package]]
Expand Down
12 changes: 12 additions & 0 deletions compiler/rustc_mir/src/transform/check_consts/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,18 @@ impl NonConstOp for Panic {
}
}

/// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
#[derive(Debug)]
pub struct PanicNonStr;
impl NonConstOp for PanicNonStr {
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
ccx.tcx.sess.struct_span_err(
span,
"argument to `panic!()` in a const context must have type `&str`",
)
}
}

#[derive(Debug)]
pub struct RawPtrComparison;
impl NonConstOp for RawPtrComparison {
Expand Down
12 changes: 10 additions & 2 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
self.super_terminator(terminator, location);

match &terminator.kind {
TerminatorKind::Call { func, .. } => {
TerminatorKind::Call { func, args, .. } => {
let ConstCx { tcx, body, param_env, .. } = *self.ccx;
let caller = self.def_id().to_def_id();

Expand Down Expand Up @@ -881,9 +881,17 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
}

// At this point, we are calling a function, `callee`, whose `DefId` is known...

if is_lang_panic_fn(tcx, callee) {
self.check_op(ops::Panic);

// const-eval of the `begin_panic` fn assumes the argument is `&str`
if Some(callee) == tcx.lang_items().begin_panic_fn() {
match args[0].ty(&self.ccx.body.local_decls, tcx).kind() {
ty::Ref(_, ty, _) if ty.is_str() => (),
_ => self.check_op(ops::PanicNonStr),
}
}

return;
}

Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,41 @@ impl CheckAttrVisitor<'tcx> {
{
return false;
}
} else if let Some(i_meta) = meta.meta_item() {
if ![
sym::cfg,
sym::hidden,
sym::html_favicon_url,
sym::html_logo_url,
sym::html_no_source,
sym::html_playground_url,
sym::html_root_url,
sym::include,
sym::inline,
sym::issue_tracker_base_url,
sym::masked,
sym::no_default_passes, // deprecated
sym::no_inline,
sym::passes, // deprecated
sym::primitive,
sym::spotlight,
sym::test,
]
.iter()
.any(|m| i_meta.has_name(*m))
{
self.tcx
.sess
.struct_span_err(
meta.span(),
&format!(
"unknown `doc` attribute `{}`",
i_meta.name_or_empty(),
),
)
.emit();
return false;
}
}
}
}
Expand Down
109 changes: 66 additions & 43 deletions compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,12 +1494,13 @@ impl<'tcx> Liveness<'_, 'tcx> {
// bindings, and we also consider the first pattern to be the "authoritative" set of ids.
// However, we should take the ids and spans of variables with the same name from the later
// patterns so the suggestions to prefix with underscores will apply to those too.
let mut vars: FxIndexMap<Symbol, (LiveNode, Variable, Vec<(HirId, Span)>)> = <_>::default();
let mut vars: FxIndexMap<Symbol, (LiveNode, Variable, Vec<(HirId, Span, Span)>)> =
<_>::default();

pat.each_binding(|_, hir_id, pat_sp, ident| {
let ln = entry_ln.unwrap_or_else(|| self.live_node(hir_id, pat_sp));
let var = self.variable(hir_id, ident.span);
let id_and_sp = (hir_id, pat_sp);
let id_and_sp = (hir_id, pat_sp, ident.span);
vars.entry(self.ir.variable_name(var))
.and_modify(|(.., hir_ids_and_spans)| hir_ids_and_spans.push(id_and_sp))
.or_insert_with(|| (ln, var, vec![id_and_sp]));
Expand All @@ -1508,15 +1509,21 @@ impl<'tcx> Liveness<'_, 'tcx> {
for (_, (ln, var, hir_ids_and_spans)) in vars {
if self.used_on_entry(ln, var) {
let id = hir_ids_and_spans[0].0;
let spans = hir_ids_and_spans.into_iter().map(|(_, sp)| sp).collect();
let spans =
hir_ids_and_spans.into_iter().map(|(_, _, ident_span)| ident_span).collect();
on_used_on_entry(spans, id, ln, var);
} else {
self.report_unused(hir_ids_and_spans, ln, var);
}
}
}

fn report_unused(&self, hir_ids_and_spans: Vec<(HirId, Span)>, ln: LiveNode, var: Variable) {
fn report_unused(
&self,
hir_ids_and_spans: Vec<(HirId, Span, Span)>,
ln: LiveNode,
var: Variable,
) {
let first_hir_id = hir_ids_and_spans[0].0;

if let Some(name) = self.should_warn(var).filter(|name| name != "self") {
Expand All @@ -1530,62 +1537,78 @@ impl<'tcx> Liveness<'_, 'tcx> {
self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans.into_iter().map(|(_, sp)| sp).collect::<Vec<_>>(),
hir_ids_and_spans
.into_iter()
.map(|(_, _, ident_span)| ident_span)
.collect::<Vec<_>>(),
|lint| {
lint.build(&format!("variable `{}` is assigned to, but never used", name))
.note(&format!("consider using `_{}` instead", name))
.emit();
},
)
} else {
self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans.iter().map(|(_, sp)| *sp).collect::<Vec<_>>(),
|lint| {
let mut err = lint.build(&format!("unused variable: `{}`", name));

let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
hir_ids_and_spans.into_iter().partition(|(hir_id, span)| {
let var = self.variable(*hir_id, *span);
self.ir.variable_is_shorthand(var)
});

let mut shorthands = shorthands
.into_iter()
.map(|(_, span)| (span, format!("{}: _", name)))
.collect::<Vec<_>>();

// If we have both shorthand and non-shorthand, prefer the "try ignoring
// the field" message, and suggest `_` for the non-shorthands. If we only
// have non-shorthand, then prefix with an underscore instead.
if !shorthands.is_empty() {
shorthands.extend(
non_shorthands
.into_iter()
.map(|(_, span)| (span, "_".to_string()))
.collect::<Vec<_>>(),
);
let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
hir_ids_and_spans.iter().copied().partition(|(hir_id, _, ident_span)| {
let var = self.variable(*hir_id, *ident_span);
self.ir.variable_is_shorthand(var)
});

// If we have both shorthand and non-shorthand, prefer the "try ignoring
// the field" message, and suggest `_` for the non-shorthands. If we only
// have non-shorthand, then prefix with an underscore instead.
if !shorthands.is_empty() {
let shorthands = shorthands
.into_iter()
.map(|(_, pat_span, _)| (pat_span, format!("{}: _", name)))
.chain(
non_shorthands
.into_iter()
.map(|(_, pat_span, _)| (pat_span, "_".to_string())),
)
.collect::<Vec<_>>();

self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans
.iter()
.map(|(_, pat_span, _)| *pat_span)
.collect::<Vec<_>>(),
|lint| {
let mut err = lint.build(&format!("unused variable: `{}`", name));
err.multipart_suggestion(
"try ignoring the field",
shorthands,
Applicability::MachineApplicable,
);
} else {
err.emit()
},
);
} else {
let non_shorthands = non_shorthands
.into_iter()
.map(|(_, _, ident_span)| (ident_span, format!("_{}", name)))
.collect::<Vec<_>>();

self.ir.tcx.struct_span_lint_hir(
lint::builtin::UNUSED_VARIABLES,
first_hir_id,
hir_ids_and_spans
.iter()
.map(|(_, _, ident_span)| *ident_span)
.collect::<Vec<_>>(),
|lint| {
let mut err = lint.build(&format!("unused variable: `{}`", name));
err.multipart_suggestion(
"if this is intentional, prefix it with an underscore",
non_shorthands
.into_iter()
.map(|(_, span)| (span, format!("_{}", name)))
.collect::<Vec<_>>(),
non_shorthands,
Applicability::MachineApplicable,
);
}

err.emit()
},
);
err.emit()
},
);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/num/dec2flt/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub const MIN_E: i16 = -305;
pub const MAX_E: i16 = 305;

#[rustfmt::skip]
pub const POWERS: ([u64; 611], [i16; 611]) = (
pub static POWERS: ([u64; 611], [i16; 611]) = (
[
0xe0b62e2929aba83c,
0x8c71dcd9ba0b4926,
Expand Down
1 change: 1 addition & 0 deletions library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub use crate::sys::windows_ext as windows;
pub mod linux;

#[cfg(doc)]
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
pub use crate::sys::wasi_ext as wasi;

// If we're not documenting libstd then we just expose the main modules as we otherwise would.
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ cfg_if::cfg_if! {
cfg_if::cfg_if! {
if #[cfg(target_os = "wasi")] {
// On WASI we'll document what's already available
#[stable(feature = "rust1", since = "1.0.0")]
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
pub use self::ext as wasi_ext;
} else if #[cfg(any(target_os = "hermit",
target_arch = "wasm32",
Expand All @@ -125,6 +125,7 @@ cfg_if::cfg_if! {
} else {
// On other platforms like Windows document the bare bones of WASI
#[path = "wasi/ext/mod.rs"]
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
pub mod wasi_ext;
}
}
2 changes: 1 addition & 1 deletion src/etc/dec2flt_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def print_proper_powers():
print()
print("#[rustfmt::skip]")
typ = "([u64; {0}], [i16; {0}])".format(len(powers))
print("pub const POWERS: ", typ, " = (", sep='')
print("pub static POWERS: ", typ, " = (", sep='')
print(" [")
for z in powers:
print(" 0x{:x},".format(z.sig))
Expand Down
7 changes: 7 additions & 0 deletions src/librustdoc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ tempfile = "3"
itertools = "0.9"
regex = "1"
rustdoc-json-types = { path = "../rustdoc-json-types" }
tracing = "0.1"
tracing-tree = "0.1.6"

[dependencies.tracing-subscriber]
version = "0.2.13"
default-features = false
features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"]

[dev-dependencies]
expect-test = "1.0"
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
debug!("get_blanket_impls({:?})", ty);
let mut impls = Vec::new();
for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() {
if !self.cx.renderinfo.access_levels.is_public(trait_def_id)
if !self.cx.cache.access_levels.is_public(trait_def_id)
|| self.cx.generated_synthetics.get(&(ty, trait_def_id)).is_some()
{
continue;
Expand Down
13 changes: 7 additions & 6 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_span::Span;

use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind};
use crate::core::DocContext;
use crate::formats::item_type::ItemType;

use super::Clean;

Expand Down Expand Up @@ -122,7 +123,7 @@ crate fn try_inline(
let target_attrs = load_attrs(cx, did);
let attrs = box merge_attrs(cx, Some(parent_module), target_attrs, attrs_clone);

cx.renderinfo.inlined.insert(did);
cx.inlined.insert(did);
let what_rustc_thinks = clean::Item::from_def_id_and_parts(did, Some(name), kind, cx);
ret.push(clean::Item { attrs, ..what_rustc_thinks });
Some(ret)
Expand Down Expand Up @@ -181,9 +182,9 @@ crate fn record_extern_fqn(cx: &mut DocContext<'_>, did: DefId, kind: clean::Typ
};

if did.is_local() {
cx.renderinfo.exact_paths.insert(did, fqn);
cx.cache.exact_paths.insert(did, fqn);
} else {
cx.renderinfo.external_paths.insert(did, (fqn, kind));
cx.cache.external_paths.insert(did, (fqn, ItemType::from(kind)));
}
}

Expand Down Expand Up @@ -315,7 +316,7 @@ crate fn build_impl(
attrs: Option<Attrs<'_>>,
ret: &mut Vec<clean::Item>,
) {
if !cx.renderinfo.inlined.insert(did) {
if !cx.inlined.insert(did) {
return;
}

Expand All @@ -327,7 +328,7 @@ crate fn build_impl(
if !did.is_local() {
if let Some(traitref) = associated_trait {
let did = traitref.def_id;
if !cx.renderinfo.access_levels.is_public(did) {
if !cx.cache.access_levels.is_public(did) {
return;
}

Expand Down Expand Up @@ -359,7 +360,7 @@ crate fn build_impl(
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id() {
if !cx.renderinfo.access_levels.is_public(did) {
if !cx.cache.access_levels.is_public(did) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
// Substitute private type aliases
if let Some(def_id) = def_id.as_local() {
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
if !cx.renderinfo.access_levels.is_exported(def_id.to_def_id()) {
if !cx.cache.access_levels.is_exported(def_id.to_def_id()) {
alias = Some(&cx.tcx.hir().expect_item(hir_id).kind);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ thread_local!(crate static MAX_DEF_IDX: RefCell<FxHashMap<CrateNum, DefIndex>> =
#[derive(Clone, Debug)]
crate struct Crate {
crate name: Symbol,
crate version: Option<String>,
crate src: FileName,
crate module: Option<Item>,
crate externs: Vec<(CrateNum, ExternalCrate)>,
Expand Down
Loading