Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Discouraging shadowing in languages with unclear lifetimes makes plenty of sense.

Clippy offers lints for (three?) distinct ways of shadowing because in most cases it turns out people who don't like shadowing only had problems with typically one specific kind of shadowing (e.g. same type unrelated shadowing, or different type same value shadowing) and since that varies why not offer to diagnose the specific problem this programmer doesn't like.

To be concrete some people are worried about things like:

  let sparrows = get_a_list_of_sparrows();
  // ....
  let sparrows = sparrows.len() + EXTRA_SPARROWS;
Whereas for some people that seems fine but they're worried about:

   let sparrows = find_wild_sparrows();
   // ....
   let sparrows = find_farmed_sparrows();
These are both shadowing the name sparrows, and Rust is fine with either but Clippy can provide different lints so that you can ban one of them while using the other freely in your codebase.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: