Say which input an error came from
With one file the module prefix is noise. With three hundred and fifty-six it is the difference between a message and a search -- the last few blockers each cost an eight-minute run and a grep to locate, and two of them turned out not to be where the message implied. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
16e1eca parent: 46b0ff0 modified
src/lower.rs +16 -5 | @@ -577,7 +577,7 @@ impl Lowerer { | ||
| 577 | 577 | for (m, f) in files { |
| 578 | 578 | self.cur_mod = m.clone(); |
| 579 | 579 | for item in &f.items { |
| 580 | - self.collect_aliases(item)?; | |
| 580 | + self.collect_aliases(item).map_err(|e| self.where_(&e))?; | |
| 581 | 581 | } |
| 582 | 582 | } |
| 583 | 583 | |
| @@ -600,7 +600,7 @@ impl Lowerer { | ||
| 600 | 600 | for (m, f) in files { |
| 601 | 601 | self.cur_mod = m.clone(); |
| 602 | 602 | for item in &f.items { |
| 603 | - self.collect(item)?; | |
| 603 | + self.collect(item).map_err(|e| self.where_(&e))?; | |
| 604 | 604 | } |
| 605 | 605 | } |
| 606 | 606 | |
| @@ -625,7 +625,7 @@ impl Lowerer { | ||
| 625 | 625 | for (m, f) in files { |
| 626 | 626 | self.cur_mod = m.clone(); |
| 627 | 627 | for item in &f.items { |
| 628 | - self.emit_assoc_consts(item)?; | |
| 628 | + self.emit_assoc_consts(item).map_err(|e| self.where_(&e))?; | |
| 629 | 629 | } |
| 630 | 630 | } |
| 631 | 631 | |
| @@ -633,7 +633,7 @@ impl Lowerer { | ||
| 633 | 633 | for (m, f) in files { |
| 634 | 634 | self.cur_mod = m.clone(); |
| 635 | 635 | for item in &f.items { |
| 636 | - self.item_types(item)?; | |
| 636 | + self.item_types(item).map_err(|e| self.where_(&e))?; | |
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | |
| @@ -666,7 +666,7 @@ impl Lowerer { | ||
| 666 | 666 | for (m, f) in files { |
| 667 | 667 | self.cur_mod = m.clone(); |
| 668 | 668 | for item in &f.items { |
| 669 | - self.item(item)?; | |
| 669 | + self.item(item).map_err(|e| self.where_(&e))?; | |
| 670 | 670 | } |
| 671 | 671 | } |
| 672 | 672 | |
| @@ -887,6 +887,17 @@ impl Lowerer { | ||
| 887 | 887 | Ok(()) |
| 888 | 888 | } |
| 889 | 889 | |
| 890 | + /// Prefix an error with the input it came from. With one file that is | |
| 891 | + /// noise; with three hundred and fifty-six it is the difference between a | |
| 892 | + /// message and a search. | |
| 893 | + fn where_(&self, e: &str) -> String { | |
| 894 | + if self.cur_mod.is_empty() || e.starts_with(&format!("{}: ", self.cur_mod)) { | |
| 895 | + e.to_string() | |
| 896 | + } else { | |
| 897 | + format!("{}: {e}", self.cur_mod) | |
| 898 | + } | |
| 899 | + } | |
| 900 | + | |
| 890 | 901 | fn collect(&mut self, item: &Item) -> Result<(), String> { |
| 891 | 902 | // A `#[cfg(..)]` item exists only under some feature set. Dropping it |
| 892 | 903 | // silently would change what the program does; picking a feature set |
| @@ -577,7 +577,7 @@ impl Lowerer { | |||
| 577 | for (m, f) in files { | 577 | for (m, f) in files { |
| 578 | self.cur_mod = m.clone(); | 578 | self.cur_mod = m.clone(); |
| 579 | for item in &f.items { | 579 | for item in &f.items { |
| 580 | - self.collect_aliases(item)?; | 580 | + self.collect_aliases(item).map_err(|e| self.where_(&e))?; |
| 581 | } | 581 | } |
| 582 | } | 582 | } |
| 583 | 583 | ||
| @@ -600,7 +600,7 @@ impl Lowerer { | |||
| 600 | for (m, f) in files { | 600 | for (m, f) in files { |
| 601 | self.cur_mod = m.clone(); | 601 | self.cur_mod = m.clone(); |
| 602 | for item in &f.items { | 602 | for item in &f.items { |
| 603 | - self.collect(item)?; | 603 | + self.collect(item).map_err(|e| self.where_(&e))?; |
| 604 | } | 604 | } |
| 605 | } | 605 | } |
| 606 | 606 | ||
| @@ -625,7 +625,7 @@ impl Lowerer { | |||
| 625 | for (m, f) in files { | 625 | for (m, f) in files { |
| 626 | self.cur_mod = m.clone(); | 626 | self.cur_mod = m.clone(); |
| 627 | for item in &f.items { | 627 | for item in &f.items { |
| 628 | - self.emit_assoc_consts(item)?; | 628 | + self.emit_assoc_consts(item).map_err(|e| self.where_(&e))?; |
| 629 | } | 629 | } |
| 630 | } | 630 | } |
| 631 | 631 | ||
| @@ -633,7 +633,7 @@ impl Lowerer { | |||
| 633 | for (m, f) in files { | 633 | for (m, f) in files { |
| 634 | self.cur_mod = m.clone(); | 634 | self.cur_mod = m.clone(); |
| 635 | for item in &f.items { | 635 | for item in &f.items { |
| 636 | - self.item_types(item)?; | 636 | + self.item_types(item).map_err(|e| self.where_(&e))?; |
| 637 | } | 637 | } |
| 638 | } | 638 | } |
| 639 | 639 | ||
| @@ -666,7 +666,7 @@ impl Lowerer { | |||
| 666 | for (m, f) in files { | 666 | for (m, f) in files { |
| 667 | self.cur_mod = m.clone(); | 667 | self.cur_mod = m.clone(); |
| 668 | for item in &f.items { | 668 | for item in &f.items { |
| 669 | - self.item(item)?; | 669 | + self.item(item).map_err(|e| self.where_(&e))?; |
| 670 | } | 670 | } |
| 671 | } | 671 | } |
| 672 | 672 | ||
| @@ -887,6 +887,17 @@ impl Lowerer { | |||
| 887 | Ok(()) | 887 | Ok(()) |
| 888 | } | 888 | } |
| 889 | 889 | ||
| 890 | + /// Prefix an error with the input it came from. With one file that is | ||
| 891 | + /// noise; with three hundred and fifty-six it is the difference between a | ||
| 892 | + /// message and a search. | ||
| 893 | + fn where_(&self, e: &str) -> String { | ||
| 894 | + if self.cur_mod.is_empty() || e.starts_with(&format!("{}: ", self.cur_mod)) { | ||
| 895 | + e.to_string() | ||
| 896 | + } else { | ||
| 897 | + format!("{}: {e}", self.cur_mod) | ||
| 898 | + } | ||
| 899 | + } | ||
| 900 | + | ||
| 890 | fn collect(&mut self, item: &Item) -> Result<(), String> { | 901 | fn collect(&mut self, item: &Item) -> Result<(), String> { |
| 891 | // A `#[cfg(..)]` item exists only under some feature set. Dropping it | 902 | // A `#[cfg(..)]` item exists only under some feature set. Dropping it |
| 892 | // silently would change what the program does; picking a feature set | 903 | // silently would change what the program does; picking a feature set |