From 291dce91b24d70382ebf1116fa836fd91960de84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Mon, 8 Jun 2020 00:00:00 +0000 Subject: [PATCH 01/31] Fallback to xml.etree.ElementTree The xml.etree.cElementTree has been deprecated since Python 3.3 and removed in Python 3.9 https://bugs.python.org/issue36543. --- src/etc/htmldocck.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/etc/htmldocck.py b/src/etc/htmldocck.py index 7789b24b62c83..2e7958325cd61 100644 --- a/src/etc/htmldocck.py +++ b/src/etc/htmldocck.py @@ -114,7 +114,10 @@ from html.parser import HTMLParser except ImportError: from HTMLParser import HTMLParser -from xml.etree import cElementTree as ET +try: + from xml.etree import cElementTree as ET +except ImportError: + from xml.etree import ElementTree as ET try: from html.entities import name2codepoint From 6b95f3102d657a5cd0549213a073b28c7e0fe609 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 12 Oct 2019 15:07:13 +0100 Subject: [PATCH 02/31] Add `format_args_capture` feature --- src/librustc_builtin_macros/format.rs | 61 ++++++++++++++++-- src/librustc_feature/active.rs | 3 + src/librustc_parse_format/lib.rs | 2 +- src/librustc_span/symbol.rs | 1 + .../fmt/feature-gate-format-args-capture.rs | 6 ++ .../feature-gate-format-args-capture.stderr | 20 ++++++ .../fmt/format-args-capture-macro-hygiene.rs | 6 ++ .../format-args-capture-macro-hygiene.stderr | 22 +++++++ .../format-args-capture-missing-variables.rs | 22 +++++++ ...rmat-args-capture-missing-variables.stderr | 52 ++++++++++++++++ src/test/ui/fmt/format-args-capture.rs | 62 +++++++++++++++++++ src/test/ui/if/ifmt-bad-arg.stderr | 15 +++++ 12 files changed, 267 insertions(+), 5 deletions(-) create mode 100644 src/test/ui/fmt/feature-gate-format-args-capture.rs create mode 100644 src/test/ui/fmt/feature-gate-format-args-capture.stderr create mode 100644 src/test/ui/fmt/format-args-capture-macro-hygiene.rs create mode 100644 src/test/ui/fmt/format-args-capture-macro-hygiene.stderr create mode 100644 src/test/ui/fmt/format-args-capture-missing-variables.rs create mode 100644 src/test/ui/fmt/format-args-capture-missing-variables.stderr create mode 100644 src/test/ui/fmt/format-args-capture.rs diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index e574b076bf84c..538d513c5d6ea 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -107,6 +107,9 @@ struct Context<'a, 'b> { arg_spans: Vec, /// All the formatting arguments that have formatting flags set, in order for diagnostics. arg_with_formatting: Vec>, + + /// Whether this format string came from a string literal, as opposed to a macro. + is_literal: bool, } /// Parses the arguments from the given list of tokens, returning the diagnostic @@ -498,10 +501,59 @@ impl<'a, 'b> Context<'a, 'b> { self.verify_arg_type(Exact(idx), ty) } None => { - let msg = format!("there is no argument named `{}`", name); - let sp = *self.arg_spans.get(self.curpiece).unwrap_or(&self.fmtsp); - let mut err = self.ecx.struct_span_err(sp, &msg[..]); - err.emit(); + let capture_feature_enabled = self + .ecx + .ecfg + .features + .map_or(false, |features| features.format_args_capture); + + // For the moment capturing variables from format strings expanded from + // literals is disabled (see RFC #2795) + let can_capture = capture_feature_enabled && self.is_literal; + + if can_capture { + // Treat this name as a variable to capture from the surrounding scope + let idx = self.args.len(); + self.arg_types.push(Vec::new()); + self.arg_unique_types.push(Vec::new()); + self.args.push( + self.ecx.expr_ident(self.fmtsp, Ident::new(name, self.fmtsp)), + ); + self.names.insert(name, idx); + self.verify_arg_type(Exact(idx), ty) + } else { + let msg = format!("there is no argument named `{}`", name); + let sp = if self.is_literal { + *self.arg_spans.get(self.curpiece).unwrap_or(&self.fmtsp) + } else { + self.fmtsp + }; + let mut err = self.ecx.struct_span_err(sp, &msg[..]); + + if capture_feature_enabled && !self.is_literal { + err.note(&format!( + "did you intend to capture a variable `{}` from \ + the surrounding scope?", + name + )); + err.note( + "for hygiene reasons format_args! cannot capture variables \ + when the format string is expanded from a macro", + ); + } else if self.ecx.parse_sess().unstable_features.is_nightly_build() { + err.note(&format!( + "did you intend to capture a variable `{}` from \ + the surrounding scope?", + name + )); + err.help( + "add `#![feature(format_args_capture)]` to the crate \ + attributes to enable", + ); + } + + err.emit(); + } } } } @@ -951,6 +1003,7 @@ pub fn expand_preparsed_format_args( invalid_refs: Vec::new(), arg_spans, arg_with_formatting: Vec::new(), + is_literal: parser.is_literal, }; // This needs to happen *after* the Parser has consumed all pieces to create all the spans diff --git a/src/librustc_feature/active.rs b/src/librustc_feature/active.rs index e2d497a3adab3..11c1908b57cac 100644 --- a/src/librustc_feature/active.rs +++ b/src/librustc_feature/active.rs @@ -577,6 +577,9 @@ declare_features! ( /// Be more precise when looking for live drops in a const context. (active, const_precise_live_drops, "1.46.0", Some(73255), None), + /// Allows capturing variables in scope using format_args! + (active, format_args_capture, "1.46.0", Some(67984), None), + // ------------------------------------------------------------------------- // feature-group-end: actual feature gates // ------------------------------------------------------------------------- diff --git a/src/librustc_parse_format/lib.rs b/src/librustc_parse_format/lib.rs index a5b5a1090cbfd..7db62f3493ede 100644 --- a/src/librustc_parse_format/lib.rs +++ b/src/librustc_parse_format/lib.rs @@ -190,7 +190,7 @@ pub struct Parser<'a> { /// Whether the source string is comes from `println!` as opposed to `format!` or `print!` append_newline: bool, /// Whether this formatting string is a literal or it comes from a macro. - is_literal: bool, + pub is_literal: bool, /// Start position of the current line. cur_line_start: usize, /// Start and end byte offset of every line of the format string. Excludes diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index 06d1f36622b94..185ce1afde90e 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -338,6 +338,7 @@ symbols! { forbid, format_args, format_args_nl, + format_args_capture, from, From, from_desugaring, diff --git a/src/test/ui/fmt/feature-gate-format-args-capture.rs b/src/test/ui/fmt/feature-gate-format-args-capture.rs new file mode 100644 index 0000000000000..21af91610915f --- /dev/null +++ b/src/test/ui/fmt/feature-gate-format-args-capture.rs @@ -0,0 +1,6 @@ +fn main() { + format!("{foo}"); //~ ERROR: there is no argument named `foo` + + // panic! doesn't hit format_args! unless there are two or more arguments. + panic!("{foo} {bar}", bar=1); //~ ERROR: there is no argument named `foo` +} diff --git a/src/test/ui/fmt/feature-gate-format-args-capture.stderr b/src/test/ui/fmt/feature-gate-format-args-capture.stderr new file mode 100644 index 0000000000000..bbd4d759fb548 --- /dev/null +++ b/src/test/ui/fmt/feature-gate-format-args-capture.stderr @@ -0,0 +1,20 @@ +error: there is no argument named `foo` + --> $DIR/feature-gate-format-args-capture.rs:2:14 + | +LL | format!("{foo}"); + | ^^^^^ + | + = note: did you intend to capture a variable `foo` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + +error: there is no argument named `foo` + --> $DIR/feature-gate-format-args-capture.rs:5:13 + | +LL | panic!("{foo} {bar}", bar=1); + | ^^^^^ + | + = note: did you intend to capture a variable `foo` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.rs b/src/test/ui/fmt/format-args-capture-macro-hygiene.rs new file mode 100644 index 0000000000000..6ca7dcc216f3a --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.rs @@ -0,0 +1,6 @@ +#![feature(format_args_capture)] + +fn main() { + format!(concat!("{foo}")); //~ ERROR: there is no argument named `foo` + format!(concat!("{ba", "r} {}"), 1); //~ ERROR: there is no argument named `bar` +} diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr new file mode 100644 index 0000000000000..42039c33d2fec --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr @@ -0,0 +1,22 @@ +error: there is no argument named `foo` + --> $DIR/format-args-capture-macro-hygiene.rs:4:13 + | +LL | format!(concat!("{foo}")); + | ^^^^^^^^^^^^^^^^ + | + = note: did you intend to capture a variable `foo` from the surrounding scope? + = note: for hygiene reasons format_args! cannot capture variables when the format string is expanded from a macro + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: there is no argument named `bar` + --> $DIR/format-args-capture-macro-hygiene.rs:5:13 + | +LL | format!(concat!("{ba", "r} {}"), 1); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: did you intend to capture a variable `bar` from the surrounding scope? + = note: for hygiene reasons format_args! cannot capture variables when the format string is expanded from a macro + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/fmt/format-args-capture-missing-variables.rs b/src/test/ui/fmt/format-args-capture-missing-variables.rs new file mode 100644 index 0000000000000..3c596ae3bb899 --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-missing-variables.rs @@ -0,0 +1,22 @@ +#![feature(format_args_capture)] + +fn main() { + format!("{} {foo} {} {bar} {}", 1, 2, 3); + //~^ ERROR: cannot find value `foo` in this scope + //~^^ ERROR: cannot find value `bar` in this scope + + format!("{foo}"); //~ ERROR: cannot find value `foo` in this scope + + format!("{valuea} {valueb}", valuea=5, valuec=7); + //~^ ERROR cannot find value `valueb` in this scope + //~^^ ERROR named argument never used + + format!(r##" + + {foo} + + "##); + //~^^^^^ ERROR: cannot find value `foo` in this scope + + panic!("{foo} {bar}", bar=1); //~ ERROR: cannot find value `foo` in this scope +} diff --git a/src/test/ui/fmt/format-args-capture-missing-variables.stderr b/src/test/ui/fmt/format-args-capture-missing-variables.stderr new file mode 100644 index 0000000000000..c3d740eef9d3c --- /dev/null +++ b/src/test/ui/fmt/format-args-capture-missing-variables.stderr @@ -0,0 +1,52 @@ +error: named argument never used + --> $DIR/format-args-capture-missing-variables.rs:10:51 + | +LL | format!("{valuea} {valueb}", valuea=5, valuec=7); + | ------------------- ^ named argument never used + | | + | formatting specifier missing + +error[E0425]: cannot find value `foo` in this scope + --> $DIR/format-args-capture-missing-variables.rs:4:13 + | +LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); + | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `bar` in this scope + --> $DIR/format-args-capture-missing-variables.rs:4:13 + | +LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); + | ^^^^^^^^^^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `foo` in this scope + --> $DIR/format-args-capture-missing-variables.rs:8:13 + | +LL | format!("{foo}"); + | ^^^^^^^ not found in this scope + +error[E0425]: cannot find value `valueb` in this scope + --> $DIR/format-args-capture-missing-variables.rs:10:13 + | +LL | format!("{valuea} {valueb}", valuea=5, valuec=7); + | ^^^^^^^^^^^^^^^^^^^ not found in this scope + +error[E0425]: cannot find value `foo` in this scope + --> $DIR/format-args-capture-missing-variables.rs:14:13 + | +LL | format!(r##" + | _____________^ +LL | | +LL | | {foo} +LL | | +LL | | "##); + | |_______^ not found in this scope + +error[E0425]: cannot find value `foo` in this scope + --> $DIR/format-args-capture-missing-variables.rs:21:12 + | +LL | panic!("{foo} {bar}", bar=1); + | ^^^^^^^^^^^^^ not found in this scope + +error: aborting due to 7 previous errors + +For more information about this error, try `rustc --explain E0425`. diff --git a/src/test/ui/fmt/format-args-capture.rs b/src/test/ui/fmt/format-args-capture.rs new file mode 100644 index 0000000000000..89dcfd8300435 --- /dev/null +++ b/src/test/ui/fmt/format-args-capture.rs @@ -0,0 +1,62 @@ +// run-pass +#![feature(format_args_capture)] + +fn main() { + named_argument_takes_precedence_to_captured(); + panic_with_single_argument_does_not_get_formatted(); + panic_with_multiple_arguments_is_formatted(); + formatting_parameters_can_be_captured(); +} + +fn named_argument_takes_precedence_to_captured() { + let foo = "captured"; + let s = format!("{foo}", foo="named"); + assert_eq!(&s, "named"); + + let s = format!("{foo}-{foo}-{foo}", foo="named"); + assert_eq!(&s, "named-named-named"); + + let s = format!("{}-{bar}-{foo}", "positional", bar="named"); + assert_eq!(&s, "positional-named-captured"); +} + +fn panic_with_single_argument_does_not_get_formatted() { + // panic! with a single argument does not perform string formatting. + // RFC #2795 suggests that this may need to change so that captured arguments are formatted. + // For stability reasons this will need to part of an edition change. + + let msg = std::panic::catch_unwind(|| { + panic!("{foo}"); + }).unwrap_err(); + + assert_eq!(msg.downcast_ref::<&str>(), Some(&"{foo}")) +} + +fn panic_with_multiple_arguments_is_formatted() { + let foo = "captured"; + + let msg = std::panic::catch_unwind(|| { + panic!("{}-{bar}-{foo}", "positional", bar="named"); + }).unwrap_err(); + + assert_eq!(msg.downcast_ref::(), Some(&"positional-named-captured".to_string())) +} + +fn formatting_parameters_can_be_captured() { + let width = 9; + let precision = 3; + + let x = 7.0; + + let s = format!("{x:width$}"); + assert_eq!(&s, " 7"); + + let s = format!("{x: $DIR/ifmt-bad-arg.rs:27:26 | LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ + | + = note: did you intend to capture a variable `bar` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable error: there is no argument named `foo` --> $DIR/ifmt-bad-arg.rs:31:14 | LL | format!("{foo}"); | ^^^^^ + | + = note: did you intend to capture a variable `foo` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable error: multiple unused formatting arguments --> $DIR/ifmt-bad-arg.rs:32:17 @@ -155,6 +164,9 @@ error: there is no argument named `valueb` | LL | format!("{valuea} {valueb}", valuea=5, valuec=7); | ^^^^^^^^ + | + = note: did you intend to capture a variable `valueb` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable error: named argument never used --> $DIR/ifmt-bad-arg.rs:45:51 @@ -205,6 +217,9 @@ error: there is no argument named `foo` | LL | {foo} | ^^^^^ + | + = note: did you intend to capture a variable `foo` from the surrounding scope? + = help: add `#![feature(format_args_capture)]` to the crate attributes to enable error: invalid format string: expected `'}'`, found `'t'` --> $DIR/ifmt-bad-arg.rs:75:1 From 8caf60407033e84592821a3f7b3917fe80d343e0 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 27 Jun 2020 18:13:47 +0100 Subject: [PATCH 03/31] Improve messaging from PR feedback --- src/librustc_builtin_macros/format.rs | 14 +++++--------- .../fmt/feature-gate-format-args-capture.stderr | 6 ++---- src/test/ui/if/ifmt-bad-arg.stderr | 15 +++++---------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 538d513c5d6ea..16e11fecf2963 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -507,8 +507,8 @@ impl<'a, 'b> Context<'a, 'b> { .features .map_or(false, |features| features.format_args_capture); - // For the moment capturing variables from format strings expanded from - // literals is disabled (see RFC #2795) + // For the moment capturing variables from format strings expanded from macros is + // disabled (see RFC #2795) let can_capture = capture_feature_enabled && self.is_literal; if can_capture { @@ -541,15 +541,11 @@ impl<'a, 'b> Context<'a, 'b> { when the format string is expanded from a macro", ); } else if self.ecx.parse_sess().unstable_features.is_nightly_build() { - err.note(&format!( - "did you intend to capture a variable `{}` from \ - the surrounding scope?", + err.help(&format!( + "if you intended to capture `{}` from the surrounding scope, add \ + `#![feature(format_args_capture)]` to the crate attributes", name )); - err.help( - "add `#![feature(format_args_capture)]` to the crate \ - attributes to enable", - ); } err.emit(); diff --git a/src/test/ui/fmt/feature-gate-format-args-capture.stderr b/src/test/ui/fmt/feature-gate-format-args-capture.stderr index bbd4d759fb548..f08f1651cb622 100644 --- a/src/test/ui/fmt/feature-gate-format-args-capture.stderr +++ b/src/test/ui/fmt/feature-gate-format-args-capture.stderr @@ -4,8 +4,7 @@ error: there is no argument named `foo` LL | format!("{foo}"); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 `foo` --> $DIR/feature-gate-format-args-capture.rs:5:13 @@ -13,8 +12,7 @@ error: there is no argument named `foo` LL | panic!("{foo} {bar}", bar=1); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = help: if you intended to capture `foo` from the surrounding scope, add `#![feature(format_args_capture)]` to the crate attributes error: aborting due to 2 previous errors diff --git a/src/test/ui/if/ifmt-bad-arg.stderr b/src/test/ui/if/ifmt-bad-arg.stderr index cbcb1df49851a..0ff478826f728 100644 --- a/src/test/ui/if/ifmt-bad-arg.stderr +++ b/src/test/ui/if/ifmt-bad-arg.stderr @@ -64,8 +64,7 @@ error: there is no argument named `foo` LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 @@ -73,8 +72,7 @@ error: there is no argument named `bar` LL | format!("{} {foo} {} {bar} {}", 1, 2, 3); | ^^^^^ | - = note: did you intend to capture a variable `bar` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 @@ -82,8 +80,7 @@ error: there is no argument named `foo` LL | format!("{foo}"); | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 @@ -165,8 +162,7 @@ error: there is no argument named `valueb` LL | format!("{valuea} {valueb}", valuea=5, valuec=7); | ^^^^^^^^ | - = note: did you intend to capture a variable `valueb` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 @@ -218,8 +214,7 @@ error: there is no argument named `foo` LL | {foo} | ^^^^^ | - = note: did you intend to capture a variable `foo` from the surrounding scope? - = help: add `#![feature(format_args_capture)]` to the crate attributes to enable + = 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 From a1217cb29de22aae3cda717e78d1edd3e9d8ffd1 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Sat, 27 Jun 2020 21:18:02 +0100 Subject: [PATCH 04/31] Add `format_args_capture` to the unstable book --- .../library-features/format-args-capture.md | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 src/doc/unstable-book/src/library-features/format-args-capture.md diff --git a/src/doc/unstable-book/src/library-features/format-args-capture.md b/src/doc/unstable-book/src/library-features/format-args-capture.md new file mode 100644 index 0000000000000..64b1b3d81bd83 --- /dev/null +++ b/src/doc/unstable-book/src/library-features/format-args-capture.md @@ -0,0 +1,47 @@ +# `format_args_capture` + +The tracking issue for this feature is: [#67984] + +[#67984]: https://github.com/rust-lang/rust/issues/67984 + +------------------------ + +Enables `format_args!` (and macros which use `format_args!` in their implementation, such +as `format!`, `print!` and `panic!`) to capture variables from the surrounding scope. +This avoids the need to pass named parameters when the binding in question +already exists in scope. + +```rust +#![feature(format_args_capture)] + +let (person, species, name) = ("Charlie Brown", "dog", "Snoopy"); + +// captures named argument `person` +print!("Hello {person}"); + +// captures named arguments `species` and `name` +format!("The {species}'s name is {name}."); +``` + +This also works for formatting parameters such as width and precision: + +```rust +#![feature(format_args_capture)] + +let precision = 2; +let s = format!("{:.precision$}", 1.324223); + +assert_eq!(&s, "1.32"); +``` + +A non-exhaustive list of macros which benefit from this functionality include: +- `format!` +- `print!` and `println!` +- `eprint!` and `eprintln!` +- `write!` and `writeln!` +- `panic!` +- `unreachable!` +- `unimplemented!` +- `todo!` +- `assert!` and similar +- macros in many thirdparty crates, such as `log` From db539c649866d9a25cb18a741436b3086b5d6e04 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 28 Jun 2020 14:21:03 -0400 Subject: [PATCH 05/31] Use raw_ref_op in A|Rc::as_ptr --- src/liballoc/lib.rs | 1 + src/liballoc/rc.rs | 6 +----- src/liballoc/sync.rs | 6 +----- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index 41c2b221704e6..c812d0c631618 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -109,6 +109,7 @@ #![feature(pattern)] #![feature(ptr_internals)] #![feature(ptr_offset_from)] +#![feature(raw_ref_op)] #![feature(rustc_attrs)] #![feature(receiver_trait)] #![feature(min_specialization)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 4d50ae9efca95..c69f2ffc43738 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -591,17 +591,13 @@ impl Rc { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(this.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: This cannot go through Deref::deref. // Instead, we manually offset the pointer rather than manifesting a reference. // This is so that the returned pointer retains the same provenance as our pointer. // This is required so that e.g. `get_mut` can write through the pointer // after the Rc is recovered through `from_raw`. - unsafe { - let offset = data_offset(&(*ptr).value); - set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset)) - } + unsafe { &raw const (*ptr).value } } /// Constructs an `Rc` from a raw pointer. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 826f0c8fa833f..5a9ab24562a30 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -590,17 +590,13 @@ impl Arc { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: This cannot go through Deref::deref. // Instead, we manually offset the pointer rather than manifesting a reference. // This is so that the returned pointer retains the same provenance as our pointer. // This is required so that e.g. `get_mut` can write through the pointer // after the Arc is recovered through `from_raw`. - unsafe { - let offset = data_offset(&(*ptr).data); - set_data_ptr(fake_ptr, (ptr as *mut u8).offset(offset)) - } + unsafe { &raw const (*ptr).data } } /// Constructs an `Arc` from a raw pointer. From e4bdf47f4c0773bba93f50900612242b929eca0b Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 28 Jun 2020 14:24:09 -0400 Subject: [PATCH 06/31] Do not require ptr validity in rc::data_offset --- src/liballoc/lib.rs | 1 + src/liballoc/rc.rs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs index c812d0c631618..ed3b09bae0540 100644 --- a/src/liballoc/lib.rs +++ b/src/liballoc/lib.rs @@ -100,6 +100,7 @@ #![feature(fundamental)] #![feature(internal_uninit_const)] #![feature(lang_items)] +#![feature(layout_for_ptr)] #![feature(libc)] #![feature(negative_impls)] #![feature(new_uninit)] diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index c69f2ffc43738..408278d5b615e 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -245,7 +245,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; use core::iter; use core::marker::{self, PhantomData, Unpin, Unsize}; -use core::mem::{self, align_of, align_of_val, forget, size_of_val}; +use core::mem::{self, align_of, align_of_val_raw, forget, size_of_val}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -2114,7 +2114,7 @@ unsafe fn data_offset(ptr: *const T) -> isize { // Because it is ?Sized, it will always be the last field in memory. // Note: This is a detail of the current implementation of the compiler, // and is not a guaranteed language detail. Do not rely on it outside of std. - unsafe { data_offset_align(align_of_val(&*ptr)) } + unsafe { data_offset_align(align_of_val_raw(ptr)) } } /// Computes the offset of the data field within `RcBox`. From d8a9c61e1a23b73c04d3058a11d1b8b2a46d635e Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sun, 28 Jun 2020 14:30:35 -0400 Subject: [PATCH 07/31] Use impl for Weak::as_ptr that works for unsized T --- src/liballoc/rc.rs | 24 +++++++++++++----------- src/liballoc/sync.rs | 24 +++++++++++++----------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 408278d5b615e..423122a690090 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -245,7 +245,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; use core::iter; use core::marker::{self, PhantomData, Unpin, Unsize}; -use core::mem::{self, align_of, align_of_val_raw, forget, size_of_val}; +use core::mem::{self, align_of_val_raw, forget, size_of_val}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -1704,9 +1704,18 @@ impl Weak { /// [`null`]: ../../std/ptr/fn.null.html #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { - let offset = data_offset_sized::(); - let ptr = self.ptr.cast::().as_ptr().wrapping_offset(offset); - ptr as *const T + let ptr: *mut RcBox = NonNull::as_ptr(self.ptr); + let fake_ptr = ptr as *mut T; + + // SAFETY: we must offset the pointer manually, and said pointer may be + // a dangling weak (usize::MAX). data_offset is safe to call, because we + // know a pointer to unsized T must be derived from a real unsized T, + // because dangling weaks are only created for sized T. wrapping_offset + // is used so that we can use the same code path for dangling weak refs. + unsafe { + let offset = data_offset(&raw const (*ptr).value); + set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + } } /// Consumes the `Weak` and turns it into a raw pointer. @@ -2117,13 +2126,6 @@ unsafe fn data_offset(ptr: *const T) -> isize { unsafe { data_offset_align(align_of_val_raw(ptr)) } } -/// Computes the offset of the data field within `RcBox`. -/// -/// Unlike [`data_offset`], this doesn't need the pointer, but it works only on `T: Sized`. -fn data_offset_sized() -> isize { - data_offset_align(align_of::()) -} - #[inline] fn data_offset_align(align: usize) -> isize { let layout = Layout::new::>(); diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 5a9ab24562a30..289aea3afcce9 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -16,7 +16,7 @@ use core::hash::{Hash, Hasher}; use core::intrinsics::abort; use core::iter; use core::marker::{PhantomData, Unpin, Unsize}; -use core::mem::{self, align_of, align_of_val, size_of_val}; +use core::mem::{self, align_of_val, size_of_val}; use core::ops::{CoerceUnsized, Deref, DispatchFromDyn, Receiver}; use core::pin::Pin; use core::ptr::{self, NonNull}; @@ -1472,9 +1472,18 @@ impl Weak { /// [`null`]: ../../std/ptr/fn.null.html #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { - let offset = data_offset_sized::(); - let ptr = self.ptr.cast::().as_ptr().wrapping_offset(offset); - ptr as *const T + let ptr: *mut ArcInner = NonNull::as_ptr(self.ptr); + let fake_ptr = ptr as *mut T; + + // SAFETY: we must offset the pointer manually, and said pointer may be + // a dangling weak (usize::MAX). data_offset is safe to call, because we + // know a pointer to unsized T must be derived from a real unsized T, + // because dangling weaks are only created for sized T. wrapping_offset + // is used so that we can use the same code path for dangling weak refs. + unsafe { + let offset = data_offset(&raw const (*ptr).data); + set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + } } /// Consumes the `Weak` and turns it into a raw pointer. @@ -2275,13 +2284,6 @@ unsafe fn data_offset(ptr: *const T) -> isize { unsafe { data_offset_align(align_of_val(&*ptr)) } } -/// Computes the offset of the data field within `ArcInner`. -/// -/// Unlike [`data_offset`], this doesn't need the pointer, but it works only on `T: Sized`. -fn data_offset_sized() -> isize { - data_offset_align(align_of::()) -} - #[inline] fn data_offset_align(align: usize) -> isize { let layout = Layout::new::>(); From fc3dc723da8daef495a170e02efb38093e05215e Mon Sep 17 00:00:00 2001 From: CAD97 Date: Tue, 30 Jun 2020 12:35:28 -0400 Subject: [PATCH 08/31] Clarify safety comment for A|Rc::as_ptr --- src/liballoc/rc.rs | 8 +++----- src/liballoc/sync.rs | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 423122a690090..8f7b8efd811f7 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -592,11 +592,9 @@ impl Rc { pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(this.ptr); - // SAFETY: This cannot go through Deref::deref. - // Instead, we manually offset the pointer rather than manifesting a reference. - // This is so that the returned pointer retains the same provenance as our pointer. - // This is required so that e.g. `get_mut` can write through the pointer - // after the Rc is recovered through `from_raw`. + // SAFETY: This cannot go through Deref::deref or Rc::inner. + // This is required to retain raw/mut provenance such that e.g. `get_mut` can + // write through the pointer after the Rc is recovered through `from_raw`. unsafe { &raw const (*ptr).value } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 289aea3afcce9..27c36f4a56933 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -591,11 +591,9 @@ impl Arc { pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); - // SAFETY: This cannot go through Deref::deref. - // Instead, we manually offset the pointer rather than manifesting a reference. - // This is so that the returned pointer retains the same provenance as our pointer. - // This is required so that e.g. `get_mut` can write through the pointer - // after the Arc is recovered through `from_raw`. + // SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner. + // This is required to retain raw/mut provenance such that e.g. `get_mut` can + // write through the pointer after the Rc is recovered through `from_raw`. unsafe { &raw const (*ptr).data } } From 0aecf3c74b7fd09460f453e7e95ae8cb65a92440 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Tue, 30 Jun 2020 12:42:09 -0400 Subject: [PATCH 09/31] Fix invalid pointer deref in Weak::as_ptr --- src/liballoc/rc.rs | 2 +- src/liballoc/sync.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 8f7b8efd811f7..ab64d5330874f 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1711,7 +1711,7 @@ impl Weak { // because dangling weaks are only created for sized T. wrapping_offset // is used so that we can use the same code path for dangling weak refs. unsafe { - let offset = data_offset(&raw const (*ptr).value); + let offset = data_offset(fake_ptr); set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 27c36f4a56933..e9af80d326f44 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1479,7 +1479,7 @@ impl Weak { // because dangling weaks are only created for sized T. wrapping_offset // is used so that we can use the same code path for dangling weak refs. unsafe { - let offset = data_offset(&raw const (*ptr).data); + let offset = data_offset(fake_ptr); set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) } } From aed88e18049f6be7d3c3b37683d05d777adb3c86 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Tue, 30 Jun 2020 12:47:23 -0400 Subject: [PATCH 10/31] Clarify when rc::data_offset is safe --- src/liballoc/rc.rs | 10 ++++++++++ src/liballoc/sync.rs | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index ab64d5330874f..24e7d5da7a684 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -2116,6 +2116,16 @@ impl AsRef for Rc { #[stable(feature = "pin", since = "1.33.0")] impl Unpin for Rc {} +/// Get the offset within an `ArcInner` for +/// a payload of type described by a pointer. +/// +/// # Safety +/// +/// This has the same safety requirements as `align_of_val_raw`. In effect: +/// +/// - This function is safe for any argument if `T` is sized, and +/// - if `T` is unsized, the pointer must have appropriate pointer metadata +/// aquired from the real instance that you are getting this offset for. unsafe fn data_offset(ptr: *const T) -> isize { // Align the unsized value to the end of the `RcBox`. // Because it is ?Sized, it will always be the last field in memory. diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index e9af80d326f44..53ce47d023b47 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -2273,7 +2273,16 @@ impl AsRef for Arc { #[stable(feature = "pin", since = "1.33.0")] impl Unpin for Arc {} -/// Computes the offset of the data field within `ArcInner`. +/// Get the offset within an `ArcInner` for +/// a payload of type described by a pointer. +/// +/// # Safety +/// +/// This has the same safety requirements as `align_of_val_raw`. In effect: +/// +/// - This function is safe for any argument if `T` is sized, and +/// - if `T` is unsized, the pointer must have appropriate pointer metadata +/// aquired from the real instance that you are getting this offset for. unsafe fn data_offset(ptr: *const T) -> isize { // Align the unsized value to the end of the `ArcInner`. // Because it is `?Sized`, it will always be the last field in memory. From b4d045719d77e40f294eb85d8e5cf8143d661718 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 24 Jun 2020 08:49:09 -0400 Subject: [PATCH 11/31] Use exhaustive match in const_prop.rs --- src/librustc_mir/transform/const_prop.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 2c1565b54261c..e4c1ca4e851b0 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -638,8 +638,20 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { return None; } + Rvalue::ThreadLocalRef(def_id) => { + trace!("skipping ThreadLocalRef({:?})", def_id); - _ => {} + return None; + } + + // There's no other checking to do at this time. + Rvalue::Aggregate(..) + | Rvalue::Use(..) + | Rvalue::Repeat(..) + | Rvalue::Len(..) + | Rvalue::Cast(..) + | Rvalue::Discriminant(..) + | Rvalue::NullaryOp(..) => {} } // FIXME we need to revisit this for #67176 From 1a0343217d34b5ef60bf7c0a86376dcddf90b8cd Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Tue, 30 Jun 2020 23:33:26 +0100 Subject: [PATCH 12/31] Amend wording of note --- src/librustc_builtin_macros/format.rs | 2 +- src/test/ui/fmt/format-args-capture-macro-hygiene.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 16e11fecf2963..019432035fe34 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -537,7 +537,7 @@ impl<'a, 'b> Context<'a, 'b> { name )); err.note( - "for hygiene reasons format_args! cannot capture variables \ + "to avoid ambiguity format_args! cannot capture variables \ when the format string is expanded from a macro", ); } else if self.ecx.parse_sess().unstable_features.is_nightly_build() { diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr index 42039c33d2fec..55bd97bafe8b3 100644 --- a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr +++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr @@ -5,7 +5,7 @@ LL | format!(concat!("{foo}")); | ^^^^^^^^^^^^^^^^ | = note: did you intend to capture a variable `foo` from the surrounding scope? - = note: for hygiene reasons format_args! cannot capture variables when the format string is expanded from a macro + = note: to avoid ambiguity format_args! cannot capture variables when the format string is expanded from a macro = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: there is no argument named `bar` @@ -15,7 +15,7 @@ LL | format!(concat!("{ba", "r} {}"), 1); | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: did you intend to capture a variable `bar` from the surrounding scope? - = note: for hygiene reasons format_args! cannot capture variables when the format string is expanded from a macro + = note: to avoid ambiguity format_args! cannot capture variables when the format string is expanded from a macro = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors From aac2f734dec39a19e412b46fcdc0e67a6eafa3ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Wed, 1 Jul 2020 16:59:50 +0200 Subject: [PATCH 13/31] Improve comments from https://github.com/rust-lang/rust/pull/72617, as suggested by RalfJung. --- src/libstd/panicking.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 97d62d958ca4f..3a81b1f9a0531 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -229,10 +229,10 @@ pub mod panic_count { thread_local! { static LOCAL_PANIC_COUNT: Cell = Cell::new(0) } // Sum of panic counts from all threads. The purpose of this is to have - // a fast path in `is_zero` (which is used by `panicking`). Access to - // this variable can be always be done with relaxed ordering because - // it is always guaranteed that, if `GLOBAL_PANIC_COUNT` is zero, - // `LOCAL_PANIC_COUNT` will be zero. + // a fast path in `is_zero` (which is used by `panicking`). In any particular + // thread, if that thread currently views `GLOBAL_PANIC_COUNT` as being zero, + // then `LOCAL_PANIC_COUNT` in that thread is zero. This invariant holds before + // and after increase and decrease, but not necessarily during their execution. static GLOBAL_PANIC_COUNT: AtomicUsize = AtomicUsize::new(0); pub fn increase() -> usize { @@ -263,6 +263,11 @@ pub mod panic_count { // Fast path: if `GLOBAL_PANIC_COUNT` is zero, all threads // (including the current one) will have `LOCAL_PANIC_COUNT` // equal to zero, so TLS access can be avoided. + // + // A relaxed atomic load is equivalent to a normal aligned memory read + // (e.g., a `mov` instruction in x86), while a TLS access might require + // calling a non-inlinable function (such as `__tls_get_addr` when using + // the GD TLS model). true } else { is_zero_slow_path() From 10ebb2cbb291ead33e8e20519611e962b594db50 Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Wed, 1 Jul 2020 11:35:17 +0100 Subject: [PATCH 14/31] Update src/librustc_builtin_macros/format.rs Apply suggestion from varkor Co-authored-by: varkor --- src/librustc_builtin_macros/format.rs | 2 +- src/test/ui/fmt/format-args-capture-macro-hygiene.stderr | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_builtin_macros/format.rs b/src/librustc_builtin_macros/format.rs index 019432035fe34..4cc83f8e31c20 100644 --- a/src/librustc_builtin_macros/format.rs +++ b/src/librustc_builtin_macros/format.rs @@ -537,7 +537,7 @@ impl<'a, 'b> Context<'a, 'b> { name )); err.note( - "to avoid ambiguity format_args! cannot capture variables \ + "to avoid ambiguity, `format_args!` cannot capture variables \ when the format string is expanded from a macro", ); } else if self.ecx.parse_sess().unstable_features.is_nightly_build() { diff --git a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr index 55bd97bafe8b3..0c5915149cd60 100644 --- a/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr +++ b/src/test/ui/fmt/format-args-capture-macro-hygiene.stderr @@ -5,7 +5,7 @@ LL | format!(concat!("{foo}")); | ^^^^^^^^^^^^^^^^ | = note: did you intend to capture a variable `foo` from the surrounding scope? - = note: to avoid ambiguity format_args! cannot capture variables when the format string is expanded from a macro + = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: there is no argument named `bar` @@ -15,7 +15,7 @@ LL | format!(concat!("{ba", "r} {}"), 1); | ^^^^^^^^^^^^^^^^^^^^^^^ | = note: did you intend to capture a variable `bar` from the surrounding scope? - = note: to avoid ambiguity format_args! cannot capture variables when the format string is expanded from a macro + = note: to avoid ambiguity, `format_args!` cannot capture variables when the format string is expanded from a macro = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors From ac40d1eff33cc6789d3c02f4a21477368574cf5e Mon Sep 17 00:00:00 2001 From: CAD97 Date: Wed, 1 Jul 2020 14:51:08 -0400 Subject: [PATCH 15/31] Apply documentation review suggestions Co-Authored-By: Ralf Jung --- src/liballoc/rc.rs | 7 ++++--- src/liballoc/sync.rs | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 24e7d5da7a684..29e0979b0eda6 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -592,8 +592,8 @@ impl Rc { pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(this.ptr); - // SAFETY: This cannot go through Deref::deref or Rc::inner. - // This is required to retain raw/mut provenance such that e.g. `get_mut` can + // SAFETY: This cannot go through Deref::deref or Rc::inner because + // this is required to retain raw/mut provenance such that e.g. `get_mut` can // write through the pointer after the Rc is recovered through `from_raw`. unsafe { &raw const (*ptr).value } } @@ -1709,7 +1709,8 @@ impl Weak { // a dangling weak (usize::MAX). data_offset is safe to call, because we // know a pointer to unsized T must be derived from a real unsized T, // because dangling weaks are only created for sized T. wrapping_offset - // is used so that we can use the same code path for dangling weak refs. + // is used so that we can use the same code path for the non-dangling + // unsized case and the potentially dangling sized case. unsafe { let offset = data_offset(fake_ptr); set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 53ce47d023b47..005821980fe2c 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -591,8 +591,8 @@ impl Arc { pub fn as_ptr(this: &Self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(this.ptr); - // SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner. - // This is required to retain raw/mut provenance such that e.g. `get_mut` can + // SAFETY: This cannot go through Deref::deref or RcBoxPtr::inner because + // this is required to retain raw/mut provenance such that e.g. `get_mut` can // write through the pointer after the Rc is recovered through `from_raw`. unsafe { &raw const (*ptr).data } } @@ -1477,7 +1477,8 @@ impl Weak { // a dangling weak (usize::MAX). data_offset is safe to call, because we // know a pointer to unsized T must be derived from a real unsized T, // because dangling weaks are only created for sized T. wrapping_offset - // is used so that we can use the same code path for dangling weak refs. + // is used so that we can use the same code path for the non-dangling + // unsized case and the potentially dangling sized case. unsafe { let offset = data_offset(fake_ptr); set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) From 98789ac75a15c78462ada2438881c8a4e4fda94a Mon Sep 17 00:00:00 2001 From: CAD97 Date: Wed, 1 Jul 2020 15:03:12 -0400 Subject: [PATCH 16/31] Simplify Weak::as_ptr impl --- src/liballoc/rc.rs | 5 ++--- src/liballoc/sync.rs | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 29e0979b0eda6..4d77779b2091d 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1703,7 +1703,6 @@ impl Weak { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { let ptr: *mut RcBox = NonNull::as_ptr(self.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: we must offset the pointer manually, and said pointer may be // a dangling weak (usize::MAX). data_offset is safe to call, because we @@ -1712,8 +1711,8 @@ impl Weak { // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { - let offset = data_offset(fake_ptr); - set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + let offset = data_offset(ptr as *mut T); + set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset)) } } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 005821980fe2c..160abe7210c77 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1471,7 +1471,6 @@ impl Weak { #[stable(feature = "weak_into_raw", since = "1.45.0")] pub fn as_ptr(&self) -> *const T { let ptr: *mut ArcInner = NonNull::as_ptr(self.ptr); - let fake_ptr = ptr as *mut T; // SAFETY: we must offset the pointer manually, and said pointer may be // a dangling weak (usize::MAX). data_offset is safe to call, because we @@ -1480,8 +1479,8 @@ impl Weak { // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { - let offset = data_offset(fake_ptr); - set_data_ptr(fake_ptr, (ptr as *mut u8).wrapping_offset(offset)) + let offset = data_offset(ptr as *mut T); + set_data_ptr(ptr as *mut T, (ptr as *mut u8).wrapping_offset(offset)) } } From 7498cad0d8dacd51f0d18bdf985c15efe55b4e8a Mon Sep 17 00:00:00 2001 From: CAD97 Date: Wed, 1 Jul 2020 16:01:34 -0400 Subject: [PATCH 17/31] Reclarify safety comments in Weak::as_ptr --- src/liballoc/rc.rs | 6 +++--- src/liballoc/sync.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 4d77779b2091d..835df66d55c4e 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1705,9 +1705,9 @@ impl Weak { let ptr: *mut RcBox = NonNull::as_ptr(self.ptr); // SAFETY: we must offset the pointer manually, and said pointer may be - // a dangling weak (usize::MAX). data_offset is safe to call, because we - // know a pointer to unsized T must be derived from a real unsized T, - // because dangling weaks are only created for sized T. wrapping_offset + // a dangling weak (usize::MAX) if T is sized. data_offset is safe to call, + // because we know that a pointer to unsized T was derived from a real + // unsized T, as dangling weaks are only created for sized T. wrapping_offset // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 160abe7210c77..875bec5b20372 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -1473,9 +1473,9 @@ impl Weak { let ptr: *mut ArcInner = NonNull::as_ptr(self.ptr); // SAFETY: we must offset the pointer manually, and said pointer may be - // a dangling weak (usize::MAX). data_offset is safe to call, because we - // know a pointer to unsized T must be derived from a real unsized T, - // because dangling weaks are only created for sized T. wrapping_offset + // a dangling weak (usize::MAX) if T is sized. data_offset is safe to call, + // because we know that a pointer to unsized T was derived from a real + // unsized T, as dangling weaks are only created for sized T. wrapping_offset // is used so that we can use the same code path for the non-dangling // unsized case and the potentially dangling sized case. unsafe { From 0f1adc8ec812df494df33640c1be147f35e5f6ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eduardo=20S=C3=A1nchez=20Mu=C3=B1oz?= Date: Thu, 2 Jul 2020 13:47:19 +0200 Subject: [PATCH 18/31] Further improve comments in libstd/panicking.rs. --- src/libstd/panicking.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 3a81b1f9a0531..9542e7209b4cf 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -264,10 +264,11 @@ pub mod panic_count { // (including the current one) will have `LOCAL_PANIC_COUNT` // equal to zero, so TLS access can be avoided. // - // A relaxed atomic load is equivalent to a normal aligned memory read - // (e.g., a `mov` instruction in x86), while a TLS access might require - // calling a non-inlinable function (such as `__tls_get_addr` when using - // the GD TLS model). + // In terms of performance, a relaxed atomic load is similar to a normal + // aligned memory read (e.g., a mov instruction in x86), but with some + // compiler optimization restrictions. On the other hand, a TLS access + // might require calling a non-inlinable function (such as `__tls_get_addr` + // when using the GD TLS model). true } else { is_zero_slow_path() From 1b5ac57bfd4b0cca3bcdd0fa75c0f0e044ebf01e Mon Sep 17 00:00:00 2001 From: CAD97 Date: Thu, 2 Jul 2020 16:53:56 -0400 Subject: [PATCH 19/31] Note Weak.ptr never dangles sooner --- src/liballoc/rc.rs | 1 + src/liballoc/sync.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs index 835df66d55c4e..fccdfa0dca92a 100644 --- a/src/liballoc/rc.rs +++ b/src/liballoc/rc.rs @@ -1641,6 +1641,7 @@ pub struct Weak { // `Weak::new` sets this to `usize::MAX` so that it doesn’t need // to allocate space on the heap. That's not a value a real pointer // will ever have because RcBox has alignment at least 2. + // This is only possible when `T: Sized`; unsized `T` never dangle. ptr: NonNull>, } diff --git a/src/liballoc/sync.rs b/src/liballoc/sync.rs index 875bec5b20372..ac3ce2255c89b 100644 --- a/src/liballoc/sync.rs +++ b/src/liballoc/sync.rs @@ -267,6 +267,7 @@ pub struct Weak { // `Weak::new` sets this to `usize::MAX` so that it doesn’t need // to allocate space on the heap. That's not a value a real pointer // will ever have because RcBox has alignment at least 2. + // This is only possible when `T: Sized`; unsized `T` never dangle. ptr: NonNull>, } From bdc1f40fcd7be14dde6f94ae5392039a72517eb7 Mon Sep 17 00:00:00 2001 From: pierwill Date: Mon, 29 Jun 2020 17:12:20 -0700 Subject: [PATCH 20/31] Standardize bibliographic citations in rustc API docs --- src/librustc_ast_pretty/pp.rs | 10 ++++------ src/librustc_data_structures/graph/dominators/mod.rs | 11 ++++++----- src/librustc_span/hygiene.rs | 9 ++++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/librustc_ast_pretty/pp.rs b/src/librustc_ast_pretty/pp.rs index e6090db3284a7..4bb806a923e6c 100644 --- a/src/librustc_ast_pretty/pp.rs +++ b/src/librustc_ast_pretty/pp.rs @@ -1,10 +1,8 @@ //! This pretty-printer is a direct reimplementation of Philip Karlton's -//! Mesa pretty-printer, as described in appendix A of -//! -//! ```text -//! STAN-CS-79-770: "Pretty Printing", by Derek C. Oppen. -//! Stanford Department of Computer Science, 1979. -//! ``` +//! Mesa pretty-printer, as described in the appendix to +//! Derek C. Oppen, "Pretty Printing" (1979), +//! Stanford Computer Science Department STAN-CS-79-770, +//! . //! //! The algorithm's aim is to break a stream into as few lines as possible //! while respecting the indentation-consistency requirements of the enclosing diff --git a/src/librustc_data_structures/graph/dominators/mod.rs b/src/librustc_data_structures/graph/dominators/mod.rs index a7f9340dead88..438a0d0c6ff97 100644 --- a/src/librustc_data_structures/graph/dominators/mod.rs +++ b/src/librustc_data_structures/graph/dominators/mod.rs @@ -1,8 +1,9 @@ -//! Algorithm citation: -//! A Simple, Fast Dominance Algorithm. -//! Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy -//! Rice Computer Science TS-06-33870 -//! +//! Finding the dominators in a control-flow graph. +//! +//! Algorithm based on Keith D. Cooper, Timothy J. Harvey, and Ken Kennedy, +//! "A Simple, Fast Dominance Algorithm", +//! Rice Computer Science TS-06-33870, +//! . use super::iterate::reverse_post_order; use super::ControlFlowGraph; diff --git a/src/librustc_span/hygiene.rs b/src/librustc_span/hygiene.rs index 60bbdd0495cc4..b8f8917fccb4a 100644 --- a/src/librustc_span/hygiene.rs +++ b/src/librustc_span/hygiene.rs @@ -1,9 +1,8 @@ -//! Machinery for hygienic macros, inspired by the `MTWT[1]` paper. +//! Machinery for hygienic macros. //! -//! `[1]` Matthew Flatt, Ryan Culpepper, David Darais, and Robert Bruce Findler. 2012. -//! *Macros that work together: Compile-time bindings, partial expansion, -//! and definition contexts*. J. Funct. Program. 22, 2 (March 2012), 181-216. -//! DOI=10.1017/S0956796812000093 +//! Inspired by Matthew Flatt et al., “Macros That Work Together: Compile-Time Bindings, Partial +//! Expansion, and Definition Contexts,” *Journal of Functional Programming* 22, no. 2 +//! (March 1, 2012): 181–216, . // Hygiene data is stored in a global variable and accessed via TLS, which // means that accesses are somewhat expensive. (`HygieneData::with` From e3f599c15cceb38159a5690a21befbe7f36f5914 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 20:54:53 -0400 Subject: [PATCH 21/31] Add test for simplify-try misoptimization --- src/test/mir-opt/issue-73223.rs | 13 + .../32bit/rustc.main.PreCodegen.diff | 249 ++++++++++++ .../32bit/rustc.main.SimplifyArmIdentity.diff | 377 ++++++++++++++++++ .../64bit/rustc.main.PreCodegen.diff | 249 ++++++++++++ .../64bit/rustc.main.SimplifyArmIdentity.diff | 377 ++++++++++++++++++ 5 files changed, 1265 insertions(+) create mode 100644 src/test/mir-opt/issue-73223.rs create mode 100644 src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff create mode 100644 src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff create mode 100644 src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff create mode 100644 src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff diff --git a/src/test/mir-opt/issue-73223.rs b/src/test/mir-opt/issue-73223.rs new file mode 100644 index 0000000000000..d93805e6cd176 --- /dev/null +++ b/src/test/mir-opt/issue-73223.rs @@ -0,0 +1,13 @@ +fn main() { + let split = match Some(1) { + Some(v) => v, + None => return, + }; + + let _prev = Some(split); + assert_eq!(split, 1); +} + +// EMIT_MIR_FOR_EACH_BIT_WIDTH +// EMIT_MIR rustc.main.SimplifyArmIdentity.diff +// EMIT_MIR rustc.main.PreCodegen.diff diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff new file mode 100644 index 0000000000000..887ebfc8c64e4 --- /dev/null +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff @@ -0,0 +1,249 @@ +- // MIR for `main` before PreCodegen ++ // MIR for `main` after PreCodegen + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 + let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _10: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _11: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _12: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _13: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _14: std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _15: &[&str]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _16: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _17: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _18: [std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _19: (&&i32, &&i32); // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _20: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _21: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _22: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _23: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _26: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 1 { + debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + scope 3 { + debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 4 { + debug left_val => _7; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug right_val => _8; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _24: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _25: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 5 { + debug arg0 => _24; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug arg1 => _25; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 6 { + debug x => _24; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _27; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _30: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _31: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + } + scope 8 { + debug x => _25; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _29; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _32: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _33: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + scope 10 { + debug pieces => _15; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug args => _16; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _34: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + } + } + scope 2 { + debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + } + scope 7 { + } + scope 9 { + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:2:28: 2:29 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } + discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &i32 + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _8 = (_5.1: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_9); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_11); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _11 = (*_7); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _12 = (*_8); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _10 = Eq(move _11, move _12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_11); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _9 = Not(move _10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + switchInt(_9) -> [false: bb1, otherwise: bb2]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + } + + bb1: { + StorageDead(_9); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:1:11: 9:2 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb2: { + StorageLive(_14); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &[&str; 3] + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_21); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _21 = _7; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _20 = &_21; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_22); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_23); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _23 = _8; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _22 = &_23; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_19.0: &&i32) = move _20; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + (_19.1: &&i32) = move _22; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_22); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _24 = (_19.0: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _25 = (_19.1: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_26); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _27 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_30); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _30 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _27) -> bb3; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb3: { + StorageLive(_31); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _31 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _24) -> bb4; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb4: { + (_26.0: &core::fmt::Opaque) = move _31; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_26.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _30; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_31); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_30); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_28); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _29 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_32); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _32 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _29) -> bb5; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb5: { + StorageLive(_33); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _33 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _25) -> bb6; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb6: { + (_28.0: &core::fmt::Opaque) = move _33; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_28.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _32; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_33); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_32); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _18 = [move _26, move _28]; // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_28); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_26); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _17 = &_18; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _16 = move _17 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_34); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + discriminant(_34) = 0; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.0: &[&str]) = move _15; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.1: std::option::Option<&[std::fmt::rt::v1::Argument]>) = move _34; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.2: &[std::fmt::ArgumentV1]) = move _16; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_34); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _13 = &_14; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + const std::rt::begin_panic_fmt(move _13); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + // ty::Const + // + ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libstd/macros.rs:LL:COL + // + literal: Const { ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt}, val: Value(Scalar()) } + } + } + diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff new file mode 100644 index 0000000000000..2c1f81f2d732d --- /dev/null +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff @@ -0,0 +1,377 @@ +- // MIR for `main` before SimplifyArmIdentity ++ // MIR for `main` after SimplifyArmIdentity + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 + let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let mut _3: isize; // in scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + let _4: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _5: !; // in scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + let mut _7: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 + let _8: (); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _9: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _10: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _11: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _12: i32; // in scope 0 at $DIR/issue-73223.rs:8:23: 8:24 + let mut _15: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _16: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _17: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _18: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _19: !; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _20: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _21: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _22: std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _23: &[&str]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _24: &[&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _25: &[&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _26: [&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _27: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _28: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _29: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _30: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _31: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _32: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _33: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _34: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _35: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _36: [std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _37: (&&i32, &&i32); // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _38: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _39: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _40: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _41: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _44: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _45: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _46: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _47: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _48: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _49: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 1 { + debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _6: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + scope 3 { + debug _prev => _6; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + let _13: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _14: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _51: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 4 { + debug left_val => _13; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug right_val => _14; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _42: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _43: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _50: &[&str; 3]; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 5 { + debug arg0 => _42; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug arg1 => _43; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 6 { + debug x => _45; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _46; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _52: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _53: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _54: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _55: &&i32; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + } + scope 8 { + debug x => _48; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _49; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _56: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _57: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _58: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _59: &&i32; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + scope 10 { + debug pieces => _23; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug args => _33; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _60: &[&str]; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _61: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _62: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + } + } + scope 2 { + debug v => _4; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + } + scope 7 { + } + scope 9 { + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:2:28: 2:29 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } + discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:3:9: 3:16 + // + literal: Const { ty: isize, val: Value(Scalar(0x00000001)) } + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + } + + bb1: { + _0 = const (); // scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:4:17: 4:23 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + } + + bb2: { +- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 +- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 +- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 +- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 ++ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 +- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 +- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 +- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 +- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 +- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _10 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_11); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &i32 + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_11); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_13); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _13 = (_9.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_14); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _14 = (_9.1: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_15); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_17); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _17 = (*_13); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _18 = (*_14); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _16 = Eq(move _17, move _18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_17); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _15 = Not(move _16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + switchInt(_15) -> [false: bb4, otherwise: bb5]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + } + + bb3: { + return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb4: { + _8 = const (); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_15); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_14); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_13); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:1:11: 9:2 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_6); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb5: { + StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_21); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_22); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_23); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_24); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_25); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &[&str; 3] + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_24); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_33); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_34); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_35); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_36); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_37); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_38); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_39); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _39 = _13; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _38 = &_39; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_40); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_41); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _41 = _14; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _40 = &_41; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_37.0: &&i32) = move _38; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + (_37.1: &&i32) = move _40; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_40); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_38); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_42); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _42 = (_37.0: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_43); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _43 = (_37.1: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_44); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_45); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _45 = _42; // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_46); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _46 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_52); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_53); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _53 = _46; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _52 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _53) -> bb6; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb6: { + StorageDead(_53); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_54); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_55); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _55 = _45; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _54 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _55) -> bb7; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb7: { + StorageDead(_55); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_44.0: &core::fmt::Opaque) = move _54; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_44.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _52; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_54); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_52); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_46); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_45); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_47); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_48); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _48 = _43; // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_49); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _49 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_56); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_57); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _57 = _49; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _56 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _57) -> bb8; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb8: { + StorageDead(_57); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_58); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_59); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _59 = _48; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _58 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _59) -> bb9; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb9: { + StorageDead(_59); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_47.0: &core::fmt::Opaque) = move _58; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_47.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _56; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_58); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_56); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_49); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_48); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _36 = [move _44, move _47]; // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_47); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_44); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_43); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_42); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _35 = &_36; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _34 = _35; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _33 = move _34 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_34); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_60); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _60 = _23; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_61); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + discriminant(_61) = 0; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_62); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _62 = _33; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.0: &[&str]) = move _60; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.1: std::option::Option<&[std::fmt::rt::v1::Argument]>) = move _61; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.2: &[std::fmt::ArgumentV1]) = move _62; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_62); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_61); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_60); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_33); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_23); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _21 = &_22; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _20 = _21; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + const std::rt::begin_panic_fmt(move _20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + // ty::Const + // + ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libstd/macros.rs:LL:COL + // + literal: Const { ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt}, val: Value(Scalar()) } + } + } + diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff new file mode 100644 index 0000000000000..887ebfc8c64e4 --- /dev/null +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff @@ -0,0 +1,249 @@ +- // MIR for `main` before PreCodegen ++ // MIR for `main` after PreCodegen + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 + let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _10: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _11: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _12: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _13: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _14: std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _15: &[&str]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _16: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _17: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _18: [std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _19: (&&i32, &&i32); // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _20: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _21: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _22: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _23: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _26: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _27: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 1 { + debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + scope 3 { + debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 4 { + debug left_val => _7; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug right_val => _8; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _24: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _25: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 5 { + debug arg0 => _24; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug arg1 => _25; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 6 { + debug x => _24; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _27; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _30: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _31: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + } + scope 8 { + debug x => _25; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _29; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _32: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _33: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + scope 10 { + debug pieces => _15; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug args => _16; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _34: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + } + } + scope 2 { + debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + } + scope 7 { + } + scope 9 { + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:2:28: 2:29 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } + discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &i32 + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _8 = (_5.1: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_9); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_11); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _11 = (*_7); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _12 = (*_8); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _10 = Eq(move _11, move _12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_12); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_11); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _9 = Not(move _10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_10); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + switchInt(_9) -> [false: bb1, otherwise: bb2]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + } + + bb1: { + StorageDead(_9); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:1:11: 9:2 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb2: { + StorageLive(_14); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &[&str; 3] + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_21); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _21 = _7; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _20 = &_21; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_22); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_23); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _23 = _8; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _22 = &_23; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_19.0: &&i32) = move _20; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + (_19.1: &&i32) = move _22; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_22); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _24 = (_19.0: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _25 = (_19.1: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_26); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _27 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_30); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _30 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _27) -> bb3; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb3: { + StorageLive(_31); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _31 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _24) -> bb4; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb4: { + (_26.0: &core::fmt::Opaque) = move _31; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_26.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _30; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_31); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_30); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_28); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _29 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_32); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _32 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _29) -> bb5; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb5: { + StorageLive(_33); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _33 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _25) -> bb6; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb6: { + (_28.0: &core::fmt::Opaque) = move _33; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_28.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _32; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_33); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_32); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _18 = [move _26, move _28]; // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_28); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_26); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _17 = &_18; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _16 = move _17 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_34); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + discriminant(_34) = 0; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.0: &[&str]) = move _15; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.1: std::option::Option<&[std::fmt::rt::v1::Argument]>) = move _34; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_14.2: &[std::fmt::ArgumentV1]) = move _16; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_34); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _13 = &_14; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + const std::rt::begin_panic_fmt(move _13); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + // ty::Const + // + ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libstd/macros.rs:LL:COL + // + literal: Const { ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt}, val: Value(Scalar()) } + } + } + diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff new file mode 100644 index 0000000000000..3233cc349f70d --- /dev/null +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff @@ -0,0 +1,377 @@ +- // MIR for `main` before SimplifyArmIdentity ++ // MIR for `main` after SimplifyArmIdentity + + fn main() -> () { + let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 + let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let mut _3: isize; // in scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + let _4: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _5: !; // in scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + let mut _7: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 + let _8: (); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _9: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _10: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _11: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _12: i32; // in scope 0 at $DIR/issue-73223.rs:8:23: 8:24 + let mut _15: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _16: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _17: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _18: i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _19: !; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _20: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _21: &std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _22: std::fmt::Arguments; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _23: &[&str]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _24: &[&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _25: &[&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _26: [&str; 3]; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _27: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _28: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _29: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _30: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _31: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _32: &str; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _33: &[std::fmt::ArgumentV1]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _34: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _35: &[std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let _36: [std::fmt::ArgumentV1; 2]; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _37: (&&i32, &&i32); // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _38: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _39: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _40: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _41: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _44: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _45: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _46: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _47: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _48: &&i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _49: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 1 { + debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _6: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + scope 3 { + debug _prev => _6; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + let _13: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _14: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _51: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 4 { + debug left_val => _13; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug right_val => _14; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _42: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let _43: &&i32; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + let mut _50: &[&str; 3]; // in scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 5 { + debug arg0 => _42; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + debug arg1 => _43; // in scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + scope 6 { + debug x => _45; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _46; // in scope 6 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _52: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _53: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _54: &core::fmt::Opaque; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _55: &&i32; // in scope 6 at $SRC_DIR/libstd/macros.rs:LL:COL + } + scope 8 { + debug x => _48; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug f => _49; // in scope 8 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _56: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _57: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _58: &core::fmt::Opaque; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _59: &&i32; // in scope 8 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + scope 10 { + debug pieces => _23; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + debug args => _33; // in scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + let mut _60: &[&str]; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _61: std::option::Option<&[std::fmt::rt::v1::Argument]>; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + let mut _62: &[std::fmt::ArgumentV1]; // in scope 10 at $SRC_DIR/libstd/macros.rs:LL:COL + } + } + } + } + scope 2 { + debug v => _4; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + } + scope 7 { + } + scope 9 { + } + + bb0: { + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 + StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + // ty::Const + // + ty: i32 + // + val: Value(Scalar(0x00000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:2:28: 2:29 + // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } + discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + // ty::Const + // + ty: isize + // + val: Value(Scalar(0x0000000000000001)) + // mir::Constant + // + span: $DIR/issue-73223.rs:3:9: 3:16 + // + literal: Const { ty: isize, val: Value(Scalar(0x0000000000000001)) } + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + } + + bb1: { + _0 = const (); // scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:4:17: 4:23 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/issue-73223.rs:4:17: 4:23 + } + + bb2: { +- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 +- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 +- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 +- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 ++ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 +- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 +- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 +- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 +- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 +- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _10 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_11); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &i32 + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_11); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_13); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _13 = (_9.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_14); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _14 = (_9.1: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_15); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_17); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _17 = (*_13); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _18 = (*_14); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _16 = Eq(move _17, move _18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_18); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_17); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _15 = Not(move _16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_16); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + switchInt(_15) -> [false: bb4, otherwise: bb5]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + } + + bb3: { + return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb4: { + _8 = const (); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_15); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_14); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_13); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _0 = const (); // scope 0 at $DIR/issue-73223.rs:1:11: 9:2 + // ty::Const + // + ty: () + // + val: Value(Scalar()) + // mir::Constant + // + span: $DIR/issue-73223.rs:1:11: 9:2 + // + literal: Const { ty: (), val: Value(Scalar()) } + StorageDead(_6); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + goto -> bb3; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 + } + + bb5: { + StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_21); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_22); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_23); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_24); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_25); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: &[&str; 3] + // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageDead(_24); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_33); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_34); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_35); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_36); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_37); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_38); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_39); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _39 = _13; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _38 = &_39; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_40); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_41); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _41 = _14; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _40 = &_41; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + (_37.0: &&i32) = move _38; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + (_37.1: &&i32) = move _40; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_40); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_38); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_42); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _42 = (_37.0: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_43); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _43 = (_37.1: &&i32); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_44); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_45); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _45 = _42; // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_46); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _46 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_52); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_53); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _53 = _46; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _52 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _53) -> bb6; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb6: { + StorageDead(_53); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_54); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_55); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _55 = _45; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _54 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _55) -> bb7; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb7: { + StorageDead(_55); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_44.0: &core::fmt::Opaque) = move _54; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_44.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _52; // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_54); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_52); // scope 7 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_46); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_45); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_47); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_48); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _48 = _43; // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + StorageLive(_49); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _49 = const <&i32 as std::fmt::Debug>::fmt as for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> (Pointer(ReifyFnPointer)); // scope 5 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + // ty::Const + // + ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL + // + literal: Const { ty: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {<&i32 as std::fmt::Debug>::fmt}, val: Value(Scalar()) } + StorageLive(_56); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_57); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _57 = _49; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _56 = const std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>(move _57) -> bb8; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) -> for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error> {std::intrinsics::transmute:: fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>, for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>>}, val: Value(Scalar()) } + } + + bb8: { + StorageDead(_57); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_58); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_59); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _59 = _48; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _58 = const std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>(move _59) -> bb9; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // ty::Const + // + ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libcore/fmt/mod.rs:LL:COL + // + literal: Const { ty: unsafe extern "rust-intrinsic" fn(&&i32) -> &core::fmt::Opaque {std::intrinsics::transmute::<&&i32, &core::fmt::Opaque>}, val: Value(Scalar()) } + } + + bb9: { + StorageDead(_59); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_47.0: &core::fmt::Opaque) = move _58; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_47.1: for<'r, 's, 't0> fn(&'r core::fmt::Opaque, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>) = move _56; // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_58); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_56); // scope 9 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_49); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_48); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + _36 = [move _44, move _47]; // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_47); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_44); // scope 5 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_43); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_42); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _35 = &_36; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _34 = _35; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _33 = move _34 as &[std::fmt::ArgumentV1] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_34); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageLive(_60); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _60 = _23; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_61); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + discriminant(_61) = 0; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageLive(_62); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + _62 = _33; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.0: &[&str]) = move _60; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.1: std::option::Option<&[std::fmt::rt::v1::Argument]>) = move _61; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + (_22.2: &[std::fmt::ArgumentV1]) = move _62; // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_62); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_61); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_60); // scope 10 at $SRC_DIR/libcore/fmt/mod.rs:LL:COL + StorageDead(_33); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + StorageDead(_23); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _21 = &_22; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + _20 = _21; // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + const std::rt::begin_panic_fmt(move _20); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL + // ty::Const + // + ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt} + // + val: Value(Scalar()) + // mir::Constant + // + span: $SRC_DIR/libstd/macros.rs:LL:COL + // + literal: Const { ty: for<'r, 's> fn(&'r std::fmt::Arguments<'s>) -> ! {std::rt::begin_panic_fmt}, val: Value(Scalar()) } + } + } + From 9248d90d20601e9d489a4a1c21df9de686b9fd82 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 20:55:06 -0400 Subject: [PATCH 22/31] [mir-opt] Prevent mis-optimization when SimplifyArmIdentity runs If temporaries are used beyond just the temporary chain, then we can't optimize out the reads and writes. --- src/librustc_mir/transform/simplify_try.rs | 51 ++++++++++++++++++- .../32bit/rustc.main.PreCodegen.diff | 37 +++++++------- .../32bit/rustc.main.SimplifyArmIdentity.diff | 19 ++++--- .../64bit/rustc.main.PreCodegen.diff | 37 +++++++------- .../64bit/rustc.main.SimplifyArmIdentity.diff | 19 ++++--- .../32bit/rustc.map.SimplifyLocals.diff | 4 +- .../64bit/rustc.map.SimplifyLocals.diff | 4 +- ...ustc.try_identity.SimplifyArmIdentity.diff | 48 +++++++++-------- ....try_identity.SimplifyBranchSame.after.mir | 34 +++++++++++-- ...ustc.try_identity.SimplifyLocals.after.mir | 36 +++++++++---- 10 files changed, 192 insertions(+), 97 deletions(-) diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 50136ac3becca..0abaa2175e141 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -12,6 +12,7 @@ use crate::transform::{simplify, MirPass, MirSource}; use itertools::Itertools as _; use rustc_index::vec::IndexVec; +use rustc_middle::mir::visit::{PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::{Ty, TyCtxt}; use rustc_target::abi::VariantIdx; @@ -75,7 +76,9 @@ struct ArmIdentityInfo<'tcx> { stmts_to_remove: Vec, } -fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option> { +fn get_arm_identity_info<'a, 'tcx>( + stmts: &'a [Statement<'tcx>], +) -> Option> { // This can't possibly match unless there are at least 3 statements in the block // so fail fast on tiny blocks. if stmts.len() < 3 { @@ -249,6 +252,7 @@ fn get_arm_identity_info<'a, 'tcx>(stmts: &'a [Statement<'tcx>]) -> Option( opt_info: &ArmIdentityInfo<'tcx>, local_decls: &IndexVec>, + local_uses: &IndexVec, ) -> bool { trace!("testing if optimization applies..."); @@ -285,6 +289,26 @@ fn optimization_applies<'tcx>( last_assigned_to = *l; } + // Check that the first and last used locals are only used twice + // since they are of the form: + // + // ``` + // _first = ((_x as Variant).n: ty); + // _n = _first; + // ... + // ((_y as Variant).n: ty) = _n; + // discriminant(_y) = z; + // ``` + for (l, r) in &opt_info.field_tmp_assignments { + if local_uses[*l] != 2 { + warn!("NO: FAILED assignment chain local {:?} was used more than twice", l); + return false; + } else if local_uses[*r] != 2 { + warn!("NO: FAILED assignment chain local {:?} was used more than twice", r); + return false; + } + } + if source_local != opt_info.local_temp_0 { trace!( "NO: start of assignment chain does not match enum variant temp: {:?} != {:?}", @@ -312,11 +336,12 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { } trace!("running SimplifyArmIdentity on {:?}", source); + let local_uses = LocalUseCounter::get_local_uses(body); let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); for bb in basic_blocks { if let Some(opt_info) = get_arm_identity_info(&bb.statements) { trace!("got opt_info = {:#?}", opt_info); - if !optimization_applies(&opt_info, local_decls) { + if !optimization_applies(&opt_info, local_decls, &local_uses) { debug!("optimization skipped for {:?}", source); continue; } @@ -358,6 +383,28 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { } } +struct LocalUseCounter { + local_uses: IndexVec, +} + +impl LocalUseCounter { + fn get_local_uses<'tcx>(body: &Body<'tcx>) -> IndexVec { + let mut counter = LocalUseCounter { local_uses: IndexVec::from_elem(0, &body.local_decls) }; + counter.visit_body(body); + counter.local_uses + } +} + +impl<'tcx> Visitor<'tcx> for LocalUseCounter { + fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { + if context.is_storage_marker() { + return; + } + + self.local_uses[*local] += 1; + } +} + /// Match on: /// ```rust /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff index 887ebfc8c64e4..59c00e1b96f96 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff @@ -3,9 +3,9 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 - let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _1: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _2: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _4: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -28,10 +28,10 @@ let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 1 { - debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 - let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + debug split => _2; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _3: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 scope 3 { - debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + debug _prev => _3; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 4 { @@ -64,7 +64,7 @@ } } scope 2 { - debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + debug v => _2; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } scope 7 { } @@ -72,22 +72,26 @@ } bb0: { - StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_1 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/issue-73223.rs:2:28: 2:29 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } - discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 - StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 - StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + discriminant(_1) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _2 = ((_1 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_3); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _4 = _2; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_3 as Some).0: i32) = move _4; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_3) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL - _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_2; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const @@ -127,8 +131,7 @@ // mir::Constant // + span: $DIR/issue-73223.rs:1:11: 9:2 // + literal: Const { ty: (), val: Value(Scalar()) } - StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 - StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_3); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 } diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff index 2c1f81f2d732d..e5b4a0328808f 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff @@ -134,18 +134,17 @@ } bb2: { -- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 -- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 -+ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 + StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 -- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff index 887ebfc8c64e4..59c00e1b96f96 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff @@ -3,9 +3,9 @@ fn main() -> () { let mut _0: (); // return place in scope 0 at $DIR/issue-73223.rs:1:11: 1:11 - let _1: i32; // in scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - let mut _2: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - let _3: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _1: std::option::Option; // in scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + let _2: i32; // in scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + let mut _4: i32; // in scope 0 at $DIR/issue-73223.rs:7:22: 7:27 let mut _5: (&i32, &i32); // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _6: &i32; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let mut _9: bool; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -28,10 +28,10 @@ let mut _28: std::fmt::ArgumentV1; // in scope 0 at $SRC_DIR/libstd/macros.rs:LL:COL let mut _29: for<'r, 's, 't0> fn(&'r &i32, &'s mut std::fmt::Formatter<'t0>) -> std::result::Result<(), std::fmt::Error>; // in scope 0 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 1 { - debug split => _1; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 - let _4: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + debug split => _2; // in scope 1 at $DIR/issue-73223.rs:2:9: 2:14 + let _3: std::option::Option; // in scope 1 at $DIR/issue-73223.rs:7:9: 7:14 scope 3 { - debug _prev => _4; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 + debug _prev => _3; // in scope 3 at $DIR/issue-73223.rs:7:9: 7:14 let _7: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL let _8: &i32; // in scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL scope 4 { @@ -64,7 +64,7 @@ } } scope 2 { - debug v => _3; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 + debug v => _2; // in scope 2 at $DIR/issue-73223.rs:3:14: 3:15 } scope 7 { } @@ -72,22 +72,26 @@ } bb0: { - StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:9: 2:14 - StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + StorageLive(_1); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + ((_1 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 // ty::Const // + ty: i32 // + val: Value(Scalar(0x00000001)) // mir::Constant // + span: $DIR/issue-73223.rs:2:28: 2:29 // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } - discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _4 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 - StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 - StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + discriminant(_1) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + _2 = ((_1 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 + StorageLive(_3); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 + StorageLive(_4); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _4 = _2; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_3 as Some).0: i32) = move _4; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_3) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_5); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL - _6 = &_1; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL + _6 = &_2; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.0: &i32) = move _6; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const @@ -127,8 +131,7 @@ // mir::Constant // + span: $DIR/issue-73223.rs:1:11: 9:2 // + literal: Const { ty: (), val: Value(Scalar()) } - StorageDead(_4); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 - StorageDead(_1); // scope 0 at $DIR/issue-73223.rs:9:1: 9:2 + StorageDead(_3); // scope 1 at $DIR/issue-73223.rs:9:1: 9:2 return; // scope 0 at $DIR/issue-73223.rs:9:2: 9:2 } diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff index 3233cc349f70d..0c2651dc3c68d 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff @@ -134,18 +134,17 @@ } bb2: { -- StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 -- _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 -- StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 -+ _6 = move _2; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageLive(_4); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _4 = ((_2 as Some).0: i32); // scope 0 at $DIR/issue-73223.rs:3:14: 3:15 + _1 = _4; // scope 2 at $DIR/issue-73223.rs:3:20: 3:21 + StorageDead(_4); // scope 0 at $DIR/issue-73223.rs:3:21: 3:22 StorageDead(_2); // scope 0 at $DIR/issue-73223.rs:5:6: 5:7 StorageLive(_6); // scope 1 at $DIR/issue-73223.rs:7:9: 7:14 -- StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 -- ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 -- StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 + StorageLive(_7); // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + _7 = _1; // scope 1 at $DIR/issue-73223.rs:7:22: 7:27 + ((_6 as Some).0: i32) = move _7; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + discriminant(_6) = 1; // scope 1 at $DIR/issue-73223.rs:7:17: 7:28 + StorageDead(_7); // scope 1 at $DIR/issue-73223.rs:7:27: 7:28 StorageLive(_8); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_9); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_10); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff index f0b696118e996..318b1b3f72a08 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff @@ -19,7 +19,9 @@ } bb1: { - _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff index 1ac6eb85441f5..ace471aaa3c82 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff @@ -19,7 +19,9 @@ } bb1: { - _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 7f8366309c089..2caff43bfb582 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -50,37 +50,35 @@ } bb1: { -- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 -- _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 -- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 + StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 -- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 -- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 -- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 + StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { -- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL -- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL -- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 -- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 -+ _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir index be61e5e2a9fff..5000a1ec36cc8 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir @@ -45,17 +45,45 @@ fn try_identity(_1: std::result::Result) -> std::result::Result bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 } bb1: { - _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 + StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 + StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 + ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { + StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 + StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index b12036f6a03e4..77804c12691ee 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -3,27 +3,25 @@ fn try_identity(_1: std::result::Result) -> std::result::Result { debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let _2: u32; // in scope 0 at $DIR/simplify_try.rs:6:9: 6:10 + let mut _2: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 let _3: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _4: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let mut _5: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _6: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + let _4: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => _4; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { debug err => _3; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _5; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => _3; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _4; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => _3; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL } } } scope 4 { - debug val => _6; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => _4; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -32,9 +30,25 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb1: { + _4 = ((_1 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 + ((_0 as Ok).0: u32) = move _4; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + } + + bb2: { + _3 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + ((_0 as Err).0: i32) = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + } + + bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } From 24bfdc98e9f02ff7974328f92a0e7ef67eab5f46 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 19:34:54 -0400 Subject: [PATCH 23/31] Fix debuginfo so that it points to the correct local --- src/librustc_middle/mir/mod.rs | 12 ++++ src/librustc_mir/transform/simplify_try.rs | 69 ++++++++++++++++--- .../32bit/rustc.map.SimplifyLocals.diff | 8 +-- .../64bit/rustc.map.SimplifyLocals.diff | 8 +-- ...ustc.try_identity.SimplifyArmIdentity.diff | 63 +++++++++-------- ....try_identity.SimplifyBranchSame.after.mir | 44 +++--------- ...ustc.try_identity.SimplifyLocals.after.mir | 33 ++------- 7 files changed, 126 insertions(+), 111 deletions(-) diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index ae59f8c542d8c..a10d6c86ad537 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -256,6 +256,18 @@ impl<'tcx> Body<'tcx> { (&mut self.basic_blocks, &mut self.local_decls) } + #[inline] + pub fn basic_blocks_local_decls_mut_and_var_debug_info( + &mut self, + ) -> ( + &mut IndexVec>, + &mut LocalDecls<'tcx>, + &mut Vec>, + ) { + self.predecessor_cache.invalidate(); + (&mut self.basic_blocks, &mut self.local_decls, &mut self.var_debug_info) + } + /// Returns `true` if a cycle exists in the control-flow graph that is reachable from the /// `START_BLOCK`. pub fn is_cfg_cyclic(&self) -> bool { diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 0abaa2175e141..778d19a3da44f 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -11,10 +11,10 @@ use crate::transform::{simplify, MirPass, MirSource}; use itertools::Itertools as _; -use rustc_index::vec::IndexVec; -use rustc_middle::mir::visit::{PlaceContext, Visitor}; +use rustc_index::{bit_set::BitSet, vec::IndexVec}; +use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; -use rustc_middle::ty::{Ty, TyCtxt}; +use rustc_middle::ty::{List, Ty, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter::{Enumerate, Peekable}; use std::slice::Iter; @@ -74,10 +74,19 @@ struct ArmIdentityInfo<'tcx> { /// The statements that should be removed (turned into nops) stmts_to_remove: Vec, + + /// Indices of debug variables that need to be adjusted to point to + // `{local_0}.{dbg_projection}`. + dbg_info_to_adjust: Vec, + + /// The projection used to rewrite debug info. + dbg_projection: &'tcx List>, } fn get_arm_identity_info<'a, 'tcx>( stmts: &'a [Statement<'tcx>], + locals_count: usize, + debug_info: &'a [VarDebugInfo<'tcx>], ) -> Option> { // This can't possibly match unless there are at least 3 statements in the block // so fail fast on tiny blocks. @@ -190,7 +199,7 @@ fn get_arm_identity_info<'a, 'tcx>( try_eat_storage_stmts(&mut stmt_iter, &mut storage_live_stmts, &mut storage_dead_stmts); let (get_variant_field_stmt, stmt) = stmt_iter.next()?; - let (local_tmp_s0, local_1, vf_s0) = match_get_variant_field(stmt)?; + let (local_tmp_s0, local_1, vf_s0, dbg_projection) = match_get_variant_field(stmt)?; try_eat_storage_stmts(&mut stmt_iter, &mut storage_live_stmts, &mut storage_dead_stmts); @@ -231,6 +240,19 @@ fn get_arm_identity_info<'a, 'tcx>( let stmt_to_overwrite = nop_stmts.iter().find(|stmt_idx| live_idx < **stmt_idx && **stmt_idx < dead_idx); + let mut tmp_assigned_vars = BitSet::new_empty(locals_count); + for (l, r) in &tmp_assigns { + tmp_assigned_vars.insert(*l); + tmp_assigned_vars.insert(*r); + } + + let mut dbg_info_to_adjust = Vec::new(); + for (i, var_info) in debug_info.iter().enumerate() { + if tmp_assigned_vars.contains(var_info.place.local) { + dbg_info_to_adjust.push(i); + } + } + Some(ArmIdentityInfo { local_temp_0: local_tmp_s0, local_1, @@ -246,6 +268,8 @@ fn get_arm_identity_info<'a, 'tcx>( source_info: discr_stmt_source_info, storage_stmts, stmts_to_remove: nop_stmts, + dbg_info_to_adjust, + dbg_projection, }) } @@ -253,6 +277,7 @@ fn optimization_applies<'tcx>( opt_info: &ArmIdentityInfo<'tcx>, local_decls: &IndexVec>, local_uses: &IndexVec, + var_debug_info: &[VarDebugInfo<'tcx>], ) -> bool { trace!("testing if optimization applies..."); @@ -309,6 +334,15 @@ fn optimization_applies<'tcx>( } } + // Check that debug info only points to full Locals and not projections. + for dbg_idx in &opt_info.dbg_info_to_adjust { + let dbg_info = &var_debug_info[*dbg_idx]; + if !dbg_info.place.projection.is_empty() { + trace!("NO: debug info for {:?} had a projection {:?}", dbg_info.name, dbg_info.place); + return false; + } + } + if source_local != opt_info.local_temp_0 { trace!( "NO: start of assignment chain does not match enum variant temp: {:?} != {:?}", @@ -337,11 +371,14 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { trace!("running SimplifyArmIdentity on {:?}", source); let local_uses = LocalUseCounter::get_local_uses(body); - let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut(); + let (basic_blocks, local_decls, debug_info) = + body.basic_blocks_local_decls_mut_and_var_debug_info(); for bb in basic_blocks { - if let Some(opt_info) = get_arm_identity_info(&bb.statements) { + if let Some(opt_info) = + get_arm_identity_info(&bb.statements, local_decls.len(), debug_info) + { trace!("got opt_info = {:#?}", opt_info); - if !optimization_applies(&opt_info, local_decls, &local_uses) { + if !optimization_applies(&opt_info, local_decls, &local_uses, &debug_info) { debug!("optimization skipped for {:?}", source); continue; } @@ -377,6 +414,14 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { bb.statements.retain(|stmt| stmt.kind != StatementKind::Nop); + // Fix the debug info to point to the right local + for dbg_index in opt_info.dbg_info_to_adjust { + let dbg_info = &mut debug_info[dbg_index]; + assert!(dbg_info.place.projection.is_empty()); + dbg_info.place.local = opt_info.local_0; + dbg_info.place.projection = opt_info.dbg_projection; + } + trace!("block is now {:?}", bb.statements); } } @@ -397,7 +442,9 @@ impl LocalUseCounter { impl<'tcx> Visitor<'tcx> for LocalUseCounter { fn visit_local(&mut self, local: &Local, context: PlaceContext, _location: Location) { - if context.is_storage_marker() { + if context.is_storage_marker() + || context == PlaceContext::NonUse(NonUseContext::VarDebugInfo) + { return; } @@ -409,13 +456,15 @@ impl<'tcx> Visitor<'tcx> for LocalUseCounter { /// ```rust /// _LOCAL_INTO = ((_LOCAL_FROM as Variant).FIELD: TY); /// ``` -fn match_get_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { +fn match_get_variant_field<'tcx>( + stmt: &Statement<'tcx>, +) -> Option<(Local, Local, VarField<'tcx>, &'tcx List>)> { match &stmt.kind { StatementKind::Assign(box (place_into, rvalue_from)) => match rvalue_from { Rvalue::Use(Operand::Copy(pf) | Operand::Move(pf)) => { let local_into = place_into.as_local()?; let (local_from, vf) = match_variant_field_place(*pf)?; - Some((local_into, local_from, vf)) + Some((local_into, local_from, vf, pf.projection)) } _ => None, }, diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff index 318b1b3f72a08..551f6db08a599 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/32bit/rustc.map.SimplifyLocals.diff @@ -5,12 +5,12 @@ debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9 let mut _0: std::option::Option>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46 let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 +- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26 - let mut _5: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 - let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 scope 1 { - debug x => _3; // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 } bb0: { @@ -19,9 +19,7 @@ } bb1: { - _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 - discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff index ace471aaa3c82..388b382b86daf 100644 --- a/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify-locals-removes-unused-discriminant-reads/64bit/rustc.map.SimplifyLocals.diff @@ -5,12 +5,12 @@ debug x => _1; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:8: 1:9 let mut _0: std::option::Option>; // return place in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:1:31: 1:46 let mut _2: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:3:9: 3:13 - let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 +- let _3: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - let mut _4: std::boxed::Box<()>; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:25: 4:26 - let mut _5: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 - let mut _6: isize; // in scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:1: 6:2 scope 1 { - debug x => _3; // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 + debug x => ((_0 as Some).0: std::boxed::Box<()>); // in scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 } bb0: { @@ -19,9 +19,7 @@ } bb1: { - _3 = move ((_1 as Some).0: std::boxed::Box<()>); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:14: 4:15 - ((_0 as Some).0: std::boxed::Box<()>) = move _3; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 - discriminant(_0) = 1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 + _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:20: 4:27 goto -> bb3; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:2:5: 5:6 } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff index 2caff43bfb582..e6d794a71508c 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyArmIdentity.diff @@ -15,22 +15,27 @@ let _10: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 let mut _11: u32; // in scope 0 at $DIR/simplify_try.rs:7:8: 7:9 scope 1 { - debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 +- debug y => _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 ++ debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 +- debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 ++ debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL +- debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL ++ debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL ++ debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 +- debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 ++ debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -50,35 +55,37 @@ } bb1: { - StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 - StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 +- _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 +- _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 +- StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 +- StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 +- _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 +- ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 +- discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 +- StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL - StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL +- StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL +- StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 +- StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 ++ _0 = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir index 5000a1ec36cc8..24bde51c7d3bb 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyBranchSame.after.mir @@ -14,22 +14,22 @@ fn try_identity(_1: std::result::Result) -> std::result::Result _2; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _6; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _9; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _8; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL let mut _12: i32; // in scope 8 at $DIR/simplify_try.rs:6:14: 6:15 } } } scope 4 { - debug val => _10; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -45,45 +45,17 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 } bb1: { - StorageLive(_10); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _10 = ((_3 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - _2 = _10; // scope 5 at $DIR/simplify_try.rs:6:13: 6:15 - StorageDead(_10); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 + _0 = move _3; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageLive(_11); // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - _11 = _2; // scope 1 at $DIR/simplify_try.rs:7:8: 7:9 - ((_0 as Ok).0: u32) = move _11; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - StorageDead(_11); // scope 1 at $DIR/simplify_try.rs:7:9: 7:10 StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 + goto -> bb2; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } bb2: { - StorageLive(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - _6 = ((_3 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _9 = _6; // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - _8 = move _9; // scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL - StorageDead(_9); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageLive(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - _12 = move _8; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - ((_0 as Err).0: i32) = move _12; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_12); // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - StorageDead(_8); // scope 3 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_6); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - StorageDead(_3); // scope 0 at $DIR/simplify_try.rs:6:15: 6:16 - StorageDead(_2); // scope 0 at $DIR/simplify_try.rs:8:1: 8:2 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb3: { return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } diff --git a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir index 77804c12691ee..929f04d4654ad 100644 --- a/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir +++ b/src/test/mir-opt/simplify_try/rustc.try_identity.SimplifyLocals.after.mir @@ -3,25 +3,22 @@ fn try_identity(_1: std::result::Result) -> std::result::Result { debug x => _1; // in scope 0 at $DIR/simplify_try.rs:5:17: 5:18 let mut _0: std::result::Result; // return place in scope 0 at $DIR/simplify_try.rs:5:41: 5:57 - let mut _2: isize; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _3: i32; // in scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - let _4: u32; // in scope 0 at $DIR/simplify_try.rs:6:13: 6:15 scope 1 { - debug y => _4; // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 + debug y => ((_0 as Ok).0: u32); // in scope 1 at $DIR/simplify_try.rs:6:9: 6:10 } scope 2 { - debug err => _3; // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 + debug err => ((_0 as Err).0: i32); // in scope 2 at $DIR/simplify_try.rs:6:14: 6:15 scope 3 { scope 7 { - debug t => _3; // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL + debug t => ((_0 as Err).0: i32); // in scope 7 at $SRC_DIR/libcore/convert/mod.rs:LL:COL } scope 8 { - debug v => _3; // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL + debug v => ((_0 as Err).0: i32); // in scope 8 at $SRC_DIR/libcore/result.rs:LL:COL } } } scope 4 { - debug val => _4; // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 + debug val => ((_0 as Ok).0: u32); // in scope 4 at $DIR/simplify_try.rs:6:13: 6:15 scope 5 { } } @@ -30,25 +27,7 @@ fn try_identity(_1: std::result::Result) -> std::result::Result [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb1: { - _4 = ((_1 as Ok).0: u32); // scope 0 at $DIR/simplify_try.rs:6:13: 6:15 - ((_0 as Ok).0: u32) = move _4; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - discriminant(_0) = 0; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 - } - - bb2: { - _3 = ((_1 as Err).0: i32); // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - ((_0 as Err).0: i32) = move _3; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - discriminant(_0) = 1; // scope 8 at $SRC_DIR/libcore/result.rs:LL:COL - goto -> bb3; // scope 0 at $DIR/simplify_try.rs:6:14: 6:15 - } - - bb3: { + _0 = move _1; // scope 1 at $DIR/simplify_try.rs:7:5: 7:10 return; // scope 0 at $DIR/simplify_try.rs:8:2: 8:2 } } From e16d6a6c6465d19c6d7091e5b59eb4b4528aa9f8 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Sun, 21 Jun 2020 19:35:16 -0400 Subject: [PATCH 24/31] Fix missing return in `optimization_applies()` --- src/librustc_mir/transform/simplify_try.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 778d19a3da44f..97a01de867e1d 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -302,6 +302,7 @@ fn optimization_applies<'tcx>( // Verify the assigment chain consists of the form b = a; c = b; d = c; etc... if opt_info.field_tmp_assignments.is_empty() { trace!("NO: no assignments found"); + return false; } let mut last_assigned_to = opt_info.field_tmp_assignments[0].1; let source_local = last_assigned_to; From df43dcd7d4c972f63a51a9fedfa06cd17ffc6479 Mon Sep 17 00:00:00 2001 From: Valentin Date: Fri, 3 Jul 2020 11:42:12 +0200 Subject: [PATCH 25/31] Fix "getting started" link The previous link is 404. --- CONTRIBUTING.md | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 373604adb0541..aad495fa3fae6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,5 +4,5 @@ Thank you for your interest in contributing to Rust! To get started, read the [Getting Started] guide in the [rustc-dev-guide]. -[Getting Started]: https://rustc-dev-guide.rust-lang.org/getting-started.md +[Getting Started]: https://rustc-dev-guide.rust-lang.org/getting-started.html [rustc-dev-guide]: https://rustc-dev-guide.rust-lang.org/ diff --git a/README.md b/README.md index 70d3d51ce9b23..639789123d832 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ The Rust build system uses a Python script called `x.py` to build the compiler, which manages the bootstrapping process. More information about it can be found by running `./x.py --help` or reading the [rustc dev guide][rustcguidebuild]. -[gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.md +[gettingstarted]: https://rustc-dev-guide.rust-lang.org/getting-started.html [rustcguidebuild]: https://rustc-dev-guide.rust-lang.org/building/how-to-build-and-run.html ### Building on a Unix-like system From 3ed320e87c150eea999a32b615885c408065777e Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 3 Jul 2020 17:21:20 +0200 Subject: [PATCH 26/31] fix typo --- src/libcore/marker.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 6040dd31847a9..fdcfae8530a3b 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -694,7 +694,7 @@ mod impls { )] #[lang = "discriminant_kind"] pub trait DiscriminantKind { - /// The type of the dicriminant, which must satisfy the trait + /// The type of the discriminant, which must satisfy the trait /// bounds required by `mem::Discriminant`. type Discriminant: Clone + Copy + Debug + Eq + PartialEq + Hash + Send + Sync + Unpin; } From 3bb6dc7628c0c8f355aaaf39e79f2b160c8d182c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Fri, 3 Jul 2020 18:27:46 +0300 Subject: [PATCH 27/31] Bump mingw-check CI image from Ubuntu 16.04 to 18.04. --- src/ci/docker/mingw-check/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/mingw-check/Dockerfile b/src/ci/docker/mingw-check/Dockerfile index 97e4d3fd7499e..21ec8bbe4b1ec 100644 --- a/src/ci/docker/mingw-check/Dockerfile +++ b/src/ci/docker/mingw-check/Dockerfile @@ -1,4 +1,4 @@ -FROM ubuntu:16.04 +FROM ubuntu:18.04 RUN apt-get update && apt-get install -y --no-install-recommends \ g++ \ From 93d662fd9d0e39145ac45fc08f35a619e0cb3f8c Mon Sep 17 00:00:00 2001 From: David Hewitt <1939362+davidhewitt@users.noreply.github.com> Date: Fri, 3 Jul 2020 18:17:53 +0100 Subject: [PATCH 28/31] Ignore test with panic on wasm targets --- src/test/ui/fmt/format-args-capture.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/ui/fmt/format-args-capture.rs b/src/test/ui/fmt/format-args-capture.rs index 89dcfd8300435..7490632110c85 100644 --- a/src/test/ui/fmt/format-args-capture.rs +++ b/src/test/ui/fmt/format-args-capture.rs @@ -1,4 +1,6 @@ // run-pass +// ignore-wasm32 +// ignore-wasm64 #![feature(format_args_capture)] fn main() { From 20caf634bd3c9783a7822e86811a7e77a88d378f Mon Sep 17 00:00:00 2001 From: pierwill Date: Tue, 30 Jun 2020 15:16:18 -0700 Subject: [PATCH 29/31] Edit docs for rustc_data_structures::graph::scc - Add newline to provide concise module summary - Add wikipedia link - Italicize O notation --- src/librustc_data_structures/graph/scc/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/librustc_data_structures/graph/scc/mod.rs b/src/librustc_data_structures/graph/scc/mod.rs index 57eaf56f268f8..2db8e466e1144 100644 --- a/src/librustc_data_structures/graph/scc/mod.rs +++ b/src/librustc_data_structures/graph/scc/mod.rs @@ -1,7 +1,9 @@ -//! Routine to compute the strongly connected components (SCCs) of a -//! graph, as well as the resulting DAG if each SCC is replaced with a -//! node in the graph. This uses Tarjan's algorithm that completes in -//! O(n) time. +//! Routine to compute the strongly connected components (SCCs) of a graph. +//! +//! Also computes as the resulting DAG if each SCC is replaced with a +//! node in the graph. This uses [Tarjan's algorithm]( +//! https://en.wikipedia.org/wiki/Tarjan%27s_strongly_connected_components_algorithm) +//! that completes in *O(n)* time. use crate::fx::FxHashSet; use crate::graph::vec_graph::VecGraph; From d64a4b57aef5e1f0a51bbae24b73e5a7acd20aef Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 Jul 2020 00:12:16 +0200 Subject: [PATCH 30/31] Create new E0768 error code for "no valid digits found for number" error --- src/librustc_error_codes/error_codes.rs | 1 + src/librustc_error_codes/error_codes/E0768.md | 13 +++++++++++++ src/librustc_parse/lexer/mod.rs | 9 ++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/librustc_error_codes/error_codes/E0768.md diff --git a/src/librustc_error_codes/error_codes.rs b/src/librustc_error_codes/error_codes.rs index 00c072e1b04a1..f687221d78e03 100644 --- a/src/librustc_error_codes/error_codes.rs +++ b/src/librustc_error_codes/error_codes.rs @@ -449,6 +449,7 @@ E0764: include_str!("./error_codes/E0764.md"), E0765: include_str!("./error_codes/E0765.md"), E0766: include_str!("./error_codes/E0766.md"), E0767: include_str!("./error_codes/E0767.md"), +E0768: include_str!("./error_codes/E0768.md"), ; // E0006, // merged with E0005 // E0008, // cannot bind by-move into a pattern guard diff --git a/src/librustc_error_codes/error_codes/E0768.md b/src/librustc_error_codes/error_codes/E0768.md new file mode 100644 index 0000000000000..24169ef512efb --- /dev/null +++ b/src/librustc_error_codes/error_codes/E0768.md @@ -0,0 +1,13 @@ +A number in a non-decimal base has no digits. + +Erroneous code example: + +```compile_fail,E0768 +let s: i32 = 0b; // error! +``` + +To fix this error, add the missing digits: + +``` +let s: i32 = 0b1; // ok! +``` diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 5050f03bea9b2..2b0e637c74e5a 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -391,7 +391,14 @@ impl<'a> StringReader<'a> { } rustc_lexer::LiteralKind::Int { base, empty_int } => { return if empty_int { - self.err_span_(start, suffix_start, "no valid digits found for number"); + self.sess + .span_diagnostic + .struct_span_err_with_code( + self.mk_sp(start, suffix_start), + "no valid digits found for number", + error_code!(E0768), + ) + .emit(); (token::Integer, sym::integer(0)) } else { self.validate_int_literal(base, start, suffix_start); From 6970c923d3c3dd4c174b621b45f0836600f1e4cd Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 4 Jul 2020 00:15:08 +0200 Subject: [PATCH 31/31] Update UI tests --- src/test/ui/parser/issue-1802-1.stderr | 3 ++- src/test/ui/parser/issue-1802-2.stderr | 3 ++- src/test/ui/parser/lex-bad-numeric-literals.stderr | 13 +++++++------ 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/test/ui/parser/issue-1802-1.stderr b/src/test/ui/parser/issue-1802-1.stderr index b7d003df56b71..954cc0beeef3e 100644 --- a/src/test/ui/parser/issue-1802-1.stderr +++ b/src/test/ui/parser/issue-1802-1.stderr @@ -1,4 +1,4 @@ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/issue-1802-1.rs:5:16 | LL | log(error, 0b); @@ -6,3 +6,4 @@ LL | log(error, 0b); error: aborting due to previous error +For more information about this error, try `rustc --explain E0768`. diff --git a/src/test/ui/parser/issue-1802-2.stderr b/src/test/ui/parser/issue-1802-2.stderr index 8491dd07cb788..49043d07b35eb 100644 --- a/src/test/ui/parser/issue-1802-2.stderr +++ b/src/test/ui/parser/issue-1802-2.stderr @@ -1,4 +1,4 @@ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/issue-1802-2.rs:5:16 | LL | log(error, 0b); @@ -6,3 +6,4 @@ LL | log(error, 0b); error: aborting due to previous error +For more information about this error, try `rustc --explain E0768`. diff --git a/src/test/ui/parser/lex-bad-numeric-literals.stderr b/src/test/ui/parser/lex-bad-numeric-literals.stderr index 151480dd012a3..f05d61603023c 100644 --- a/src/test/ui/parser/lex-bad-numeric-literals.stderr +++ b/src/test/ui/parser/lex-bad-numeric-literals.stderr @@ -46,7 +46,7 @@ error: hexadecimal float literal is not supported LL | 0x9.0e-9; | ^^^^^^^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:11:5 | LL | 0o; @@ -64,31 +64,31 @@ error: hexadecimal float literal is not supported LL | 0x539.0; | ^^^^^^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:18:5 | LL | 0x; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:19:5 | LL | 0xu32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:20:5 | LL | 0ou32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:21:5 | LL | 0bu32; | ^^ -error: no valid digits found for number +error[E0768]: no valid digits found for number --> $DIR/lex-bad-numeric-literals.rs:22:5 | LL | 0b; @@ -138,3 +138,4 @@ LL | 0b101f64; error: aborting due to 23 previous errors +For more information about this error, try `rustc --explain E0768`.