1 use std::iter::ExactSizeIterator;
4 use rustc_ast::ast::{self, FnRetTy, Mutability};
5 use rustc_span::{symbol::kw, BytePos, Span};
7 use crate::config::lists::*;
8 use crate::config::{IndentStyle, TypeDensity, Version};
9 use crate::expr::{format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ExprType};
11 definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
13 use crate::macros::{rewrite_macro, MacroPosition};
15 use crate::pairs::{rewrite_pair, PairParts};
16 use crate::rewrite::{Rewrite, RewriteContext};
17 use crate::shape::Shape;
18 use crate::source_map::SpanUtils;
19 use crate::spanned::Spanned;
21 colon_spaces, extra_offset, first_line_width, format_extern, format_mutability,
22 last_line_extendable, last_line_width, mk_sp, rewrite_ident,
25 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
26 pub(crate) enum PathContext {
32 // Does not wrap on simple segments.
33 pub(crate) fn rewrite_path(
34 context: &RewriteContext<'_>,
35 path_context: PathContext,
36 qself: Option<&ast::QSelf>,
40 let skip_count = qself.map_or(0, |x| x.position);
42 let mut result = if path.is_global() && qself.is_none() && path_context != PathContext::Import {
48 let mut span_lo = path.span.lo();
50 if let Some(qself) = qself {
53 let fmt_ty = qself.ty.rewrite(context, shape)?;
54 result.push_str(&fmt_ty);
57 result.push_str(" as ");
58 if path.is_global() && path_context != PathContext::Import {
59 result.push_str("::");
63 let shape = shape.sub_width(3)?;
65 result = rewrite_path_segments(
68 path.segments.iter().take(skip_count),
76 result.push_str(">::");
77 span_lo = qself.ty.span.hi() + BytePos(1);
80 rewrite_path_segments(
83 path.segments.iter().skip(skip_count),
91 fn rewrite_path_segments<'a, I>(
92 path_context: PathContext,
97 context: &RewriteContext<'_>,
101 I: Iterator<Item = &'a ast::PathSegment>,
103 let mut first = true;
104 let shape = shape.visual_indent(0);
106 for segment in iter {
107 // Indicates a global path, shouldn't be rendered.
108 if segment.ident.name == kw::PathRoot {
114 buffer.push_str("::");
117 let extra_offset = extra_offset(&buffer, shape);
118 let new_shape = shape.shrink_left(extra_offset)?;
119 let segment_string = rewrite_segment(
128 buffer.push_str(&segment_string);
135 pub(crate) enum SegmentParam<'a> {
136 Const(&'a ast::AnonConst),
137 LifeTime(&'a ast::Lifetime),
139 Binding(&'a ast::AssocTyConstraint),
142 impl<'a> SegmentParam<'a> {
143 fn from_generic_arg(arg: &ast::GenericArg) -> SegmentParam<'_> {
145 ast::GenericArg::Lifetime(ref lt) => SegmentParam::LifeTime(lt),
146 ast::GenericArg::Type(ref ty) => SegmentParam::Type(ty),
147 ast::GenericArg::Const(const_) => SegmentParam::Const(const_),
152 impl<'a> Spanned for SegmentParam<'a> {
153 fn span(&self) -> Span {
155 SegmentParam::Const(const_) => const_.value.span,
156 SegmentParam::LifeTime(lt) => lt.ident.span,
157 SegmentParam::Type(ty) => ty.span,
158 SegmentParam::Binding(binding) => binding.span,
163 impl<'a> Rewrite for SegmentParam<'a> {
164 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
166 SegmentParam::Const(const_) => const_.rewrite(context, shape),
167 SegmentParam::LifeTime(lt) => lt.rewrite(context, shape),
168 SegmentParam::Type(ty) => ty.rewrite(context, shape),
169 SegmentParam::Binding(assoc_ty_constraint) => {
170 let mut result = match assoc_ty_constraint.kind {
171 ast::AssocTyConstraintKind::Bound { .. } => {
172 format!("{}: ", rewrite_ident(context, assoc_ty_constraint.ident))
174 ast::AssocTyConstraintKind::Equality { .. } => {
175 match context.config.type_punctuation_density() {
176 TypeDensity::Wide => {
177 format!("{} = ", rewrite_ident(context, assoc_ty_constraint.ident))
179 TypeDensity::Compressed => {
180 format!("{}=", rewrite_ident(context, assoc_ty_constraint.ident))
186 let budget = shape.width.checked_sub(result.len())?;
187 let rewrite = assoc_ty_constraint
189 .rewrite(context, Shape::legacy(budget, shape.indent + result.len()))?;
190 result.push_str(&rewrite);
197 impl Rewrite for ast::AssocTyConstraintKind {
198 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
200 ast::AssocTyConstraintKind::Equality { ty } => ty.rewrite(context, shape),
201 ast::AssocTyConstraintKind::Bound { bounds } => bounds.rewrite(context, shape),
206 // Formats a path segment. There are some hacks involved to correctly determine
207 // the segment's associated span since it's not part of the AST.
209 // The span_lo is assumed to be greater than the end of any previous segment's
210 // parameters and lesser or equal than the start of current segment.
212 // span_hi is assumed equal to the end of the entire path.
214 // When the segment contains a positive number of parameters, we update span_lo
215 // so that invariants described above will hold for the next segment.
217 path_context: PathContext,
218 segment: &ast::PathSegment,
219 span_lo: &mut BytePos,
221 context: &RewriteContext<'_>,
223 ) -> Option<String> {
224 let mut result = String::with_capacity(128);
225 result.push_str(rewrite_ident(context, segment.ident));
227 let ident_len = result.len();
228 let shape = if context.use_block_indent() {
229 shape.offset_left(ident_len)?
231 shape.shrink_left(ident_len)?
234 if let Some(ref args) = segment.args {
236 ast::GenericArgs::AngleBracketed(ref data) if !data.args.is_empty() => {
237 let param_list = data
241 ast::AngleBracketedArg::Arg(generic_arg) => {
242 SegmentParam::from_generic_arg(generic_arg)
244 ast::AngleBracketedArg::Constraint(constraint) => {
245 SegmentParam::Binding(constraint)
248 .collect::<Vec<_>>();
250 // HACK: squeeze out the span between the identifier and the parameters.
251 // The hack is requried so that we don't remove the separator inside macro calls.
252 // This does not work in the presence of comment, hoping that people are
253 // sane about where to put their comment.
254 let separator_snippet = context
255 .snippet(mk_sp(segment.ident.span.hi(), data.span.lo()))
257 let force_separator = context.inside_macro() && separator_snippet.starts_with("::");
258 let separator = if path_context == PathContext::Expr || force_separator {
263 result.push_str(separator);
265 let generics_str = overflow::rewrite_with_angle_brackets(
270 mk_sp(*span_lo, span_hi),
273 // Update position of last bracket.
276 .span_after(mk_sp(*span_lo, span_hi), "<");
278 result.push_str(&generics_str)
280 ast::GenericArgs::Parenthesized(ref data) => {
281 result.push_str(&format_function_type(
282 data.inputs.iter().map(|x| &**x),
297 fn format_function_type<'a, I>(
302 context: &RewriteContext<'_>,
306 I: ExactSizeIterator,
307 <I as Iterator>::Item: Deref,
308 <I::Item as Deref>::Target: Rewrite + Spanned + 'a,
310 debug!("format_function_type {:#?}", shape);
312 let ty_shape = match context.config.indent_style() {
314 IndentStyle::Block => shape.offset_left(4)?,
315 IndentStyle::Visual => shape.block_left(4)?,
317 let output = match *output {
318 FnRetTy::Ty(ref ty) => {
319 let type_str = ty.rewrite(context, ty_shape)?;
320 format!(" -> {}", type_str)
322 FnRetTy::Default(..) => String::new(),
325 let list_shape = if context.use_block_indent() {
327 shape.block().indent.block_indent(context.config),
332 let budget = shape.width.checked_sub(2)?;
334 let offset = shape.indent + 1;
335 Shape::legacy(budget, offset)
338 let is_inputs_empty = inputs.len() == 0;
339 let list_lo = context.snippet_provider.span_after(span, "(");
340 let (list_str, tactic) = if is_inputs_empty {
341 let tactic = get_tactics(&[], &output, shape);
342 let list_hi = context.snippet_provider.span_before(span, ")");
343 let comment = context
345 .span_to_snippet(mk_sp(list_lo, list_hi))?
347 let comment = if comment.starts_with("//") {
350 &list_shape.indent.to_string_with_newline(context.config),
352 &shape.block().indent.to_string_with_newline(context.config)
359 let items = itemize_list(
360 context.snippet_provider,
364 |arg| arg.span().lo(),
365 |arg| arg.span().hi(),
366 |arg| arg.rewrite(context, list_shape),
372 let item_vec: Vec<_> = items.collect();
373 let tactic = get_tactics(&item_vec, &output, shape);
374 let trailing_separator = if !context.use_block_indent() || variadic {
375 SeparatorTactic::Never
377 context.config.trailing_comma()
380 let fmt = ListFormatting::new(list_shape, context.config)
382 .trailing_separator(trailing_separator)
383 .ends_with_newline(tactic.ends_with_newline(context.config.indent_style()))
384 .preserve_newline(true);
385 (write_list(&item_vec, &fmt)?, tactic)
388 let args = if tactic == DefinitiveListTactic::Horizontal
389 || !context.use_block_indent()
392 format!("({})", list_str)
396 list_shape.indent.to_string_with_newline(context.config),
398 shape.block().indent.to_string_with_newline(context.config),
401 if output.is_empty() || last_line_width(&args) + first_line_width(&output) <= shape.width {
402 Some(format!("{}{}", args, output))
407 list_shape.indent.to_string(context.config),
413 fn type_bound_colon(context: &RewriteContext<'_>) -> &'static str {
414 colon_spaces(context.config)
417 // If the return type is multi-lined, then force to use multiple lines for
418 // arguments as well.
419 fn get_tactics(item_vec: &[ListItem], output: &str, shape: Shape) -> DefinitiveListTactic {
420 if output.contains('\n') {
421 DefinitiveListTactic::Vertical
425 ListTactic::HorizontalVertical,
427 // 2 is for the case of ',\n'
428 shape.width.saturating_sub(2 + output.len()),
433 impl Rewrite for ast::WherePredicate {
434 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
435 // FIXME: dead spans?
436 let result = match *self {
437 ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
438 ref bound_generic_params,
443 let type_str = bounded_ty.rewrite(context, shape)?;
444 let colon = type_bound_colon(context).trim_end();
445 let lhs = if let Some(lifetime_str) =
446 rewrite_lifetime_param(context, shape, bound_generic_params)
448 format!("for<{}> {}{}", lifetime_str, type_str, colon)
450 format!("{}{}", type_str, colon)
453 rewrite_assign_rhs(context, lhs, bounds, shape)?
455 ast::WherePredicate::RegionPredicate(ast::WhereRegionPredicate {
459 }) => rewrite_bounded_lifetime(lifetime, bounds, context, shape)?,
460 ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
465 let lhs_ty_str = lhs_ty.rewrite(context, shape).map(|lhs| lhs + " =")?;
466 rewrite_assign_rhs(context, lhs_ty_str, &**rhs_ty, shape)?
474 impl Rewrite for ast::GenericArg {
475 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
477 ast::GenericArg::Lifetime(ref lt) => lt.rewrite(context, shape),
478 ast::GenericArg::Type(ref ty) => ty.rewrite(context, shape),
479 ast::GenericArg::Const(ref const_) => const_.rewrite(context, shape),
484 fn rewrite_bounded_lifetime(
486 bounds: &[ast::GenericBound],
487 context: &RewriteContext<'_>,
489 ) -> Option<String> {
490 let result = lt.rewrite(context, shape)?;
492 if bounds.is_empty() {
495 let colon = type_bound_colon(context);
496 let overhead = last_line_width(&result) + colon.len();
497 let result = format!(
501 join_bounds(context, shape.sub_width(overhead)?, bounds, true)?
507 impl Rewrite for ast::AnonConst {
508 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
509 format_expr(&self.value, ExprType::SubExpression, context, shape)
513 impl Rewrite for ast::Lifetime {
514 fn rewrite(&self, context: &RewriteContext<'_>, _: Shape) -> Option<String> {
515 Some(rewrite_ident(context, self.ident).to_owned())
519 impl Rewrite for ast::GenericBound {
520 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
522 ast::GenericBound::Trait(ref poly_trait_ref, trait_bound_modifier) => {
523 let snippet = context.snippet(self.span());
524 let has_paren = snippet.starts_with('(') && snippet.ends_with(')');
525 let rewrite = match trait_bound_modifier {
526 ast::TraitBoundModifier::None => poly_trait_ref.rewrite(context, shape),
527 ast::TraitBoundModifier::Maybe => poly_trait_ref
528 .rewrite(context, shape.offset_left(1)?)
529 .map(|s| format!("?{}", s)),
530 ast::TraitBoundModifier::MaybeConst => poly_trait_ref
531 .rewrite(context, shape.offset_left(7)?)
532 .map(|s| format!("?const {}", s)),
533 ast::TraitBoundModifier::MaybeConstMaybe => poly_trait_ref
534 .rewrite(context, shape.offset_left(8)?)
535 .map(|s| format!("?const ?{}", s)),
537 rewrite.map(|s| if has_paren { format!("({})", s) } else { s })
539 ast::GenericBound::Outlives(ref lifetime) => lifetime.rewrite(context, shape),
544 impl Rewrite for ast::GenericBounds {
545 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
547 return Some(String::new());
550 join_bounds(context, shape, self, true)
554 impl Rewrite for ast::GenericParam {
555 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
556 let mut result = String::with_capacity(128);
557 // FIXME: If there are more than one attributes, this will force multiline.
558 match self.attrs.rewrite(context, shape) {
559 Some(ref rw) if !rw.is_empty() => result.push_str(&format!("{} ", rw)),
563 if let rustc_ast::ast::GenericParamKind::Const { ref ty } = &self.kind {
564 result.push_str("const ");
565 result.push_str(rewrite_ident(context, self.ident));
566 result.push_str(": ");
567 result.push_str(&ty.rewrite(context, shape)?);
569 result.push_str(rewrite_ident(context, self.ident));
572 if !self.bounds.is_empty() {
573 result.push_str(type_bound_colon(context));
574 result.push_str(&self.bounds.rewrite(context, shape)?)
576 if let ast::GenericParamKind::Type {
577 default: Some(ref def),
580 let eq_str = match context.config.type_punctuation_density() {
581 TypeDensity::Compressed => "=",
582 TypeDensity::Wide => " = ",
584 result.push_str(eq_str);
585 let budget = shape.width.checked_sub(result.len())?;
587 def.rewrite(context, Shape::legacy(budget, shape.indent + result.len()))?;
588 result.push_str(&rewrite);
595 impl Rewrite for ast::PolyTraitRef {
596 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
597 if let Some(lifetime_str) =
598 rewrite_lifetime_param(context, shape, &self.bound_generic_params)
600 // 6 is "for<> ".len()
601 let extra_offset = lifetime_str.len() + 6;
604 .rewrite(context, shape.offset_left(extra_offset)?)?;
606 Some(format!("for<{}> {}", lifetime_str, path_str))
608 self.trait_ref.rewrite(context, shape)
613 impl Rewrite for ast::TraitRef {
614 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
615 rewrite_path(context, PathContext::Type, None, &self.path, shape)
619 impl Rewrite for ast::Ty {
620 fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> {
622 ast::TyKind::TraitObject(ref bounds, tobj_syntax) => {
623 // we have to consider 'dyn' keyword is used or not!!!
624 let is_dyn = tobj_syntax == ast::TraitObjectSyntax::Dyn;
625 // 4 is length of 'dyn '
626 let shape = if is_dyn { shape.offset_left(4)? } else { shape };
627 let mut res = bounds.rewrite(context, shape)?;
628 // We may have falsely removed a trailing `+` inside macro call.
629 if context.inside_macro() && bounds.len() == 1 {
630 if context.snippet(self.span).ends_with('+') && !res.ends_with('+') {
635 Some(format!("dyn {}", res))
640 ast::TyKind::Ptr(ref mt) => {
641 let prefix = match mt.mutbl {
642 Mutability::Mut => "*mut ",
643 Mutability::Not => "*const ",
646 rewrite_unary_prefix(context, prefix, &*mt.ty, shape)
648 ast::TyKind::Rptr(ref lifetime, ref mt) => {
649 let mut_str = format_mutability(mt.mutbl);
650 let mut_len = mut_str.len();
651 Some(match *lifetime {
652 Some(ref lifetime) => {
653 let lt_budget = shape.width.checked_sub(2 + mut_len)?;
654 let lt_str = lifetime.rewrite(
656 Shape::legacy(lt_budget, shape.indent + 2 + mut_len),
658 let lt_len = lt_str.len();
659 let budget = shape.width.checked_sub(2 + mut_len + lt_len)?;
666 Shape::legacy(budget, shape.indent + 2 + mut_len + lt_len)
671 let budget = shape.width.checked_sub(1 + mut_len)?;
677 Shape::legacy(budget, shape.indent + 1 + mut_len)
683 // FIXME: we drop any comments here, even though it's a silly place to put
685 ast::TyKind::Paren(ref ty) => {
686 if context.config.version() == Version::One
687 || context.config.indent_style() == IndentStyle::Visual
689 let budget = shape.width.checked_sub(2)?;
691 .rewrite(context, Shape::legacy(budget, shape.indent + 1))
692 .map(|ty_str| format!("({})", ty_str));
696 if let Some(sh) = shape.sub_width(2) {
697 if let Some(ref s) = ty.rewrite(context, sh) {
698 if !s.contains('\n') {
699 return Some(format!("({})", s));
704 let indent_str = shape.indent.to_string_with_newline(context.config);
706 .block_indent(context.config.tab_spaces())
707 .with_max_width(context.config);
708 let rw = ty.rewrite(context, shape)?;
711 shape.to_string_with_newline(context.config),
716 ast::TyKind::Slice(ref ty) => {
717 let budget = shape.width.checked_sub(4)?;
718 ty.rewrite(context, Shape::legacy(budget, shape.indent + 1))
719 .map(|ty_str| format!("[{}]", ty_str))
721 ast::TyKind::Tup(ref items) => {
722 rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
724 ast::TyKind::Path(ref q_self, ref path) => {
725 rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape)
727 ast::TyKind::Array(ref ty, ref repeats) => rewrite_pair(
730 PairParts::new("[", "; ", "]"),
733 SeparatorPlace::Back,
735 ast::TyKind::Infer => {
736 if shape.width >= 1 {
742 ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape),
743 ast::TyKind::Never => Some(String::from("!")),
744 ast::TyKind::MacCall(ref mac) => {
745 rewrite_macro(mac, None, context, shape, MacroPosition::Expression)
747 ast::TyKind::ImplicitSelf => Some(String::from("")),
748 ast::TyKind::ImplTrait(_, ref it) => {
749 // Empty trait is not a parser error.
751 return Some("impl".to_owned());
753 let rw = if context.config.version() == Version::One {
754 it.rewrite(context, shape)
756 join_bounds(context, shape, it, false)
759 let space = if it_str.is_empty() { "" } else { " " };
760 format!("impl{}{}", space, it_str)
763 ast::TyKind::CVarArgs => Some("...".to_owned()),
764 ast::TyKind::Err | ast::TyKind::Typeof(..) => unreachable!(),
770 bare_fn: &ast::BareFnTy,
772 context: &RewriteContext<'_>,
774 ) -> Option<String> {
775 debug!("rewrite_bare_fn {:#?}", shape);
777 let mut result = String::with_capacity(128);
779 if let Some(ref lifetime_str) = rewrite_lifetime_param(context, shape, &bare_fn.generic_params)
781 result.push_str("for<");
782 // 6 = "for<> ".len(), 4 = "for<".
783 // This doesn't work out so nicely for multiline situation with lots of
784 // rightward drift. If that is a problem, we could use the list stuff.
785 result.push_str(lifetime_str);
786 result.push_str("> ");
789 result.push_str(crate::utils::format_unsafety(bare_fn.unsafety));
791 result.push_str(&format_extern(
793 context.config.force_explicit_abi(),
797 result.push_str("fn");
799 let func_ty_shape = if context.use_block_indent() {
800 shape.offset_left(result.len())?
802 shape.visual_indent(result.len()).sub_width(result.len())?
805 let rewrite = format_function_type(
806 bare_fn.decl.inputs.iter(),
807 &bare_fn.decl.output,
808 bare_fn.decl.c_variadic(),
814 result.push_str(&rewrite);
819 fn is_generic_bounds_in_order(generic_bounds: &[ast::GenericBound]) -> bool {
820 let is_trait = |b: &ast::GenericBound| match b {
821 ast::GenericBound::Outlives(..) => false,
822 ast::GenericBound::Trait(..) => true,
824 let is_lifetime = |b: &ast::GenericBound| !is_trait(b);
825 let last_trait_index = generic_bounds.iter().rposition(is_trait);
826 let first_lifetime_index = generic_bounds.iter().position(is_lifetime);
827 match (last_trait_index, first_lifetime_index) {
828 (Some(last_trait_index), Some(first_lifetime_index)) => {
829 last_trait_index < first_lifetime_index
836 context: &RewriteContext<'_>,
838 items: &[ast::GenericBound],
840 ) -> Option<String> {
841 debug_assert!(!items.is_empty());
843 // Try to join types in a single line
844 let joiner = match context.config.type_punctuation_density() {
845 TypeDensity::Compressed => "+",
846 TypeDensity::Wide => " + ",
848 let type_strs = items
850 .map(|item| item.rewrite(context, shape))
851 .collect::<Option<Vec<_>>>()?;
852 let result = type_strs.join(joiner);
853 if items.len() <= 1 || (!result.contains('\n') && result.len() <= shape.width) {
857 // We need to use multiple lines.
858 let (type_strs, offset) = if need_indent {
859 // Rewrite with additional indentation.
860 let nested_shape = shape
861 .block_indent(context.config.tab_spaces())
862 .with_max_width(context.config);
863 let type_strs = items
865 .map(|item| item.rewrite(context, nested_shape))
866 .collect::<Option<Vec<_>>>()?;
867 (type_strs, nested_shape.indent)
869 (type_strs, shape.indent)
872 let is_bound_extendable = |s: &str, b: &ast::GenericBound| match b {
873 ast::GenericBound::Outlives(..) => true,
874 ast::GenericBound::Trait(..) => last_line_extendable(s),
876 let mut result = String::with_capacity(128);
877 result.push_str(&type_strs[0]);
878 let mut can_be_put_on_the_same_line = is_bound_extendable(&result, &items[0]);
879 let generic_bounds_in_order = is_generic_bounds_in_order(items);
880 for (bound, bound_str) in items[1..].iter().zip(type_strs[1..].iter()) {
881 if generic_bounds_in_order && can_be_put_on_the_same_line {
882 result.push_str(joiner);
884 result.push_str(&offset.to_string_with_newline(context.config));
885 result.push_str("+ ");
887 result.push_str(bound_str);
888 can_be_put_on_the_same_line = is_bound_extendable(bound_str, bound);
894 pub(crate) fn can_be_overflowed_type(
895 context: &RewriteContext<'_>,
900 ast::TyKind::Tup(..) => context.use_block_indent() && len == 1,
901 ast::TyKind::Rptr(_, ref mutty) | ast::TyKind::Ptr(ref mutty) => {
902 can_be_overflowed_type(context, &*mutty.ty, len)
908 /// Returns `None` if there is no `LifetimeDef` in the given generic parameters.
909 fn rewrite_lifetime_param(
910 context: &RewriteContext<'_>,
912 generic_params: &[ast::GenericParam],
913 ) -> Option<String> {
914 let result = generic_params
916 .filter(|p| match p.kind {
917 ast::GenericParamKind::Lifetime => true,
920 .map(|lt| lt.rewrite(context, shape))
921 .collect::<Option<Vec<_>>>()?
923 if result.is_empty() {