about summary refs log tree commit diff
path: root/compiler/rustc_session
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2022-11-25 17:14:25 -0800
committerEsteban Küber <esteban@kuber.com.ar>2022-11-28 14:08:18 -0800
commit7674edeebac02ce9b3ee6434e5a4ab6a085005f9 (patch)
treeb7a2e8e44842af103bb021aebc88bf0fa3607e3b /compiler/rustc_session
parent8a09420ac48658cad726e0a6997687ceac4151e3 (diff)
downloadrust-7674edeebac02ce9b3ee6434e5a4ab6a085005f9.tar.gz
rust-7674edeebac02ce9b3ee6434e5a4ab6a085005f9.zip
Detect long types in E0308 and write them to disk
On type error with long types, print an abridged type and write the full
type to disk.

Print the widest possible short type while still fitting in the
terminal.
Diffstat (limited to 'compiler/rustc_session')
-rw-r--r--compiler/rustc_session/Cargo.toml1
-rw-r--r--compiler/rustc_session/src/session.rs11
2 files changed, 12 insertions, 0 deletions
diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml
index a052f293341..cbbba2252bf 100644
--- a/compiler/rustc_session/Cargo.toml
+++ b/compiler/rustc_session/Cargo.toml
@@ -18,6 +18,7 @@ rustc_fs_util = { path = "../rustc_fs_util" }
 rustc_ast = { path = "../rustc_ast" }
 rustc_lint_defs = { path = "../rustc_lint_defs" }
 smallvec = "1.8.1"
+termize = "0.1.1"
 
 [target.'cfg(unix)'.dependencies]
 libc = "0.2"
diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs
index e99e460913e..4c049a8d628 100644
--- a/compiler/rustc_session/src/session.rs
+++ b/compiler/rustc_session/src/session.rs
@@ -952,6 +952,17 @@ impl Session {
     ) -> Option<Symbol> {
         attrs.iter().find(|at| at.has_name(name)).and_then(|at| at.value_str())
     }
+
+    pub fn diagnostic_width(&self) -> usize {
+        let default_column_width = 140;
+        if let Some(width) = self.opts.diagnostic_width {
+            width
+        } else if self.opts.unstable_opts.ui_testing {
+            default_column_width
+        } else {
+            termize::dimensions().map_or(default_column_width, |(w, _)| w)
+        }
+    }
 }
 
 // JUSTIFICATION: defn of the suggested wrapper fns