Skip to content

Commit 40a331d

Browse files
authored
Unrolled build for rust-lang#139846
Rollup merge of rust-lang#139846 - nnethercote:kw-Empty-rustdoc, r=GuillaumeGomez Remove `kw::Empty` uses in rustdoc Helps with rust-lang#137978. r? ``@GuillaumeGomez``
2 parents 3920514 + 65942d1 commit 40a331d

File tree

8 files changed

+63
-46
lines changed

8 files changed

+63
-46
lines changed

Diff for: src/librustdoc/clean/mod.rs

+32-26
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,22 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
117117
hir::ItemKind::Use(path, kind) => {
118118
let hir::UsePath { segments, span, .. } = *path;
119119
let path = hir::Path { segments, res: *res, span };
120-
clean_use_statement_inner(import, name, &path, kind, cx, &mut Default::default())
120+
clean_use_statement_inner(
121+
import,
122+
Some(name),
123+
&path,
124+
kind,
125+
cx,
126+
&mut Default::default(),
127+
)
121128
}
122129
_ => unreachable!(),
123130
}
124131
}));
125132
items.extend(doc.items.values().flat_map(|(item, renamed, _)| {
126133
// Now we actually lower the imports, skipping everything else.
127134
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
128-
let name = renamed.unwrap_or(kw::Empty); // using kw::Empty is a bit of a hack
129-
clean_use_statement(item, name, path, hir::UseKind::Glob, cx, &mut inserted)
135+
clean_use_statement(item, *renamed, path, hir::UseKind::Glob, cx, &mut inserted)
130136
} else {
131137
// skip everything else
132138
Vec::new()
@@ -1072,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
10721078
..
10731079
} = param
10741080
{
1075-
func.decl
1076-
.inputs
1077-
.values
1078-
.insert(a.get() as _, Argument { name, type_: *ty, is_const: true });
1081+
func.decl.inputs.values.insert(
1082+
a.get() as _,
1083+
Argument { name: Some(name), type_: *ty, is_const: true },
1084+
);
10791085
} else {
10801086
panic!("unexpected non const in position {pos}");
10811087
}
@@ -1132,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
11321138
// If at least one argument has a name, use `_` as the name of unnamed
11331139
// arguments. Otherwise omit argument names.
11341140
let default_name = if idents.iter().any(|ident| nonempty_name(ident).is_some()) {
1135-
kw::Underscore
1141+
Some(kw::Underscore)
11361142
} else {
1137-
kw::Empty
1143+
None
11381144
};
11391145

11401146
Arguments {
@@ -1143,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
11431149
.enumerate()
11441150
.map(|(i, ty)| Argument {
11451151
type_: clean_ty(ty, cx),
1146-
name: idents.get(i).and_then(nonempty_name).unwrap_or(default_name),
1152+
name: idents.get(i).and_then(nonempty_name).or(default_name),
11471153
is_const: false,
11481154
})
11491155
.collect(),
@@ -1162,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
11621168
.iter()
11631169
.zip(body.params)
11641170
.map(|(ty, param)| Argument {
1165-
name: name_from_pat(param.pat),
1171+
name: Some(name_from_pat(param.pat)),
11661172
type_: clean_ty(ty, cx),
11671173
is_const: false,
11681174
})
@@ -1218,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
12181224
.iter()
12191225
.map(|t| Argument {
12201226
type_: clean_middle_ty(t.map_bound(|t| *t), cx, None, None),
1221-
name: if let Some(Some(ident)) = names.next() {
1227+
name: Some(if let Some(Some(ident)) = names.next() {
12221228
ident.name
12231229
} else {
12241230
kw::Underscore
1225-
},
1231+
}),
12261232
is_const: false,
12271233
})
12281234
.collect(),
@@ -2792,10 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
27922798
use hir::ItemKind;
27932799

27942800
let def_id = item.owner_id.to_def_id();
2795-
let mut name = renamed.unwrap_or_else(|| {
2796-
// FIXME: using kw::Empty is a bit of a hack
2797-
cx.tcx.hir_opt_name(item.hir_id()).unwrap_or(kw::Empty)
2798-
});
2801+
let mut name = if renamed.is_some() { renamed } else { cx.tcx.hir_opt_name(item.hir_id()) };
27992802

28002803
cx.with_param_env(def_id, |cx| {
28012804
let kind = match item.kind {
@@ -2836,7 +2839,7 @@ fn clean_maybe_renamed_item<'tcx>(
28362839
item_type: Some(type_),
28372840
})),
28382841
item.owner_id.def_id.to_def_id(),
2839-
name,
2842+
name.unwrap(),
28402843
import_id,
28412844
renamed,
28422845
));
@@ -2861,13 +2864,15 @@ fn clean_maybe_renamed_item<'tcx>(
28612864
}),
28622865
ItemKind::Impl(impl_) => return clean_impl(impl_, item.owner_id.def_id, cx),
28632866
ItemKind::Macro(_, macro_def, MacroKind::Bang) => MacroItem(Macro {
2864-
source: display_macro_source(cx, name, macro_def),
2867+
source: display_macro_source(cx, name.unwrap(), macro_def),
28652868
macro_rules: macro_def.macro_rules,
28662869
}),
2867-
ItemKind::Macro(_, _, macro_kind) => clean_proc_macro(item, &mut name, macro_kind, cx),
2870+
ItemKind::Macro(_, _, macro_kind) => {
2871+
clean_proc_macro(item, name.as_mut().unwrap(), macro_kind, cx)
2872+
}
28682873
// proc macros can have a name set by attributes
28692874
ItemKind::Fn { ref sig, generics, body: body_id, .. } => {
2870-
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
2875+
clean_fn_or_proc_macro(item, sig, generics, body_id, name.as_mut().unwrap(), cx)
28712876
}
28722877
ItemKind::Trait(_, _, _, generics, bounds, item_ids) => {
28732878
let items = item_ids
@@ -2883,7 +2888,7 @@ fn clean_maybe_renamed_item<'tcx>(
28832888
}))
28842889
}
28852890
ItemKind::ExternCrate(orig_name, _) => {
2886-
return clean_extern_crate(item, name, orig_name, cx);
2891+
return clean_extern_crate(item, name.unwrap(), orig_name, cx);
28872892
}
28882893
ItemKind::Use(path, kind) => {
28892894
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
@@ -2895,7 +2900,7 @@ fn clean_maybe_renamed_item<'tcx>(
28952900
cx,
28962901
kind,
28972902
item.owner_id.def_id.to_def_id(),
2898-
name,
2903+
name.unwrap(),
28992904
import_id,
29002905
renamed,
29012906
)]
@@ -3006,7 +3011,7 @@ fn clean_extern_crate<'tcx>(
30063011

