Skip to content

Commit 02e2ed9

Browse files
authored
Unrolled build for #142873
Rollup merge of #142873 - Urgau:issue-139830, r=BoxyUwU Don't suggest changing a method inside a expansion Fixes #139830 r? compiler
2 parents 706f244 + 188023a commit 02e2ed9

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1723,8 +1723,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17231723
// Don't emit a suggestion if we found an actual method
17241724
// that had unsatisfied trait bounds
17251725
if unsatisfied_predicates.is_empty()
1726-
// ...or if we already suggested that name because of `rustc_confusable` annotation.
1726+
// ...or if we already suggested that name because of `rustc_confusable` annotation
17271727
&& Some(similar_candidate.name()) != confusable_suggested
1728+
// and if the we aren't in an expansion.
1729+
&& !span.from_expansion()
17281730
{
17291731
self.find_likely_intended_associated_item(
17301732
&mut err,

tests/ui/hygiene/no_implicit_prelude.stderr

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ LL | ().clone()
2323
| ^^^^^
2424
|
2525
= help: items from traits can only be used if the trait is in scope
26-
help: there is a method `clone_from` with a similar name, but with different arguments
27-
--> $SRC_DIR/core/src/clone.rs:LL:COL
2826
= note: this error originates in the macro `::bar::m` (in Nightly builds, run with -Z macro-backtrace for more info)
2927
help: trait `Clone` which provides `clone` is implemented but not in scope; perhaps you want to import it
3028
|
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Make sure we don't suggest a method change inside the `write!` macro.
2+
//
3+
// See <https://github.com/rust-lang/rust/issues/139830>
4+
5+
fn main() {
6+
let mut buf = String::new();
7+
let _ = write!(buf, "foo");
8+
//~^ ERROR cannot write into `String`
9+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0599]: cannot write into `String`
2+
--> $DIR/missing-writer-issue-139830.rs:7:20
3+
|
4+
LL | let _ = write!(buf, "foo");
5+
| ^^^
6+
--> $SRC_DIR/core/src/fmt/mod.rs:LL:COL
7+
|
8+
= note: the method is available for `String` here
9+
|
10+
note: must implement `io::Write`, `fmt::Write`, or have a `write_fmt` method
11+
--> $DIR/missing-writer-issue-139830.rs:7:20
12+
|
13+
LL | let _ = write!(buf, "foo");
14+
| ^^^
15+
= help: items from traits can only be used if the trait is in scope
16+
help: trait `Write` which provides `write_fmt` is implemented but not in scope; perhaps you want to import it
17+
|
18+
LL + use std::fmt::Write;
19+
|
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)