1
Fork 0

Conditionally allow lowering RTN (..) in paths

This commit is contained in:
Michael Goulet 2024-08-26 14:51:26 -04:00
parent 6d788a18c5
commit 19881b5a5a
13 changed files with 141 additions and 54 deletions

View file

@ -48,6 +48,8 @@ hir_analysis_auto_deref_reached_recursion_limit = reached the recursion limit wh
hir_analysis_bad_precise_capture = expected {$kind} parameter in `use<...>` precise captures list, found {$found}
hir_analysis_bad_return_type_notation_position = return type notation not allowed in this position yet
hir_analysis_cannot_capture_late_bound_const =
cannot capture late-bound const parameter in {$what}
.label = parameter defined here

View file

@ -1693,3 +1693,10 @@ pub(crate) struct CmseCallGeneric {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(hir_analysis_bad_return_type_notation_position)]
pub(crate) struct BadReturnTypeNotation {
#[primary_span]
pub span: Span,
}

View file

@ -53,7 +53,7 @@ use rustc_trait_selection::traits::{self, ObligationCtxt};
use tracing::{debug, debug_span, instrument};
use crate::bounds::Bounds;
use crate::errors::{AmbiguousLifetimeBound, WildPatTy};
use crate::errors::{AmbiguousLifetimeBound, BadReturnTypeNotation, WildPatTy};
use crate::hir_ty_lowering::errors::{prohibit_assoc_item_constraint, GenericsArgsErrExtend};
use crate::hir_ty_lowering::generics::{check_generic_arg_count, lower_generic_args};
use crate::middle::resolve_bound_vars as rbv;
@ -1910,6 +1910,19 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
ty::BoundConstness::NotConst,
)
}
// Deny any qpath types that were successfully lowered in AST lowering.
Res::Def(DefKind::AssocFn, _)
if let [.., _trait_segment, item_segment] = &path.segments[..]
&& item_segment.args.is_some_and(|args| {
matches!(
args.parenthesized,
hir::GenericArgsParentheses::ReturnTypeNotation
)
}) =>
{
let guar = self.dcx().emit_err(BadReturnTypeNotation { span: path.span });
Ty::new_error(tcx, guar)
}
Res::PrimTy(prim_ty) => {
assert_eq!(opt_self_ty, None);
let _ = self.prohibit_generic_args(