Skip to content

Commit 952c573

Browse files
committed
Auto merge of #85258 - GuillaumeGomez:rollup-kzay7o5, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - #85068 (Fix diagnostic for cross crate private tuple struct constructors) - #85175 (Rustdoc cleanup) - #85177 (add BITS associated constant to core::num::Wrapping) - #85240 (Don't suggest adding `'static` lifetime to arguments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d2df620 + 3761ada commit 952c573

27 files changed

+258
-329
lines changed

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
114114
);
115115

116116
diag.span_label(span, format!("lifetime `{}` required", named));
117-
diag.span_suggestion(
118-
new_ty_span,
119-
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
120-
new_ty.to_string(),
121-
Applicability::Unspecified,
122-
);
117+
// Suggesting `'static` is nearly always incorrect, and can steer users
118+
// down the wrong path.
119+
if *named != ty::ReStatic {
120+
diag.span_suggestion(
121+
new_ty_span,
122+
&format!("add explicit lifetime `{}` to {}", named, span_label_var),
123+
new_ty.to_string(),
124+
Applicability::Unspecified,
125+
);
126+
}
123127

124128
Some(diag)
125129
}

compiler/rustc_metadata/src/rmeta/decoder.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
2727
use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState};
2828
use rustc_middle::mir::{self, Body, Promoted};
2929
use rustc_middle::ty::codec::TyDecoder;
30-
use rustc_middle::ty::{self, Ty, TyCtxt};
30+
use rustc_middle::ty::{self, Ty, TyCtxt, Visibility};
3131
use rustc_serialize::{opaque, Decodable, Decoder};
3232
use rustc_session::Session;
3333
use rustc_span::hygiene::ExpnDataDecodeMode;
@@ -1312,6 +1312,17 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13121312
.collect()
13131313
}
13141314

1315+
fn get_struct_field_visibilities(&self, id: DefIndex) -> Vec<Visibility> {
1316+
self.root
1317+
.tables
1318+
.children
1319+
.get(self, id)
1320+
.unwrap_or_else(Lazy::empty)
1321+
.decode(self)
1322+
.map(|field_index| self.get_visibility(field_index))
1323+
.collect()
1324+
}
1325+
13151326
fn get_inherent_implementations_for_type(
13161327
&self,
13171328
tcx: TyCtxt<'tcx>,

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
88
use rustc_data_structures::stable_map::FxHashMap;
99
use rustc_data_structures::svh::Svh;
1010
use rustc_hir as hir;
11-
use rustc_hir::def::DefKind;
11+
use rustc_hir::def::{CtorKind, DefKind};
1212
use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
1313
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash};
1414
use rustc_middle::hir::exports::Export;
@@ -17,7 +17,7 @@ use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata};
1717
use rustc_middle::middle::exported_symbols::ExportedSymbol;
1818
use rustc_middle::middle::stability::DeprecationEntry;
1919
use rustc_middle::ty::query::Providers;
20-
use rustc_middle::ty::{self, TyCtxt};
20+
use rustc_middle::ty::{self, TyCtxt, Visibility};
2121
use rustc_session::utils::NativeLibKind;
2222
use rustc_session::{CrateDisambiguator, Session};
2323
use rustc_span::source_map::{Span, Spanned};
@@ -392,6 +392,20 @@ impl CStore {
392392
self.get_crate_data(def.krate).get_struct_field_names(def.index, sess)
393393
}
394394

395+
pub fn struct_field_visibilities_untracked(&self, def: DefId) -> Vec<Visibility> {
396+
self.get_crate_data(def.krate).get_struct_field_visibilities(def.index)
397+
}
398+
399+
pub fn ctor_def_id_and_kind_untracked(&self, def: DefId) -> Option<(DefId, CtorKind)> {
400+
self.get_crate_data(def.krate).get_ctor_def_id(def.index).map(|ctor_def_id| {
401+
(ctor_def_id, self.get_crate_data(def.krate).get_ctor_kind(def.index))
402+
})
403+
}
404+
405+
pub fn visibility_untracked(&self, def: DefId) -> Visibility {
406+
self.get_crate_data(def.krate).get_visibility(def.index)
407+
}
408+
395409
pub fn item_children_untracked(
396410
&self,
397411
def_id: DefId,

compiler/rustc_resolve/src/build_reduced_graph.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,20 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
995995
// Record some extra data for better diagnostics.
996996
let cstore = self.r.cstore();
997997
match res {
998-
Res::Def(DefKind::Struct | DefKind::Union, def_id) => {
998+
Res::Def(DefKind::Struct, def_id) => {
999+
let field_names = cstore.struct_field_names_untracked(def_id, self.r.session);
1000+
let ctor = cstore.ctor_def_id_and_kind_untracked(def_id);
1001+
if let Some((ctor_def_id, ctor_kind)) = ctor {
1002+
let ctor_res = Res::Def(DefKind::Ctor(CtorOf::Struct, ctor_kind), ctor_def_id);
1003+
let ctor_vis = cstore.visibility_untracked(ctor_def_id);
1004+
let field_visibilities = cstore.struct_field_visibilities_untracked(def_id);
1005+
self.r
1006+
.struct_constructors
1007+
.insert(def_id, (ctor_res, ctor_vis, field_visibilities));
1008+
}
1009+
self.insert_field_names(def_id, field_names);
1010+
}
1011+
Res::Def(DefKind::Union, def_id) => {
9991012
let field_names = cstore.struct_field_names_untracked(def_id, self.r.session);
10001013
self.insert_field_names(def_id, field_names);
10011014
}
@@ -1007,12 +1020,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10071020
self.r.has_self.insert(def_id);
10081021
}
10091022
}
1010-
Res::Def(DefKind::Ctor(CtorOf::Struct, ..), def_id) => {
1011-
let parent = cstore.def_key(def_id).parent;
1012-
if let Some(struct_def_id) = parent.map(|index| DefId { index, ..def_id }) {
1013-
self.r.struct_constructors.insert(struct_def_id, (res, vis, vec![]));
1014-
}
1015-
}
10161023
_ => {}
10171024
}
10181025
}

