about summary refs log tree commit diff
path: root/src/librustc_mir/util/mod.rs
blob: 0e7f473a3e70d2af498488f8531661fdf6cac6bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use core::unicode::property::Pattern_White_Space;
use rustc::ty::TyCtxt;
use syntax_pos::Span;

pub mod borrowck_errors;
pub mod elaborate_drops;
pub mod def_use;
pub mod patch;

mod alignment;
mod graphviz;
pub(crate) mod pretty;
pub mod liveness;
pub mod collect_writes;

pub use self::alignment::is_disaligned;
pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
pub use self::graphviz::{graphviz_safe_def_name, write_mir_graphviz};
pub use self::graphviz::write_node_label as write_graphviz_node_label;

/// If possible, suggest replacing `ref` with `ref mut`.
pub fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
    tcx: TyCtxt<'cx, 'gcx, 'tcx>,
    binding_span: Span,
) -> Option<(String)> {
    let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).unwrap();
    if hi_src.starts_with("ref")
        && hi_src["ref".len()..].starts_with(Pattern_White_Space)
    {
        let replacement = format!("ref mut{}", &hi_src["ref".len()..]);
        Some(replacement)
    } else {
        None
    }
}