Skip to content

Commit ef0d592

Browse files
committed
Auto merge of #82688 - GuillaumeGomez:rollup-b754t11, r=GuillaumeGomez
Rollup of 7 pull requests Successful merges: - #80734 (check that first arg to `panic!()` in const is `&str`) - #81932 (Always compile rustdoc with debug logging enabled when `download-rustc` is set) - #82018 (Remove the dummy cache in `DocContext`; delete RenderInfo) - #82598 (Check stability and feature attributes in rustdoc) - #82655 (Highlight identifier span instead of whole pattern span in `unused` lint) - #82662 (Warn about unknown doc attributes) - #82676 (Change twice used large const table to static) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4f20caa + 9a0ac7c commit ef0d592

Some content is hidden

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

50 files changed

+503
-202
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -4554,6 +4554,9 @@ dependencies = [
45544554
"serde_json",
45554555
"smallvec 1.6.1",
45564556
"tempfile",
4557+
"tracing",
4558+
"tracing-subscriber",
4559+
"tracing-tree",
45574560
]
45584561

45594562
[[package]]

compiler/rustc_mir/src/transform/check_consts/ops.rs

+12
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,18 @@ impl NonConstOp for Panic {
377377
}
378378
}
379379

380+
/// A call to a `panic()` lang item where the first argument is _not_ a `&str`.
381+
#[derive(Debug)]
382+
pub struct PanicNonStr;
383+
impl NonConstOp for PanicNonStr {
384+
fn build_error(&self, ccx: &ConstCx<'_, 'tcx>, span: Span) -> DiagnosticBuilder<'tcx> {
385+
ccx.tcx.sess.struct_span_err(
386+
span,
387+
"argument to `panic!()` in a const context must have type `&str`",
388+
)
389+
}
390+
}
391+
380392
#[derive(Debug)]
381393
pub struct RawPtrComparison;
382394
impl NonConstOp for RawPtrComparison {

compiler/rustc_mir/src/transform/check_consts/validation.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
819819
self.super_terminator(terminator, location);
820820

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

@@ -881,9 +881,17 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
881881
}
882882

883883
// At this point, we are calling a function, `callee`, whose `DefId` is known...
884-
885884
if is_lang_panic_fn(tcx, callee) {
886885
self.check_op(ops::Panic);
886+
887+
// const-eval of the `begin_panic` fn assumes the argument is `&str`
888+
if Some(callee) == tcx.lang_items().begin_panic_fn() {
889+
match args[0].ty(&self.ccx.body.local_decls, tcx).kind() {
890+
ty::Ref(_, ty, _) if ty.is_str() => (),
891+
_ => self.check_op(ops::PanicNonStr),
892+
}
893+
}
894+
887895
return;
888896
}
889897

compiler/rustc_passes/src/check_attr.rs

+35
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,41 @@ impl CheckAttrVisitor<'tcx> {
544544
{
545545
return false;
546546
}
547+
} else if let Some(i_meta) = meta.meta_item() {
548+
if ![
549+
sym::cfg,
550+
sym::hidden,
551+
sym::html_favicon_url,
552+
sym::html_logo_url,
553+
sym::html_no_source,
554+
sym::html_playground_url,
555+
sym::html_root_url,
556+
sym::include,
557+
sym::inline,
558+
sym::issue_tracker_base_url,
559+
sym::masked,
560+
sym::no_default_passes, // deprecated
561+
sym::no_inline,
562+
sym::passes, // deprecated
563+
sym::primitive,
564+
sym::spotlight,
565+
sym::test,
566+
]
567+
.iter()
568+
.any(|m| i_meta.has_name(*m))
569+
{
570+
self.tcx
571+
.sess
572+
.struct_span_err(
573+
meta.span(),
574+
&format!(
575+
"unknown `doc` attribute `{}`",
576+
i_meta.name_or_empty(),
577+
),
578+
)
579+
.emit();
580+
return false;
581+
}
547582
}
548583
}
549584
}

compiler/rustc_passes/src/liveness.rs

