Skip to content

Commit abfd4d1

Browse files
committed
Move suggest_ref_mut into rustc_mir::borrow_check
1 parent 2cc2b94 commit abfd4d1

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

Diff for: src/librustc_mir/borrow_check/mutability_errors.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use core::unicode::property::Pattern_White_Space;
12
use rustc::hir;
23
use rustc::hir::Node;
34
use rustc::mir::{self, BindingForm, ClearCrossCrate, Local, Location, Body};
@@ -10,7 +11,6 @@ use syntax_pos::symbol::kw;
1011
use crate::borrow_check::MirBorrowckCtxt;
1112
use crate::borrow_check::error_reporting::BorrowedContentSource;
1213
use crate::util::collect_writes::FindAssignments;
13-
use crate::util::suggest_ref_mut;
1414
use rustc_errors::Applicability;
1515

1616
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
@@ -628,3 +628,16 @@ fn annotate_struct_field(
628628

629629
None
630630
}
631+
632+
/// If possible, suggest replacing `ref` with `ref mut`.
633+
fn suggest_ref_mut(tcx: TyCtxt<'_>, binding_span: Span) -> Option<(String)> {
634+
let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).unwrap();
635+
if hi_src.starts_with("ref")
636+
&& hi_src["ref".len()..].starts_with(Pattern_White_Space)
637+
{
638+
let replacement = format!("ref mut{}", &hi_src["ref".len()..]);
639+
Some(replacement)
640+
} else {
641+
None
642+
}
643+
}

Diff for: src/librustc_mir/util/mod.rs

-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
use core::unicode::property::Pattern_White_Space;
2-
use rustc::ty::TyCtxt;
3-
use syntax_pos::Span;
4-
51
pub mod aggregate;
62
pub mod borrowck_errors;
73
pub mod elaborate_drops;
@@ -19,16 +15,3 @@ pub use self::alignment::is_disaligned;
1915
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
2016
pub use self::graphviz::{graphviz_safe_def_name, write_mir_graphviz};
2117
pub use self::graphviz::write_node_label as write_graphviz_node_label;
22-
23-
/// If possible, suggest replacing `ref` with `ref mut`.
24-
pub fn suggest_ref_mut(tcx: TyCtxt<'_>, binding_span: Span) -> Option<(String)> {
25-
let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).unwrap();
26-
if hi_src.starts_with("ref")
27-
&& hi_src["ref".len()..].starts_with(Pattern_White_Space)
28-
{
29-
let replacement = format!("ref mut{}", &hi_src["ref".len()..]);
30-
Some(replacement)
31-
} else {
32-
None
33-
}
34-
}

0 commit comments

Comments
 (0)