summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_infer/src/errors
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:32 +0000
commit4547b622d8d29df964fa2914213088b148c498fc (patch)
tree9fc6b25f3c3add6b745be9a2400a6e96140046e9 /compiler/rustc_infer/src/errors
parentReleasing progress-linux version 1.66.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-4547b622d8d29df964fa2914213088b148c498fc.tar.xz
rustc-4547b622d8d29df964fa2914213088b148c498fc.zip
Merging upstream version 1.67.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_infer/src/errors')
-rw-r--r--compiler/rustc_infer/src/errors/mod.rs51
-rw-r--r--compiler/rustc_infer/src/errors/note_and_explain.rs7
2 files changed, 39 insertions, 19 deletions
diff --git a/compiler/rustc_infer/src/errors/mod.rs b/compiler/rustc_infer/src/errors/mod.rs
index 2131d1906..74c4c65cc 100644
--- a/compiler/rustc_infer/src/errors/mod.rs
+++ b/compiler/rustc_infer/src/errors/mod.rs
@@ -109,8 +109,9 @@ pub struct InferenceBadError<'a> {
#[derive(Subdiagnostic)]
pub enum SourceKindSubdiag<'a> {
- #[suggestion_verbose(
+ #[suggestion(
infer_source_kind_subdiag_let,
+ style = "verbose",
code = ": {type_name}",
applicability = "has-placeholders"
)]
@@ -135,8 +136,9 @@ pub enum SourceKindSubdiag<'a> {
parent_prefix: String,
parent_name: String,
},
- #[suggestion_verbose(
+ #[suggestion(
infer_source_kind_subdiag_generic_suggestion,
+ style = "verbose",
code = "::<{args}>",
applicability = "has-placeholders"
)]
@@ -150,8 +152,9 @@ pub enum SourceKindSubdiag<'a> {
#[derive(Subdiagnostic)]
pub enum SourceKindMultiSuggestion<'a> {
- #[multipart_suggestion_verbose(
+ #[multipart_suggestion(
infer_source_kind_fully_qualified,
+ style = "verbose",
applicability = "has-placeholders"
)]
FullyQualified {
@@ -163,8 +166,9 @@ pub enum SourceKindMultiSuggestion<'a> {
adjustment: &'a str,
successor_pos: &'a str,
},
- #[multipart_suggestion_verbose(
+ #[multipart_suggestion(
infer_source_kind_closure_return,
+ style = "verbose",
applicability = "has-placeholders"
)]
ClosureReturn {
@@ -176,6 +180,18 @@ pub enum SourceKindMultiSuggestion<'a> {
},
}
+#[derive(Subdiagnostic)]
+#[suggestion(
+ infer_suggest_add_let_for_letchains,
+ style = "verbose",
+ applicability = "machine-applicable",
+ code = "let "
+)]
+pub(crate) struct SuggAddLetForLetChains {
+ #[primary_span]
+ pub span: Span,
+}
+
impl<'a> SourceKindMultiSuggestion<'a> {
pub fn new_fully_qualified(
span: Span,
@@ -359,7 +375,7 @@ impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
return false;
};
- if !lifetime_sub.name.is_anonymous() || !lifetime_sup.name.is_anonymous() {
+ if !lifetime_sub.is_anonymous() || !lifetime_sup.is_anonymous() {
return false;
};
@@ -391,20 +407,20 @@ impl AddToDiagnostic for AddLifetimeParamsSuggestion<'_> {
let suggestion_param_name =
suggestion_param_name.map(|n| n.to_string()).unwrap_or_else(|| "'a".to_owned());
- debug!(?lifetime_sup.span);
- debug!(?lifetime_sub.span);
- let make_suggestion = |span: rustc_span::Span| {
- if span.is_empty() {
- (span, format!("{}, ", suggestion_param_name))
- } else if let Ok("&") = self.tcx.sess.source_map().span_to_snippet(span).as_deref()
- {
- (span.shrink_to_hi(), format!("{} ", suggestion_param_name))
+ debug!(?lifetime_sup.ident.span);
+ debug!(?lifetime_sub.ident.span);
+ let make_suggestion = |ident: Ident| {
+ let sugg = if ident.name == kw::Empty {
+ format!("{}, ", suggestion_param_name)
+ } else if ident.name == kw::UnderscoreLifetime && ident.span.is_empty() {
+ format!("{} ", suggestion_param_name)
} else {
- (span, suggestion_param_name.clone())
- }
+ suggestion_param_name.clone()
+ };
+ (ident.span, sugg)
};
let mut suggestions =
- vec![make_suggestion(lifetime_sub.span), make_suggestion(lifetime_sup.span)];
+ vec![make_suggestion(lifetime_sub.ident), make_suggestion(lifetime_sup.ident)];
if introduce_new {
let new_param_suggestion = if let Some(first) =
@@ -478,8 +494,9 @@ pub enum ImplicitStaticLifetimeSubdiag {
#[primary_span]
span: Span,
},
- #[suggestion_verbose(
+ #[suggestion(
infer_implicit_static_lifetime_suggestion,
+ style = "verbose",
code = " + '_",
applicability = "maybe-incorrect"
)]
diff --git a/compiler/rustc_infer/src/errors/note_and_explain.rs b/compiler/rustc_infer/src/errors/note_and_explain.rs
index 6a29d8562..7aaa5ce2f 100644
--- a/compiler/rustc_infer/src/errors/note_and_explain.rs
+++ b/compiler/rustc_infer/src/errors/note_and_explain.rs
@@ -89,10 +89,13 @@ impl<'a> DescriptionCtx<'a> {
};
me.span = Some(sp);
}
- ty::BrAnon(idx) => {
+ ty::BrAnon(idx, span) => {
me.kind = "anon_num_here";
me.num_arg = idx+1;
- me.span = Some(tcx.def_span(scope));
+ me.span = match span {
+ Some(_) => span,
+ None => Some(tcx.def_span(scope)),
+ }
},
_ => {
me.kind = "defined_here_reg";