Merge pull request #19127 from ChayimFriedman2/different-generic-args

feat: Refactor path lowering and serve a new path diagnostic
This commit is contained in:
Lukas Wirth 2025-02-17 08:30:10 +00:00 committed by GitHub
commit 09db657439
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 1222 additions and 1144 deletions

View file

@ -112,6 +112,7 @@ diagnostics![
UnusedMut,
UnusedVariable,
GenericArgsProhibited,
ParenthesizedGenericArgsWithoutFnTrait,
];
#[derive(Debug)]
@ -414,6 +415,11 @@ pub struct GenericArgsProhibited {
pub reason: GenericArgsProhibitedReason,
}
#[derive(Debug)]
pub struct ParenthesizedGenericArgsWithoutFnTrait {
pub args: InFile<AstPtr<ast::ParenthesizedArgList>>,
}
impl AnyDiagnostic {
pub(crate) fn body_validation_diagnostic(
db: &dyn HirDatabase,
@ -703,8 +709,8 @@ impl AnyDiagnostic {
diag: &PathLoweringDiagnostic,
path: InFile<ast::Path>,
) -> Option<AnyDiagnostic> {
Some(match diag {
&PathLoweringDiagnostic::GenericArgsProhibited { segment, reason } => {
Some(match *diag {
PathLoweringDiagnostic::GenericArgsProhibited { segment, reason } => {
let segment = hir_segment_to_ast_segment(&path.value, segment)?;
let args = if let Some(generics) = segment.generic_arg_list() {
AstPtr::new(&generics).wrap_left()
@ -714,6 +720,12 @@ impl AnyDiagnostic {
let args = path.with_value(args);
GenericArgsProhibited { args, reason }.into()
}
PathLoweringDiagnostic::ParenthesizedGenericArgsWithoutFnTrait { segment } => {
let segment = hir_segment_to_ast_segment(&path.value, segment)?;
let args = AstPtr::new(&segment.parenthesized_arg_list()?);
let args = path.with_value(args);
ParenthesizedGenericArgsWithoutFnTrait { args }.into()
}
})
}