Skip to content

Suppress suggestions while span is in external library #139316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1996,6 +1996,14 @@ impl HumanEmitter {
return Ok(());
};

if suggestion
.substitutions
.iter()
.any(|s| s.parts.iter().any(|p| is_external_library(sm, p.span)))
{
return Ok(());
}

// Render the replacements for each suggestion
let suggestions = suggestion.splice_lines(sm);
debug!(?suggestions);
Expand Down Expand Up @@ -3532,3 +3540,13 @@ pub(crate) fn should_show_source_code(
.map(|path| ignored_directories.iter().all(|dir| !path.starts_with(dir)))
.unwrap_or(true)
}

fn is_external_library(sm: &SourceMap, span: Span) -> bool {
let filename = sm.span_to_filename(span);
if let Some(path) = filename.into_local_path() {
path.to_string_lossy().contains(".cargo/registry/src/")
|| path.to_string_lossy().contains(".rustup/toolchains/")
} else {
false
}
}
Loading