Skip to content

Commit 84abaf3

Browse files
committed
Auto merge of rust-lang#92664 - ehuss:rollup-t9yrvk5, r=ehuss
Rollup of 8 pull requests Successful merges: - rust-lang#84640 (Implement `TryFrom<char>` for `u8`) - rust-lang#92336 (Remove &self from PrintState::to_string) - rust-lang#92375 (Consolidate checking for msvc when generating debuginfo) - rust-lang#92568 (Add note about non_exhaustive to variant_count) - rust-lang#92600 (Add some missing `#[must_use]` to some `f{32,64}` operations) - rust-lang#92610 (Create CSS class instead of using inline style for search results) - rust-lang#92632 (Implement stabilization of `#[feature(available_parallelism)]`) - rust-lang#92650 (Fix typo in `StableCrateId` docs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e012a19 + 05cfc4f commit 84abaf3

File tree

15 files changed

+142
-95
lines changed

15 files changed

+142
-95
lines changed

compiler/rustc_ast_pretty/src/pprust/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ pub fn attribute_to_string(attr: &ast::Attribute) -> String {
7373
}
7474

7575
pub fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
76-
State::new().to_string(f)
76+
State::to_string(f)
7777
}
7878

7979
pub fn crate_to_string_for_macros(krate: &ast::Crate) -> String {
80-
State::new().to_string(|s| {
80+
State::to_string(|s| {
8181
s.print_inner_attributes(&krate.attrs);
8282
for item in &krate.items {
8383
s.print_item(item);

compiler/rustc_ast_pretty/src/pprust/state.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ pub fn literal_to_string(lit: token::Lit) -> String {
211211
}
212212

213213
fn visibility_qualified(vis: &ast::Visibility, s: &str) -> String {
214-
format!("{}{}", State::new().to_string(|s| s.print_visibility(vis)), s)
214+
format!("{}{}", State::to_string(|s| s.print_visibility(vis)), s)
215215
}
216216

217217
impl std::ops::Deref for State<'_> {
@@ -793,55 +793,55 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
793793
}
794794

795795
fn ty_to_string(&self, ty: &ast::Ty) -> String {
796-
self.to_string(|s| s.print_type(ty))
796+
Self::to_string(|s| s.print_type(ty))
797797
}
798798

799799
fn bounds_to_string(&self, bounds: &[ast::GenericBound]) -> String {
800-
self.to_string(|s| s.print_type_bounds("", bounds))
800+
Self::to_string(|s| s.print_type_bounds("", bounds))
801801
}
802802

803803
fn pat_to_string(&self, pat: &ast::Pat) -> String {
804-
self.to_string(|s| s.print_pat(pat))
804+
Self::to_string(|s| s.print_pat(pat))
805805
}
806806

807807
fn expr_to_string(&self, e: &ast::Expr) -> String {
808-
self.to_string(|s| s.print_expr(e))
808+
Self::to_string(|s| s.print_expr(e))
809809
}
810810

811811
fn tt_to_string(&self, tt: &TokenTree) -> String {
812-
self.to_string(|s| s.print_tt(tt, false))
812+
Self::to_string(|s| s.print_tt(tt, false))
813813
}
814814

815815
fn tts_to_string(&self, tokens: &TokenStream) -> String {
816-
self.to_string(|s| s.print_tts(tokens, false))
816+
Self::to_string(|s| s.print_tts(tokens, false))
817817
}
818818

819819
fn stmt_to_string(&self, stmt: &ast::Stmt) -> String {
820-
self.to_string(|s| s.print_stmt(stmt))
820+
Self::to_string(|s| s.print_stmt(stmt))
821821
}
822822

823823
fn item_to_string(&self, i: &ast::Item) -> String {
824-
self.to_string(|s| s.print_item(i))
824+
Self::to_string(|s| s.print_item(i))
825825
}
826826

827827
fn generic_params_to_string(&self, generic_params: &[ast::GenericParam]) -> String {
828-
self.to_string(|s| s.print_generic_params(generic_params))
828+
Self::to_string(|s| s.print_generic_params(generic_params))
829829
}
830830

831831
fn path_to_string(&self, p: &ast::Path) -> String {
832-
self.to_string(|s| s.print_path(p, false, 0))
832+
Self::to_string(|s| s.print_path(p, false, 0))
833833
}
834834

835835
fn path_segment_to_string(&self, p: &ast::PathSegment) -> String {
836-
self.to_string(|s| s.print_path_segment(p, false))
836+
Self::to_string(|s| s.print_path_segment(p, false))
837837
}
838838

839839
fn vis_to_string(&self, v: &ast::Visibility) -> String {
840-
self.to_string(|s| s.print_visibility(v))
840+
Self::to_string(|s| s.print_visibility(v))
841841
}
842842

843843
fn block_to_string(&self, blk: &ast::Block) -> String {
844-
self.to_string(|s| {
844+
Self::to_string(|s| {
845845
// Containing cbox, will be closed by `print_block` at `}`.
846846
s.cbox(INDENT_UNIT);
847847
// Head-ibox, will be closed by `print_block` after `{`.
@@ -851,22 +851,22 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
851851
}
852852

853853
fn meta_list_item_to_string(&self, li: &ast::NestedMetaItem) -> String {
854-
self.to_string(|s| s.print_meta_list_item(li))
854+
Self::to_string(|s| s.print_meta_list_item(li))
855855
}
856856

857857
fn attr_item_to_string(&self, ai: &ast::AttrItem) -> String {
858-
self.to_string(|s| s.print_attr_item(ai, ai.path.span))
858+
Self::to_string(|s| s.print_attr_item(ai, ai.path.span))
859859
}
860860

861861
fn attribute_to_string(&self, attr: &ast::Attribute) -> String {
862-
self.to_string(|s| s.print_attribute(attr))
862+
Self::to_string(|s| s.print_attribute(attr))
863863
}
864864

865865
fn param_to_string(&self, arg: &ast::Param) -> String {
866-
self.to_string(|s| s.print_param(arg, false))
866+
Self::to_string(|s| s.print_param(arg, false))
867867
}
868868

869-
fn to_string(&self, f: impl FnOnce(&mut State<'_>)) -> String {
869+
fn to_string(f: impl FnOnce(&mut State<'_>)) -> String {
870870
let mut printer = State::new();
871871
f(&mut printer);
872872
printer.s.eof()
@@ -1202,7 +1202,7 @@ impl<'a> State<'a> {
12021202
);
12031203
}
12041204
ast::ItemKind::Mod(unsafety, ref mod_kind) => {
1205-
self.head(self.to_string(|s| {
1205+
self.head(Self::to_string(|s| {
12061206
s.print_visibility(&item.vis);
12071207
s.print_unsafety(unsafety);
12081208
s.word("mod");
@@ -1228,7 +1228,7 @@ impl<'a> State<'a> {
12281228
}
12291229
}
12301230
ast::ItemKind::ForeignMod(ref nmod) => {
1231-
self.head(self.to_string(|s| {
1231+
self.head(Self::to_string(|s| {
12321232
s.print_unsafety(nmod.unsafety);
12331233
s.word("extern");
12341234
}));
@@ -1450,7 +1450,7 @@ impl<'a> State<'a> {
14501450
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
14511451
},
14521452
ast::VisibilityKind::Restricted { ref path, .. } => {
1453-
let path = self.to_string(|s| s.print_path(path, false, 0));
1453+
let path = Self::to_string(|s| s.print_path(path, false, 0));
14541454
if path == "self" || path == "super" {
14551455
self.word_nbsp(format!("pub({})", path))
14561456
} else {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::llvm::debuginfo::{
1818
use crate::value::Value;
1919

2020
use cstr::cstr;
21+
use rustc_codegen_ssa::debuginfo::type_names::cpp_like_debuginfo;
2122
use rustc_codegen_ssa::traits::*;
2223
use rustc_data_structures::fingerprint::Fingerprint;
2324
use rustc_data_structures::fx::FxHashMap;
@@ -933,16 +934,16 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l
933934

934935
// When targeting MSVC, emit MSVC style type names for compatibility with
935936
// .natvis visualizers (and perhaps other existing native debuggers?)
936-
let msvc_like_names = cx.tcx.sess.target.is_like_msvc;
937+
let cpp_like_debuginfo = cpp_like_debuginfo(cx.tcx);
937938

938939
let (name, encoding) = match t.kind() {
939940
ty::Never => ("!", DW_ATE_unsigned),
940941
ty::Tuple(elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
941942
ty::Bool => ("bool", DW_ATE_boolean),
942943
ty::Char => ("char", DW_ATE_unsigned_char),
943-
ty::Int(int_ty) if msvc_like_names => (int_ty.msvc_basic_name(), DW_ATE_signed),
944-
ty::Uint(uint_ty) if msvc_like_names => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
945-
ty::Float(float_ty) if msvc_like_names => (float_ty.msvc_basic_name(), DW_ATE_float),
944+
ty::Int(int_ty) if cpp_like_debuginfo => (int_ty.msvc_basic_name(), DW_ATE_signed),
945+
ty::Uint(uint_ty) if cpp_like_debuginfo => (uint_ty.msvc_basic_name(), DW_ATE_unsigned),
946+
ty::Float(float_ty) if cpp_like_debuginfo => (float_ty.msvc_basic_name(), DW_ATE_float),
946947
ty::Int(int_ty) => (int_ty.name_str(), DW_ATE_signed),
947948
ty::Uint(uint_ty) => (uint_ty.name_str(), DW_ATE_unsigned),
948949
ty::Float(float_ty) => (float_ty.name_str(), DW_ATE_float),
@@ -959,7 +960,7 @@ fn basic_type_metadata<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'l
959960
)
960961
};
961962

962-
if !msvc_like_names {
963+
if !cpp_like_debuginfo {
963964
return ty_metadata;
964965
}
965966

@@ -1525,13 +1526,6 @@ fn prepare_union_metadata<'ll, 'tcx>(
15251526
// Enums
15261527
//=-----------------------------------------------------------------------------
15271528

1528-
/// DWARF variant support is only available starting in LLVM 8, but
1529-
/// on MSVC we have to use the fallback mode, because LLVM doesn't
1530-
/// lower variant parts to PDB.
1531-
fn use_enum_fallback(cx: &CodegenCx<'_, '_>) -> bool {
1532-
cx.sess().target.is_like_msvc
1533-
}
1534-
15351529
// FIXME(eddyb) maybe precompute this? Right now it's computed once
15361530
// per generator monomorphization, but it doesn't depend on substs.
15371531
fn generator_layout_and_saved_local_names<'tcx>(
@@ -1606,7 +1600,10 @@ impl<'ll, 'tcx> EnumMemberDescriptionFactory<'ll, 'tcx> {
16061600
_ => bug!(),
16071601
};
16081602

1609-
let fallback = use_enum_fallback(cx);
1603+
// While LLVM supports generating debuginfo for variant types (enums), it doesn't support
1604+
// lowering that debuginfo to CodeView records for msvc targets. So if we are targeting
1605+
// msvc, then we need to use a different, fallback encoding of the debuginfo.
1606+
let fallback = cpp_like_debuginfo(cx.tcx);
16101607
// This will always find the metadata in the type map.
16111608
let self_metadata = type_metadata(cx, self.enum_type, self.span);
16121609

@@ -2159,7 +2156,10 @@ fn prepare_enum_metadata<'ll, 'tcx>(
21592156
return FinalMetadata(discriminant_type_metadata(tag.value));
21602157
}
21612158

2162-
if use_enum_fallback(cx) {
2159+
// While LLVM supports generating debuginfo for variant types (enums), it doesn't support
2160+
// lowering that debuginfo to CodeView records for msvc targets. So if we are targeting
2161+
// msvc, then we need to use a different encoding of the debuginfo.
2162+
if cpp_like_debuginfo(tcx) {
21632163
let discriminant_type_metadata = match layout.variants {
21642164
Variants::Single { .. } => None,
21652165
Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. }

0 commit comments

Comments
 (0)