Skip to content

Commit cb26b35

Browse files
committed
Make some diagnostics not depend on the source of what they reference being available
1 parent 71ec145 commit cb26b35

File tree

228 files changed

+417
-1504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+417
-1504
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,13 +1527,15 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
15271527
if let Some(virtual_dir) = &sess.opts.unstable_opts.simulate_remapped_rust_src_base
15281528
{
15291529
if let Some(real_dir) = &sess.opts.real_rust_source_base_dir {
1530-
if let rustc_span::FileName::Real(ref mut old_name) = name {
1531-
if let rustc_span::RealFileName::LocalPath(local) = old_name {
1532-
if let Ok(rest) = local.strip_prefix(real_dir) {
1533-
*old_name = rustc_span::RealFileName::Remapped {
1534-
local_path: None,
1535-
virtual_name: virtual_dir.join(rest),
1536-
};
1530+
for subdir in ["library", "compiler"] {
1531+
if let rustc_span::FileName::Real(ref mut old_name) = name {
1532+
if let rustc_span::RealFileName::LocalPath(local) = old_name {
1533+
if let Ok(rest) = local.strip_prefix(real_dir.join(subdir)) {
1534+
*old_name = rustc_span::RealFileName::Remapped {
1535+
local_path: None,
1536+
virtual_name: virtual_dir.join(subdir).join(rest),
1537+
};
1538+
}
15371539
}
15381540
}
15391541
}

compiler/rustc_privacy/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,15 +1308,15 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
13081308
let is_local_static =
13091309
if let DefKind::Static(_) = kind { def_id.is_local() } else { false };
13101310
if !self.item_is_accessible(def_id) && !is_local_static {
1311-
let sess = self.tcx.sess;
1312-
let sm = sess.source_map();
1313-
let name = match qpath {
1314-
hir::QPath::Resolved(..) | hir::QPath::LangItem(..) => {
1315-
sm.span_to_snippet(qpath.span()).ok()
1311+
let name = match *qpath {
1312+
hir::QPath::LangItem(it, ..) => {
1313+
self.tcx.lang_items().get(it).map(|did| self.tcx.def_path_str(did))
13161314
}
1315+
hir::QPath::Resolved(_, path) => Some(self.tcx.def_path_str(path.res.def_id())),
13171316
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
13181317
};
13191318
let kind = kind.descr(def_id);
1319+
let sess = self.tcx.sess;
13201320
let _ = match name {
13211321
Some(name) => {
13221322
sess.emit_err(ItemIsPrivate { span, kind, descr: (&name).into() })

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2179,15 +2179,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21792179
format!("does not implement `{}`", trait_pred.print_modifiers_and_trait_path())
21802180
};
21812181

2182-
let mut explain_yield = |interior_span: Span,
2183-
yield_span: Span,
2184-
scope_span: Option<Span>| {
2185-
let mut span = MultiSpan::from_span(yield_span);
2186-
if let Ok(snippet) = source_map.span_to_snippet(interior_span) {
2187-
// #70935: If snippet contains newlines, display "the value" instead
2188-
// so that we do not emit complex diagnostics.
2189-
let snippet = &format!("`{}`", snippet);
2190-
let snippet = if snippet.contains('\n') { "the value" } else { snippet };
2182+
let mut explain_yield =
2183+
|interior_span: Span, yield_span: Span, scope_span: Option<Span>| {
2184+
let mut span = MultiSpan::from_span(yield_span);
2185+
let snippet = match source_map.span_to_snippet(interior_span) {
2186+
// #70935: If snippet contains newlines, display "the value" instead
2187+
// so that we do not emit complex diagnostics.
2188+
Ok(snippet) if !snippet.contains('\n') => format!("`{}`", snippet),
2189+
_ => "the value".to_string(),
2190+
};
21912191
// note: future is not `Send` as this value is used across an await
21922192
// --> $DIR/issue-70935-complex-spans.rs:13:9
21932193
// |
@@ -2234,8 +2234,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22342234
if let Some((span, msg)) = scope_note {
22352235
err.span_note(span, &msg);
22362236
}
2237-
}
2238-
};
2237+
};
22392238
match interior_or_upvar_span {
22402239
GeneratorInteriorOrUpvar::Interior(interior_span, interior_extra_info) => {
22412240
if let Some((scope_span, yield_span, expr, from_awaited_ty)) = interior_extra_info {

src/test/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,8 +661,7 @@ LL | #[derive(Diagnostic)]
661661
note: required by a bound in `DiagnosticBuilder::<'a, G>::set_arg`
662662
--> $COMPILER_DIR/rustc_errors/src/diagnostic_builder.rs:LL:CC
663663
|
664-
LL | arg: impl IntoDiagnosticArg,
665-
| ^^^^^^^^^^^^^^^^^ required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
664+
= note: required by this bound in `DiagnosticBuilder::<'a, G>::set_arg`
666665
= note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info)
667666

668667
error: aborting due to 83 previous errors

src/test/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ LL | | }
1717
= note: struct `core::alloc::Layout` and struct `Layout` have similar names, but are actually distinct types
1818
note: struct `core::alloc::Layout` is defined in crate `core`
1919
--> $SRC_DIR/core/src/alloc/layout.rs:LL:COL
20-
|
21-
LL | pub struct Layout {
22-
| ^^^^^^^^^^^^^^^^^
2320
note: struct `Layout` is defined in the current crate
2421
--> $DIR/alloc-error-handler-bad-signature-2.rs:7:1
2522
|

src/test/ui/associated-type-bounds/issue-99828.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ LL | fn get_iter(vec: &[i32]) -> impl Iterator<Item = {}> + '_ {
1515
|
1616
note: associated type defined here
1717
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
18-
|
19-
LL | type Item;
20-
| ^^^^^^^^^
2118

2219
error: aborting due to 2 previous errors
2320

src/test/ui/associated-types/defaults-wf.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ LL | type Ty = Vec<[u8]>;
77
= help: the trait `Sized` is not implemented for `[u8]`
88
note: required by a bound in `Vec`
99
--> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
10-
|
11-
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
12-
| ^ required by this bound in `Vec`
1310

1411
error: aborting due to previous error
1512

src/test/ui/associated-types/trait-with-supertraits-needing-sized-self.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ LL | trait ArithmeticOps: Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self>
66
|
77
note: required by a bound in `Add`
88
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
9-
|
10-
LL | pub trait Add<Rhs = Self> {
11-
| ^^^^^^^^^^ required by this bound in `Add`
129
help: consider further restricting `Self`
1310
|
1411
LL | trait ArithmeticOps: Add<Output=Self> + Sub<Output=Self> + Mul<Output=Self> + Div<Output=Self> + Sized {}

src/test/ui/async-await/generator-desc.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ LL | fun(async {}, async {});
1212
found `async` block `[async block@$DIR/generator-desc.rs:10:19: 10:27]`
1313
note: function defined here
1414
--> $SRC_DIR/core/src/future/mod.rs:LL:COL
15-
|
16-
LL | pub const fn identity_future<O, Fut: Future<Output = O>>(f: Fut) -> Fut {
17-
| ^^^^^^^^^^^^^^^
1815

1916
error[E0308]: mismatched types
2017
--> $DIR/generator-desc.rs:12:16

src/test/ui/async-await/issue-72442.stderr

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ LL | let mut f = File::open(path.to_str())?;
88
|
99
note: required by a bound in `File::open`
1010
--> $SRC_DIR/std/src/fs.rs:LL:COL
11-
|
12-
LL | pub fn open<P: AsRef<Path>>(path: P) -> io::Result<File> {
13-
| ^^^^^^^^^^^ required by this bound in `File::open`
1411

1512
error: aborting due to previous error
1613

0 commit comments

Comments
 (0)