-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix erroneous span for borrowck error #98022
Merged
bors
merged 1 commit into
rust-lang:master
from
compiler-errors:erroneous-borrowck-span
Jun 21, 2022
Merged
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 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 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 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,16 @@ | ||
trait Foo { | ||
const ASSOC: bool = true; | ||
} | ||
impl<T> Foo for fn(T) {} | ||
|
||
fn foo(_x: i32) {} | ||
|
||
fn impls_foo<T: Foo>(_x: T) {} | ||
|
||
fn main() { | ||
impls_foo(foo as fn(i32)); | ||
|
||
<fn(&u8) as Foo>::ASSOC; | ||
//~^ ERROR implementation of `Foo` is not general enough | ||
//~| ERROR implementation of `Foo` is not general enough | ||
} |
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,20 @@ | ||
error: implementation of `Foo` is not general enough | ||
--> $DIR/issue-97997.rs:13:5 | ||
| | ||
LL | <fn(&u8) as Foo>::ASSOC; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough | ||
| | ||
= note: `Foo` would have to be implemented for the type `for<'r> fn(&'r u8)` | ||
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0` | ||
|
||
error: implementation of `Foo` is not general enough | ||
--> $DIR/issue-97997.rs:13:5 | ||
| | ||
LL | <fn(&u8) as Foo>::ASSOC; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough | ||
| | ||
= note: `Foo` would have to be implemented for the type `for<'r> fn(&'r u8)` | ||
= note: ...but `Foo` is actually implemented for the type `fn(&'0 u8)`, for some specific lifetime `'0` | ||
|
||
error: aborting due to 2 previous errors | ||
|
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.
It seems like you've identified the right course of action (modifying Body.required_consts instead of here).
I'd be ok with landing this as a temporary hack, but I'd rather getting sign off from somebody immediately related to the
const
generics effort. I'd punt to @oli-obk, but he'll be somewhat unavailable.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.
I wonder if we should just unconditionally use the constant's span, it seems like that span will always be better than what we can guess from the location (or we'll just end up fetching the constant's span at the location anyway). At which point it begs the question of whether we should be passing a location to
visit_constant
at all.A quick skim of all
visit_constant
andvisit_const
suggest that we're only really interested in the span, not the actual mir location.anyway. Leaving the hack comment and fixing this in a follow up PR seems the quickest way forward.
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.
Yeah, I looked into that refactoring, but we also use Location (and not Locations) as a key to some different HashMaps in different MIR stages? I'll see if I can give the refactoring another go, though.