summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_infer/src/infer/error_reporting
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 18:31:44 +0000
commitc23a457e72abe608715ac76f076f47dc42af07a5 (patch)
tree2772049aaf84b5c9d0ed12ec8d86812f7a7904b6 /compiler/rustc_infer/src/infer/error_reporting
parentReleasing progress-linux version 1.73.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-c23a457e72abe608715ac76f076f47dc42af07a5.tar.xz
rustc-c23a457e72abe608715ac76f076f47dc42af07a5.zip
Merging upstream version 1.74.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_infer/src/infer/error_reporting')
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/mod.rs36
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs39
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs2
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs2
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs6
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs14
-rw-r--r--compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs20
7 files changed, 41 insertions, 78 deletions
diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
index ac5468f3d..72cfc1337 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs
@@ -242,12 +242,9 @@ fn msg_span_from_named_region<'tcx>(
};
(text, Some(span))
}
- ty::BrAnon(span) => (
+ ty::BrAnon => (
"the anonymous lifetime as defined here".to_string(),
- Some(match span {
- Some(span) => span,
- None => tcx.def_span(scope)
- })
+ Some(tcx.def_span(scope))
),
_ => (
format!("the lifetime `{region}` as defined here"),
@@ -262,11 +259,7 @@ fn msg_span_from_named_region<'tcx>(
..
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
ty::RePlaceholder(ty::PlaceholderRegion {
- bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(Some(span)), .. },
- ..
- }) => ("the anonymous lifetime defined here".to_owned(), Some(span)),
- ty::RePlaceholder(ty::PlaceholderRegion {
- bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. },
+ bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon, .. },
..
}) => ("an anonymous lifetime".to_owned(), None),
_ => bug!("{:?}", region),
@@ -1616,7 +1609,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// | expected `()`, found closure
// |
// = note: expected unit type `()`
- // found closure `[closure@$DIR/issue-20862.rs:2:5: 2:14 x:_]`
+ // found closure `{closure@$DIR/issue-20862.rs:2:5: 2:14 x:_}`
//
// Also ignore opaque `Future`s that come from async fns.
if !self.ignore_span.overlaps(span)
@@ -1642,8 +1635,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ValuePairs::Terms(infer::ExpectedFound { expected, found }) => {
match (expected.unpack(), found.unpack()) {
(ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => {
- let is_simple_err =
- expected.is_simple_text() && found.is_simple_text();
+ let is_simple_err = expected.is_simple_text(self.tcx)
+ && found.is_simple_text(self.tcx);
OpaqueTypesVisitor::visit_expected_found(
self.tcx, expected, found, span,
)
@@ -1660,7 +1653,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
_ => (false, Mismatch::Fixed("type")),
}
}
- ValuePairs::Sigs(infer::ExpectedFound { expected, found }) => {
+ ValuePairs::PolySigs(infer::ExpectedFound { expected, found }) => {
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
.report(diag);
(false, Mismatch::Fixed("signature"))
@@ -1885,7 +1878,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
s
};
- if !(values.expected.is_simple_text() && values.found.is_simple_text())
+ if !(values.expected.is_simple_text(self.tcx) && values.found.is_simple_text(self.tcx))
|| (exp_found.is_some_and(|ef| {
// This happens when the type error is a subset of the expectation,
// like when you have two references but one is `usize` and the other
@@ -2232,15 +2225,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
ret => ret,
}
}
- infer::Sigs(exp_found) => {
+ infer::PolySigs(exp_found) => {
let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() {
return None;
}
- let (exp, fnd) = self.cmp_fn_sig(
- &ty::Binder::dummy(exp_found.expected),
- &ty::Binder::dummy(exp_found.found),
- );
+ let (exp, fnd) = self.cmp_fn_sig(&exp_found.expected, &exp_found.found);
Some((exp, fnd, None, None))
}
}
@@ -2927,6 +2917,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
| IfExpression { .. }
| LetElse
| StartFunctionType
+ | LangFunctionType(_)
| IntrinsicType
| MethodReceiver => Error0308,
@@ -2971,6 +2962,9 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
LetElse => ObligationCauseFailureCode::NoDiverge { span, subdiags },
MainFunctionType => ObligationCauseFailureCode::FnMainCorrectType { span },
StartFunctionType => ObligationCauseFailureCode::FnStartCorrectType { span, subdiags },
+ &LangFunctionType(lang_item_name) => {
+ ObligationCauseFailureCode::FnLangCorrectType { span, subdiags, lang_item_name }
+ }
IntrinsicType => ObligationCauseFailureCode::IntrinsicCorrectType { span, subdiags },
MethodReceiver => ObligationCauseFailureCode::MethodCorrectType { span, subdiags },
@@ -3006,6 +3000,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
IfExpressionWithNoElse => "`if` missing an `else` returns `()`",
MainFunctionType => "`main` function has the correct type",
StartFunctionType => "`#[start]` function has the correct type",
+ LangFunctionType(_) => "lang item function has the correct type",
IntrinsicType => "intrinsic has the correct type",
MethodReceiver => "method receiver has the correct type",
_ => "types are compatible",
@@ -3028,6 +3023,7 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> {
IfExpressionWithNoElse => "no_else",
MainFunctionType => "fn_main_correct_type",
StartFunctionType => "fn_start_correct_type",
+ LangFunctionType(_) => "fn_lang_correct_type",
IntrinsicType => "intrinsic_correct_type",
MethodReceiver => "method_correct_type",
_ => "other",
diff --git a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
index f2a3c47bd..a9029a8ce 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
@@ -1,5 +1,5 @@
use crate::errors::{
- AmbiguousImpl, AmbiguousReturn, AnnotationRequired, InferenceBadError, NeedTypeInfoInGenerator,
+ AmbiguousImpl, AmbiguousReturn, AnnotationRequired, InferenceBadError,
SourceKindMultiSuggestion, SourceKindSubdiag,
};
use crate::infer::error_reporting::TypeErrCtxt;
@@ -595,39 +595,6 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
-impl<'tcx> InferCtxt<'tcx> {
- pub fn need_type_info_err_in_generator(
- &self,
- kind: hir::GeneratorKind,
- span: Span,
- ty: ty::Term<'tcx>,
- ) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
- let ty = self.resolve_vars_if_possible(ty);
- let data = self.extract_inference_diagnostics_data(ty.into(), None);
-
- NeedTypeInfoInGenerator {
- bad_label: data.make_bad_error(span),
- span,
- generator_kind: GeneratorKindAsDiagArg(kind),
- }
- .into_diagnostic(&self.tcx.sess.parse_sess.span_diagnostic)
- }
-}
-
-pub struct GeneratorKindAsDiagArg(pub hir::GeneratorKind);
-
-impl IntoDiagnosticArg for GeneratorKindAsDiagArg {
- fn into_diagnostic_arg(self) -> rustc_errors::DiagnosticArgValue<'static> {
- let kind = match self.0 {
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Block) => "async_block",
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Closure) => "async_closure",
- hir::GeneratorKind::Async(hir::AsyncGeneratorKind::Fn) => "async_fn",
- hir::GeneratorKind::Gen => "generator",
- };
- rustc_errors::DiagnosticArgValue::Str(kind.into())
- }
-}
-
#[derive(Debug)]
struct InferSource<'tcx> {
span: Span,
@@ -951,7 +918,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
//
// See the `need_type_info/issue-103053.rs` test for
// a example.
- if !matches!(path.res, Res::Def(DefKind::TyAlias { .. }, _)) => {
+ if !matches!(path.res, Res::Def(DefKind::TyAlias, _)) => {
if let Some(ty) = self.opt_node_type(expr.hir_id)
&& let ty::Adt(_, args) = ty.kind()
{
@@ -1080,7 +1047,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
) => {
if tcx.res_generics_def_id(path.res) != Some(def.did()) {
match path.res {
- Res::Def(DefKind::TyAlias { .. }, _) => {
+ Res::Def(DefKind::TyAlias, _) => {
// FIXME: Ideally we should support this. For that
// we have to map back from the self type to the
// type alias though. That's difficult.
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
index 07f04ec1e..1b43022f8 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/named_anon_conflict.rs
@@ -61,7 +61,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
let is_impl_item = region_info.is_impl_item;
match br {
- ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(..) => {}
+ ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon => {}
_ => {
/* not an anonymous region */
debug!("try_report_named_anon_conflict: not an anonymous region");
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs
index f903f7a49..4aec28b05 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_error.rs
@@ -385,7 +385,7 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
let highlight_trait_ref = |trait_ref| Highlighted {
tcx: self.tcx(),
- highlight: RegionHighlightMode::new(self.tcx()),
+ highlight: RegionHighlightMode::default(),
value: trait_ref,
};
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs
index 8a78a1956..f5b891253 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/placeholder_relation.rs
@@ -36,15 +36,13 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
ty::BrNamed(def_id, symbol) => {
(Some(self.tcx().def_span(def_id)), Some(symbol))
}
- ty::BrAnon(span) => (*span, None),
- ty::BrEnv => (None, None),
+ ty::BrAnon | ty::BrEnv => (None, None),
};
let (sup_span, sup_symbol) = match sup_name {
ty::BrNamed(def_id, symbol) => {
(Some(self.tcx().def_span(def_id)), Some(symbol))
}
- ty::BrAnon(span) => (*span, None),
- ty::BrEnv => (None, None),
+ ty::BrAnon | ty::BrEnv => (None, None),
};
let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {
(Some(sub_span), Some(sup_span), Some(&sub_symbol), Some(&sup_symbol)) => {
diff --git a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs
index 12d38ced0..cb51254a1 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/nice_region_error/trait_impl_difference.rs
@@ -35,14 +35,14 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code()
&& sub_trace.values == sup_trace.values
- && let ValuePairs::Sigs(ExpectedFound { expected, found }) = sub_trace.values
+ && let ValuePairs::PolySigs(ExpectedFound { expected, found }) = sub_trace.values
{
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
// all of the region highlighting machinery only deals with those.
let guar = self.emit_err(
var_origin.span(),
- Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(expected)),
- Ty::new_fn_ptr(self.cx.tcx,ty::Binder::dummy(found)),
+ Ty::new_fn_ptr(self.cx.tcx, expected),
+ Ty::new_fn_ptr(self.cx.tcx, found),
*trait_item_def_id,
);
return Some(guar);
@@ -67,9 +67,9 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
impl<'tcx> HighlightBuilder<'tcx> {
- fn build(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
+ fn build(ty: Ty<'tcx>) -> RegionHighlightMode<'tcx> {
let mut builder =
- HighlightBuilder { highlight: RegionHighlightMode::new(tcx), counter: 1 };
+ HighlightBuilder { highlight: RegionHighlightMode::default(), counter: 1 };
builder.visit_ty(ty);
builder.highlight
}
@@ -85,12 +85,12 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
}
}
- let expected_highlight = HighlightBuilder::build(self.tcx(), expected);
+ let expected_highlight = HighlightBuilder::build(expected);
let expected = self
.cx
.extract_inference_diagnostics_data(expected.into(), Some(expected_highlight))
.name;
- let found_highlight = HighlightBuilder::build(self.tcx(), found);
+ let found_highlight = HighlightBuilder::build(found);
let found =
self.cx.extract_inference_diagnostics_data(found.into(), Some(found_highlight)).name;
diff --git a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
index 372539d73..5c3beee28 100644
--- a/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
+++ b/compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs
@@ -266,12 +266,10 @@ impl<T> Trait<T> for X {
}
}
}
- (ty::FnPtr(_), ty::FnDef(def, _))
- if let hir::def::DefKind::Fn = tcx.def_kind(def) => {
- diag.note(
- "when the arguments and return types match, functions can be coerced \
- to function pointers",
- );
+ (ty::FnPtr(sig), ty::FnDef(def_id, _)) | (ty::FnDef(def_id, _), ty::FnPtr(sig)) => {
+ if tcx.fn_sig(*def_id).skip_binder().unsafety() < sig.unsafety() {
+ diag.note("unsafe functions cannot be coerced into safe function pointers");
+ }
}
_ => {}
}
@@ -618,9 +616,13 @@ fn foo(&self) -> Self::T { String::new() }
for item in &items[..] {
if let hir::AssocItemKind::Type = item.kind {
let assoc_ty = tcx.type_of(item.id.owner_id).instantiate_identity();
-
- if self.infcx.can_eq(param_env, assoc_ty, found) {
- diag.span_label(item.span, "expected this associated type");
+ if let hir::Defaultness::Default { has_value: true } = tcx.defaultness(item.id.owner_id)
+ && self.infcx.can_eq(param_env, assoc_ty, found)
+ {
+ diag.span_label(
+ item.span,
+ "associated type is `default` and may be overridden",
+ );
return true;
}
}