30073012
fn clean_use_statement<'tcx>(
30083013
import: &hir::Item<'tcx>,
3009-
name: Symbol,
3014+
name: Option<Symbol>,
30103015
path: &hir::UsePath<'tcx>,
30113016
kind: hir::UseKind,
30123017
cx: &mut DocContext<'tcx>,
@@ -3023,7 +3028,7 @@ fn clean_use_statement<'tcx>(
30233028

30243029
fn clean_use_statement_inner<'tcx>(
30253030
import: &hir::Item<'tcx>,
3026-
name: Symbol,
3031+
name: Option<Symbol>,
30273032
path: &hir::Path<'tcx>,
30283033
kind: hir::UseKind,
30293034
cx: &mut DocContext<'tcx>,
@@ -3042,7 +3047,7 @@ fn clean_use_statement_inner<'tcx>(
30423047
let visibility = cx.tcx.visibility(import.owner_id);
30433048
let attrs = cx.tcx.hir_attrs(import.hir_id());
30443049
let inline_attr = hir_attr_lists(attrs, sym::doc).get_word_attr(sym::inline);
3045-
let pub_underscore = visibility.is_public() && name == kw::Underscore;
3050+
let pub_underscore = visibility.is_public() && name == Some(kw::Underscore);
30463051
let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
30473052
let import_def_id = import.owner_id.def_id;
30483053

