Skip to content

Fix outdated doc comment #144838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1534,10 +1534,10 @@ impl Type {
matches!(self, Type::Path { path: Path { res: Res::Def(DefKind::TyAlias, _), .. } })
}

/// Check if two types are "the same" for documentation purposes.
/// Check if this type is a subtype of another type for documentation purposes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like the current behavior of the function is closer to checking if another type is a subtype of this type (this was the argument flipping I mentioned in the original issue).

Maybe my intuition is backwards, so I would wait for a second opinion before renaming the function or anything, but at the very least it should at least have a not of how generics are handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that function is working exactly like self.is_doc_subtype_of(other) and example in doc comment showing it

let generic = Type::Generic(rustc_span::symbol::sym::Any);
let unit = Type::Primitive(PrimitiveType::Unit);
assert!(unit.is_doc_subtype_of(&generic, &cache));

it reads like "unit is subtype of generic" which is true, or am I missing something?

///
/// This is different from `Eq`, because it knows that things like
/// `Placeholder` are possible matches for everything.
/// `Infer` and generics have special subtyping rules.
///
/// This relation is not commutative when generics are involved:
///
Expand All @@ -1548,8 +1548,8 @@ impl Type {
/// let cache = Cache::new(false);
/// let generic = Type::Generic(rustc_span::symbol::sym::Any);
/// let unit = Type::Primitive(PrimitiveType::Unit);
/// assert!(!generic.is_same(&unit, &cache));
/// assert!(unit.is_same(&generic, &cache));
/// assert!(!generic.is_doc_subtype_of(&unit, &cache));
/// assert!(unit.is_doc_subtype_of(&generic, &cache));
/// ```
///
/// An owned type is also the same as its borrowed variants (this is commutative),
Expand Down
Loading