Improve self-dependency hint to make shadowing clear (#9716)

This commit is contained in:
Charlie Marsh 2024-12-10 09:50:14 -05:00 committed by GitHub
parent 4c334e67a3
commit 6fb0d797ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 12 deletions

View File

@ -617,7 +617,8 @@ impl PubGrubReportFormatter<'_> {
&& workspace_members.contains(package_name)
{
output_hints.insert(PubGrubHint::DependsOnItself {
package: package.clone(),
package: package_name.clone(),
workspace: self.is_workspace() && !self.is_single_project_workspace(),
});
}
}
@ -956,9 +957,12 @@ pub(crate) enum PubGrubHint {
workspace: bool,
},
/// A package depends on itself at an incompatible version.
DependsOnItself { package: PubGrubPackage },
DependsOnItself {
package: PackageName,
workspace: bool,
},
/// A package was available on an index, but not at the correct version, and at least one
/// subsequent index was not queried. As such, a compatible version may be available on an
/// subsequent index was not queried. As such, a compatible version may be available on
/// one of the remaining indexes.
UncheckedIndex {
package: PubGrubPackage,
@ -1022,7 +1026,8 @@ enum PubGrubHintCore {
workspace: bool,
},
DependsOnItself {
package: PubGrubPackage,
package: PackageName,
workspace: bool,
},
UncheckedIndex {
package: PubGrubPackage,
@ -1088,7 +1093,9 @@ impl From<PubGrubHint> for PubGrubHintCore {
dependency,
workspace,
},
PubGrubHint::DependsOnItself { package } => Self::DependsOnItself { package },
PubGrubHint::DependsOnItself { package, workspace } => {
Self::DependsOnItself { package, workspace }
}
PubGrubHint::UncheckedIndex { package, .. } => Self::UncheckedIndex { package },
PubGrubHint::UnauthorizedIndex { index } => Self::UnauthorizedIndex { index },
PubGrubHint::ForbiddenIndex { index } => Self::ForbiddenIndex { index },
@ -1331,13 +1338,20 @@ impl std::fmt::Display for PubGrubHint {
dependency.cyan(),
)
}
Self::DependsOnItself { package } => {
Self::DependsOnItself { package, workspace } => {
let project = if *workspace {
"workspace member"
} else {
"project"
};
write!(
f,
"{}{} The package `{}` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.",
"{}{} The {project} `{}` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `{}`, consider renaming the {project} `{}` to avoid creating a conflict.",
"hint".bold().cyan(),
":".bold(),
package.cyan(),
package.cyan(),
package.cyan(),
)
}
Self::UncheckedIndex {

View File

@ -19527,7 +19527,7 @@ fn lock_self_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
Because your project depends on itself at an incompatible version (project==0.2.0), we can conclude that your project's requirements are unsatisfiable.
hint: The package `project` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);
Ok(())
@ -19662,7 +19662,7 @@ fn lock_self_extra_to_same_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);
Ok(())
@ -19696,7 +19696,7 @@ fn lock_self_extra_to_other_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);
Ok(())
@ -19831,7 +19831,7 @@ fn lock_self_extra_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
Because project[foo] depends on itself at an incompatible version (project==0.2.0) and your project requires project[foo], we can conclude that your project's requirements are unsatisfiable.
hint: The package `project[foo]` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);
Ok(())
@ -19960,7 +19960,7 @@ fn lock_self_marker_incompatible() -> Result<()> {
× No solution found when resolving dependencies:
Because only project{sys_platform == 'win32'}<=0.1 is available and your project depends on itself at an incompatible version (project{sys_platform == 'win32'}>0.1), we can conclude that your project's requirements are unsatisfiable.
hint: The package `project` depends on itself at an incompatible version. This is likely a mistake. Consider removing the dependency.
hint: The project `project` depends on itself at an incompatible version. This is likely a mistake. If you intended to depend on a third-party package named `project`, consider renaming the project `project` to avoid creating a conflict.
"###);
Ok(())