-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fix diag span errors for bad_placeholder #116511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
chenyukang
wants to merge
1
commit into
rust-lang:master
from
chenyukang:yukang-fix-116502-span-errors
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,42 @@ | ||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
macro_rules! Tuple { | ||
{ $A:ty,$B:ty } => { ($A, $B) } | ||
} | ||
|
||
fn main() { | ||
let x: Tuple!(i32, i32) = (1, 2); | ||
} | ||
|
||
fn issue_36540() { | ||
let _ = 0; | ||
macro_rules! m { | ||
() => { | ||
_ | ||
//~^ ERROR in expressions | ||
//~| ERROR in expressions | ||
//~| ERROR the placeholder `_` is not allowed | ||
//~| ERROR the placeholder `_` is not allowed | ||
//~| ERROR the placeholder `_` is not allowed | ||
//~| ERROR the placeholder `_` is not allowed | ||
}; | ||
} | ||
struct S<T = m!()>(m!(), T) | ||
where | ||
T: Trait<m!()>; | ||
|
||
let x: m!() = m!(); | ||
std::cell::Cell::<m!()>::new(m!()); | ||
impl<T> std::ops::Index<m!()> for dyn Trait<(m!(), T)> | ||
where | ||
T: Trait<m!()>, | ||
{ | ||
type Output = m!(); | ||
fn index(&self, i: m!()) -> &m!() { | ||
unimplemented!() | ||
} | ||
} | ||
} | ||
|
||
trait Trait<T> {} | ||
impl Trait<i32> for i32 {} |
This file contains hidden or 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,120 @@ | ||
error: in expressions, `_` can only be used on the left-hand side of an assignment | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ `_` not allowed here | ||
... | ||
LL | let x: m!() = m!(); | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error: in expressions, `_` can only be used on the left-hand side of an assignment | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ `_` not allowed here | ||
... | ||
LL | std::cell::Cell::<m!()>::new(m!()); | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| not allowed in type signatures | ||
| not allowed in type signatures | ||
... | ||
LL | struct S<T = m!()>(m!(), T) | ||
| ---- ---- in this macro invocation | ||
| | | ||
| in this macro invocation | ||
LL | where | ||
LL | T: Trait<m!()>; | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: use type parameters instead | ||
| | ||
LL ~ U | ||
LL | | ||
... | ||
LL | } | ||
LL ~ struct S<U>(m!(), T) | ||
| | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| not allowed in type signatures | ||
| not allowed in type signatures | ||
... | ||
LL | impl<T> std::ops::Index<m!()> for dyn Trait<(m!(), T)> | ||
| ---- ---- in this macro invocation | ||
| | | ||
| in this macro invocation | ||
LL | where | ||
LL | T: Trait<m!()>, | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: use type parameters instead | ||
| | ||
LL ~ U | ||
LL | | ||
... | ||
LL | std::cell::Cell::<m!()>::new(m!()); | ||
LL ~ impl<T, U> std::ops::Index<m!()> for dyn Trait<(m!(), T)> | ||
| | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for associated types | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ not allowed in type signatures | ||
... | ||
LL | type Output = m!(); | ||
| ---- in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
|
||
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions | ||
--> $DIR/issue-116502-span-error.rs:15:13 | ||
| | ||
LL | _ | ||
| ^ | ||
| | | ||
| not allowed in type signatures | ||
| not allowed in type signatures | ||
... | ||
LL | fn index(&self, i: m!()) -> &m!() { | ||
| ---- ---- in this macro invocation | ||
| | | ||
| in this macro invocation | ||
| | ||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) | ||
help: use type parameters instead | ||
| | ||
LL ~ T | ||
LL | | ||
... | ||
LL | type Output = m!(); | ||
LL ~ fn index<T>(&self, i: m!()) -> &m!() { | ||
| | ||
help: try replacing `_` with the type in the corresponding trait method signature | ||
| | ||
LL | {type error} | ||
| | ||
|
||
error: aborting due to 6 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0121`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably should fix this suggestion anyways
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems the
help
diag you pointed out is another issue.The root cause in the issue is we inserted duplicated
span
intoHirPlaceholderCollector
here:rust/compiler/rustc_hir_analysis/src/collect.rs
Line 129 in a483969
in the scenario of code like:
This PR is trying to remove the duplicated ones, since we're mapping spans with same type
type_name
.Maybe we need to use
Set
instead ofVec
inHirPlaceholderCollector
? I'm not sure about it.