- // ends in `$target` we *could* be in the target libdir, and always
- // assume that we may be in the main libdir.
- sysroot_candidates.push(path.to_owned());
-
- if path.ends_with(target) {
- sysroot_candidates.extend(path.parent() // chop off `$target`
- .and_then(|p| p.parent()) // chop off `rustlib`
- .and_then(|p| p.parent()) // chop off `lib`
- .map(|s| s.to_owned()));
+ // doesn't end in `$target` we *could* be in the main libdir, and always
+ // assume that we may be in the target libdir.
+ libdir_candidates.push(path.to_owned());
+
+ if !path.parent().map_or(false, |p| p.ends_with(target)) {
+ libdir_candidates.push(path.join(filesearch::target_lib_path(target)));