library/core/src/num/wrapping.rs

+15
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ macro_rules! wrapping_int_impl {
433433
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
434434
pub const MAX: Self = Self(<$t>::MAX);
435435

436+
/// Returns the size of this integer type in bits.
437+
///
438+
/// # Examples
439+
///
440+
/// Basic usage:
441+
///
442+
/// ```
443+
/// #![feature(wrapping_int_impl)]
444+
/// use std::num::Wrapping;
445+
///
446+
#[doc = concat!("assert_eq!(<Wrapping<", stringify!($t), ">>::BITS, ", stringify!($t), "::BITS);")]
447+
/// ```
448+
#[unstable(feature = "wrapping_int_impl", issue = "32463")]
449+
pub const BITS: u32 = <$t>::BITS;
450+
436451
/// Returns the number of ones in the binary representation of `self`.
437452
///
438453
/// # Examples

src/librustdoc/html/render/print_item.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -573,10 +573,6 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
573573
)
574574
}
575575

576-
fn write_loading_content(w: &mut Buffer, extra_content: &str) {
577-
write!(w, "{}<span class=\"loading-content\">Loading content...</span>", extra_content)
578-
}
579-
580576
fn trait_item(w: &mut Buffer, cx: &Context<'_>, m: &clean::Item, t: &clean::Item) {
581577
let name = m.name.as_ref().unwrap();
582578
info!("Documenting {} on {:?}", name, t.name);
@@ -601,7 +597,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
601597
for t in types {
602598
trait_item(w, cx, t, it);
603599
}
604-
write_loading_content(w, "</div>");
600+
w.write_str("</div>");
605601
}
606602

607603
if !consts.is_empty() {
@@ -614,7 +610,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
614610
for t in consts {
615611
trait_item(w, cx, t, it);
616612
}
617-
write_loading_content(w, "</div>");
613+
w.write_str("</div>");
618614
}
619615

620616
// Output the documentation for each function individually
@@ -628,7 +624,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
628624
for m in required {
629625
trait_item(w, cx, m, it);
630626
}
631-
write_loading_content(w, "</div>");
627+
w.write_str("</div>");
632628
}
633629
if !provided.is_empty() {
634630
write_small_section_header(
@@ -640,7 +636,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
640636
for m in provided {
641637
trait_item(w, cx, m, it);
642638
}
643-
write_loading_content(w, "</div>");
639+
w.write_str("</div>");
644640
}
645641

646642
// If there are methods directly on this trait object, render them here.
@@ -703,7 +699,6 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
703699
&[],
704700
);
705701
}
706-
write_loading_content(w, "");
707702
}
708703

709704
write_small_section_header(
@@ -715,7 +710,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
715710
for implementor in concrete {
716711
render_implementor(cx, implementor, it, w, &implementor_dups, &[]);
717712
}
718-
write_loading_content(w, "</div>");
713+
w.write_str("</div>");
719714

720715
if t.is_auto {
721716
write_small_section_header(
@@ -734,7 +729,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
734729
&collect_paths_for_type(implementor.inner_impl().for_.clone(), &cx.cache),
735730
);
736731
}
737-
write_loading_content(w, "</div>");
732+
w.write_str("</div>");
738733
}
739734
} else {
740735
// even without any implementations to write in, we still want the heading and list, so the
@@ -743,18 +738,16 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
743738
w,
744739
"implementors",
745740
"Implementors",
746-
"<div class=\"item-list\" id=\"implementors-list\">",
741+
"<div class=\"item-list\" id=\"implementors-list\"></div>",
747742
);
748-
write_loading_content(w, "</div>");
749743

750744
if t.is_auto {
751745
write_small_section_header(
752746
w,
753747
"synthetic-implementors",
754748
"Auto implementors",
755-
"<div class=\"item-list\" id=\"synthetic-implementors-list\">",
749+
"<div class=\"item-list\" id=\"synthetic-implementors-list\"></div>",
756750
);
757-
write_loading_content(w, "</div>");
758751
}
759752
}
760753

0 commit comments

Comments
 (0)