about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2023-03-11 04:10:09 +0000
committerMichael Goulet <michael@errs.io>2023-03-28 01:02:15 +0000
commit104aacb49fb37265fb923e3b779de3c388abd92c (patch)
treebe3daaea4f4204da4bc7fbc937c47805bc54b745 /compiler/rustc_hir_analysis/src
parent0308d4ad187e7715d2bb7efcfce58e6d93362f07 (diff)
downloadrust-104aacb49fb37265fb923e3b779de3c388abd92c.tar.gz
rust-104aacb49fb37265fb923e3b779de3c388abd92c.zip
Add tests and error messages
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/astconv/mod.rs28
-rw-r--r--compiler/rustc_hir_analysis/src/errors.rs28
2 files changed, 47 insertions, 9 deletions
diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs
index 83343930010..1e590d93c8c 100644
--- a/compiler/rustc_hir_analysis/src/astconv/mod.rs
+++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs
@@ -1086,9 +1086,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
 
         let tcx = self.tcx();
 
-        // TODO: rtn comment goes here
-        let associated_return_type_bound =
-            binding.gen_args.parenthesized && tcx.features().associated_return_type_bounds;
+        let return_type_notation =
+            binding.gen_args.parenthesized && tcx.features().return_type_notation;
 
         let candidate = if return_type_notation {
             if self.trait_defines_associated_item_named(
@@ -1098,8 +1097,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             ) {
                 trait_ref
             } else {
-                // TODO: error
-                todo!()
+                return Err(tcx.sess.emit_err(crate::errors::ReturnTypeNotationMissingMethod {
+                    span: binding.span,
+                    trait_name: tcx.item_name(trait_ref.def_id()),
+                    assoc_name: binding.item_name.name,
+                }));
             }
         } else if self.trait_defines_associated_item_named(
             trait_ref.def_id(),
@@ -1218,7 +1220,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
             {
                 alias_ty
             } else {
-                todo!("found return type of {output:?}");
+                return Err(self.tcx().sess.emit_err(
+                    crate::errors::ReturnTypeNotationOnNonRpitit {
+                        span: binding.span,
+                        ty: tcx.liberate_late_bound_regions(assoc_item.def_id, output),
+                        fn_span: tcx.hir().span_if_local(assoc_item.def_id),
+                        note: (),
+                    },
+                ));
             };
 
             // Finally, move the fn return type's bound vars over to account for the early bound
@@ -1292,9 +1301,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
         }
 
         match binding.kind {
-            ConvertedBindingKind::Equality(..) if associated_return_type_bound => {
-                // TODO: error
-                todo!()
+            ConvertedBindingKind::Equality(..) if return_type_notation => {
+                return Err(self.tcx().sess.emit_err(
+                    crate::errors::ReturnTypeNotationEqualityBound { span: binding.span },
+                ));
             }
             ConvertedBindingKind::Equality(mut term) => {
                 // "Desugar" a constraint like `T: Iterator<Item = u32>` this to
diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs
index f57197edeb7..c71ce9a0bc7 100644
--- a/compiler/rustc_hir_analysis/src/errors.rs
+++ b/compiler/rustc_hir_analysis/src/errors.rs
@@ -471,6 +471,18 @@ pub(crate) struct InvalidUnionField {
     pub note: (),
 }
 
+#[derive(Diagnostic)]
+#[diag(hir_analysis_return_type_notation_on_non_rpitit)]
+pub(crate) struct ReturnTypeNotationOnNonRpitit<'tcx> {
+    #[primary_span]
+    pub span: Span,
+    pub ty: Ty<'tcx>,
+    #[label]
+    pub fn_span: Option<Span>,
+    #[note]
+    pub note: (),
+}
+
 #[derive(Subdiagnostic)]
 #[multipart_suggestion(hir_analysis_invalid_union_field_sugg, applicability = "machine-applicable")]
 pub(crate) struct InvalidUnionFieldSuggestion {
@@ -479,3 +491,19 @@ pub(crate) struct InvalidUnionFieldSuggestion {
     #[suggestion_part(code = ">")]
     pub hi: Span,
 }
+
+#[derive(Diagnostic)]
+#[diag(hir_analysis_return_type_notation_equality_bound)]
+pub(crate) struct ReturnTypeNotationEqualityBound {
+    #[primary_span]
+    pub span: Span,
+}
+
+#[derive(Diagnostic)]
+#[diag(hir_analysis_return_type_notation_missing_method)]
+pub(crate) struct ReturnTypeNotationMissingMethod {
+    #[primary_span]
+    pub span: Span,
+    pub trait_name: Symbol,
+    pub assoc_name: Symbol,
+}