Skip to content

rustdoc-json: Show implied outlives-bounds #142226

Open
@obi1kenobi

Description

@obi1kenobi

Implied bounds are a serious and underappreciated SemVer hazard:

  • They are public API, but not obvious nor written down explicitly in the location where they are public API.
  • They are "infectious", behaving similarly to auto-traits, and therefore able to cause a "spooky action at a distance" style of breakage.

Consider the following example:

pub fn example<'a, T>(value: Wrapper<'a, T>) {}

pub struct Wrapper<'a, T>(Inner<'a, T>);

struct Inner<'a, T>(&'a i64, T);

impl<'a, T> Wrapper<'a, T> { ... }

impl<'a, T> Inner<'a, T> { ... }

Noting that Inner is a private type, let's say it sees the following change:

- struct Inner<'a, T>(&'a i64, T);
+ struct Inner<'a, T: 'a>(&'a T);

The new T: 'a bound propagates in "infectious" fashion from Inner to Wrapper to example, causing breaking changes in the public API of both Wrapper and example.

Today, neither the HTML nor the JSON outputs of rustdoc show implicit bounds. Despite the breaking change, the rustdoc HTML and JSON outputs will be identical before and after this change, making it completely invisible to both consumers of the API and the maintainers who wish to not needlessly break their users.

The issue is not specific to "outlives" bounds — it also appears with T: ?Sized bounds and (I believe) any kind of trait or lifetime bound that is valid in Rust. This issue requests information on all kinds of implicit bounds.

cargo-semver-checks would like to be able to analyze changes to bounds and flag SemVer hazards. The lack of implicit bounds data means that we currently cannot do so in either direction:

  • We cannot see implicit bounds, so SemVer breakage caused by implicit bounds is invisible to us.
  • We cannot report breakage due to additions of an explicit bound, because the bound may have already been implied.
  • We cannot claim that the removal of an explicit bound in trait associated items is breaking, since (I believe) the bound may still be implied.

Exposing rustc's implicit bounds data in rustdoc JSON would resolve this problem for cargo-semver-checks. Unrelatedly, as a user of rustdoc HTML, I'd also love to see implicit bounds in HTML as well.

cc @aDotInTheVoid

@rustbot label A-rustdoc-json

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-implied-boundsArea: Implied bounds / inferred outlives-boundsA-lifetimesArea: Lifetimes / regionsA-rustdoc-jsonArea: Rustdoc JSON backendC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions