-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #48914 - gaurikholkar:e0389, r=nikomatsakis
Modify compile-fail/E0389 error message WIP This fixes #47388 cc @nikomatsakis @estebank r? @nikomatsakis Certain ui tests were failing locally. I'll check if the same happens here too.
- Loading branch information
Showing
8 changed files
with
182 additions
and
24 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
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,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 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,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 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`. |