Skip to content

Commit 720ec68

Browse files
authored
Rollup merge of #71870 - ltratt:more_specific_type_name_doc, r=kennytm
Be slightly more precise about any::type_name()'s guarantees. The first commit in this PR rephrases the current documentation for `any::type_name()` to be a little more specific about the guarantees (or lack thereof) that this function makes. The second commit explicitly documents that lifetimes are currently not included in the output (since this bit me particularly hard recently).
2 parents 7893d9a + 003ed80 commit 720ec68

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/libcore/any.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,16 @@ impl TypeId {
446446
/// # Note
447447
///
448448
/// This is intended for diagnostic use. The exact contents and format of the
449-
/// string are not specified, other than being a best-effort description of the
450-
/// type. For example, `type_name::<Option<String>>()` could return the
451-
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
452-
/// `"foobar"`. In addition, the output may change between versions of the
453-
/// compiler.
449+
/// string returned are not specified, other than being a best-effort
450+
/// description of the type. For example, amongst the strings
451+
/// that `type_name::<Option<String>>()` might return are `"Option<String>"` and
452+
/// `"std::option::Option<std::string::String>"`.
454453
///
455-
/// The type name should not be considered a unique identifier of a type;
456-
/// multiple types may share the same type name.
454+
/// The returned string must not be considered to be a unique identifier of a
455+
/// type as multiple types may map to the same type name. Similarly, there is no
456+
/// guarantee that all parts of a type will appear in the returned string: for
457+
/// example, lifetime specifiers are currently not included. In addition, the
458+
/// output may change between versions of the compiler.
457459
///
458460
/// The current implementation uses the same infrastructure as compiler
459461
/// diagnostics and debuginfo, but this is not guaranteed.

0 commit comments

Comments
 (0)