Rollup merge of #105514 - estebank:is_visible, r=oli-obk
Introduce `Span::is_visible` r? `@oli-obk`
This commit is contained in:
commit
cf840069f3
@ -491,6 +491,10 @@ pub fn with_parent(&self, parent: Option<LocalDefId>) -> Span {
|
|||||||
pub fn is_dummy(self) -> bool {
|
pub fn is_dummy(self) -> bool {
|
||||||
self.lo.0 == 0 && self.hi.0 == 0
|
self.lo.0 == 0 && self.hi.0 == 0
|
||||||
}
|
}
|
||||||
|
#[inline]
|
||||||
|
pub fn is_visible(self, sm: &SourceMap) -> bool {
|
||||||
|
!self.is_dummy() && sm.is_span_accessible(self.span())
|
||||||
|
}
|
||||||
/// Returns `true` if `self` fully encloses `other`.
|
/// Returns `true` if `self` fully encloses `other`.
|
||||||
pub fn contains(self, other: Self) -> bool {
|
pub fn contains(self, other: Self) -> bool {
|
||||||
self.lo <= other.lo && other.hi <= self.hi
|
self.lo <= other.lo && other.hi <= self.hi
|
||||||
@ -556,6 +560,11 @@ pub fn is_dummy(self) -> bool {
|
|||||||
self.data_untracked().is_dummy()
|
self.data_untracked().is_dummy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn is_visible(self, sm: &SourceMap) -> bool {
|
||||||
|
self.data_untracked().is_visible(sm)
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
|
/// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_expansion(self) -> bool {
|
pub fn from_expansion(self) -> bool {
|
||||||
|
@ -2413,19 +2413,19 @@ fn note_obligation_cause_code<T>(
|
|||||||
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
|
| ObligationCauseCode::ExprBindingObligation(item_def_id, span, ..) => {
|
||||||
let item_name = tcx.def_path_str(item_def_id);
|
let item_name = tcx.def_path_str(item_def_id);
|
||||||
let mut multispan = MultiSpan::from(span);
|
let mut multispan = MultiSpan::from(span);
|
||||||
|
let sm = tcx.sess.source_map();
|
||||||
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
|
if let Some(ident) = tcx.opt_item_ident(item_def_id) {
|
||||||
let sm = tcx.sess.source_map();
|
|
||||||
let same_line =
|
let same_line =
|
||||||
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
|
match (sm.lookup_line(ident.span.hi()), sm.lookup_line(span.lo())) {
|
||||||
(Ok(l), Ok(r)) => l.line == r.line,
|
(Ok(l), Ok(r)) => l.line == r.line,
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
if !ident.span.is_dummy() && !ident.span.overlaps(span) && !same_line {
|
if ident.span.is_visible(sm) && !ident.span.overlaps(span) && !same_line {
|
||||||
multispan.push_span_label(ident.span, "required by a bound in this");
|
multispan.push_span_label(ident.span, "required by a bound in this");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let descr = format!("required by a bound in `{}`", item_name);
|
let descr = format!("required by a bound in `{}`", item_name);
|
||||||
if !span.is_dummy() {
|
if span.is_visible(sm) {
|
||||||
let msg = format!("required by this bound in `{}`", item_name);
|
let msg = format!("required by this bound in `{}`", item_name);
|
||||||
multispan.push_span_label(span, msg);
|
multispan.push_span_label(span, msg);
|
||||||
err.span_note(multispan, &descr);
|
err.span_note(multispan, &descr);
|
||||||
|
@ -8,8 +8,6 @@ error[E0277]: `MyError` doesn't implement `std::fmt::Display`
|
|||||||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
|
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
|
||||||
note: required by a bound in `std::error::Error`
|
note: required by a bound in `std::error::Error`
|
||||||
--> $SRC_DIR/core/src/error.rs:LL:COL
|
--> $SRC_DIR/core/src/error.rs:LL:COL
|
||||||
|
|
|
||||||
= note: required by this bound in `std::error::Error`
|
|
||||||
|
|
||||||
error[E0277]: `MyError` doesn't implement `Debug`
|
error[E0277]: `MyError` doesn't implement `Debug`
|
||||||
--> $DIR/issue-71363.rs:4:6
|
--> $DIR/issue-71363.rs:4:6
|
||||||
@ -21,8 +19,6 @@ error[E0277]: `MyError` doesn't implement `Debug`
|
|||||||
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
|
= note: add `#[derive(Debug)]` to `MyError` or manually `impl Debug for MyError`
|
||||||
note: required by a bound in `std::error::Error`
|
note: required by a bound in `std::error::Error`
|
||||||
--> $SRC_DIR/core/src/error.rs:LL:COL
|
--> $SRC_DIR/core/src/error.rs:LL:COL
|
||||||
|
|
|
||||||
= note: required by this bound in `std::error::Error`
|
|
||||||
help: consider annotating `MyError` with `#[derive(Debug)]`
|
help: consider annotating `MyError` with `#[derive(Debug)]`
|
||||||
|
|
|
|
||||||
3 | #[derive(Debug)]
|
3 | #[derive(Debug)]
|
||||||
|
Loading…
Reference in New Issue
Block a user