Skip to content

Commit fd7029d

Browse files
committed
Suppress suggestions while span is in external library
Signed-off-by: xizheyin <[email protected]>
1 parent 7753df3 commit fd7029d

File tree

4 files changed

+18
-68
lines changed

4 files changed

+18
-68
lines changed

compiler/rustc_errors/src/emitter.rs

+18
Original file line numberDiff line numberDiff line change
@@ -1996,6 +1996,14 @@ impl HumanEmitter {
19961996
return Ok(());
19971997
};
19981998

1999+
if suggestion
2000+
.substitutions
2001+
.iter()
2002+
.any(|s| s.parts.iter().any(|p| is_external_library(sm, p.span)))
2003+
{
2004+
return Ok(());
2005+
}
2006+
19992007
// Render the replacements for each suggestion
20002008
let suggestions = suggestion.splice_lines(sm);
20012009
debug!(?suggestions);
@@ -3532,3 +3540,13 @@ pub(crate) fn should_show_source_code(
35323540
.map(|path| ignored_directories.iter().all(|dir| !path.starts_with(dir)))
35333541
.unwrap_or(true)
35343542
}
3543+
3544+
fn is_external_library(sm: &SourceMap, span: Span) -> bool {
3545+
let filename = sm.span_to_filename(span);
3546+
if let Some(path) = filename.into_local_path() {
3547+
path.to_string_lossy().contains(".cargo/registry/src/")
3548+
|| path.to_string_lossy().contains(".rustup/toolchains/")
3549+
} else {
3550+
false
3551+
}
3552+
}

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

-4
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
449449
err: &mut Diag<'_>,
450450
trait_pred: ty::PolyTraitPredicate<'tcx>,
451451
) -> bool {
452-
if obligation.cause.span.in_external_macro(self.infcx.tcx.sess.source_map()) {
453-
return false;
454-
}
455-
456452
let mut code = obligation.cause.code();
457453
if let ObligationCauseCode::FunctionArg { arg_hir_id, call_hir_id, .. } = code
458454
&& let Some(typeck_results) = &self.typeck_results

tests/ui/macros/dont-suggest-within-macro-issue-139251.rs

-14
This file was deleted.

tests/ui/macros/dont-suggest-within-macro-issue-139251.stderr

-50
This file was deleted.

0 commit comments

Comments
 (0)