]> git.lizzy.rs Git - rust.git/blob - src/librustc_mir/util/mod.rs
Rollup merge of #53413 - eddyb:featured-in-the-latest-edition, r=varkor
[rust.git] / src / librustc_mir / util / mod.rs
1 // Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 use core::unicode::property::Pattern_White_Space;
12 use rustc::ty;
13 use syntax_pos::Span;
14
15 pub mod borrowck_errors;
16 pub mod elaborate_drops;
17 pub mod def_use;
18 pub mod patch;
19
20 mod alignment;
21 mod graphviz;
22 pub(crate) mod pretty;
23 pub mod liveness;
24 pub mod collect_writes;
25
26 pub use self::alignment::is_disaligned;
27 pub use self::pretty::{dump_enabled, dump_mir, write_mir_pretty, PassWhere};
28 pub use self::graphviz::{write_mir_graphviz};
29 pub use self::graphviz::write_node_label as write_graphviz_node_label;
30
31 /// If possible, suggest replacing `ref` with `ref mut`.
32 pub fn suggest_ref_mut<'cx, 'gcx, 'tcx>(
33     tcx: ty::TyCtxt<'cx, 'gcx, 'tcx>,
34     binding_span: Span,
35 ) -> Option<(String)> {
36     let hi_src = tcx.sess.codemap().span_to_snippet(binding_span).unwrap();
37     if hi_src.starts_with("ref")
38         && hi_src["ref".len()..].starts_with(Pattern_White_Space)
39     {
40         let replacement = format!("ref mut{}", &hi_src["ref".len()..]);
41         Some(replacement)
42     } else {
43         None
44     }
45 }