]>
git.proxmox.com Git - rustc.git/blob - vendor/codespan-reporting/examples/term.rs
1 use structopt
::StructOpt
;
4 use codespan_reporting
::diagnostic
::{Diagnostic, Label}
;
5 use codespan_reporting
::term
::termcolor
::StandardStream
;
6 use codespan_reporting
::term
::{emit, ColorArg}
;
8 #[derive(Debug, StructOpt)]
9 #[structopt(name = "emit")]
11 /// Configure coloring of output
15 default_value
= "auto",
16 raw(possible_values
= "ColorArg::VARIANTS", case_insensitive
= "true")
22 let opts
= Opts
::from_args();
23 let mut files
= Files
::new();
25 let file_id1
= files
.add(
35 {-# BUILTIN NATRAL Nat #-}
41 succ n₁ + n₂ = succ (n₁ + n₂)
46 succ n₁ - succ n₂ = n₁ - n₂
51 let file_id2
= files
.add(
63 let file_id3
= files
.add(
70 fizz₁ num = case (mod num 5) (mod num 3) of
77 case (mod num 5) (mod num 3) of
87 // Unknown builtin error
88 Diagnostic
::new_error(
89 "unknown builtin: `NATRAL`",
90 Label
::new(file_id1
, 96..102, "unknown builtin"),
93 "there is a builtin with a similar name: `NATURAL`".to_owned()
95 // Unused parameter warning
96 Diagnostic
::new_warning(
97 "unused parameter pattern: `n₂`",
98 Label
::new(file_id1
, 285..289, "unused parameter"),
100 .with_notes(vec
!["consider using a wildcard pattern: `_`".to_owned()]),
101 // Unexpected type error
102 Diagnostic
::new_error(
103 "unexpected type in application of `_+_`",
104 Label
::new(file_id2
, 37..44, "expected `Nat`, found `String`"),
107 .with_secondary_labels(vec
![Label
::new(
110 "based on the definition of `_+_`",
112 // Incompatible match clause error
113 Diagnostic
::new_error(
114 "`case` clauses have incompatible types",
115 Label
::new(file_id3
, 163..166, "expected `String`, found `Nat`"),
118 .with_notes(vec
![unindent
::unindent(
120 expected type `String`
124 .with_secondary_labels(vec
![
125 Label
::new(file_id3
, 62..166, "`case` clauses have incompatible types"),
126 Label
::new(file_id3
, 41..47, "expected type `String` found here"),
128 // Incompatible match clause error
129 Diagnostic
::new_error(
130 "`case` clauses have incompatible types",
131 Label
::new(file_id3
, 303..306, "expected `String`, found `Nat`"),
134 .with_notes(vec
![unindent
::unindent(
136 expected type `String`
140 .with_secondary_labels(vec
![
141 Label
::new(file_id3
, 186..306, "`case` clauses have incompatible types"),
142 Label
::new(file_id3
, 233..243, "this is found to be of type `String`"),
143 Label
::new(file_id3
, 259..265, "this is found to be of type `String`"),
144 Label
::new(file_id3
, 281..287, "this is found to be of type `String`"),
148 let writer
= StandardStream
::stderr(opts
.color
.into());
149 let config
= codespan_reporting
::term
::Config
::default();
150 for diagnostic
in &diagnostics
{
151 emit(&mut writer
.lock(), &config
, &files
, &diagnostic
).unwrap();