1
Fork 0

Auto merge of #76934 - camelid:rustdoc-allow-generic-params, r=jyn514

Allow generic parameters in intra-doc links

Fixes #62834.

---

The contents of the generics will be mostly ignored (except for warning
if fully-qualified syntax is used, which is currently unsupported in
intra-doc links - see issue #74563).

* Allow links like `Vec<T>`, `Result<T, E>`, and `Option<Box<T>>`
* Allow links like `Vec::<T>::new()`
* Warn on
  * Unbalanced angle brackets (e.g. `Vec<T` or `Vec<T>>`)
  * Missing type to apply generics to (`<T>` or `<Box<T>>`)
  * Use of fully-qualified syntax (`<Vec as IntoIterator>::into_iter`)
  * Invalid path separator (`Vec:<T>:new`)
  * Too many angle brackets (`Vec<<T>>`)
  * Empty angle brackets (`Vec<>`)

Note that this implementation *does* allow some constructs that aren't
valid in the actual Rust syntax, for example `Box::<T>new()`. That may
not be supported in rustdoc in the future; it is an implementation
detail.
This commit is contained in:
bors 2020-10-10 21:19:50 +00:00
commit b1af43bc63
12 changed files with 441 additions and 20 deletions

View file

@ -92,7 +92,7 @@ rustc_queries! {
/// Computes the `DefId` of the corresponding const parameter in case the `key` is a
/// const argument and returns `None` otherwise.
///
/// ```rust
/// ```ignore (incomplete)
/// let a = foo::<7>();
/// // ^ Calling `opt_const_param_of` for this argument,
///
@ -162,10 +162,12 @@ rustc_queries! {
/// Specifically this is the bounds written on the trait's type
/// definition, or those after the `impl` keyword
///
/// ```ignore (incomplete)
/// type X: Bound + 'lt
/// ^^^^^^^^^^^
/// // ^^^^^^^^^^^
/// impl Debug + Display
/// ^^^^^^^^^^^^^^^
/// // ^^^^^^^^^^^^^^^
/// ```
///
/// `key` is the `DefId` of the associated type or opaque type.
///
@ -176,18 +178,22 @@ rustc_queries! {
/// Elaborated version of the predicates from `explicit_item_bounds`.
///
/// Example for
/// For example:
///
/// ```
/// trait MyTrait {
/// type MyAType: Eq + ?Sized`
/// type MyAType: Eq + ?Sized;
/// }
/// ```
///
/// `explicit_item_bounds` returns `[<Self as MyTrait>::MyAType: Eq]`,
/// and `item_bounds` returns
/// ```text
/// [
/// <Self as Trait>::MyAType: Eq,
/// <Self as Trait>::MyAType: PartialEq<<Self as Trait>::MyAType>
/// ]
/// ```
///
/// Bounds from the parent (e.g. with nested impl trait) are not included.
query item_bounds(key: DefId) -> &'tcx ty::List<ty::Predicate<'tcx>> {