Skip to content

Commit e422612

Browse files
authored
Rollup merge of #87088 - FabianWolff:issue-87060, r=estebank
Fix stray notes when the source code is not available Fixes #87060. To reproduce it with a local build of rustc, you have to copy the compiler (e.g. `build/x86_64-unknown-linux-gnu/stage1/`) somewhere and then rename the compiler source directory (maybe there is a smarter way as well). Then, rustc won't find the standard library sources and report stray notes such as ``` note: deref defined here ``` with no location for "here". Another example I've found is this: ```rust use std::ops::Add; fn foo<T: Add<Output=()>>(x: T) { x + x; } fn main() {} ``` ``` error[E0382]: use of moved value: `x` --> binop.rs:4:9 | 3 | fn foo<T: Add<Output=()>>(x: T) { | - move occurs because `x` has type `T`, which does not implement the `Copy` trait 4 | x + x; | ----^ | | | | | value used here after move | `x` moved due to usage in operator | note: calling this operator moves the left-hand side help: consider further restricting this bound | 3 | fn foo<T: Add<Output=()> + Copy>(x: T) { | ^^^^^^ error: aborting due to previous error ``` where, again, the note is supposed to point somewhere but doesn't. I have fixed this by checking whether the corresponding source code is actually available before emitting the note.
2 parents 000dbd2 + 57fcb2e commit e422612

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,19 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
218218
);
219219
if self.fn_self_span_reported.insert(fn_span) {
220220
err.span_note(
221-
self_arg.span,
221+
// Check whether the source is accessible
222+
if self
223+
.infcx
224+
.tcx
225+
.sess
226+
.source_map()
227+
.span_to_snippet(self_arg.span)
228+
.is_ok()
229+
{
230+
self_arg.span
231+
} else {
232+
fn_call_span
233+
},
222234
"calling this operator moves the left-hand side",
223235
);
224236
}
@@ -429,7 +441,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
429441
deref_target_ty
430442
));
431443

432-
err.span_note(deref_target, "deref defined here");
444+
// Check first whether the source is accessible (issue #87060)
445+
if self.infcx.tcx.sess.source_map().span_to_snippet(deref_target).is_ok() {
446+
err.span_note(deref_target, "deref defined here");
447+
}
433448
}
434449

435450
if let Some((_, mut old_err)) =

0 commit comments

Comments
 (0)