Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
long-long-float committed Mar 23, 2024
1 parent a0452d3 commit 67e91e9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 4 additions & 1 deletion compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,10 @@ impl<'hir> Generics<'hir> {
/// Returns bounds span for suggestions.
/// If the span including lifetime bound needs parentheses, it returns a span to the open parenthese at the second item.
/// e.g. `dyn Future<Output = ()> + 'static` needs parentheses `(dyn Future<Output = ()>) + 'static`
pub fn bounds_span_for_suggestions(&self, param_def_id: LocalDefId) -> Option<(Span, Option<Span>)> {
pub fn bounds_span_for_suggestions(
&self,
param_def_id: LocalDefId,
) -> Option<(Span, Option<Span>)> {
fn get_inner_ty<'a, 'b>(bound: &'a GenericBound<'b>) -> Option<&'a Ty<'b>> {
match bound {
GenericBound::Trait(data, _) => {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3278,7 +3278,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
param.name.ident(),
));
let bounds_span = ast_generics.bounds_span_for_suggestions(def_id);
if rcvr_ty.is_ref() && param.is_impl_trait() && let Some((bounds_span, _)) = bounds_span {
if rcvr_ty.is_ref()
&& param.is_impl_trait()
&& let Some((bounds_span, _)) = bounds_span
{
err.multipart_suggestions(
msg,
candidates.iter().map(|t| {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2402,8 +2402,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case.
let hir_generics = self.tcx.hir().get_generics(scope).unwrap();
let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id)
{
let sugg_span = match hir_generics.bounds_span_for_suggestions(def_id) {
Some((span, open_paren_sp)) => Some((span, true, open_paren_sp)),
// If `param` corresponds to `Self`, no usable suggestion span.
None if generics.has_self && param.index == 0 => None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2931,12 +2931,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
_ => {}
};
// Didn't add an indirection suggestion, so add a general suggestion to relax `Sized`.
let (span, separator) = if let Some((s, _)) = generics.bounds_span_for_suggestions(param.def_id)
{
(s, " +")
} else {
(param.name.ident().span.shrink_to_hi(), ":")
};
let (span, separator) =
if let Some((s, _)) = generics.bounds_span_for_suggestions(param.def_id) {
(s, " +")
} else {
(param.name.ident().span.shrink_to_hi(), ":")
};
err.span_suggestion_verbose(
span,
"consider relaxing the implicit `Sized` restriction",
Expand Down

0 comments on commit 67e91e9

Please sign in to comment.