-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Modify compile-fail/E0389 error message WIP #48914
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
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7d590b5
changes for new compile-fail/E0389 message
gaurikholkar 308e30e
adding Visitor changes
gaurikholkar f60788b
update visit_local for FindLocalAssignmentVisitor
gaurikholkar 3f0ce08
minor refactorings to fix trait import issue
gaurikholkar bfc9b76
add collect_writes.rs
gaurikholkar 7a266a6
minor changes
gaurikholkar 0c7fc04
code refactor, modify compile-fail tests
gaurikholkar fdb2f7f
tidy fixes
gaurikholkar 55bd914
fix warnings
gaurikholkar 50299c6
add ui test for E0594
gaurikholkar 7745b52
fix tidy issues
gaurikholkar 311a8be
address code review comments
gaurikholkar 6c649fb
address code review comments
gaurikholkar 1b06fe1
Merge branch 'master' of https://github.com/rust-lang/rust into e0389
gaurikholkar c119206
Update borrowck_errors.rs
gaurikholkar 12d1415
tidy fixes
gaurikholkar 1fb25fb
reduce nested loops in the code
gaurikholkar e6938ee
fix ui test
gaurikholkar 6686d10
tidy fix
gaurikholkar e18a83b
fix ui test
gaurikholkar e5a96a4
modify the error message- CR Comments
gaurikholkar cbde62c
fix tidy errors
gaurikholkar 2ad20e8
tidy fixes
gaurikholkar c792d1e
tidy fixes
gaurikholkar 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
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,67 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use rustc::mir::{Local, Location}; | ||
use rustc::mir::Mir; | ||
use rustc::mir::visit::PlaceContext; | ||
use rustc::mir::visit::Visitor; | ||
|
||
crate trait FindAssignments { | ||
// Finds all statements that assign directly to local (i.e., X = ...) | ||
// and returns their locations. | ||
fn find_assignments(&self, local: Local) -> Vec<Location>; | ||
} | ||
|
||
impl<'tcx> FindAssignments for Mir<'tcx>{ | ||
fn find_assignments(&self, local: Local) -> Vec<Location>{ | ||
let mut visitor = FindLocalAssignmentVisitor{ needle: local, locations: vec![]}; | ||
visitor.visit_mir(self); | ||
visitor.locations | ||
} | ||
} | ||
|
||
// The Visitor walks the MIR to return the assignment statements corresponding | ||
// to a Local. | ||
struct FindLocalAssignmentVisitor { | ||
needle: Local, | ||
locations: Vec<Location>, | ||
} | ||
|
||
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor { | ||
fn visit_local(&mut self, | ||
local: &Local, | ||
place_context: PlaceContext<'tcx>, | ||
location: Location) { | ||
if self.needle != *local { | ||
return; | ||
} | ||
|
||
match place_context { | ||
PlaceContext::Store | PlaceContext::Call => { | ||
self.locations.push(location); | ||
} | ||
PlaceContext::AsmOutput | | ||
PlaceContext::Drop | | ||
PlaceContext::Inspect | | ||
PlaceContext::Borrow { .. } | | ||
PlaceContext::Projection(..) | | ||
PlaceContext::Copy | | ||
PlaceContext::Move | | ||
PlaceContext::StorageLive | | ||
PlaceContext::StorageDead | | ||
PlaceContext::Validate => { | ||
// TO-DO | ||
// self.super_local(local) | ||
} | ||
} | ||
} | ||
// TO-DO | ||
// fn super_local() | ||
} |
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
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,20 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
#![feature(nll)] | ||
struct FancyNum { | ||
num: u8, | ||
} | ||
|
||
fn main() { | ||
let mut fancy = FancyNum{ num: 5 }; | ||
let fancy_ref = &(&mut fancy); | ||
fancy_ref.num = 6; //~ ERROR E0594 | ||
println!("{}", fancy_ref.num); | ||
} |
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,11 @@ | ||
error[E0594]: cannot assign to data in a `&` reference | ||
--> $DIR/issue-47388.rs:18:5 | ||
| | ||
LL | let fancy_ref = &(&mut fancy); | ||
| ------------- help: consider changing this to be a mutable reference: `&mut` | ||
LL | fancy_ref.num = 6; //~ ERROR E0594 | ||
| ^^^^^^^^^^^^^^^^^ `fancy_ref` is a `&` reference, so the data it refers to cannot be written | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0594`. |
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.
I believe either the span or the suggestion text might be incorrect. It should either suggest
&mut (&mut fancy)
for this span, or use a span only selecting the&
.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.
Filed #49859