]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/util/mod.rs
Fix lint findings in librustc_mir
[rust.git] / src / librustc_mir / util / mod.rs
1 use core::unicode::property::Pattern_White_Space;
2 use rustc::ty::TyCtxt;
3 use syntax_pos::Span;
4
5 pub mod borrowck_errors;
6 pub mod elaborate_drops;
7 pub mod def_use;
8 pub mod patch;
9
10 mod alignment;
11 mod graphviz;
12 pub(crate) mod pretty;
13 pub mod liveness;
14 pub mod collect_writes;
15
16 pub use self::alignment::is_disaligned;
17 pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
18 pub use self::graphviz::{graphviz_safe_def_name, write_mir_graphviz};
19 pub use self::graphviz::write_node_label as write_graphviz_node_label;
20
21 /// If possible, suggest replacing `ref` with `ref mut`.
22 pub fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
23     tcx: TyCtxt<'cx, 'gcx, 'tcx>,
24     binding_span: Span,
25 ) -> Option<(String)> {
26     let hi_src = tcx.sess.source_map().span_to_snippet(binding_span).unwrap();
27     if hi_src.starts_with("ref")
28         && hi_src["ref".len()..].starts_with(Pattern_White_Space)
29     {
30         let replacement = format!("ref mut{}", &hi_src["ref".len()..]);
31         Some(replacement)
32     } else {
33         None
34     }
35 }