summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_ast_lowering/src/path.rs
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_ast_lowering/src/path.rs
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_ast_lowering/src/path.rs')
-rw-r--r--compiler/rustc_ast_lowering/src/path.rs58
1 files changed, 34 insertions, 24 deletions
diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs
index 888776ccc..592fc5aa6 100644
--- a/compiler/rustc_ast_lowering/src/path.rs
+++ b/compiler/rustc_ast_lowering/src/path.rs
@@ -9,17 +9,17 @@ use rustc_ast::{self as ast, *};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, PartialRes, Res};
use rustc_hir::GenericArg;
-use rustc_span::symbol::{kw, Ident};
+use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::{BytePos, Span, DUMMY_SP};
-use smallvec::smallvec;
+use smallvec::{smallvec, SmallVec};
impl<'a, 'hir> LoweringContext<'a, 'hir> {
#[instrument(level = "trace", skip(self))]
pub(crate) fn lower_qpath(
&mut self,
id: NodeId,
- qself: &Option<QSelf>,
+ qself: &Option<ptr::P<QSelf>>,
p: &Path,
param_mode: ParamMode,
itctx: &ImplTraitContext,
@@ -144,13 +144,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
);
}
- pub(crate) fn lower_path_extra(
+ pub(crate) fn lower_use_path(
&mut self,
- res: Res,
+ res: SmallVec<[Res; 3]>,
p: &Path,
param_mode: ParamMode,
- ) -> &'hir hir::Path<'hir> {
- self.arena.alloc(hir::Path {
+ ) -> &'hir hir::UsePath<'hir> {
+ self.arena.alloc(hir::UsePath {
res,
segments: self.arena.alloc_from_iter(p.segments.iter().map(|segment| {
self.lower_path_segment(
@@ -165,17 +165,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
})
}
- pub(crate) fn lower_path(
- &mut self,
- id: NodeId,
- p: &Path,
- param_mode: ParamMode,
- ) -> &'hir hir::Path<'hir> {
- let res = self.expect_full_res(id);
- let res = self.lower_res(res);
- self.lower_path_extra(res, p, param_mode)
- }
-
pub(crate) fn lower_path_segment(
&mut self,
path_span: Span,
@@ -185,13 +174,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
itctx: &ImplTraitContext,
) -> hir::PathSegment<'hir> {
debug!("path_span: {:?}, lower_path_segment(segment: {:?})", path_span, segment,);
- let (mut generic_args, infer_args) = if let Some(ref generic_args) = segment.args {
- match **generic_args {
- GenericArgs::AngleBracketed(ref data) => {
+ let (mut generic_args, infer_args) = if let Some(generic_args) = segment.args.as_deref() {
+ match generic_args {
+ GenericArgs::AngleBracketed(data) => {
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
}
- GenericArgs::Parenthesized(ref data) => match parenthesized_generic_args {
- ParenthesizedGenericArgs::Ok => self.lower_parenthesized_parameter_data(data),
+ GenericArgs::Parenthesized(data) => match parenthesized_generic_args {
+ ParenthesizedGenericArgs::Ok => {
+ self.lower_parenthesized_parameter_data(data, itctx)
+ }
ParenthesizedGenericArgs::Err => {
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
let sub = if !data.inputs.is_empty() {
@@ -307,7 +298,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let id = NodeId::from_u32(i);
let l = self.lower_lifetime(&Lifetime {
id,
- ident: Ident::new(kw::UnderscoreLifetime, elided_lifetime_span),
+ ident: Ident::new(kw::Empty, elided_lifetime_span),
});
GenericArg::Lifetime(l)
}),
@@ -344,6 +335,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_parenthesized_parameter_data(
&mut self,
data: &ParenthesizedArgs,
+ itctx: &ImplTraitContext,
) -> (GenericArgsCtor<'hir>, bool) {
// Switch to `PassThrough` mode for anonymous lifetimes; this
// means that we permit things like `&Ref<T>`, where `Ref` has
@@ -355,6 +347,24 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lower_ty_direct(ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitParam))
}));
let output_ty = match output {
+ // Only allow `impl Trait` in return position. i.e.:
+ // ```rust
+ // fn f(_: impl Fn() -> impl Debug) -> impl Fn() -> impl Debug
+ // // disallowed --^^^^^^^^^^ allowed --^^^^^^^^^^
+ // ```
+ FnRetTy::Ty(ty) if matches!(itctx, ImplTraitContext::ReturnPositionOpaqueTy { .. }) => {
+ if self.tcx.features().impl_trait_in_fn_trait_return {
+ self.lower_ty(&ty, itctx)
+ } else {
+ self.lower_ty(
+ &ty,
+ &ImplTraitContext::FeatureGated(
+ ImplTraitPosition::FnTraitReturn,
+ sym::impl_trait_in_fn_trait_return,
+ ),
+ )
+ }
+ }
FnRetTy::Ty(ty) => {
self.lower_ty(&ty, &ImplTraitContext::Disallowed(ImplTraitPosition::FnTraitReturn))
}