--- /dev/null
+// run-fail
+// error-pattern:explicit panic
+// ignore-emscripten no processes
+
+fn f() -> ! {
+ panic!()
+}
+
+fn g() -> isize {
+ let x = if true {
+ f()
+ } else {
+ 10
+ };
+ return x;
+}
+
+fn main() {
+ g();
+}
--- /dev/null
+// run-fail
+// error-pattern:explicit panic
+// ignore-emscripten no processes
+
+fn main() {
+ let _x = if false {
+ 0
+ } else if true {
+ panic!()
+ } else {
+ 10
+ };
+}
--- /dev/null
+fn main() {
+ let x = if true { 10i32 } else { 10u32 };
+ //~^ ERROR `if` and `else` have incompatible types
+ //~| expected `i32`, found `u32`
+}
--- /dev/null
+error[E0308]: `if` and `else` have incompatible types
+ --> $DIR/if-branch-types.rs:2:38
+ |
+LL | let x = if true { 10i32 } else { 10u32 };
+ | ----- ^^^^^ expected `i32`, found `u32`
+ | |
+ | expected because of this
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// run-fail
+// error-pattern:Number is odd
+// ignore-emscripten no processes
+
+fn even(x: usize) -> bool {
+ if x < 2 {
+ return false;
+ } else if x == 2 {
+ return true;
+ } else {
+ return even(x - 2);
+ }
+}
+
+fn foo(x: usize) {
+ if even(x) {
+ println!("{}", x);
+ } else {
+ panic!("Number is odd");
+ }
+}
+
+fn main() {
+ foo(3);
+}
--- /dev/null
+// run-fail
+// error-pattern:quux
+// ignore-emscripten no processes
+
+fn my_err(s: String) -> ! {
+ println!("{}", s);
+ panic!("quux");
+}
+
+fn main() {
+ if my_err("bye".to_string()) {
+ }
+}
--- /dev/null
+fn main() {
+ if let Some(b) = None {
+ //~^ NOTE `if` and `else` have incompatible types
+ ()
+ //~^ NOTE expected because of this
+ } else {
+ 1
+ };
+ //~^^ ERROR: `if` and `else` have incompatible types
+ //~| NOTE expected `()`, found integer
+}
--- /dev/null
+error[E0308]: `if` and `else` have incompatible types
+ --> $DIR/if-let-arm-types.rs:7:9
+ |
+LL | / if let Some(b) = None {
+LL | |
+LL | | ()
+ | | -- expected because of this
+LL | |
+LL | | } else {
+LL | | 1
+ | | ^ expected `()`, found integer
+LL | | };
+ | |_____- `if` and `else` have incompatible types
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// check-pass
+
+fn macros() {
+ macro_rules! foo{
+ ($p:pat, $e:expr, $b:block) => {{
+ if let $p = $e $b
+ //~^ WARN irrefutable if-let
+ //~| WARN irrefutable if-let
+ }}
+ }
+ macro_rules! bar{
+ ($p:pat, $e:expr, $b:block) => {{
+ foo!($p, $e, $b)
+ }}
+ }
+
+ foo!(a, 1, {
+ println!("irrefutable pattern");
+ });
+ bar!(a, 1, {
+ println!("irrefutable pattern");
+ });
+}
+
+pub fn main() {
+ if let a = 1 { //~ WARN irrefutable if-let
+ println!("irrefutable pattern");
+ }
+
+ if let a = 1 { //~ WARN irrefutable if-let
+ println!("irrefutable pattern");
+ } else if true {
+ println!("else-if in irrefutable if-let");
+ } else {
+ println!("else in irrefutable if-let");
+ }
+
+ if let 1 = 2 {
+ println!("refutable pattern");
+ } else if let a = 1 { //~ WARN irrefutable if-let
+ println!("irrefutable pattern");
+ }
+
+ if true {
+ println!("if");
+ } else if let a = 1 { //~ WARN irrefutable if-let
+ println!("irrefutable pattern");
+ }
+}
--- /dev/null
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:6:13
+ |
+LL | if let $p = $e $b
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | / foo!(a, 1, {
+LL | | println!("irrefutable pattern");
+LL | | });
+ | |_______- in this macro invocation
+ |
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
+ = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:6:13
+ |
+LL | if let $p = $e $b
+ | ^^^^^^^^^^^^^^^^^
+...
+LL | / bar!(a, 1, {
+LL | | println!("irrefutable pattern");
+LL | | });
+ | |_______- in this macro invocation
+ |
+ = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:26:5
+ |
+LL | / if let a = 1 {
+LL | | println!("irrefutable pattern");
+LL | | }
+ | |_____^
+
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:30:5
+ |
+LL | / if let a = 1 {
+LL | | println!("irrefutable pattern");
+LL | | } else if true {
+LL | | println!("else-if in irrefutable if-let");
+LL | | } else {
+LL | | println!("else in irrefutable if-let");
+LL | | }
+ | |_____^
+
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:40:12
+ |
+LL | } else if let a = 1 {
+ | ____________^
+LL | | println!("irrefutable pattern");
+LL | | }
+ | |_____^
+
+warning: irrefutable if-let pattern
+ --> $DIR/if-let.rs:46:12
+ |
+LL | } else if let a = 1 {
+ | ____________^
+LL | | println!("irrefutable pattern");
+LL | | }
+ | |_____^
+
+warning: 6 warnings emitted
+
--- /dev/null
+// check-pass
+
+// This used to ICE because the "if" being unreachable was not handled correctly
+fn err() {
+ if loop {} {}
+}
+
+fn main() {}
--- /dev/null
+// Checks for `if` expressions with respect to default match bindings.
+// Specifically, we do not accept `if cond { ... }` where `cond: &mut? bool`.
+// Meanwhile, `match cond { true => ..., _ => ... }` does accept that.
+
+// FIXME(@rust-lang/lang-team): consider relaxing this?
+
+fn b_ref<'a>() -> &'a bool { &true }
+fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
+
+fn main() {
+ // This is OK:
+ match b_ref() { true => {}, _ => {} }
+ match b_mut_ref() { true => {}, _ => {} }
+ match &true { true => {}, _ => {} }
+ match &mut true { true => {}, _ => {} }
+
+ // This is NOT:
+ if b_ref() {} //~ ERROR mismatched types [E0308]
+ if b_mut_ref() {} //~ ERROR mismatched types [E0308]
+ if &true {} //~ ERROR mismatched types [E0308]
+ if &mut true {} //~ ERROR mismatched types [E0308]
+
+ // This is also NOT:
+ while b_ref() {} //~ ERROR mismatched types [E0308]
+ while b_mut_ref() {} //~ ERROR mismatched types [E0308]
+ while &true {} //~ ERROR mismatched types [E0308]
+ while &mut true {} //~ ERROR mismatched types [E0308]
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:18:8
+ |
+LL | if b_ref() {}
+ | ^^^^^^^
+ | |
+ | expected `bool`, found `&bool`
+ | help: consider dereferencing the borrow: `*b_ref()`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:19:8
+ |
+LL | if b_mut_ref() {}
+ | ^^^^^^^^^^^
+ | |
+ | expected `bool`, found `&mut bool`
+ | help: consider dereferencing the borrow: `*b_mut_ref()`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:20:8
+ |
+LL | if &true {}
+ | ^^^^^
+ | |
+ | expected `bool`, found `&bool`
+ | help: consider removing the borrow: `true`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:21:8
+ |
+LL | if &mut true {}
+ | ^^^^^^^^^
+ | |
+ | expected `bool`, found `&mut bool`
+ | help: consider removing the borrow: `true`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:24:11
+ |
+LL | while b_ref() {}
+ | ^^^^^^^
+ | |
+ | expected `bool`, found `&bool`
+ | help: consider dereferencing the borrow: `*b_ref()`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:25:11
+ |
+LL | while b_mut_ref() {}
+ | ^^^^^^^^^^^
+ | |
+ | expected `bool`, found `&mut bool`
+ | help: consider dereferencing the borrow: `*b_mut_ref()`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:26:11
+ |
+LL | while &true {}
+ | ^^^^^
+ | |
+ | expected `bool`, found `&bool`
+ | help: consider removing the borrow: `true`
+
+error[E0308]: mismatched types
+ --> $DIR/if-no-match-bindings.rs:27:11
+ |
+LL | while &mut true {}
+ | ^^^^^^^^^
+ | |
+ | expected `bool`, found `&mut bool`
+ | help: consider removing the borrow: `true`
+
+error: aborting due to 8 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+// error-pattern:mismatched types
+// issue #513
+
+fn f() { }
+
+fn main() {
+
+ // f is not a bool
+ if f { }
+}
--- /dev/null
+error[E0308]: mismatched types
+ --> $DIR/if-typeck.rs:9:8
+ |
+LL | if f { }
+ | ^ expected `bool`, found fn item
+ |
+ = note: expected type `bool`
+ found fn item `fn() {f}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+fn main() {
+ let n = 1;
+ if 5 == {
+ //~^ NOTE this `if` expression has a condition, but no block
+ println!("five");
+ }
+}
+//~^ ERROR expected `{`, found `}`
+//~| NOTE expected `{`
--- /dev/null
+error: expected `{`, found `}`
+ --> $DIR/if-without-block.rs:7:1
+ |
+LL | if 5 == {
+ | -- this `if` expression has a condition, but no block
+...
+LL | }
+ | ^ expected `{`
+ |
+ = help: maybe you forgot the right operand of the condition?
+
+error: aborting due to previous error
+
--- /dev/null
+fn foo(bar: usize) -> usize {
+ if bar % 5 == 0 {
+ return 3;
+ }
+ //~^^^ ERROR `if` may be missing an `else` clause
+}
+
+fn foo2(bar: usize) -> usize {
+ let x: usize = if bar % 5 == 0 {
+ return 3;
+ };
+ //~^^^ ERROR `if` may be missing an `else` clause
+ x
+}
+
+fn foo3(bar: usize) -> usize {
+ if bar % 5 == 0 {
+ 3
+ }
+ //~^^^ ERROR `if` may be missing an `else` clause
+}
+
+fn foo_let(bar: usize) -> usize {
+ if let 0 = 1 {
+ return 3;
+ }
+ //~^^^ ERROR `if` may be missing an `else` clause
+}
+
+fn foo2_let(bar: usize) -> usize {
+ let x: usize = if let 0 = 1 {
+ return 3;
+ };
+ //~^^^ ERROR `if` may be missing an `else` clause
+ x
+}
+
+fn foo3_let(bar: usize) -> usize {
+ if let 0 = 1 {
+ 3
+ }
+ //~^^^ ERROR `if` may be missing an `else` clause
+}
+
+// FIXME(60254): deduplicate first error in favor of second.
+
+fn main() {
+ let _ = foo(1);
+}
--- /dev/null
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:2:5
+ |
+LL | fn foo(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if bar % 5 == 0 {
+LL | | return 3;
+LL | | }
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:9:20
+ |
+LL | let x: usize = if bar % 5 == 0 {
+ | _________-__________^
+ | | |
+ | | expected because of this assignment
+LL | | return 3;
+LL | | };
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:17:5
+ |
+LL | fn foo3(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if bar % 5 == 0 {
+LL | | 3
+LL | | }
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:24:5
+ |
+LL | fn foo_let(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if let 0 = 1 {
+LL | | return 3;
+LL | | }
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:31:20
+ |
+LL | let x: usize = if let 0 = 1 {
+ | _________-__________^
+ | | |
+ | | expected because of this assignment
+LL | | return 3;
+LL | | };
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-as-fn-expr.rs:39:5
+ |
+LL | fn foo3_let(bar: usize) -> usize {
+ | ----- expected `usize` because of this return type
+LL | / if let 0 = 1 {
+LL | | 3
+LL | | }
+ | |_____^ expected `usize`, found `()`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error: aborting due to 6 previous errors
+
+For more information about this error, try `rustc --explain E0317`.
--- /dev/null
+fn main() {
+ let a = if true { true };
+ //~^ ERROR `if` may be missing an `else` clause [E0317]
+ //~| expected `()`, found `bool`
+ println!("{}", a);
+}
--- /dev/null
+error[E0317]: `if` may be missing an `else` clause
+ --> $DIR/if-without-else-result.rs:2:13
+ |
+LL | let a = if true { true };
+ | ^^^^^^^^^^----^^
+ | | |
+ | | found here
+ | expected `()`, found `bool`
+ |
+ = note: `if` expressions without `else` evaluate to `()`
+ = help: consider adding an `else` block that evaluates to the expected type
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0317`.
--- /dev/null
+fn main() {
+ // bad arguments to the format! call
+
+ // bad number of arguments, see #44954 (originally #15780)
+
+ format!("{}");
+ //~^ ERROR: 1 positional argument in format string, but no arguments were given
+
+ format!("{1}", 1);
+ //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
+ //~^^ ERROR: argument never used
+
+ format!("{} {}");
+ //~^ ERROR: 2 positional arguments in format string, but no arguments were given
+
+ format!("{0} {1}", 1);
+ //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
+
+ format!("{0} {1} {2}", 1, 2);
+ //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
+
+ format!("{} {value} {} {}", 1, value=2);
+ //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
+ format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
+ //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
+
+ format!("{} {foo} {} {bar} {}", 1, 2, 3);
+ //~^ ERROR: there is no argument named `foo`
+ //~^^ ERROR: there is no argument named `bar`
+
+ format!("{foo}"); //~ ERROR: no argument named `foo`
+ format!("", 1, 2); //~ ERROR: multiple unused formatting arguments
+ format!("{}", 1, 2); //~ ERROR: argument never used
+ format!("{1}", 1, 2); //~ ERROR: argument never used
+ format!("{}", 1, foo=2); //~ ERROR: named argument never used
+ format!("{foo}", 1, foo=2); //~ ERROR: argument never used
+ format!("", foo=2); //~ ERROR: named argument never used
+ format!("{} {}", 1, 2, foo=1, bar=2); //~ ERROR: multiple unused formatting arguments
+
+ format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
+ format!("{foo} {} {}", foo=1, 2); //~ ERROR: positional arguments cannot follow
+
+ // bad named arguments, #35082
+
+ format!("{valuea} {valueb}", valuea=5, valuec=7);
+ //~^ ERROR there is no argument named `valueb`
+ //~^^ ERROR named argument never used
+
+ // bad syntax of the format string
+
+ format!("{"); //~ ERROR: expected `'}'` but string was terminated
+
+ format!("foo } bar"); //~ ERROR: unmatched `}` found
+ format!("foo }"); //~ ERROR: unmatched `}` found
+
+ format!("foo %s baz", "bar"); //~ ERROR: argument never used
+
+ format!(r##"
+
+ {foo}
+
+ "##);
+ //~^^^ ERROR: there is no argument named `foo`
+
+ // bad syntax in format string with multiple newlines, #53836
+ format!("first number: {}
+second number: {}
+third number: {}
+fourth number: {}
+fifth number: {}
+sixth number: {}
+seventh number: {}
+eighth number: {}
+ninth number: {
+tenth number: {}",
+ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
+ //~^^ ERROR: invalid format string
+ println!("{} {:.*} {}", 1, 3.2, 4);
+ //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
+ //~| ERROR mismatched types
+ println!("{} {:07$.*} {}", 1, 3.2, 4);
+ //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
+ //~| ERROR mismatched types
+ println!("{} {:07$} {}", 1, 3.2, 4);
+ //~^ ERROR invalid reference to positional argument 7 (there are 3 arguments)
+ println!("{:foo}", 1); //~ ERROR unknown format trait `foo`
+ println!("{5} {:4$} {6:7$}", 1);
+ //~^ ERROR invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
+
+ // We used to ICE here because we tried to unconditionally access the first argument, which
+ // doesn't exist.
+ println!("{:.*}");
+ //~^ ERROR 2 positional arguments in format string, but no arguments were given
+}
--- /dev/null
+error: 1 positional argument in format string, but no arguments were given
+ --> $DIR/ifmt-bad-arg.rs:6:14
+ |
+LL | format!("{}");
+ | ^^
+
+error: invalid reference to positional argument 1 (there is 1 argument)
+ --> $DIR/ifmt-bad-arg.rs:9:14
+ |
+LL | format!("{1}", 1);
+ | ^^^
+ |
+ = note: positional arguments are zero-based
+
+error: argument never used
+ --> $DIR/ifmt-bad-arg.rs:9:20
+ |
+LL | format!("{1}", 1);
+ | ----- ^ argument never used
+ | |
+ | formatting specifier missing
+
+error: 2 positional arguments in format string, but no arguments were given
+ --> $DIR/ifmt-bad-arg.rs:13:14
+ |
+LL | format!("{} {}");
+ | ^^ ^^
+
+error: invalid reference to positional argument 1 (there is 1 argument)
+ --> $DIR/ifmt-bad-arg.rs:16:18
+ |
+LL | format!("{0} {1}", 1);
+ | ^^^
+ |
+ = note: positional arguments are zero-based
+
+error: invalid reference to positional argument 2 (there are 2 arguments)
+ --> $DIR/ifmt-bad-arg.rs:19:22
+ |
+LL | format!("{0} {1} {2}", 1, 2);
+ | ^^^
+ |
+ = note: positional arguments are zero-based
+
+error: invalid reference to positional argument 2 (there are 2 arguments)
+ --> $DIR/ifmt-bad-arg.rs:22:28
+ |
+LL | format!("{} {value} {} {}", 1, value=2);
+ | ^^
+ |
+ = note: positional arguments are zero-based
+
+error: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
+ --> $DIR/ifmt-bad-arg.rs:24:38
+ |
+LL | format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
+ | ^^ ^^ ^^
+ |
+ = note: positional arguments are zero-based
+
+error: there is no argument named `foo`
+ --> $DIR/ifmt-bad-arg.rs:27:17
+ |
+LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
+ | ^^^^^
+ |
+ = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
+
+error: there is no argument named `bar`
+ --> $DIR/ifmt-bad-arg.rs:27:26
+ |
+LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
+ | ^^^^^
+ |
+ = help: if you intended to capture `bar` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
+
+error: there is no argument named `foo`
+ --> $DIR/ifmt-bad-arg.rs:31:14
+ |
+LL | format!("{foo}");
+ | ^^^^^
+ |
+ = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
+
+error: multiple unused formatting arguments
+ --> $DIR/ifmt-bad-arg.rs:32:17
+ |
+LL | format!("", 1, 2);
+ | -- ^ ^ argument never used
+ | | |
+ | | argument never used
+ | multiple missing formatting specifiers
+
+error: argument never used
+ --> $DIR/ifmt-bad-arg.rs:33:22
+ |
+LL | format!("{}", 1, 2);
+ | ---- ^ argument never used
+ | |
+ | formatting specifier missing
+
+error: argument never used
+ --> $DIR/ifmt-bad-arg.rs:34:20
+ |
+LL | format!("{1}", 1, 2);
+ | ----- ^ argument never used
+ | |
+ | formatting specifier missing
+
+error: named argument never used
+ --> $DIR/ifmt-bad-arg.rs:35:26
+ |
+LL | format!("{}", 1, foo=2);
+ | ---- ^ named argument never used
+ | |
+ | formatting specifier missing
+
+error: argument never used
+ --> $DIR/ifmt-bad-arg.rs:36:22
+ |
+LL | format!("{foo}", 1, foo=2);
+ | ------- ^ argument never used
+ | |
+ | formatting specifier missing
+
+error: named argument never used
+ --> $DIR/ifmt-bad-arg.rs:37:21
+ |
+LL | format!("", foo=2);
+ | -- ^ named argument never used
+ | |
+ | formatting specifier missing
+
+error: multiple unused formatting arguments
+ --> $DIR/ifmt-bad-arg.rs:38:32
+ |
+LL | format!("{} {}", 1, 2, foo=1, bar=2);
+ | ------- ^ ^ named argument never used
+ | | |
+ | | named argument never used
+ | multiple missing formatting specifiers
+
+error: duplicate argument named `foo`
+ --> $DIR/ifmt-bad-arg.rs:40:33
+ |
+LL | format!("{foo}", foo=1, foo=2);
+ | - ^ duplicate argument
+ | |
+ | previously here
+
+error: positional arguments cannot follow named arguments
+ --> $DIR/ifmt-bad-arg.rs:41:35
+ |
+LL | format!("{foo} {} {}", foo=1, 2);
+ | - ^ positional arguments must be before named arguments
+ | |
+ | named argument
+
+error: there is no argument named `valueb`
+ --> $DIR/ifmt-bad-arg.rs:45:23
+ |
+LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
+ | ^^^^^^^^
+ |
+ = help: if you intended to capture `valueb` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
+
+error: named argument never used
+ --> $DIR/ifmt-bad-arg.rs:45:51
+ |
+LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
+ | ------------------- ^ named argument never used
+ | |
+ | formatting specifier missing
+
+error: invalid format string: expected `'}'` but string was terminated
+ --> $DIR/ifmt-bad-arg.rs:51:15
+ |
+LL | format!("{");
+ | -^ expected `'}'` in format string
+ | |
+ | because of this opening brace
+ |
+ = note: if you intended to print `{`, you can escape it using `{{`
+
+error: invalid format string: unmatched `}` found
+ --> $DIR/ifmt-bad-arg.rs:53:18
+ |
+LL | format!("foo } bar");
+ | ^ unmatched `}` in format string
+ |
+ = note: if you intended to print `}`, you can escape it using `}}`
+
+error: invalid format string: unmatched `}` found
+ --> $DIR/ifmt-bad-arg.rs:54:18
+ |
+LL | format!("foo }");
+ | ^ unmatched `}` in format string
+ |
+ = note: if you intended to print `}`, you can escape it using `}}`
+
+error: argument never used
+ --> $DIR/ifmt-bad-arg.rs:56:27
+ |
+LL | format!("foo %s baz", "bar");
+ | -- ^^^^^ argument never used
+ | |
+ | help: format specifiers use curly braces: `{}`
+ |
+ = note: printf formatting not supported; see the documentation for `std::fmt`
+
+error: there is no argument named `foo`
+ --> $DIR/ifmt-bad-arg.rs:60:9
+ |
+LL | {foo}
+ | ^^^^^
+ |
+ = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
+
+error: invalid format string: expected `'}'`, found `'t'`
+ --> $DIR/ifmt-bad-arg.rs:75:1
+ |
+LL | ninth number: {
+ | - because of this opening brace
+LL | tenth number: {}",
+ | ^ expected `}` in format string
+ |
+ = note: if you intended to print `{`, you can escape it using `{{`
+
+error: 4 positional arguments in format string, but there are 3 arguments
+ --> $DIR/ifmt-bad-arg.rs:78:15
+ |
+LL | println!("{} {:.*} {}", 1, 3.2, 4);
+ | ^^ ^^--^ ^^ - --- -
+ | | |
+ | | this parameter corresponds to the precision flag
+ | this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
+ |
+ = note: positional arguments are zero-based
+ = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
+
+error: 4 positional arguments in format string, but there are 3 arguments
+ --> $DIR/ifmt-bad-arg.rs:81:15
+ |
+LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
+ | ^^ ^^^----^ ^^ - --- -
+ | | | |
+ | | | this parameter corresponds to the precision flag
+ | | this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
+ | this width flag expects an `usize` argument at position 7, but there are 3 arguments
+ |
+ = note: positional arguments are zero-based
+ = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
+
+error: invalid reference to positional argument 7 (there are 3 arguments)
+ --> $DIR/ifmt-bad-arg.rs:84:18
+ |
+LL | println!("{} {:07$} {}", 1, 3.2, 4);
+ | ^^^--^
+ | |
+ | this width flag expects an `usize` argument at position 7, but there are 3 arguments
+ |
+ = note: positional arguments are zero-based
+ = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
+
+error: unknown format trait `foo`
+ --> $DIR/ifmt-bad-arg.rs:86:17
+ |
+LL | println!("{:foo}", 1);
+ | ^^^
+ |
+ = note: the only appropriate formatting traits are:
+ - ``, which uses the `Display` trait
+ - `?`, which uses the `Debug` trait
+ - `e`, which uses the `LowerExp` trait
+ - `E`, which uses the `UpperExp` trait
+ - `o`, which uses the `Octal` trait
+ - `p`, which uses the `Pointer` trait
+ - `b`, which uses the `Binary` trait
+ - `x`, which uses the `LowerHex` trait
+ - `X`, which uses the `UpperHex` trait
+
+error: invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
+ --> $DIR/ifmt-bad-arg.rs:87:15
+ |
+LL | println!("{5} {:4$} {6:7$}", 1);
+ | ^^^ ^^--^ ^^^--^
+ | | |
+ | | this width flag expects an `usize` argument at position 7, but there is 1 argument
+ | this width flag expects an `usize` argument at position 4, but there is 1 argument
+ |
+ = note: positional arguments are zero-based
+ = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
+
+error: 2 positional arguments in format string, but no arguments were given
+ --> $DIR/ifmt-bad-arg.rs:92:15
+ |
+LL | println!("{:.*}");
+ | ^^--^
+ | |
+ | this precision flag adds an extra required argument at position 0, which is why there are 2 arguments expected
+ |
+ = note: positional arguments are zero-based
+ = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
+
+error[E0308]: mismatched types
+ --> $DIR/ifmt-bad-arg.rs:78:32
+ |
+LL | println!("{} {:.*} {}", 1, 3.2, 4);
+ | ^^^ expected `usize`, found floating-point number
+ |
+ = note: expected reference `&usize`
+ found reference `&{float}`
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0308]: mismatched types
+ --> $DIR/ifmt-bad-arg.rs:81:35
+ |
+LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
+ | ^^^ expected `usize`, found floating-point number
+ |
+ = note: expected reference `&usize`
+ found reference `&{float}`
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 36 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
--- /dev/null
+fn main() {
+ format_args!(); //~ ERROR: requires at least a format string argument
+ format_args!(|| {}); //~ ERROR: must be a string literal
+}
--- /dev/null
+error: requires at least a format string argument
+ --> $DIR/ifmt-bad-format-args.rs:2:5
+ |
+LL | format_args!();
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: format argument must be a string literal
+ --> $DIR/ifmt-bad-format-args.rs:3:18
+ |
+LL | format_args!(|| {});
+ | ^^^^^
+ |
+help: you might be missing a string literal to format with
+ |
+LL | format_args!("{}", || {});
+ | ^^^^^
+
+error: aborting due to 2 previous errors
+
--- /dev/null
+fn main() {
+ format!("{:X}", "3");
+ //~^ ERROR: `str: UpperHex` is not satisfied
+}
--- /dev/null
+error[E0277]: the trait bound `str: UpperHex` is not satisfied
+ --> $DIR/ifmt-unimpl.rs:2:21
+ |
+LL | format!("{:X}", "3");
+ | ^^^ the trait `UpperHex` is not implemented for `str`
+ |
+ = note: required because of the requirements on the impl of `UpperHex` for `&str`
+ = note: required by `std::fmt::UpperHex::fmt`
+ = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.
--- /dev/null
+fn main() {
+ format!("{:notimplemented}", "3");
+ //~^ ERROR: unknown format trait `notimplemented`
+}
--- /dev/null
+error: unknown format trait `notimplemented`
+ --> $DIR/ifmt-unknown-trait.rs:2:16
+ |
+LL | format!("{:notimplemented}", "3");
+ | ^^^^^^^^^^^^^^
+ |
+ = note: the only appropriate formatting traits are:
+ - ``, which uses the `Display` trait
+ - `?`, which uses the `Debug` trait
+ - `e`, which uses the `LowerExp` trait
+ - `E`, which uses the `UpperExp` trait
+ - `o`, which uses the `Octal` trait
+ - `p`, which uses the `Pointer` trait
+ - `b`, which uses the `Binary` trait
+ - `x`, which uses the `LowerHex` trait
+ - `X`, which uses the `UpperHex` trait
+
+error: aborting due to previous error
+
+++ /dev/null
-// run-fail
-// error-pattern:explicit panic
-// ignore-emscripten no processes
-
-fn f() -> ! {
- panic!()
-}
-
-fn g() -> isize {
- let x = if true {
- f()
- } else {
- 10
- };
- return x;
-}
-
-fn main() {
- g();
-}
+++ /dev/null
-// run-fail
-// error-pattern:explicit panic
-// ignore-emscripten no processes
-
-fn main() {
- let _x = if false {
- 0
- } else if true {
- panic!()
- } else {
- 10
- };
-}
+++ /dev/null
-fn main() {
- let x = if true { 10i32 } else { 10u32 };
- //~^ ERROR `if` and `else` have incompatible types
- //~| expected `i32`, found `u32`
-}
+++ /dev/null
-error[E0308]: `if` and `else` have incompatible types
- --> $DIR/if-branch-types.rs:2:38
- |
-LL | let x = if true { 10i32 } else { 10u32 };
- | ----- ^^^^^ expected `i32`, found `u32`
- | |
- | expected because of this
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-// run-fail
-// error-pattern:Number is odd
-// ignore-emscripten no processes
-
-fn even(x: usize) -> bool {
- if x < 2 {
- return false;
- } else if x == 2 {
- return true;
- } else {
- return even(x - 2);
- }
-}
-
-fn foo(x: usize) {
- if even(x) {
- println!("{}", x);
- } else {
- panic!("Number is odd");
- }
-}
-
-fn main() {
- foo(3);
-}
+++ /dev/null
-// run-fail
-// error-pattern:quux
-// ignore-emscripten no processes
-
-fn my_err(s: String) -> ! {
- println!("{}", s);
- panic!("quux");
-}
-
-fn main() {
- if my_err("bye".to_string()) {
- }
-}
+++ /dev/null
-fn main() {
- if let Some(b) = None {
- //~^ NOTE `if` and `else` have incompatible types
- ()
- //~^ NOTE expected because of this
- } else {
- 1
- };
- //~^^ ERROR: `if` and `else` have incompatible types
- //~| NOTE expected `()`, found integer
-}
+++ /dev/null
-error[E0308]: `if` and `else` have incompatible types
- --> $DIR/if-let-arm-types.rs:7:9
- |
-LL | / if let Some(b) = None {
-LL | |
-LL | | ()
- | | -- expected because of this
-LL | |
-LL | | } else {
-LL | | 1
- | | ^ expected `()`, found integer
-LL | | };
- | |_____- `if` and `else` have incompatible types
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-// check-pass
-
-fn macros() {
- macro_rules! foo{
- ($p:pat, $e:expr, $b:block) => {{
- if let $p = $e $b
- //~^ WARN irrefutable if-let
- //~| WARN irrefutable if-let
- }}
- }
- macro_rules! bar{
- ($p:pat, $e:expr, $b:block) => {{
- foo!($p, $e, $b)
- }}
- }
-
- foo!(a, 1, {
- println!("irrefutable pattern");
- });
- bar!(a, 1, {
- println!("irrefutable pattern");
- });
-}
-
-pub fn main() {
- if let a = 1 { //~ WARN irrefutable if-let
- println!("irrefutable pattern");
- }
-
- if let a = 1 { //~ WARN irrefutable if-let
- println!("irrefutable pattern");
- } else if true {
- println!("else-if in irrefutable if-let");
- } else {
- println!("else in irrefutable if-let");
- }
-
- if let 1 = 2 {
- println!("refutable pattern");
- } else if let a = 1 { //~ WARN irrefutable if-let
- println!("irrefutable pattern");
- }
-
- if true {
- println!("if");
- } else if let a = 1 { //~ WARN irrefutable if-let
- println!("irrefutable pattern");
- }
-}
+++ /dev/null
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:6:13
- |
-LL | if let $p = $e $b
- | ^^^^^^^^^^^^^^^^^
-...
-LL | / foo!(a, 1, {
-LL | | println!("irrefutable pattern");
-LL | | });
- | |_______- in this macro invocation
- |
- = note: `#[warn(irrefutable_let_patterns)]` on by default
- = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:6:13
- |
-LL | if let $p = $e $b
- | ^^^^^^^^^^^^^^^^^
-...
-LL | / bar!(a, 1, {
-LL | | println!("irrefutable pattern");
-LL | | });
- | |_______- in this macro invocation
- |
- = note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:26:5
- |
-LL | / if let a = 1 {
-LL | | println!("irrefutable pattern");
-LL | | }
- | |_____^
-
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:30:5
- |
-LL | / if let a = 1 {
-LL | | println!("irrefutable pattern");
-LL | | } else if true {
-LL | | println!("else-if in irrefutable if-let");
-LL | | } else {
-LL | | println!("else in irrefutable if-let");
-LL | | }
- | |_____^
-
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:40:12
- |
-LL | } else if let a = 1 {
- | ____________^
-LL | | println!("irrefutable pattern");
-LL | | }
- | |_____^
-
-warning: irrefutable if-let pattern
- --> $DIR/if-let.rs:46:12
- |
-LL | } else if let a = 1 {
- | ____________^
-LL | | println!("irrefutable pattern");
-LL | | }
- | |_____^
-
-warning: 6 warnings emitted
-
+++ /dev/null
-// check-pass
-
-// This used to ICE because the "if" being unreachable was not handled correctly
-fn err() {
- if loop {} {}
-}
-
-fn main() {}
+++ /dev/null
-// Checks for `if` expressions with respect to default match bindings.
-// Specifically, we do not accept `if cond { ... }` where `cond: &mut? bool`.
-// Meanwhile, `match cond { true => ..., _ => ... }` does accept that.
-
-// FIXME(@rust-lang/lang-team): consider relaxing this?
-
-fn b_ref<'a>() -> &'a bool { &true }
-fn b_mut_ref<'a>() -> &'a mut bool { &mut true }
-
-fn main() {
- // This is OK:
- match b_ref() { true => {}, _ => {} }
- match b_mut_ref() { true => {}, _ => {} }
- match &true { true => {}, _ => {} }
- match &mut true { true => {}, _ => {} }
-
- // This is NOT:
- if b_ref() {} //~ ERROR mismatched types [E0308]
- if b_mut_ref() {} //~ ERROR mismatched types [E0308]
- if &true {} //~ ERROR mismatched types [E0308]
- if &mut true {} //~ ERROR mismatched types [E0308]
-
- // This is also NOT:
- while b_ref() {} //~ ERROR mismatched types [E0308]
- while b_mut_ref() {} //~ ERROR mismatched types [E0308]
- while &true {} //~ ERROR mismatched types [E0308]
- while &mut true {} //~ ERROR mismatched types [E0308]
-}
+++ /dev/null
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:18:8
- |
-LL | if b_ref() {}
- | ^^^^^^^
- | |
- | expected `bool`, found `&bool`
- | help: consider dereferencing the borrow: `*b_ref()`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:19:8
- |
-LL | if b_mut_ref() {}
- | ^^^^^^^^^^^
- | |
- | expected `bool`, found `&mut bool`
- | help: consider dereferencing the borrow: `*b_mut_ref()`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:20:8
- |
-LL | if &true {}
- | ^^^^^
- | |
- | expected `bool`, found `&bool`
- | help: consider removing the borrow: `true`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:21:8
- |
-LL | if &mut true {}
- | ^^^^^^^^^
- | |
- | expected `bool`, found `&mut bool`
- | help: consider removing the borrow: `true`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:24:11
- |
-LL | while b_ref() {}
- | ^^^^^^^
- | |
- | expected `bool`, found `&bool`
- | help: consider dereferencing the borrow: `*b_ref()`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:25:11
- |
-LL | while b_mut_ref() {}
- | ^^^^^^^^^^^
- | |
- | expected `bool`, found `&mut bool`
- | help: consider dereferencing the borrow: `*b_mut_ref()`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:26:11
- |
-LL | while &true {}
- | ^^^^^
- | |
- | expected `bool`, found `&bool`
- | help: consider removing the borrow: `true`
-
-error[E0308]: mismatched types
- --> $DIR/if-no-match-bindings.rs:27:11
- |
-LL | while &mut true {}
- | ^^^^^^^^^
- | |
- | expected `bool`, found `&mut bool`
- | help: consider removing the borrow: `true`
-
-error: aborting due to 8 previous errors
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-// error-pattern:mismatched types
-// issue #513
-
-fn f() { }
-
-fn main() {
-
- // f is not a bool
- if f { }
-}
+++ /dev/null
-error[E0308]: mismatched types
- --> $DIR/if-typeck.rs:9:8
- |
-LL | if f { }
- | ^ expected `bool`, found fn item
- |
- = note: expected type `bool`
- found fn item `fn() {f}`
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-fn main() {
- let n = 1;
- if 5 == {
- //~^ NOTE this `if` expression has a condition, but no block
- println!("five");
- }
-}
-//~^ ERROR expected `{`, found `}`
-//~| NOTE expected `{`
+++ /dev/null
-error: expected `{`, found `}`
- --> $DIR/if-without-block.rs:7:1
- |
-LL | if 5 == {
- | -- this `if` expression has a condition, but no block
-...
-LL | }
- | ^ expected `{`
- |
- = help: maybe you forgot the right operand of the condition?
-
-error: aborting due to previous error
-
+++ /dev/null
-fn foo(bar: usize) -> usize {
- if bar % 5 == 0 {
- return 3;
- }
- //~^^^ ERROR `if` may be missing an `else` clause
-}
-
-fn foo2(bar: usize) -> usize {
- let x: usize = if bar % 5 == 0 {
- return 3;
- };
- //~^^^ ERROR `if` may be missing an `else` clause
- x
-}
-
-fn foo3(bar: usize) -> usize {
- if bar % 5 == 0 {
- 3
- }
- //~^^^ ERROR `if` may be missing an `else` clause
-}
-
-fn foo_let(bar: usize) -> usize {
- if let 0 = 1 {
- return 3;
- }
- //~^^^ ERROR `if` may be missing an `else` clause
-}
-
-fn foo2_let(bar: usize) -> usize {
- let x: usize = if let 0 = 1 {
- return 3;
- };
- //~^^^ ERROR `if` may be missing an `else` clause
- x
-}
-
-fn foo3_let(bar: usize) -> usize {
- if let 0 = 1 {
- 3
- }
- //~^^^ ERROR `if` may be missing an `else` clause
-}
-
-// FIXME(60254): deduplicate first error in favor of second.
-
-fn main() {
- let _ = foo(1);
-}
+++ /dev/null
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:2:5
- |
-LL | fn foo(bar: usize) -> usize {
- | ----- expected `usize` because of this return type
-LL | / if bar % 5 == 0 {
-LL | | return 3;
-LL | | }
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:9:20
- |
-LL | let x: usize = if bar % 5 == 0 {
- | _________-__________^
- | | |
- | | expected because of this assignment
-LL | | return 3;
-LL | | };
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:17:5
- |
-LL | fn foo3(bar: usize) -> usize {
- | ----- expected `usize` because of this return type
-LL | / if bar % 5 == 0 {
-LL | | 3
-LL | | }
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:24:5
- |
-LL | fn foo_let(bar: usize) -> usize {
- | ----- expected `usize` because of this return type
-LL | / if let 0 = 1 {
-LL | | return 3;
-LL | | }
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:31:20
- |
-LL | let x: usize = if let 0 = 1 {
- | _________-__________^
- | | |
- | | expected because of this assignment
-LL | | return 3;
-LL | | };
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-as-fn-expr.rs:39:5
- |
-LL | fn foo3_let(bar: usize) -> usize {
- | ----- expected `usize` because of this return type
-LL | / if let 0 = 1 {
-LL | | 3
-LL | | }
- | |_____^ expected `usize`, found `()`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error: aborting due to 6 previous errors
-
-For more information about this error, try `rustc --explain E0317`.
+++ /dev/null
-fn main() {
- let a = if true { true };
- //~^ ERROR `if` may be missing an `else` clause [E0317]
- //~| expected `()`, found `bool`
- println!("{}", a);
-}
+++ /dev/null
-error[E0317]: `if` may be missing an `else` clause
- --> $DIR/if-without-else-result.rs:2:13
- |
-LL | let a = if true { true };
- | ^^^^^^^^^^----^^
- | | |
- | | found here
- | expected `()`, found `bool`
- |
- = note: `if` expressions without `else` evaluate to `()`
- = help: consider adding an `else` block that evaluates to the expected type
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0317`.
+++ /dev/null
-fn main() {
- // bad arguments to the format! call
-
- // bad number of arguments, see #44954 (originally #15780)
-
- format!("{}");
- //~^ ERROR: 1 positional argument in format string, but no arguments were given
-
- format!("{1}", 1);
- //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
- //~^^ ERROR: argument never used
-
- format!("{} {}");
- //~^ ERROR: 2 positional arguments in format string, but no arguments were given
-
- format!("{0} {1}", 1);
- //~^ ERROR: invalid reference to positional argument 1 (there is 1 argument)
-
- format!("{0} {1} {2}", 1, 2);
- //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
-
- format!("{} {value} {} {}", 1, value=2);
- //~^ ERROR: invalid reference to positional argument 2 (there are 2 arguments)
- format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
- //~^ ERROR: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
-
- format!("{} {foo} {} {bar} {}", 1, 2, 3);
- //~^ ERROR: there is no argument named `foo`
- //~^^ ERROR: there is no argument named `bar`
-
- format!("{foo}"); //~ ERROR: no argument named `foo`
- format!("", 1, 2); //~ ERROR: multiple unused formatting arguments
- format!("{}", 1, 2); //~ ERROR: argument never used
- format!("{1}", 1, 2); //~ ERROR: argument never used
- format!("{}", 1, foo=2); //~ ERROR: named argument never used
- format!("{foo}", 1, foo=2); //~ ERROR: argument never used
- format!("", foo=2); //~ ERROR: named argument never used
- format!("{} {}", 1, 2, foo=1, bar=2); //~ ERROR: multiple unused formatting arguments
-
- format!("{foo}", foo=1, foo=2); //~ ERROR: duplicate argument
- format!("{foo} {} {}", foo=1, 2); //~ ERROR: positional arguments cannot follow
-
- // bad named arguments, #35082
-
- format!("{valuea} {valueb}", valuea=5, valuec=7);
- //~^ ERROR there is no argument named `valueb`
- //~^^ ERROR named argument never used
-
- // bad syntax of the format string
-
- format!("{"); //~ ERROR: expected `'}'` but string was terminated
-
- format!("foo } bar"); //~ ERROR: unmatched `}` found
- format!("foo }"); //~ ERROR: unmatched `}` found
-
- format!("foo %s baz", "bar"); //~ ERROR: argument never used
-
- format!(r##"
-
- {foo}
-
- "##);
- //~^^^ ERROR: there is no argument named `foo`
-
- // bad syntax in format string with multiple newlines, #53836
- format!("first number: {}
-second number: {}
-third number: {}
-fourth number: {}
-fifth number: {}
-sixth number: {}
-seventh number: {}
-eighth number: {}
-ninth number: {
-tenth number: {}",
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
- //~^^ ERROR: invalid format string
- println!("{} {:.*} {}", 1, 3.2, 4);
- //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
- //~| ERROR mismatched types
- println!("{} {:07$.*} {}", 1, 3.2, 4);
- //~^ ERROR 4 positional arguments in format string, but there are 3 arguments
- //~| ERROR mismatched types
- println!("{} {:07$} {}", 1, 3.2, 4);
- //~^ ERROR invalid reference to positional argument 7 (there are 3 arguments)
- println!("{:foo}", 1); //~ ERROR unknown format trait `foo`
- println!("{5} {:4$} {6:7$}", 1);
- //~^ ERROR invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
-
- // We used to ICE here because we tried to unconditionally access the first argument, which
- // doesn't exist.
- println!("{:.*}");
- //~^ ERROR 2 positional arguments in format string, but no arguments were given
-}
+++ /dev/null
-error: 1 positional argument in format string, but no arguments were given
- --> $DIR/ifmt-bad-arg.rs:6:14
- |
-LL | format!("{}");
- | ^^
-
-error: invalid reference to positional argument 1 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:9:14
- |
-LL | format!("{1}", 1);
- | ^^^
- |
- = note: positional arguments are zero-based
-
-error: argument never used
- --> $DIR/ifmt-bad-arg.rs:9:20
- |
-LL | format!("{1}", 1);
- | ----- ^ argument never used
- | |
- | formatting specifier missing
-
-error: 2 positional arguments in format string, but no arguments were given
- --> $DIR/ifmt-bad-arg.rs:13:14
- |
-LL | format!("{} {}");
- | ^^ ^^
-
-error: invalid reference to positional argument 1 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:16:18
- |
-LL | format!("{0} {1}", 1);
- | ^^^
- |
- = note: positional arguments are zero-based
-
-error: invalid reference to positional argument 2 (there are 2 arguments)
- --> $DIR/ifmt-bad-arg.rs:19:22
- |
-LL | format!("{0} {1} {2}", 1, 2);
- | ^^^
- |
- = note: positional arguments are zero-based
-
-error: invalid reference to positional argument 2 (there are 2 arguments)
- --> $DIR/ifmt-bad-arg.rs:22:28
- |
-LL | format!("{} {value} {} {}", 1, value=2);
- | ^^
- |
- = note: positional arguments are zero-based
-
-error: invalid reference to positional arguments 3, 4 and 5 (there are 3 arguments)
- --> $DIR/ifmt-bad-arg.rs:24:38
- |
-LL | format!("{name} {value} {} {} {} {} {} {}", 0, name=1, value=2);
- | ^^ ^^ ^^
- |
- = note: positional arguments are zero-based
-
-error: there is no argument named `foo`
- --> $DIR/ifmt-bad-arg.rs:27:17
- |
-LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
- | ^^^^^
- |
- = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
-
-error: there is no argument named `bar`
- --> $DIR/ifmt-bad-arg.rs:27:26
- |
-LL | format!("{} {foo} {} {bar} {}", 1, 2, 3);
- | ^^^^^
- |
- = help: if you intended to capture `bar` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
-
-error: there is no argument named `foo`
- --> $DIR/ifmt-bad-arg.rs:31:14
- |
-LL | format!("{foo}");
- | ^^^^^
- |
- = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
-
-error: multiple unused formatting arguments
- --> $DIR/ifmt-bad-arg.rs:32:17
- |
-LL | format!("", 1, 2);
- | -- ^ ^ argument never used
- | | |
- | | argument never used
- | multiple missing formatting specifiers
-
-error: argument never used
- --> $DIR/ifmt-bad-arg.rs:33:22
- |
-LL | format!("{}", 1, 2);
- | ---- ^ argument never used
- | |
- | formatting specifier missing
-
-error: argument never used
- --> $DIR/ifmt-bad-arg.rs:34:20
- |
-LL | format!("{1}", 1, 2);
- | ----- ^ argument never used
- | |
- | formatting specifier missing
-
-error: named argument never used
- --> $DIR/ifmt-bad-arg.rs:35:26
- |
-LL | format!("{}", 1, foo=2);
- | ---- ^ named argument never used
- | |
- | formatting specifier missing
-
-error: argument never used
- --> $DIR/ifmt-bad-arg.rs:36:22
- |
-LL | format!("{foo}", 1, foo=2);
- | ------- ^ argument never used
- | |
- | formatting specifier missing
-
-error: named argument never used
- --> $DIR/ifmt-bad-arg.rs:37:21
- |
-LL | format!("", foo=2);
- | -- ^ named argument never used
- | |
- | formatting specifier missing
-
-error: multiple unused formatting arguments
- --> $DIR/ifmt-bad-arg.rs:38:32
- |
-LL | format!("{} {}", 1, 2, foo=1, bar=2);
- | ------- ^ ^ named argument never used
- | | |
- | | named argument never used
- | multiple missing formatting specifiers
-
-error: duplicate argument named `foo`
- --> $DIR/ifmt-bad-arg.rs:40:33
- |
-LL | format!("{foo}", foo=1, foo=2);
- | - ^ duplicate argument
- | |
- | previously here
-
-error: positional arguments cannot follow named arguments
- --> $DIR/ifmt-bad-arg.rs:41:35
- |
-LL | format!("{foo} {} {}", foo=1, 2);
- | - ^ positional arguments must be before named arguments
- | |
- | named argument
-
-error: there is no argument named `valueb`
- --> $DIR/ifmt-bad-arg.rs:45:23
- |
-LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
- | ^^^^^^^^
- |
- = help: if you intended to capture `valueb` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
-
-error: named argument never used
- --> $DIR/ifmt-bad-arg.rs:45:51
- |
-LL | format!("{valuea} {valueb}", valuea=5, valuec=7);
- | ------------------- ^ named argument never used
- | |
- | formatting specifier missing
-
-error: invalid format string: expected `'}'` but string was terminated
- --> $DIR/ifmt-bad-arg.rs:51:15
- |
-LL | format!("{");
- | -^ expected `'}'` in format string
- | |
- | because of this opening brace
- |
- = note: if you intended to print `{`, you can escape it using `{{`
-
-error: invalid format string: unmatched `}` found
- --> $DIR/ifmt-bad-arg.rs:53:18
- |
-LL | format!("foo } bar");
- | ^ unmatched `}` in format string
- |
- = note: if you intended to print `}`, you can escape it using `}}`
-
-error: invalid format string: unmatched `}` found
- --> $DIR/ifmt-bad-arg.rs:54:18
- |
-LL | format!("foo }");
- | ^ unmatched `}` in format string
- |
- = note: if you intended to print `}`, you can escape it using `}}`
-
-error: argument never used
- --> $DIR/ifmt-bad-arg.rs:56:27
- |
-LL | format!("foo %s baz", "bar");
- | -- ^^^^^ argument never used
- | |
- | help: format specifiers use curly braces: `{}`
- |
- = note: printf formatting not supported; see the documentation for `std::fmt`
-
-error: there is no argument named `foo`
- --> $DIR/ifmt-bad-arg.rs:60:9
- |
-LL | {foo}
- | ^^^^^
- |
- = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes
-
-error: invalid format string: expected `'}'`, found `'t'`
- --> $DIR/ifmt-bad-arg.rs:75:1
- |
-LL | ninth number: {
- | - because of this opening brace
-LL | tenth number: {}",
- | ^ expected `}` in format string
- |
- = note: if you intended to print `{`, you can escape it using `{{`
-
-error: 4 positional arguments in format string, but there are 3 arguments
- --> $DIR/ifmt-bad-arg.rs:78:15
- |
-LL | println!("{} {:.*} {}", 1, 3.2, 4);
- | ^^ ^^--^ ^^ - --- -
- | | |
- | | this parameter corresponds to the precision flag
- | this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
- |
- = note: positional arguments are zero-based
- = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-
-error: 4 positional arguments in format string, but there are 3 arguments
- --> $DIR/ifmt-bad-arg.rs:81:15
- |
-LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
- | ^^ ^^^----^ ^^ - --- -
- | | | |
- | | | this parameter corresponds to the precision flag
- | | this precision flag adds an extra required argument at position 1, which is why there are 4 arguments expected
- | this width flag expects an `usize` argument at position 7, but there are 3 arguments
- |
- = note: positional arguments are zero-based
- = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-
-error: invalid reference to positional argument 7 (there are 3 arguments)
- --> $DIR/ifmt-bad-arg.rs:84:18
- |
-LL | println!("{} {:07$} {}", 1, 3.2, 4);
- | ^^^--^
- | |
- | this width flag expects an `usize` argument at position 7, but there are 3 arguments
- |
- = note: positional arguments are zero-based
- = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-
-error: unknown format trait `foo`
- --> $DIR/ifmt-bad-arg.rs:86:17
- |
-LL | println!("{:foo}", 1);
- | ^^^
- |
- = note: the only appropriate formatting traits are:
- - ``, which uses the `Display` trait
- - `?`, which uses the `Debug` trait
- - `e`, which uses the `LowerExp` trait
- - `E`, which uses the `UpperExp` trait
- - `o`, which uses the `Octal` trait
- - `p`, which uses the `Pointer` trait
- - `b`, which uses the `Binary` trait
- - `x`, which uses the `LowerHex` trait
- - `X`, which uses the `UpperHex` trait
-
-error: invalid reference to positional arguments 4, 5, 6 and 7 (there is 1 argument)
- --> $DIR/ifmt-bad-arg.rs:87:15
- |
-LL | println!("{5} {:4$} {6:7$}", 1);
- | ^^^ ^^--^ ^^^--^
- | | |
- | | this width flag expects an `usize` argument at position 7, but there is 1 argument
- | this width flag expects an `usize` argument at position 4, but there is 1 argument
- |
- = note: positional arguments are zero-based
- = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-
-error: 2 positional arguments in format string, but no arguments were given
- --> $DIR/ifmt-bad-arg.rs:92:15
- |
-LL | println!("{:.*}");
- | ^^--^
- | |
- | this precision flag adds an extra required argument at position 0, which is why there are 2 arguments expected
- |
- = note: positional arguments are zero-based
- = note: for information about formatting flags, visit https://doc.rust-lang.org/std/fmt/index.html
-
-error[E0308]: mismatched types
- --> $DIR/ifmt-bad-arg.rs:78:32
- |
-LL | println!("{} {:.*} {}", 1, 3.2, 4);
- | ^^^ expected `usize`, found floating-point number
- |
- = note: expected reference `&usize`
- found reference `&{float}`
- = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error[E0308]: mismatched types
- --> $DIR/ifmt-bad-arg.rs:81:35
- |
-LL | println!("{} {:07$.*} {}", 1, 3.2, 4);
- | ^^^ expected `usize`, found floating-point number
- |
- = note: expected reference `&usize`
- found reference `&{float}`
- = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to 36 previous errors
-
-For more information about this error, try `rustc --explain E0308`.
+++ /dev/null
-fn main() {
- format_args!(); //~ ERROR: requires at least a format string argument
- format_args!(|| {}); //~ ERROR: must be a string literal
-}
+++ /dev/null
-error: requires at least a format string argument
- --> $DIR/ifmt-bad-format-args.rs:2:5
- |
-LL | format_args!();
- | ^^^^^^^^^^^^^^^
- |
- = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: format argument must be a string literal
- --> $DIR/ifmt-bad-format-args.rs:3:18
- |
-LL | format_args!(|| {});
- | ^^^^^
- |
-help: you might be missing a string literal to format with
- |
-LL | format_args!("{}", || {});
- | ^^^^^
-
-error: aborting due to 2 previous errors
-
+++ /dev/null
-fn main() {
- format!("{:X}", "3");
- //~^ ERROR: `str: UpperHex` is not satisfied
-}
+++ /dev/null
-error[E0277]: the trait bound `str: UpperHex` is not satisfied
- --> $DIR/ifmt-unimpl.rs:2:21
- |
-LL | format!("{:X}", "3");
- | ^^^ the trait `UpperHex` is not implemented for `str`
- |
- = note: required because of the requirements on the impl of `UpperHex` for `&str`
- = note: required by `std::fmt::UpperHex::fmt`
- = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
+++ /dev/null
-fn main() {
- format!("{:notimplemented}", "3");
- //~^ ERROR: unknown format trait `notimplemented`
-}
+++ /dev/null
-error: unknown format trait `notimplemented`
- --> $DIR/ifmt-unknown-trait.rs:2:16
- |
-LL | format!("{:notimplemented}", "3");
- | ^^^^^^^^^^^^^^
- |
- = note: the only appropriate formatting traits are:
- - ``, which uses the `Display` trait
- - `?`, which uses the `Debug` trait
- - `e`, which uses the `LowerExp` trait
- - `E`, which uses the `UpperExp` trait
- - `o`, which uses the `Octal` trait
- - `p`, which uses the `Pointer` trait
- - `b`, which uses the `Binary` trait
- - `x`, which uses the `LowerHex` trait
- - `X`, which uses the `UpperHex` trait
-
-error: aborting due to previous error
-