@@ -3108,6 +3113,7 @@ fn clean_use_statement_inner<'tcx>(
31083113
}
31093114
Import::new_glob(resolve_use_source(cx, path), true)
31103115
} else {
3116+
let name = name.unwrap();
31113117
if inline_attr.is_none()
31123118
&& let Res::Def(DefKind::Mod, did) = path.res
31133119
&& !did.is_local()

Diff for: src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1426,15 +1426,15 @@ pub(crate) struct Arguments {
14261426
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
14271427
pub(crate) struct Argument {
14281428
pub(crate) type_: Type,
1429-
pub(crate) name: Symbol,
1429+
pub(crate) name: Option<Symbol>,
14301430
/// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
14311431
/// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
14321432
pub(crate) is_const: bool,
14331433
}
14341434

14351435
impl Argument {
14361436
pub(crate) fn to_receiver(&self) -> Option<&Type> {
1437-
if self.name == kw::SelfLower { Some(&self.type_) } else { None }
1437+
if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
14381438
}
14391439
}
14401440

Diff for: src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ pub(super) fn clean_middle_path<'tcx>(
234234
args: ty::Binder<'tcx, GenericArgsRef<'tcx>>,
235235
) -> Path {
236236
let def_kind = cx.tcx.def_kind(did);
237-
let name = cx.tcx.opt_item_name(did).unwrap_or(kw::Empty);
237+
let name = cx.tcx.opt_item_name(did).unwrap_or(sym::dummy);
238238
Path {
239239
res: Res::Def(def_kind, did),
240240
segments: thin_vec![PathSegment {

Diff for: src/librustdoc/html/format.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ impl clean::Arguments {
12411241
.iter()
12421242
.map(|input| {
12431243
fmt::from_fn(|f| {
1244-
if !input.name.is_empty() {
1245-
write!(f, "{}: ", input.name)?;
1244+
if let Some(name) = input.name {
1245+
write!(f, "{}: ", name)?;
12461246
}
12471247
input.type_.print(cx).fmt(f)
12481248
})
@@ -1364,7 +1364,9 @@ impl clean::FnDecl {
13641364
if input.is_const {
13651365
write!(f, "const ")?;
13661366
}
1367-
write!(f, "{}: ", input.name)?;
1367+
if let Some(name) = input.name {
1368+
write!(f, "{}: ", name)?;
1369+
}
13681370
input.type_.print(cx).fmt(f)?;
13691371
}
13701372
match (line_wrapping_indent, last_input_index) {

Diff for: src/librustdoc/html/render/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub(crate) struct IndexItemFunctionType {
223223
inputs: Vec<RenderType>,
224224
output: Vec<RenderType>,
225225
where_clause: Vec<Vec<RenderType>>,
226-
param_names: Vec<Symbol>,
226+
param_names: Vec<Option<Symbol>>,
227227
}
228228

229229
impl IndexItemFunctionType {

Diff for: src/librustdoc/html/render/print_item.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def_id::DefId;
1111
use rustc_index::IndexVec;
1212
use rustc_middle::ty::{self, TyCtxt};
1313
use rustc_span::hygiene::MacroKind;
14-
use rustc_span::symbol::{Symbol, kw, sym};
14+
use rustc_span::symbol::{Symbol, sym};
1515
use tracing::{debug, info};
1616

1717
use super::type_layout::document_type_layout;
@@ -347,9 +347,12 @@ fn item_module(cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) -> i
347347
// but we actually want stable items to come first
348348
return is_stable2.cmp(&is_stable1);
349349
}
350-
let lhs = i1.name.unwrap_or(kw::Empty);
351-
let rhs = i2.name.unwrap_or(kw::Empty);
352-
compare_names(lhs.as_str(), rhs.as_str())
350+
match (i1.name, i2.name) {
351+
(Some(name1), Some(name2)) => compare_names(name1.as_str(), name2.as_str()),
352+
(Some(_), None) => Ordering::Greater,
353+
(None, Some(_)) => Ordering::Less,
354+
(None, None) => Ordering::Equal,
355+
}
353356
}
354357

355358
let tcx = cx.tcx();

Diff for: src/librustdoc/html/render/search_index.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,11 @@ pub(crate) fn build_index(
709709
let mut result = Vec::new();
710710
for (index, item) in self.items.iter().enumerate() {
711711
if let Some(ty) = &item.search_type
712-
&& let my =
713-
ty.param_names.iter().map(|sym| sym.as_str()).collect::<Vec<_>>()
712+
&& let my = ty
713+
.param_names
714+
.iter()
715+
.filter_map(|sym| sym.map(|sym| sym.to_string()))
716+
.collect::<Vec<_>>()
714717
&& my != prev
715718
{
716719
result.push((index, my.join(",")));
@@ -1372,7 +1375,7 @@ fn simplify_fn_constraint<'a>(
13721375
/// Used to allow type-based search on constants and statics.
13731376
fn make_nullary_fn(
13741377
clean_type: &clean::Type,
1375-
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Symbol>, Vec<Vec<RenderType>>) {
1378+
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Option<Symbol>>, Vec<Vec<RenderType>>) {
13761379
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
13771380
let output = get_index_type(clean_type, vec![], &mut rgen);
13781381
(vec![], vec![output], vec![], vec![])
@@ -1387,7 +1390,7 @@ fn get_fn_inputs_and_outputs(
13871390
tcx: TyCtxt<'_>,
13881391
impl_or_trait_generics: Option<&(clean::Type, clean::Generics)>,
13891392
cache: &Cache,
1390-
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Symbol>, Vec<Vec<RenderType>>) {
1393+
) -> (Vec<RenderType>, Vec<RenderType>, Vec<Option<Symbol>>, Vec<Vec<RenderType>>) {
13911394
let decl = &func.decl;
13921395

13931396
let mut rgen: FxIndexMap<SimplifiedParam, (isize, Vec<RenderType>)> = Default::default();
@@ -1441,10 +1444,10 @@ fn get_fn_inputs_and_outputs(
14411444
simplified_params
14421445
.iter()
14431446
.map(|(name, (_idx, _traits))| match name {
1444-
SimplifiedParam::Symbol(name) => *name,
1445-
SimplifiedParam::Anonymous(_) => kw::Empty,
1447+
SimplifiedParam::Symbol(name) => Some(*name),
1448+
SimplifiedParam::Anonymous(_) => None,
14461449
SimplifiedParam::AssociatedType(def_id, name) => {
1447-
Symbol::intern(&format!("{}::{}", tcx.item_name(*def_id), name))
1450+
Some(Symbol::intern(&format!("{}::{}", tcx.item_name(*def_id), name)))
14481451
}
14491452
})
14501453
.collect(),

Diff for: src/librustdoc/json/conversions.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_hir::def::CtorKind;
1111
use rustc_hir::def_id::DefId;
1212
use rustc_metadata::rendered_const;
1313
use rustc_middle::{bug, ty};
14-
use rustc_span::{Pos, Symbol};
14+
use rustc_span::{Pos, Symbol, kw};
1515
use rustdoc_json_types::*;
1616

1717
use crate::clean::{self, ItemId};
@@ -611,7 +611,10 @@ impl FromClean<clean::FnDecl> for FunctionSignature {
611611
inputs: inputs
612612
.values
613613
.into_iter()
614-
.map(|arg| (arg.name.to_string(), arg.type_.into_json(renderer)))
614+
// `_` is the most sensible name for missing param names.
615+
.map(|arg| {
616+
(arg.name.unwrap_or(kw::Underscore).to_string(), arg.type_.into_json(renderer))
617+
})
615618
.collect(),
616619
output: if output.is_unit() { None } else { Some(output.into_json(renderer)) },
617620
is_c_variadic: c_variadic,

0 commit comments

Comments
 (0)