Skip to content

Commit c2d8485

Browse files
authored
Rollup merge of #97845 - estebank:spancito, r=compiler-errors
Use more targeted suggestion when confusing i8 with std::i8 r? `@compiler-errors`
2 parents 5870156 + 8542dd0 commit c2d8485

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

compiler/rustc_typeck/src/astconv/mod.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -1577,18 +1577,17 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
15771577
name: Symbol,
15781578
) -> ErrorGuaranteed {
15791579
let mut err = struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type");
1580-
if let (true, Ok(snippet)) = (
1581-
self.tcx()
1582-
.resolutions(())
1583-
.confused_type_with_std_module
1584-
.keys()
1585-
.any(|full_span| full_span.contains(span)),
1586-
self.tcx().sess.source_map().span_to_snippet(span),
1587-
) {
1580+
if self
1581+
.tcx()
1582+
.resolutions(())
1583+
.confused_type_with_std_module
1584+
.keys()
1585+
.any(|full_span| full_span.contains(span))
1586+
{
15881587
err.span_suggestion(
1589-
span,
1588+
span.shrink_to_lo(),
15901589
"you are looking for the module in `std`, not the primitive type",
1591-
format!("std::{}", snippet),
1590+
"std::".to_string(),
15921591
Applicability::MachineApplicable,
15931592
);
15941593
} else {

compiler/rustc_typeck/src/check/method/suggest.rs

+10-14
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
327327
);
328328
}
329329
if let Some(span) = tcx.resolutions(()).confused_type_with_std_module.get(&span) {
330-
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(*span) {
331-
err.span_suggestion(
332-
*span,
333-
"you are looking for the module in `std`, \
334-
not the primitive type",
335-
format!("std::{}", snippet),
336-
Applicability::MachineApplicable,
337-
);
338-
}
330+
err.span_suggestion(
331+
span.shrink_to_lo(),
332+
"you are looking for the module in `std`, not the primitive type",
333+
"std::".to_string(),
334+
Applicability::MachineApplicable,
335+
);
339336
}
340337
if let ty::RawPtr(_) = &actual.kind() {
341338
err.note(
342339
"try using `<*const T>::as_ref()` to get a reference to the \
343-
type behind the pointer: https://doc.rust-lang.org/std/\
344-
primitive.pointer.html#method.as_ref",
340+
type behind the pointer: https://doc.rust-lang.org/std/\
341+
primitive.pointer.html#method.as_ref",
345342
);
346343
err.note(
347-
"using `<*const T>::as_ref()` on a pointer \
348-
which is unaligned or points to invalid \
349-
or uninitialized memory is undefined behavior",
344+
"using `<*const T>::as_ref()` on a pointer which is unaligned or points \
345+
to invalid or uninitialized memory is undefined behavior",
350346
);
351347
}
352348

src/test/ui/suggestions/suggest-std-when-using-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let pi = f32::consts::PI;
77
help: you are looking for the module in `std`, not the primitive type
88
|
99
LL | let pi = std::f32::consts::PI;
10-
| ~~~~~~~~~~~~~~~~
10+
| +++++
1111

1212
error[E0599]: no function or associated item named `from_utf8` found for type `str` in the current scope
1313
--> $DIR/suggest-std-when-using-type.rs:5:14
@@ -18,7 +18,7 @@ LL | str::from_utf8(bytes)
1818
help: you are looking for the module in `std`, not the primitive type
1919
|
2020
LL | std::str::from_utf8(bytes)
21-
| ~~~~~~~~~~~~~~~~~~~
21+
| +++++
2222

2323
error: aborting due to 2 previous errors
2424

0 commit comments

Comments
 (0)