+66-43
Original file line numberDiff line numberDiff line change
@@ -1494,12 +1494,13 @@ impl<'tcx> Liveness<'_, 'tcx> {
14941494
// bindings, and we also consider the first pattern to be the "authoritative" set of ids.
14951495
// However, we should take the ids and spans of variables with the same name from the later
14961496
// patterns so the suggestions to prefix with underscores will apply to those too.
1497-
let mut vars: FxIndexMap<Symbol, (LiveNode, Variable, Vec<(HirId, Span)>)> = <_>::default();
1497+
let mut vars: FxIndexMap<Symbol, (LiveNode, Variable, Vec<(HirId, Span, Span)>)> =
1498+
<_>::default();
14981499

14991500
pat.each_binding(|_, hir_id, pat_sp, ident| {
15001501
let ln = entry_ln.unwrap_or_else(|| self.live_node(hir_id, pat_sp));
15011502
let var = self.variable(hir_id, ident.span);
1502-
let id_and_sp = (hir_id, pat_sp);
1503+
let id_and_sp = (hir_id, pat_sp, ident.span);
15031504
vars.entry(self.ir.variable_name(var))
15041505
.and_modify(|(.., hir_ids_and_spans)| hir_ids_and_spans.push(id_and_sp))
15051506
.or_insert_with(|| (ln, var, vec![id_and_sp]));
@@ -1508,15 +1509,21 @@ impl<'tcx> Liveness<'_, 'tcx> {
15081509
for (_, (ln, var, hir_ids_and_spans)) in vars {
15091510
if self.used_on_entry(ln, var) {
15101511
let id = hir_ids_and_spans[0].0;
1511-
let spans = hir_ids_and_spans.into_iter().map(|(_, sp)| sp).collect();
1512+
let spans =
1513+
hir_ids_and_spans.into_iter().map(|(_, _, ident_span)| ident_span).collect();
15121514
on_used_on_entry(spans, id, ln, var);
15131515
} else {
15141516
self.report_unused(hir_ids_and_spans, ln, var);
15151517
}
15161518
}
15171519
}
15181520

1519-
fn report_unused(&self, hir_ids_and_spans: Vec<(HirId, Span)>, ln: LiveNode, var: Variable) {
1521+
fn report_unused(
1522+
&self,
1523+
hir_ids_and_spans: Vec<(HirId, Span, Span)>,
1524+
ln: LiveNode,
1525+
var: Variable,
1526+
) {
15201527
let first_hir_id = hir_ids_and_spans[0].0;
15211528

15221529
if let Some(name) = self.should_warn(var).filter(|name| name != "self") {
@@ -1530,62 +1537,78 @@ impl<'tcx> Liveness<'_, 'tcx> {
15301537
self.ir.tcx.struct_span_lint_hir(
15311538
lint::builtin::UNUSED_VARIABLES,
15321539
first_hir_id,
1533-
hir_ids_and_spans.into_iter().map(|(_, sp)| sp).collect::<Vec<_>>(),
1540+
hir_ids_and_spans
1541+
.into_iter()
1542+
.map(|(_, _, ident_span)| ident_span)
1543+
.collect::<Vec<_>>(),
15341544
|lint| {
15351545
lint.build(&format!("variable `{}` is assigned to, but never used", name))
15361546
.note(&format!("consider using `_{}` instead", name))
15371547
.emit();
15381548
},
15391549
)
15401550
} else {
1541-
self.ir.tcx.struct_span_lint_hir(
1542-
lint::builtin::UNUSED_VARIABLES,
1543-
first_hir_id,
1544-
hir_ids_and_spans.iter().map(|(_, sp)| *sp).collect::<Vec<_>>(),
1545-
|lint| {
1546-
let mut err = lint.build(&format!("unused variable: `{}`", name));
1547-
1548-
let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
1549-
hir_ids_and_spans.into_iter().partition(|(hir_id, span)| {
1550-
let var = self.variable(*hir_id, *span);
1551-
self.ir.variable_is_shorthand(var)
1552-
});
1553-
1554-
let mut shorthands = shorthands
1555-
.into_iter()
1556-
.map(|(_, span)| (span, format!("{}: _", name)))
1557-
.collect::<Vec<_>>();
1558-
1559-
// If we have both shorthand and non-shorthand, prefer the "try ignoring
1560-
// the field" message, and suggest `_` for the non-shorthands. If we only
1561-
// have non-shorthand, then prefix with an underscore instead.
1562-
if !shorthands.is_empty() {
1563-
shorthands.extend(
1564-
non_shorthands
1565-
.into_iter()
1566-
.map(|(_, span)| (span, "_".to_string()))
1567-
.collect::<Vec<_>>(),
1568-
);
1551+
let (shorthands, non_shorthands): (Vec<_>, Vec<_>) =
1552+
hir_ids_and_spans.iter().copied().partition(|(hir_id, _, ident_span)| {
1553+
let var = self.variable(*hir_id, *ident_span);
1554+
self.ir.variable_is_shorthand(var)
1555+
});
15691556

1557+
// If we have both shorthand and non-shorthand, prefer the "try ignoring
1558+
// the field" message, and suggest `_` for the non-shorthands. If we only
1559+
// have non-shorthand, then prefix with an underscore instead.
1560+
if !shorthands.is_empty() {
1561+
let shorthands = shorthands
1562+
.into_iter()
1563+
.map(|(_, pat_span, _)| (pat_span, format!("{}: _", name)))
1564+
.chain(
1565+
non_shorthands
1566+
.into_iter()
1567+
.map(|(_, pat_span, _)| (pat_span, "_".to_string())),
1568+
)
1569+
.collect::<Vec<_>>();
1570+
1571+
self.ir.tcx.struct_span_lint_hir(
1572+
lint::builtin::UNUSED_VARIABLES,
1573+
first_hir_id,
1574+
hir_ids_and_spans
1575+
.iter()
1576+
.map(|(_, pat_span, _)| *pat_span)
1577+
.collect::<Vec<_>>(),
1578+
|lint| {
1579+
let mut err = lint.build(&format!("unused variable: `{}`", name));
15701580
err.multipart_suggestion(
15711581
"try ignoring the field",
15721582
shorthands,
15731583
Applicability::MachineApplicable,
15741584
);
1575-
} else {
1585+
err.emit()
1586+
},
1587+
);
1588+
} else {
1589+
let non_shorthands = non_shorthands
1590+
.into_iter()
1591+
.map(|(_, _, ident_span)| (ident_span, format!("_{}", name)))
1592+
.collect::<Vec<_>>();
1593+
1594+
self.ir.tcx.struct_span_lint_hir(
1595+
lint::builtin::UNUSED_VARIABLES,
1596+
first_hir_id,
1597+
hir_ids_and_spans
1598+
.iter()
1599+
.map(|(_, _, ident_span)| *ident_span)
1600+
.collect::<Vec<_>>(),
1601+
|lint| {
1602+
let mut err = lint.build(&format!("unused variable: `{}`", name));
15761603
err.multipart_suggestion(
15771604
"if this is intentional, prefix it with an underscore",
1578-
non_shorthands
1579-
.into_iter()
1580-
.map(|(_, span)| (span, format!("_{}", name)))
1581-
.collect::<Vec<_>>(),
1605+
non_shorthands,
15821606
Applicability::MachineApplicable,
15831607
);
1584-
}
1585-
1586-
err.emit()
1587-
},
1588-
);
1608+
err.emit()
1609+
},
1610+
);
1611+
}
15891612
}
15901613
}
15911614
}

library/core/src/num/dec2flt/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub const MIN_E: i16 = -305;
55
pub const MAX_E: i16 = 305;
66

77
#[rustfmt::skip]
8-
pub const POWERS: ([u64; 611], [i16; 611]) = (
8+
pub static POWERS: ([u64; 611], [i16; 611]) = (
99
[
1010
0xe0b62e2929aba83c,
1111
0x8c71dcd9ba0b4926,

library/std/src/os/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub use crate::sys::windows_ext as windows;
2323
pub mod linux;
2424

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

2829
// If we're not documenting libstd then we just expose the main modules as we otherwise would.

library/std/src/sys/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ cfg_if::cfg_if! {
111111
cfg_if::cfg_if! {
112112
if #[cfg(target_os = "wasi")] {
113113
// On WASI we'll document what's already available
114-
#[stable(feature = "rust1", since = "1.0.0")]
114+
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
115115
pub use self::ext as wasi_ext;
116116
} else if #[cfg(any(target_os = "hermit",
117117
target_arch = "wasm32",
@@ -125,6 +125,7 @@ cfg_if::cfg_if! {
125125
} else {
126126
// On other platforms like Windows document the bare bones of WASI
127127
#[path = "wasi/ext/mod.rs"]
128+
#[stable(feature = "wasi_ext_doc", since = "1.35.0")]
128129
pub mod wasi_ext;
129130
}
130131
}

src/etc/dec2flt_table.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def print_proper_powers():
113113
print()
114114
print("#[rustfmt::skip]")
115115
typ = "([u64; {0}], [i16; {0}])".format(len(powers))
116-
print("pub const POWERS: ", typ, " = (", sep='')
116+
print("pub static POWERS: ", typ, " = (", sep='')
117117
print(" [")
118118
for z in powers:
119119
print(" 0x{:x},".format(z.sig))

src/librustdoc/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ tempfile = "3"
1919
itertools = "0.9"
2020
regex = "1"
2121
rustdoc-json-types = { path = "../rustdoc-json-types" }
22+
tracing = "0.1"
23+
tracing-tree = "0.1.6"
24+
25+
[dependencies.tracing-subscriber]
26+
version = "0.2.13"
27+
default-features = false
28+
features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"]
2229

2330
[dev-dependencies]
2431
expect-test = "1.0"

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
2121
debug!("get_blanket_impls({:?})", ty);
2222
let mut impls = Vec::new();
2323
for &trait_def_id in self.cx.tcx.all_traits(LOCAL_CRATE).iter() {
24-
if !self.cx.renderinfo.access_levels.is_public(trait_def_id)
24+
if !self.cx.cache.access_levels.is_public(trait_def_id)
2525
|| self.cx.generated_synthetics.get(&(ty, trait_def_id)).is_some()
2626
{
2727
continue;

src/librustdoc/clean/inline.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_span::Span;
1717

1818
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind};
1919
use crate::core::DocContext;
20+
use crate::formats::item_type::ItemType;
2021

2122
use super::Clean;
2223

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

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

183184
if did.is_local() {
184-
cx.renderinfo.exact_paths.insert(did, fqn);
185+
cx.cache.exact_paths.insert(did, fqn);
185186
} else {
186-
cx.renderinfo.external_paths.insert(did, (fqn, kind));
187+
cx.cache.external_paths.insert(did, (fqn, ItemType::from(kind)));
187188
}
188189
}
189190

@@ -315,7 +316,7 @@ crate fn build_impl(
315316
attrs: Option<Attrs<'_>>,
316317
ret: &mut Vec<clean::Item>,
317318
) {
318-
if !cx.renderinfo.inlined.insert(did) {
319+
if !cx.inlined.insert(did) {
319320
return;
320321
}
321322

@@ -327,7 +328,7 @@ crate fn build_impl(
327328
if !did.is_local() {
328329
if let Some(traitref) = associated_trait {
329330
let did = traitref.def_id;
330-
if !cx.renderinfo.access_levels.is_public(did) {
331+
if !cx.cache.access_levels.is_public(did) {
331332
return;
332333
}
333334

@@ -359,7 +360,7 @@ crate fn build_impl(
359360
// reachable in rustdoc generated documentation
360361
if !did.is_local() {
361362
if let Some(did) = for_.def_id() {
362-
if !cx.renderinfo.access_levels.is_public(did) {
363+
if !cx.cache.access_levels.is_public(did) {
363364
return;
364365
}
365366

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
13041304
// Substitute private type aliases
13051305
if let Some(def_id) = def_id.as_local() {
13061306
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
1307-
if !cx.renderinfo.access_levels.is_exported(def_id.to_def_id()) {
1307+
if !cx.cache.access_levels.is_exported(def_id.to_def_id()) {
13081308
alias = Some(&cx.tcx.hir().expect_item(hir_id).kind);
13091309
}
13101310
}

src/librustdoc/clean/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ thread_local!(crate static MAX_DEF_IDX: RefCell<FxHashMap<CrateNum, DefIndex>> =
5050
#[derive(Clone, Debug)]
5151
crate struct Crate {
5252
crate name: Symbol,
53-
crate version: Option<String>,
5453
crate src: FileName,
5554
crate module: Option<Item>,
5655
crate externs: Vec<(CrateNum, ExternalCrate)>,

0 commit comments

Comments
 (0)