Skip to content

Commit

Permalink
Auto merge of rust-lang#82688 - GuillaumeGomez:rollup-b754t11, r=Guil…
Browse files Browse the repository at this point in the history
…laumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#80734 (check that first arg to `panic!()` in const is `&str`)
 - rust-lang#81932 (Always compile rustdoc with debug logging enabled when `download-rustc` is set)
 - rust-lang#82018 (Remove the dummy cache in `DocContext`; delete RenderInfo)
 - rust-lang#82598 (Check stability and feature attributes in rustdoc)
 - rust-lang#82655 (Highlight identifier span instead of whole pattern span in `unused` lint)
 - rust-lang#82662 (Warn about unknown doc attributes)
 - rust-lang#82676 (Change twice used large const table to static)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 2, 2021
2 parents 4f20caa + 9a0ac7c commit ef0d592
Show file tree
Hide file tree
Showing 50 changed files with 503 additions and 202 deletions.
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

0 comments on commit ef0d592

Please sign in to comment.