Skip to content

Commit 1c7a6db

Browse files
committed
Add docs to NoBoundsException
1 parent 9d7c394 commit 1c7a6db

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

compiler/rustc_lint/src/unused.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,8 +1039,25 @@ pub(crate) struct UnusedParens {
10391039
in_no_bounds_pos: FxHashMap<ast::NodeId, NoBoundsException>,
10401040
}
10411041

1042+
/// Whether parentheses may be omitted from a type without resulting in ambiguity.
1043+
///
1044+
/// ```
1045+
/// type Example = Box<dyn Fn() -> &'static (dyn Trait) + Send>
1046+
/// ```
1047+
///
1048+
/// Here, `&'static (dyn Trait) + Send` is a `TypeNoBounds`. As such, it may not directly
1049+
/// contain `ImplTraitType` or `TraitObjectType` which is why `(dyn Trait)` is parenthesized.
1050+
/// However, an exception is made for `ImplTraitTypeOneBound` and `TraitObjectTypeOneBound`.
1051+
/// The following is accepted because there is no `+`.
1052+
///
1053+
/// ```
1054+
/// type Example = Box<dyn Fn() -> &'static dyn Trait>
1055+
/// ```
10421056
enum NoBoundsException {
1057+
/// The type must be parenthesized.
10431058
None,
1059+
/// The type is the last bound of the containing type expression. If it has exactly one bound,
1060+
/// parentheses around the type are unnecessary.
10441061
OneBound,
10451062
}
10461063

0 commit comments

Comments
 (0)