diff options
| author | bors <bors@rust-lang.org> | 2023-08-31 06:20:39 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-08-31 06:20:39 +0000 |
| commit | 2518c0ffeb112b5ecf409c5ea7825b46bb3db8ec (patch) | |
| tree | c5f0f668af52a644dad21229e18c952893832fb1 /compiler/rustc_parse/src/parser/ty.rs | |
| parent | d9c11c65ee93b6dfd0c71f17812c68d316fce183 (diff) | |
| parent | f57b41519dc3bd863650114c344e8e7db7a1cc2d (diff) | |
| download | rust-2518c0ffeb112b5ecf409c5ea7825b46bb3db8ec.tar.gz rust-2518c0ffeb112b5ecf409c5ea7825b46bb3db8ec.zip | |
Auto merge of #3044 - rust-lang:rustup-2023-08-31, r=RalfJung
Automatic sync from rustc
Diffstat (limited to 'compiler/rustc_parse/src/parser/ty.rs')
| -rw-r--r-- | compiler/rustc_parse/src/parser/ty.rs | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 661113666cd..a25b0f1f893 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -891,18 +891,32 @@ impl<'a> Parser<'a> { // that we do not use the try operator when parsing the type because // if it fails then we get a parser error which we don't want (we're trying // to recover from errors, not make more). - let path = if self.may_recover() - && matches!(ty.kind, TyKind::Ptr(..) | TyKind::Ref(..)) - && let TyKind::Path(_, path) = &ty.peel_refs().kind { - // Just get the indirection part of the type. - let span = ty.span.until(path.span); - - err.span_suggestion_verbose( - span, - "consider removing the indirection", - "", - Applicability::MaybeIncorrect, - ); + let path = if self.may_recover() { + let (span, message, sugg, path, applicability) = match &ty.kind { + TyKind::Ptr(..) | TyKind::Ref(..) if let TyKind::Path(_, path) = &ty.peel_refs().kind => { + ( + ty.span.until(path.span), + "consider removing the indirection", + "", + path, + Applicability::MaybeIncorrect + ) + } + TyKind::ImplTrait(_, bounds) + if let [GenericBound::Trait(tr, ..), ..] = bounds.as_slice() => + { + ( + ty.span.until(tr.span), + "use the trait bounds directly", + "", + &tr.trait_ref.path, + Applicability::MachineApplicable + ) + } + _ => return Err(err) + }; + + err.span_suggestion_verbose(span, message, sugg, applicability); path.clone() } else { |
