Skip to content

Commit cf84006

Browse files
authored
Rollup merge of #105514 - estebank:is_visible, r=oli-obk
Introduce `Span::is_visible` r? `@oli-obk`
2 parents 9e87dd9 + b9da55a commit cf84006

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Diff for: compiler/rustc_span/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,10 @@ impl SpanData {
491491
pub fn is_dummy(self) -> bool {
492492
self.lo.0 == 0 && self.hi.0 == 0
493493
}
494+
#[inline]
495+
pub fn is_visible(self, sm: &SourceMap) -> bool {
496+
!self.is_dummy() && sm.is_span_accessible(self.span())
497+
}
494498
/// Returns `true` if `self` fully encloses `other`.
495499
pub fn contains(self, other: Self) -> bool {
496500
self.lo <= other.lo && other.hi <= self.hi
@@ -556,6 +560,11 @@ impl Span {
556560
self.data_untracked().is_dummy()
557561
}
558562

563+
#[inline]
564+
pub fn is_visible(self, sm: &SourceMap) -> bool {
565+
self.data_untracked().is_visible(sm)
566+
}
567+
559568
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
560569
#[inline]
561570
pub fn from_expansion(self) -> bool {

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2413,19 +2413,19 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24132413
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
24142414
let item_name = tcx.def_path_str(item_def_id);
24152415
let mut multispan = MultiSpan::from(span);
2416+
let sm = tcx.sess.source_map();
24162417
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
2417-
let sm = tcx.sess.source_map();
24182418
let same_line =
24192419
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
24202420
(Ok(l), Ok(r)) => l.line == r.line,
24212421
_ => true,
24222422
};
2423-
if !ident.span.is_dummy() && !ident.span.overlaps(span) && !same_line {
2423+
if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
24242424
multispan.push_span_label(ident.span, "required by a bound in this");
24252425
}
24262426
}
24272427
let descr = format!("required by a bound in `{}`", item_name);
2428-
if !span.is_dummy() {
2428+
if span.is_visible(sm) {
24292429
let msg = format!("required by this bound in `{}`", item_name);
24302430
multispan.push_span_label(span, msg);
24312431
err.span_note(multispan, &descr);

Diff for: src/test/ui/span/issue-71363.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ error[E0277]: `MyError` doesn't implement `std::fmt::Display`
88
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
99
note: required by a bound in `std::error::Error`
1010
--> $SRC_DIR/core/src/error.rs:LL:COL
11-
|
12-
= note: required by this bound in `std::error::Error`
1311

1412
error[E0277]: `MyError` doesn't implement `Debug`
1513
--> $DIR/issue-71363.rs:4:6
@@ -21,8 +19,6 @@ error[E0277]: `MyError` doesn't implement `Debug`
2119
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
2220
note: required by a bound in `std::error::Error`
2321
--> $SRC_DIR/core/src/error.rs:LL:COL
24-
|
25-
= note: required by this bound in `std::error::Error`
2622
help: consider annotating `MyError` with `#[derive(Debug)]`
2723
|
2824
3 | #[derive(Debug)]

0 commit comments

Comments
 (0)