@@ -2086,12 +2086,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20862086 span : Span ,
20872087 rbp : RelaxedBoundPolicy < ' _ > ,
20882088 ) {
2089- // Even though feature `more_maybe_bounds` bypasses the given policy and (currently) enables
2090- // relaxed bounds in every conceivable position[^1], we don't want to advertise it to the user
2091- // (via a feature gate) since it's super internal. Besides this, it'd be quite distracting .
2089+ // Even though feature `more_maybe_bounds` enables the user to relax all default bounds
2090+ // other than `Sized` in a lot more positions (thereby bypassing the given policy), we don't
2091+ // want to advertise it to the user (via a feature gate error ) since it's super internal.
20922092 //
2093- // [^1]: Strictly speaking, this is incorrect (at the very least for `Sized`) because it's
2094- // no longer fully consistent with default trait elaboration in HIR ty lowering.
2093+ // FIXME(more_maybe_bounds): Moreover, if we actually were to add proper default traits
2094+ // (like a hypothetical `Move` or `Leak`) we would want to validate the location according
2095+ // to default trait elaboration in HIR ty lowering (which depends on the specific trait in
2096+ // question: E.g., `?Sized` & `?Move` most likely won't be allowed in all the same places).
20952097
20962098 match rbp {
20972099 RelaxedBoundPolicy :: Allowed => return ,
@@ -2105,17 +2107,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
21052107 }
21062108 RelaxedBoundPolicy :: Forbidden ( reason) => {
21072109 let gate = |context, subject| {
2108- if self . tcx . features ( ) . more_maybe_bounds ( ) {
2110+ let extended = self . tcx . features ( ) . more_maybe_bounds ( ) ;
2111+ let is_sized = trait_ref
2112+ . trait_def_id ( )
2113+ . is_some_and ( |def_id| self . tcx . is_lang_item ( def_id, hir:: LangItem :: Sized ) ) ;
2114+
2115+ if extended && !is_sized {
21092116 return ;
21102117 }
21112118
2119+ let prefix = if extended { "`Sized` " } else { "" } ;
21122120 let mut diag = self . dcx ( ) . struct_span_err (
21132121 span,
2114- format ! ( "relaxed bounds are not permitted in {context}" ) ,
2122+ format ! ( "relaxed {prefix} bounds are not permitted in {context}" ) ,
21152123 ) ;
2116- if let Some ( def_id) = trait_ref. trait_def_id ( )
2117- && self . tcx . is_lang_item ( def_id, hir:: LangItem :: Sized )
2118- {
2124+ if is_sized {
21192125 diag. note ( format ! (
21202126 "{subject} are not implicitly bounded by `Sized`, \
21212127 so there is nothing to relax"
0 commit comments