@@ -84,7 +84,7 @@ pub(super) fn cargo(
84
84
85
85
let ( manifest_path, manifest_error_range) = {
86
86
let mae = error. downcast_ref :: < ManifestAwareError > ( ) ;
87
- ( mae. map ( |e| e. manifest_path ( ) . clone ( ) ) , mae. map ( |e| e. manifest_error_range ( ) ) )
87
+ ( mae. map ( |e| e. manifest_path ( ) . clone ( ) ) , mae. and_then ( |e| e. manifest_error_range ( ) ) )
88
88
} ;
89
89
BuildResult :: CargoError { error, stdout, manifest_path, manifest_error_range }
90
90
}
@@ -805,15 +805,15 @@ pub struct ManifestAwareError {
805
805
cause : anyhow:: Error ,
806
806
/// The path to a manifest file within the project that seems the closest to the error's origin.
807
807
nearest_project_manifest : PathBuf ,
808
- manifest_error_range : Range ,
808
+ manifest_error_range : Option < Range > ,
809
809
}
810
810
811
811
impl ManifestAwareError {
812
812
fn new ( cause : anyhow:: Error , root_manifest : & Path , ws : Option < & Workspace < ' _ > > ) -> Self {
813
813
let project_dir = root_manifest. parent ( ) . unwrap ( ) ;
814
814
let mut err_path = root_manifest;
815
815
// Cover whole manifest if we haven't any better idea.
816
- let mut err_range = Range { start : Position :: new ( 0 , 0 ) , end : Position :: new ( 9999 , 0 ) } ;
816
+ let mut err_range = None ;
817
817
818
818
if let Some ( manifest_err) = cause. downcast_ref :: < ManifestError > ( ) {
819
819
// Scan through any manifest errors to pin the error more precisely.
@@ -828,15 +828,25 @@ impl ManifestAwareError {
828
828
fn find_toml_error (
829
829
err : & ( dyn std:: error:: Error + ' static ) ,
830
830
) -> Option < ( usize , usize ) > {
831
- match err. downcast_ref :: < toml:: de:: Error > ( ) {
832
- Some ( toml_err) => toml_err. line_col ( ) ,
833
- None => find_toml_error ( err. source ( ) ?) ,
831
+ if let Some ( toml_err) = err. downcast_ref :: < toml_edit:: TomlError > ( ) {
832
+ toml_err. line_col ( )
833
+ } else if let Some ( toml_err) = err. downcast_ref :: < toml_edit:: de:: Error > ( ) {
834
+ toml_err. line_col ( )
835
+ } else if let Some ( toml_err) = err. downcast_ref :: < toml:: de:: Error > ( ) {
836
+ toml_err. line_col ( )
837
+ } else {
838
+ find_toml_error ( err. source ( ) ?)
834
839
}
835
840
}
836
841
if let Some ( ( line, col) ) = find_toml_error ( last_cause) {
842
+ let line = line as _ ;
843
+ let start_col = col as _ ;
844
+ let end_col = start_col + 1 ;
837
845
// Use TOML deserializiation error position.
838
- err_range. start = Position :: new ( line as _ , col as _ ) ;
839
- err_range. end = Position :: new ( line as _ , col as u64 + 1 ) ;
846
+ err_range = Some ( Range {
847
+ start : Position :: new ( line, start_col) ,
848
+ end : Position :: new ( line, end_col) ,
849
+ } ) ;
840
850
}
841
851
} else {
842
852
let nearest_cause = manifest_err
@@ -868,7 +878,7 @@ impl ManifestAwareError {
868
878
& self . nearest_project_manifest
869
879
}
870
880
871
- pub fn manifest_error_range ( & self ) -> Range {
881
+ pub fn manifest_error_range ( & self ) -> Option < Range > {
872
882
self . manifest_error_range
873
883
}
874
884
}
0 commit comments