-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix suggestions span for when expr is from macro expansions
- Loading branch information
Showing
5 changed files
with
193 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
tests/ui/typeck/issue-110017-format-into-help-deletes-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
pub fn foo(x: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
Err(format!("error: {x}")) | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
macro_rules! outer { | ||
($x: expr) => { | ||
inner!($x) | ||
} | ||
} | ||
|
||
macro_rules! inner { | ||
($x: expr) => { | ||
format!("error: {}", $x) | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
|
||
fn bar(x: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
Err(outer!(x)) | ||
} | ||
|
||
macro_rules! entire_fn_outer { | ||
() => { | ||
entire_fn!(); | ||
} | ||
} | ||
|
||
macro_rules! entire_fn { | ||
() => { | ||
pub fn baz(x: &str) -> Result<(), Box<dyn std::error::Error>> { | ||
Err(format!("error: {x}")) | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
} | ||
|
||
entire_fn_outer!(); | ||
|
||
fn main() {} |
45 changes: 45 additions & 0 deletions
45
tests/ui/typeck/issue-110017-format-into-help-deletes-macro.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-110017-format-into-help-deletes-macro.rs:2:9 | ||
| | ||
LL | Err(format!("error: {x}")) | ||
| ^^^^^^^^^^^^^^^^^^^^^ expected `Box<dyn Error>`, found `String` | ||
| | ||
= note: expected struct `Box<dyn std::error::Error>` | ||
found struct `String` | ||
= note: this error originates in the macro `format` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: call `Into::into` on this expression to convert `String` into `Box<dyn std::error::Error>` | ||
| | ||
LL | Err(format!("error: {x}").into()) | ||
| +++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-110017-format-into-help-deletes-macro.rs:20:9 | ||
| | ||
LL | Err(outer!(x)) | ||
| ^^^^^^^^^ expected `Box<dyn Error>`, found `String` | ||
| | ||
= note: expected struct `Box<dyn std::error::Error>` | ||
found struct `String` | ||
= note: this error originates in the macro `format` which comes from the expansion of the macro `outer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: call `Into::into` on this expression to convert `String` into `Box<dyn std::error::Error>` | ||
| | ||
LL | Err(outer!(x).into()) | ||
| +++++++ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-110017-format-into-help-deletes-macro.rs:38:1 | ||
| | ||
LL | entire_fn_outer!(); | ||
| ^^^^^^^^^^^^^^^^^^ expected `Box<dyn Error>`, found `String` | ||
| | ||
= note: expected struct `Box<dyn std::error::Error>` | ||
found struct `String` | ||
= note: this error originates in the macro `format` which comes from the expansion of the macro `entire_fn_outer` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: call `Into::into` on this expression to convert `String` into `Box<dyn std::error::Error>` | ||
| | ||
LL | Err(format!("error: {x}").into()) | ||
| +++++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
34 changes: 34 additions & 0 deletions
34
tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// https://github.com/rust-lang/rust/issues/112007 | ||
fn bug_report<W: std::fmt::Write>(w: &mut W) -> std::fmt::Result { | ||
if true { | ||
writeln!(w, "`;?` here ->")?; | ||
} else { | ||
writeln!(w, "but not here") | ||
//~^ ERROR mismatched types | ||
} | ||
Ok(()) | ||
} | ||
|
||
macro_rules! baz { | ||
($w: expr) => { | ||
bar!($w) | ||
} | ||
} | ||
|
||
macro_rules! bar { | ||
($w: expr) => { | ||
writeln!($w, "but not here") | ||
//~^ ERROR mismatched types | ||
} | ||
} | ||
|
||
fn foo<W: std::fmt::Write>(w: &mut W) -> std::fmt::Result { | ||
if true { | ||
writeln!(w, "`;?` here ->")?; | ||
} else { | ||
baz!(w) | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() {} |
50 changes: 50 additions & 0 deletions
50
tests/ui/typeck/issue-112007-leaked-writeln-macro-internals.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-112007-leaked-writeln-macro-internals.rs:6:9 | ||
| | ||
LL | / if true { | ||
LL | | writeln!(w, "`;?` here ->")?; | ||
LL | | } else { | ||
LL | | writeln!(w, "but not here") | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `()`, found `Result<(), Error>` | ||
LL | | | ||
LL | | } | ||
| |_____- expected this to be `()` | ||
| | ||
= note: expected unit type `()` | ||
found enum `Result<(), std::fmt::Error>` | ||
= note: this error originates in the macro `writeln` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider using a semicolon here | ||
| | ||
LL | }; | ||
| + | ||
help: you might have meant to return this value | ||
| | ||
LL | return writeln!(w, "but not here"); | ||
| ++++++ + | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/issue-112007-leaked-writeln-macro-internals.rs:29:9 | ||
| | ||
LL | / if true { | ||
LL | | writeln!(w, "`;?` here ->")?; | ||
LL | | } else { | ||
LL | | baz!(w) | ||
| | ^^^^^^^ expected `()`, found `Result<(), Error>` | ||
LL | | } | ||
| |_____- expected this to be `()` | ||
| | ||
= note: expected unit type `()` | ||
found enum `Result<(), std::fmt::Error>` | ||
= note: this error originates in the macro `writeln` which comes from the expansion of the macro `baz` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: consider using a semicolon here | ||
| | ||
LL | }; | ||
| + | ||
help: you might have meant to return this value | ||
| | ||
LL | return baz!(w); | ||
| ++++++ + | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |