Remove another kw::Empty use in rustdoc.
Again by using `Option<Symbol>` to represent "no name".
This commit is contained in:
parent
e53f2a01ce
commit
31320a925f
4 changed files with 31 additions and 23 deletions
|
|
@ -117,7 +117,14 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
|
|||
hir::ItemKind::Use(path, kind) => {
|
||||
let hir::UsePath { segments, span, .. } = *path;
|
||||
let path = hir::Path { segments, res: *res, span };
|
||||
clean_use_statement_inner(import, Some(name), &path, kind, cx, &mut Default::default())
|
||||
clean_use_statement_inner(
|
||||
import,
|
||||
Some(name),
|
||||
&path,
|
||||
kind,
|
||||
cx,
|
||||
&mut Default::default(),
|
||||
)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
|
|
@ -1071,10 +1078,10 @@ fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attrib
|
|||
..
|
||||
} = param
|
||||
{
|
||||
func.decl
|
||||
.inputs
|
||||
.values
|
||||
.insert(a.get() as _, Argument { name, type_: *ty, is_const: true });
|
||||
func.decl.inputs.values.insert(
|
||||
a.get() as _,
|
||||
Argument { name: Some(name), type_: *ty, is_const: true },
|
||||
);
|
||||
} else {
|
||||
panic!("unexpected non const in position {pos}");
|
||||
}
|
||||
|
|
@ -1131,9 +1138,9 @@ fn clean_args_from_types_and_names<'tcx>(
|
|||
// If at least one argument has a name, use `_` as the name of unnamed
|
||||
// arguments. Otherwise omit argument names.
|
||||
let default_name = if idents.iter().any(|ident| nonempty_name(ident).is_some()) {
|
||||
kw::Underscore
|
||||
Some(kw::Underscore)
|
||||
} else {
|
||||
kw::Empty
|
||||
None
|
||||
};
|
||||
|
||||
Arguments {
|
||||
|
|
@ -1142,7 +1149,7 @@ fn clean_args_from_types_and_names<'tcx>(
|
|||
.enumerate()
|
||||
.map(|(i, ty)| Argument {
|
||||
type_: clean_ty(ty, cx),
|
||||
name: idents.get(i).and_then(nonempty_name).unwrap_or(default_name),
|
||||
name: idents.get(i).and_then(nonempty_name).or(default_name),
|
||||
is_const: false,
|
||||
})
|
||||
.collect(),
|
||||
|
|
@ -1161,7 +1168,7 @@ fn clean_args_from_types_and_body_id<'tcx>(
|
|||
.iter()
|
||||
.zip(body.params)
|
||||
.map(|(ty, param)| Argument {
|
||||
name: name_from_pat(param.pat),
|
||||
name: Some(name_from_pat(param.pat)),
|
||||
type_: clean_ty(ty, cx),
|
||||
is_const: false,
|
||||
})
|
||||
|
|
@ -1217,11 +1224,11 @@ fn clean_poly_fn_sig<'tcx>(
|
|||
.iter()
|
||||
.map(|t| Argument {
|
||||
type_: clean_middle_ty(t.map_bound(|t| *t), cx, None, None),
|
||||
name: if let Some(Some(ident)) = names.next() {
|
||||
name: Some(if let Some(Some(ident)) = names.next() {
|
||||
ident.name
|
||||
} else {
|
||||
kw::Underscore
|
||||
},
|
||||
}),
|
||||
is_const: false,
|
||||
})
|
||||
.collect(),
|
||||
|
|
@ -2791,11 +2798,7 @@ fn clean_maybe_renamed_item<'tcx>(
|
|||
use hir::ItemKind;
|
||||
|
||||
let def_id = item.owner_id.to_def_id();
|
||||
let mut name = if renamed.is_some() {
|
||||
renamed
|
||||
} else {
|
||||
cx.tcx.hir_opt_name(item.hir_id())
|
||||
};
|
||||
let mut name = if renamed.is_some() { renamed } else { cx.tcx.hir_opt_name(item.hir_id()) };
|
||||
|
||||
cx.with_param_env(def_id, |cx| {
|
||||
let kind = match item.kind {
|
||||
|
|
|
|||
|
|
@ -1426,7 +1426,7 @@ pub(crate) struct Arguments {
|
|||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub(crate) struct Argument {
|
||||
pub(crate) type_: Type,
|
||||
pub(crate) name: Symbol,
|
||||
pub(crate) name: Option<Symbol>,
|
||||
/// This field is used to represent "const" arguments from the `rustc_legacy_const_generics`
|
||||
/// feature. More information in <https://github.com/rust-lang/rust/issues/83167>.
|
||||
pub(crate) is_const: bool,
|
||||
|
|
@ -1434,7 +1434,7 @@ pub(crate) struct Argument {
|
|||
|
||||
impl Argument {
|
||||
pub(crate) fn to_receiver(&self) -> Option<&Type> {
|
||||
if self.name == kw::SelfLower { Some(&self.type_) } else { None }
|
||||
if self.name == Some(kw::SelfLower) { Some(&self.type_) } else { None }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1238,8 +1238,8 @@ impl clean::Arguments {
|
|||
.iter()
|
||||
.map(|input| {
|
||||
fmt::from_fn(|f| {
|
||||
if !input.name.is_empty() {
|
||||
write!(f, "{}: ", input.name)?;
|
||||
if let Some(name) = input.name {
|
||||
write!(f, "{}: ", name)?;
|
||||
}
|
||||
input.type_.print(cx).fmt(f)
|
||||
})
|
||||
|
|
@ -1361,7 +1361,9 @@ impl clean::FnDecl {
|
|||
if input.is_const {
|
||||
write!(f, "const ")?;
|
||||
}
|
||||
write!(f, "{}: ", input.name)?;
|
||||
if let Some(name) = input.name {
|
||||
write!(f, "{}: ", name)?;
|
||||
}
|
||||
input.type_.print(cx).fmt(f)?;
|
||||
}
|
||||
match (line_wrapping_indent, last_input_index) {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use rustc_hir::def::CtorKind;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_metadata::rendered_const;
|
||||
use rustc_middle::{bug, ty};
|
||||
use rustc_span::{Pos, Symbol};
|
||||
use rustc_span::{Pos, Symbol, kw};
|
||||
use rustdoc_json_types::*;
|
||||
|
||||
use crate::clean::{self, ItemId};
|
||||
|
|
@ -611,7 +611,10 @@ impl FromClean<clean::FnDecl> for FunctionSignature {
|
|||
inputs: inputs
|
||||
.values
|
||||
.into_iter()
|
||||
.map(|arg| (arg.name.to_string(), arg.type_.into_json(renderer)))
|
||||
// `_` is the most sensible name for missing param names.
|
||||
.map(|arg| {
|
||||
(arg.name.unwrap_or(kw::Underscore).to_string(), arg.type_.into_json(renderer))
|
||||
})
|
||||
.collect(),
|
||||
output: if output.is_unit() { None } else { Some(output.into_json(renderer)) },
|
||||
is_c_variadic: c_variadic,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue