Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename ParenthesizedGenericArgs to GenericArgsMode #129625

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use rustc_span::Span;
use rustc_target::spec::abi;
use {rustc_ast as ast, rustc_hir as hir};

use super::{ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs};
use super::{GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode};
use crate::{ImplTraitPosition, ResolverAstLoweringExt};

pub(crate) struct DelegationResults<'hir> {
Expand Down Expand Up @@ -323,7 +323,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
delegation.path.span,
ast_segment,
ParamMode::Optional,
ParenthesizedGenericArgs::Err,
GenericArgsMode::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use super::errors::{
NeverPatternWithBody, NeverPatternWithGuard, UnderscoreExprLhsAssign,
};
use super::{
ImplTraitContext, LoweringContext, ParamMode, ParenthesizedGenericArgs, ResolverAstLoweringExt,
GenericArgsMode, ImplTraitContext, LoweringContext, ParamMode, ResolverAstLoweringExt,
};
use crate::errors::YieldInClosure;
use crate::{fluent_generated, FnDeclKind, ImplTraitPosition};
Expand Down Expand Up @@ -107,7 +107,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
e.span,
seg,
ParamMode::Optional,
ParenthesizedGenericArgs::Err,
GenericArgsMode::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
// Method calls can't have bound modifiers
None,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ enum ParamMode {
Optional,
}

enum ParenthesizedGenericArgs {
enum GenericArgsMode {
ParenSugar,
Err,
}
Expand Down
37 changes: 18 additions & 19 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use super::errors::{
GenericTypeWithParentheses, UseAngleBrackets,
};
use super::{
GenericArgsCtor, ImplTraitContext, LifetimeRes, LoweringContext, ParamMode,
ParenthesizedGenericArgs, ResolverAstLoweringExt,
GenericArgsCtor, GenericArgsMode, ImplTraitContext, LifetimeRes, LoweringContext, ParamMode,
ResolverAstLoweringExt,
};
use crate::ImplTraitPosition;

Expand Down Expand Up @@ -90,30 +90,30 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
_ => param_mode,
};

let parenthesized_generic_args = match base_res {
let generic_args_mode = match base_res {
// `a::b::Trait(Args)`
Res::Def(DefKind::Trait, _) if i + 1 == proj_start => {
ParenthesizedGenericArgs::ParenSugar
GenericArgsMode::ParenSugar
}
// `a::b::Trait(Args)::TraitItem`
Res::Def(DefKind::AssocFn, _)
| Res::Def(DefKind::AssocConst, _)
| Res::Def(DefKind::AssocTy, _)
if i + 2 == proj_start =>
{
ParenthesizedGenericArgs::ParenSugar
GenericArgsMode::ParenSugar
}
// Avoid duplicated errors.
Res::Err => ParenthesizedGenericArgs::ParenSugar,
Res::Err => GenericArgsMode::ParenSugar,
// An error
_ => ParenthesizedGenericArgs::Err,
_ => GenericArgsMode::Err,
};

self.lower_path_segment(
p.span,
segment,
param_mode,
parenthesized_generic_args,
generic_args_mode,
itctx,
bound_modifier_allowed_features.clone(),
)
Expand Down Expand Up @@ -168,7 +168,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p.span,
segment,
param_mode,
ParenthesizedGenericArgs::Err,
GenericArgsMode::Err,
itctx,
None,
));
Expand Down Expand Up @@ -210,7 +210,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
p.span,
segment,
param_mode,
ParenthesizedGenericArgs::Err,
GenericArgsMode::Err,
ImplTraitContext::Disallowed(ImplTraitPosition::Path),
None,
)
Expand All @@ -224,7 +224,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
path_span: Span,
segment: &PathSegment,
param_mode: ParamMode,
parenthesized_generic_args: ParenthesizedGenericArgs,
generic_args_mode: GenericArgsMode,
itctx: ImplTraitContext,
// Additional features ungated with a bound modifier like `async`.
// This is passed down to the implicit associated type binding in
Expand All @@ -237,14 +237,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericArgs::AngleBracketed(data) => {
self.lower_angle_bracketed_parameter_data(data, param_mode, itctx)
}
GenericArgs::Parenthesized(data) => match parenthesized_generic_args {
ParenthesizedGenericArgs::ParenSugar => self
.lower_parenthesized_parameter_data(
data,
itctx,
bound_modifier_allowed_features,
),
ParenthesizedGenericArgs::Err => {
GenericArgs::Parenthesized(data) => match generic_args_mode {
GenericArgsMode::ParenSugar => self.lower_parenthesized_parameter_data(
data,
itctx,
bound_modifier_allowed_features,
),
GenericArgsMode::Err => {
// Suggest replacing parentheses with angle brackets `Trait(params...)` to `Trait<params...>`
let sub = if !data.inputs.is_empty() {
// Start of the span to the 1st character of 1st argument
Expand Down
Loading