diff --git a/.gitmodules b/.gitmodules index 2eae52b2eac54..a327aaa8d5a34 100644 --- a/.gitmodules +++ b/.gitmodules @@ -44,3 +44,6 @@ [submodule "src/tools/rust-analyzer"] path = src/tools/rust-analyzer url = https://github.com/rust-analyzer/rust-analyzer.git +[submodule "library/backtrace"] + path = library/backtrace + url = https://github.com/rust-lang/backtrace-rs.git diff --git a/Cargo.lock b/Cargo.lock index 42f749ca90c51..7e90b7e6fba1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,10 +1,26 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "adler32" -version = "1.0.3" +name = "addr2line" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" +checksum = "1b6a2d3371669ab3ca9797670853d61402b03d0b4b9ebf33d677dfa720203072" +dependencies = [ + "compiler_builtins", + "gimli", + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", +] + +[[package]] +name = "adler" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-core", +] [[package]] name = "aho-corasick" @@ -45,7 +61,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7021ce4924a3f25f802b2cccd1af585e39ea1a363a1aa2e72afe54b67a3a7a7" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", ] [[package]] @@ -63,6 +79,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.8", +] + [[package]] name = "anyhow" version = "1.0.31" @@ -125,28 +150,14 @@ checksum = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d" [[package]] name = "backtrace" -version = "0.3.46" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1e692897359247cc6bb902933361652380af0f1b7651ae5c5013407f30e109e" +version = "0.3.50" dependencies = [ - "backtrace-sys", + "addr2line", "cfg-if", - "compiler_builtins", "libc", + "miniz_oxide", + "object", "rustc-demangle", - "rustc-std-workspace-core", -] - -[[package]] -name = "backtrace-sys" -version = "0.1.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fbebbe1c9d1f383a9cc7e8ccdb471b91c8d024ee9c2ca5b5346121fe8b4399" -dependencies = [ - "cc", - "compiler_builtins", - "libc", - "rustc-std-workspace-core", ] [[package]] @@ -494,7 +505,7 @@ version = "2.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "atty", "bitflags", "strsim", @@ -614,12 +625,12 @@ dependencies = [ "glob", "lazy_static", "libc", - "log", "miow 0.3.3", "regex", "rustfix", "serde", "serde_json", + "tracing", "walkdir", "winapi 0.3.8", ] @@ -689,9 +700,9 @@ dependencies = [ [[package]] name = "crc32fast" -version = "1.1.2" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91d5240c6975ef33aeb5f148f35275c25eda8e8a5f95abe421978b05b8bf192" +checksum = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" dependencies = [ "cfg-if", ] @@ -1024,9 +1035,9 @@ checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d" [[package]] name = "flate2" -version = "1.0.12" +version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3" +checksum = "68c90b0fc46cf89d227cc78b40e494ff81287a92dd07631e5af0d06fe3cf885e" dependencies = [ "cfg-if", "crc32fast", @@ -1160,6 +1171,17 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", +] + [[package]] name = "git2" version = "0.13.5" @@ -1728,6 +1750,15 @@ dependencies = [ "tendril", ] +[[package]] +name = "matchers" +version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" +dependencies = [ + "regex-automata", +] + [[package]] name = "matches" version = "0.1.8" @@ -1820,11 +1851,14 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.3.5" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f3f74f726ae935c3f514300cc6773a0c9492abc5e972d42ba0c0ebb88757625" +checksum = "be0f75932c1f6cfae3c04000e40114adf955636e19040f9c0a2c380702aa1c7f" dependencies = [ - "adler32", + "adler", + "compiler_builtins", + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", ] [[package]] @@ -1956,6 +1990,17 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab52be62400ca80aa00285d25253d7f7c437b7375c4de678f5405d3afe82ca5" +dependencies = [ + "compiler_builtins", + "rustc-std-workspace-alloc", + "rustc-std-workspace-core", +] + [[package]] name = "once_cell" version = "1.1.0" @@ -2287,7 +2332,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" dependencies = [ - "ansi_term", + "ansi_term 0.11.0", "ctor", "difference", "output_vt100", @@ -2651,6 +2696,16 @@ dependencies = [ "thread_local", ] +[[package]] +name = "regex-automata" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4" +dependencies = [ + "byteorder", + "regex-syntax", +] + [[package]] name = "regex-syntax" version = "0.6.17" @@ -3201,7 +3256,6 @@ name = "rustc_ast" version = "0.0.0" dependencies = [ "bitflags", - "log", "rustc_data_structures", "rustc_index", "rustc_lexer", @@ -3210,13 +3264,13 @@ dependencies = [ "rustc_span", "scoped-tls", "smallvec 1.4.0", + "tracing", ] [[package]] name = "rustc_ast_lowering" version = "0.0.0" dependencies = [ - "log", "rustc_arena", "rustc_ast", "rustc_ast_pretty", @@ -3228,6 +3282,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3235,7 +3290,6 @@ name = "rustc_ast_passes" version = "0.0.0" dependencies = [ "itertools 0.8.0", - "log", "rustc_ast", "rustc_ast_pretty", "rustc_attr", @@ -3245,16 +3299,17 @@ dependencies = [ "rustc_parse", "rustc_session", "rustc_span", + "tracing", ] [[package]] name = "rustc_ast_pretty" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_span", "rustc_target", + "tracing", ] [[package]] @@ -3277,7 +3332,6 @@ dependencies = [ name = "rustc_builtin_macros" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_ast_pretty", "rustc_attr", @@ -3291,6 +3345,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3300,7 +3355,6 @@ dependencies = [ "bitflags", "flate2", "libc", - "log", "measureme", "rustc-demangle", "rustc_ast", @@ -3320,6 +3374,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3330,7 +3385,6 @@ dependencies = [ "cc", "jobserver", "libc", - "log", "memmap", "num_cpus", "pathdiff", @@ -3350,6 +3404,7 @@ dependencies = [ "rustc_symbol_mangling", "rustc_target", "tempfile", + "tracing", ] [[package]] @@ -3364,7 +3419,6 @@ dependencies = [ "jobserver", "lazy_static", "libc", - "log", "measureme", "once_cell", "parking_lot 0.10.2", @@ -3377,6 +3431,7 @@ dependencies = [ "smallvec 1.4.0", "stable_deref_trait", "stacker", + "tracing", "winapi 0.3.8", ] @@ -3384,10 +3439,8 @@ dependencies = [ name = "rustc_driver" version = "0.0.0" dependencies = [ - "env_logger 0.7.1", "lazy_static", "libc", - "log", "rustc_ast", "rustc_ast_pretty", "rustc_codegen_ssa", @@ -3409,6 +3462,8 @@ dependencies = [ "rustc_session", "rustc_span", "rustc_target", + "tracing", + "tracing-subscriber", "winapi 0.3.8", ] @@ -3422,12 +3477,12 @@ version = "0.0.0" dependencies = [ "annotate-snippets 0.8.0", "atty", - "log", "rustc_data_structures", "rustc_serialize", "rustc_span", "termcolor", "termize", + "tracing", "unicode-width", "winapi 0.3.8", ] @@ -3436,7 +3491,6 @@ dependencies = [ name = "rustc_expand" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_ast_passes", "rustc_ast_pretty", @@ -3450,6 +3504,7 @@ dependencies = [ "rustc_session", "rustc_span", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3474,7 +3529,6 @@ name = "rustc_hir" version = "0.0.0" dependencies = [ "lazy_static", - "log", "rustc_ast", "rustc_data_structures", "rustc_index", @@ -3483,6 +3537,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3500,7 +3555,6 @@ dependencies = [ name = "rustc_incremental" version = "0.0.0" dependencies = [ - "log", "rand 0.7.3", "rustc_ast", "rustc_data_structures", @@ -3511,6 +3565,7 @@ dependencies = [ "rustc_serialize", "rustc_session", "rustc_span", + "tracing", ] [[package]] @@ -3525,7 +3580,6 @@ dependencies = [ name = "rustc_infer" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_data_structures", "rustc_errors", @@ -3539,6 +3593,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3546,7 +3601,6 @@ name = "rustc_interface" version = "0.0.0" dependencies = [ "libc", - "log", "once_cell", "rustc-rayon", "rustc_ast", @@ -3582,6 +3636,7 @@ dependencies = [ "rustc_typeck", "smallvec 1.4.0", "tempfile", + "tracing", "winapi 0.3.8", ] @@ -3596,7 +3651,6 @@ dependencies = [ name = "rustc_lint" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_ast_pretty", "rustc_attr", @@ -3610,6 +3664,7 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", + "tracing", "unicode-security", ] @@ -3638,7 +3693,6 @@ version = "0.0.0" dependencies = [ "flate2", "libc", - "log", "memmap", "rustc_ast", "rustc_attr", @@ -3655,6 +3709,7 @@ dependencies = [ "rustc_target", "smallvec 1.4.0", "stable_deref_trait", + "tracing", "winapi 0.3.8", ] @@ -3665,7 +3720,6 @@ dependencies = [ "bitflags", "byteorder", "chalk-ir", - "log", "measureme", "polonius-engine", "rustc-rayon-core", @@ -3686,6 +3740,7 @@ dependencies = [ "rustc_target", "scoped-tls", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3694,7 +3749,6 @@ version = "0.0.0" dependencies = [ "either", "itertools 0.8.0", - "log", "log_settings", "polonius-engine", "rustc_apfloat", @@ -3715,13 +3769,13 @@ dependencies = [ "rustc_target", "rustc_trait_selection", "smallvec 1.4.0", + "tracing", ] [[package]] name = "rustc_mir_build" version = "0.0.0" dependencies = [ - "log", "rustc_apfloat", "rustc_arena", "rustc_ast", @@ -3738,6 +3792,7 @@ dependencies = [ "rustc_target", "rustc_trait_selection", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3745,7 +3800,6 @@ name = "rustc_parse" version = "0.0.0" dependencies = [ "bitflags", - "log", "rustc_ast", "rustc_ast_pretty", "rustc_data_structures", @@ -3754,6 +3808,7 @@ dependencies = [ "rustc_lexer", "rustc_session", "rustc_span", + "tracing", "unicode-normalization", ] @@ -3769,7 +3824,6 @@ dependencies = [ name = "rustc_passes" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_attr", "rustc_data_structures", @@ -3781,6 +3835,7 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", + "tracing", ] [[package]] @@ -3801,7 +3856,6 @@ dependencies = [ name = "rustc_privacy" version = "0.0.0" dependencies = [ - "log", "rustc_attr", "rustc_data_structures", "rustc_errors", @@ -3810,13 +3864,13 @@ dependencies = [ "rustc_session", "rustc_span", "rustc_typeck", + "tracing", ] [[package]] name = "rustc_query_system" version = "0.0.0" dependencies = [ - "log", "parking_lot 0.10.2", "rustc-rayon-core", "rustc_arena", @@ -3826,6 +3880,7 @@ dependencies = [ "rustc_serialize", "rustc_span", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3833,7 +3888,6 @@ name = "rustc_resolve" version = "0.0.0" dependencies = [ "bitflags", - "log", "rustc_arena", "rustc_ast", "rustc_ast_lowering", @@ -3850,13 +3904,13 @@ dependencies = [ "rustc_session", "rustc_span", "smallvec 1.4.0", + "tracing", ] [[package]] name = "rustc_save_analysis" version = "0.0.0" dependencies = [ - "log", "rls-data", "rls-span", "rustc_ast", @@ -3869,6 +3923,7 @@ dependencies = [ "rustc_session", "rustc_span", "serde_json", + "tracing", ] [[package]] @@ -3885,7 +3940,6 @@ version = "0.0.0" dependencies = [ "bitflags", "getopts", - "log", "num_cpus", "rustc_ast", "rustc_data_structures", @@ -3895,6 +3949,7 @@ dependencies = [ "rustc_serialize", "rustc_span", "rustc_target", + "tracing", ] [[package]] @@ -3902,7 +3957,6 @@ name = "rustc_span" version = "0.0.0" dependencies = [ "cfg-if", - "log", "md-5", "rustc_arena", "rustc_data_structures", @@ -3911,6 +3965,7 @@ dependencies = [ "rustc_serialize", "scoped-tls", "sha-1", + "tracing", "unicode-width", ] @@ -3918,7 +3973,6 @@ dependencies = [ name = "rustc_symbol_mangling" version = "0.0.0" dependencies = [ - "log", "punycode", "rustc-demangle", "rustc_ast", @@ -3928,6 +3982,7 @@ dependencies = [ "rustc_session", "rustc_span", "rustc_target", + "tracing", ] [[package]] @@ -3935,12 +3990,12 @@ name = "rustc_target" version = "0.0.0" dependencies = [ "bitflags", - "log", "rustc_data_structures", "rustc_index", "rustc_macros", "rustc_serialize", "rustc_span", + "tracing", ] [[package]] @@ -3957,7 +4012,6 @@ checksum = "b725dadae9fabc488df69a287f5a99c5eaf5d10853842a8a3dfac52476f544ee" name = "rustc_trait_selection" version = "0.0.0" dependencies = [ - "log", "rustc_ast", "rustc_attr", "rustc_data_structures", @@ -3972,6 +4026,7 @@ dependencies = [ "rustc_span", "rustc_target", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -3980,7 +4035,6 @@ version = "0.0.0" dependencies = [ "chalk-ir", "chalk-solve", - "log", "rustc_ast", "rustc_data_structures", "rustc_hir", @@ -3990,13 +4044,13 @@ dependencies = [ "rustc_span", "rustc_trait_selection", "smallvec 1.4.0", + "tracing", ] [[package]] name = "rustc_ty" version = "0.0.0" dependencies = [ - "log", "rustc_data_structures", "rustc_errors", "rustc_hir", @@ -4006,13 +4060,13 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", + "tracing", ] [[package]] name = "rustc_typeck" version = "0.0.0" dependencies = [ - "log", "rustc_arena", "rustc_ast", "rustc_attr", @@ -4028,6 +4082,7 @@ dependencies = [ "rustc_target", "rustc_trait_selection", "smallvec 1.4.0", + "tracing", ] [[package]] @@ -4257,6 +4312,15 @@ dependencies = [ "opaque-debug", ] +[[package]] +name = "sharded-slab" +version = "0.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06d5a3f5166fb5b42a5439f2eee8b9de149e235961e3eb21c5808fc3ea17ff3e" +dependencies = [ + "lazy_static", +] + [[package]] name = "shell-escape" version = "0.1.4" @@ -4348,8 +4412,8 @@ dependencies = [ name = "std" version = "0.0.0" dependencies = [ + "addr2line", "alloc", - "backtrace", "cfg-if", "compiler_builtins", "core", @@ -4358,10 +4422,13 @@ dependencies = [ "hashbrown", "hermit-abi", "libc", + "miniz_oxide", + "object", "panic_abort", "panic_unwind", "profiler_builtins", "rand 0.7.3", + "rustc-demangle", "unwind", "wasi", ] @@ -4901,9 +4968,9 @@ dependencies = [ [[package]] name = "tracing" -version = "0.1.15" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41f40ed0e162c911ac6fcb53ecdc8134c46905fdbbae8c50add462a538b495f" +checksum = "f0aae59226cf195d8e74d4b34beae1859257efb4e5fed3f147d2dc2c7d372178" dependencies = [ "cfg-if", "tracing-attributes", @@ -4912,9 +4979,9 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.8" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99bbad0de3fd923c9c3232ead88510b783e5a4d16a6154adffa3d53308de984c" +checksum = "f0693bf8d6f2bf22c690fc61a9d21ac69efdbb894a17ed596b9af0f01e64b84b" dependencies = [ "proc-macro2 1.0.3", "quote 1.0.2", @@ -4923,13 +4990,29 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.10" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa83a9a47081cd522c09c81b31aec2c9273424976f922ad61c053b58350b715" +checksum = "b2734b5a028fa697686f16c6d18c2c6a3c7e41513f9a213abb6754c4acb3c8d7" dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-subscriber" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7b33f8b2ef2ab0c3778c12646d9c42a24f7772bee4cdafc72199644a9f58fdc" +dependencies = [ + "ansi_term 0.12.1", + "lazy_static", + "matchers", + "parking_lot 0.9.0", + "regex", + "sharded-slab", + "smallvec 1.4.0", + "tracing-core", +] + [[package]] name = "typenum" version = "1.12.0" diff --git a/Cargo.toml b/Cargo.toml index 4e49d697be1fb..1936e35aa4c5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,18 @@ overflow-checks = false # per-crate configuration isn't specifiable in the environment. codegen-units = 10000 +# These dependencies of the standard library implement symbolication for +# backtraces on most platforms. Their debuginfo causes both linking to be slower +# (more data to chew through) and binaries to be larger without really all that +# much benefit. This section turns them all to down to have no debuginfo which +# helps to improve link times a little bit. +[profile.release.package] +addr2line.debug = 0 +adler.debug = 0 +gimli.debug = 0 +miniz_oxide.debug = 0 +object.debug = 0 + # We want the RLS to use the version of Cargo that we've got vendored in this # repository to ensure that the same exact version of Cargo is used by both the # RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository @@ -80,5 +92,11 @@ rustc-std-workspace-core = { path = 'library/rustc-std-workspace-core' } rustc-std-workspace-alloc = { path = 'library/rustc-std-workspace-alloc' } rustc-std-workspace-std = { path = 'library/rustc-std-workspace-std' } +# This crate's integration with libstd is a bit wonky, so we use a submodule +# instead of a crates.io dependency. Make sure everything else in the repo is +# also using the submodule, however, so we can avoid duplicate copies of the +# source code for this crate. +backtrace = { path = "library/backtrace" } + [patch."https://github.com/rust-lang/rust-clippy"] clippy_lints = { path = "src/tools/clippy/clippy_lints" } diff --git a/RELEASES.md b/RELEASES.md index f36cdee0975a0..4859532f7a1f7 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,25 @@ +Version 1.45.2 (2020-08-03) +========================== + +* [Fix bindings in tuple struct patterns][74954] +* [Fix track_caller integration with trait objects][74784] + +[74954]: https://github.com/rust-lang/rust/issues/74954 +[74784]: https://github.com/rust-lang/rust/issues/74784 + +Version 1.45.1 (2020-07-30) +========================== + +* [Fix const propagation with references.][73613] +* [rustfmt accepts rustfmt_skip in cfg_attr again.][73078] +* [Avoid spurious implicit region bound.][74509] +* [Install clippy on x.py install][74457] + +[73613]: https://github.com/rust-lang/rust/pull/73613 +[73078]: https://github.com/rust-lang/rust/issues/73078 +[74509]: https://github.com/rust-lang/rust/pull/74509 +[74457]: https://github.com/rust-lang/rust/pull/74457 + Version 1.45.0 (2020-07-16) ========================== diff --git a/library/alloc/src/collections/linked_list.rs b/library/alloc/src/collections/linked_list.rs index 1f875f6c5217f..02a746f0e2488 100644 --- a/library/alloc/src/collections/linked_list.rs +++ b/library/alloc/src/collections/linked_list.rs @@ -1110,32 +1110,17 @@ impl IterMut<'_, T> { /// Inserts the given element just after the element most recently returned by `.next()`. /// The inserted element does not appear in the iteration. /// - /// # Examples - /// - /// ``` - /// #![feature(linked_list_extras)] - /// - /// use std::collections::LinkedList; - /// - /// let mut list: LinkedList<_> = vec![1, 3, 4].into_iter().collect(); - /// - /// { - /// let mut it = list.iter_mut(); - /// assert_eq!(it.next().unwrap(), &1); - /// // insert `2` after `1` - /// it.insert_next(2); - /// } - /// { - /// let vec: Vec<_> = list.into_iter().collect(); - /// assert_eq!(vec, [1, 2, 3, 4]); - /// } - /// ``` + /// This method will be removed soon. #[inline] #[unstable( feature = "linked_list_extras", reason = "this is probably better handled by a cursor type -- we'll see", issue = "27794" )] + #[rustc_deprecated( + reason = "Deprecated in favor of CursorMut methods. This method will be removed soon.", + since = "1.47.0" + )] pub fn insert_next(&mut self, element: T) { match self.head { // `push_back` is okay with aliasing `element` references @@ -1163,27 +1148,17 @@ impl IterMut<'_, T> { /// Provides a reference to the next element, without changing the iterator. /// - /// # Examples - /// - /// ``` - /// #![feature(linked_list_extras)] - /// - /// use std::collections::LinkedList; - /// - /// let mut list: LinkedList<_> = vec![1, 2, 3].into_iter().collect(); - /// - /// let mut it = list.iter_mut(); - /// assert_eq!(it.next().unwrap(), &1); - /// assert_eq!(it.peek_next().unwrap(), &2); - /// // We just peeked at 2, so it was not consumed from the iterator. - /// assert_eq!(it.next().unwrap(), &2); - /// ``` + /// This method will be removed soon. #[inline] #[unstable( feature = "linked_list_extras", reason = "this is probably better handled by a cursor type -- we'll see", issue = "27794" )] + #[rustc_deprecated( + reason = "Deprecated in favor of CursorMut methods. This method will be removed soon.", + since = "1.47.0" + )] pub fn peek_next(&mut self) -> Option<&mut T> { if self.len == 0 { None diff --git a/library/alloc/src/collections/linked_list/tests.rs b/library/alloc/src/collections/linked_list/tests.rs index b8c93a28bba81..ad643a7bdf194 100644 --- a/library/alloc/src/collections/linked_list/tests.rs +++ b/library/alloc/src/collections/linked_list/tests.rs @@ -153,33 +153,6 @@ fn test_clone_from() { } } -#[test] -fn test_insert_prev() { - let mut m = list_from(&[0, 2, 4, 6, 8]); - let len = m.len(); - { - let mut it = m.iter_mut(); - it.insert_next(-2); - loop { - match it.next() { - None => break, - Some(elt) => { - it.insert_next(*elt + 1); - match it.peek_next() { - Some(x) => assert_eq!(*x, *elt + 2), - None => assert_eq!(8, *elt), - } - } - } - } - it.insert_next(0); - it.insert_next(1); - } - check_links(&m); - assert_eq!(m.len(), 3 + len * 2); - assert_eq!(m.into_iter().collect::>(), [-2, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1]); -} - #[test] #[cfg_attr(target_os = "emscripten", ignore)] fn test_send() { diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 90e2d2531c552..097db30d634cc 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -69,13 +69,13 @@ #![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] -#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings #![allow(explicit_outlives_requirements)] #![allow(incomplete_features)] #![deny(unsafe_op_in_unsafe_fn)] #![cfg_attr(not(test), feature(generator_trait))] #![cfg_attr(test, feature(test))] #![feature(allocator_api)] +#![feature(array_chunks)] #![feature(allow_internal_unstable)] #![feature(arbitrary_self_types)] #![feature(box_patterns)] diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index d3450cfbc814e..116df63f94b69 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -1692,8 +1692,9 @@ impl Weak { /// Consumes the `Weak` and turns it into a raw pointer. /// - /// This converts the weak pointer into a raw pointer, preserving the original weak count. It - /// can be turned back into the `Weak` with [`from_raw`]. + /// This converts the weak pointer into a raw pointer, while still preserving the ownership of + /// one weak reference (the weak count is not modified by this operation). It can be turned + /// back into the `Weak` with [`from_raw`]. /// /// The same restrictions of accessing the target of the pointer as with /// [`as_ptr`] apply. @@ -1728,17 +1729,18 @@ impl Weak { /// This can be used to safely get a strong reference (by calling [`upgrade`] /// later) or to deallocate the weak count by dropping the `Weak`. /// - /// It takes ownership of one weak count (with the exception of pointers created by [`new`], - /// as these don't have any corresponding weak count). + /// It takes ownership of one weak reference (with the exception of pointers created by [`new`], + /// as these don't own anything; the method still works on them). /// /// # Safety /// - /// The pointer must have originated from the [`into_raw`] and must still own its potential - /// weak reference count. + /// The pointer must have originated from the [`into_raw`] and must still own its potential + /// weak reference. /// - /// It is allowed for the strong count to be 0 at the time of calling this, but the weak count - /// must be non-zero or the pointer must have originated from a dangling `Weak` (one created - /// by [`new`]). + /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this + /// takes ownership of one weak reference currently represented as a raw pointer (the weak + /// count is not modified by this operation) and therefore it must be paired with a previous + /// call to [`into_raw`]. /// /// # Examples /// diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 3d51115fe01d3..b791c775548cd 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -95,6 +95,8 @@ use crate::borrow::ToOwned; use crate::boxed::Box; use crate::vec::Vec; +#[unstable(feature = "array_chunks", issue = "74985")] +pub use core::slice::ArrayChunks; #[stable(feature = "slice_get_slice", since = "1.28.0")] pub use core::slice::SliceIndex; #[stable(feature = "from_ref", since = "1.28.0")] diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 906beba2a6296..58cab9c5c6388 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -1462,8 +1462,9 @@ impl Weak { /// Consumes the `Weak` and turns it into a raw pointer. /// - /// This converts the weak pointer into a raw pointer, preserving the original weak count. It - /// can be turned back into the `Weak` with [`from_raw`]. + /// This converts the weak pointer into a raw pointer, while still preserving the ownership of + /// one weak reference (the weak count is not modified by this operation). It can be turned + /// back into the `Weak` with [`from_raw`]. /// /// The same restrictions of accessing the target of the pointer as with /// [`as_ptr`] apply. @@ -1493,24 +1494,23 @@ impl Weak { result } - /// Converts a raw pointer previously created by [`into_raw`] back into - /// `Weak`. + /// Converts a raw pointer previously created by [`into_raw`] back into `Weak`. /// /// This can be used to safely get a strong reference (by calling [`upgrade`] /// later) or to deallocate the weak count by dropping the `Weak`. /// - /// It takes ownership of one weak count (with the exception of pointers created by [`new`], - /// as these don't have any corresponding weak count). + /// It takes ownership of one weak reference (with the exception of pointers created by [`new`], + /// as these don't own anything; the method still works on them). /// /// # Safety /// /// The pointer must have originated from the [`into_raw`] and must still own its potential - /// weak reference count. - /// - /// It is allowed for the strong count to be 0 at the time of calling this, but the weak count - /// must be non-zero or the pointer must have originated from a dangling `Weak` (one created - /// by [`new`]). + /// weak reference. /// + /// It is allowed for the strong count to be 0 at the time of calling this. Nevertheless, this + /// takes ownership of one weak reference currently represented as a raw pointer (the weak + /// count is not modified by this operation) and therefore it must be paired with a previous + /// call to [`into_raw`]. /// # Examples /// /// ``` diff --git a/library/alloc/src/vec.rs b/library/alloc/src/vec.rs index f5a3d0cd4af87..9eb37bf473fed 100644 --- a/library/alloc/src/vec.rs +++ b/library/alloc/src/vec.rs @@ -1510,20 +1510,18 @@ impl Vec { /// Simple usage: /// /// ``` - /// #![feature(vec_leak)] - /// /// let x = vec![1, 2, 3]; - /// let static_ref: &'static mut [usize] = Vec::leak(x); + /// let static_ref: &'static mut [usize] = x.leak(); /// static_ref[0] += 1; /// assert_eq!(static_ref, &[2, 2, 3]); /// ``` - #[unstable(feature = "vec_leak", issue = "62195")] + #[stable(feature = "vec_leak", since = "1.47.0")] #[inline] - pub fn leak<'a>(vec: Vec) -> &'a mut [T] + pub fn leak<'a>(self) -> &'a mut [T] where T: 'a, // Technically not needed, but kept to be explicit. { - Box::leak(vec.into_boxed_slice()) + Box::leak(self.into_boxed_slice()) } } diff --git a/library/backtrace b/library/backtrace new file mode 160000 index 0000000000000..4083a90168d60 --- /dev/null +++ b/library/backtrace @@ -0,0 +1 @@ +Subproject commit 4083a90168d605b682ba166a0c01f86b3384e474 diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 550e07f9d5710..fcf5454308b47 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -61,7 +61,6 @@ #![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] -#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings #![allow(explicit_outlives_requirements)] #![allow(incomplete_features)] #![feature(allow_internal_unstable)] @@ -82,6 +81,7 @@ #![feature(const_fn_union)] #![feature(const_generics)] #![feature(const_option)] +#![feature(const_precise_live_drops)] #![feature(const_ptr_offset)] #![feature(const_ptr_offset_from)] #![feature(const_raw_ptr_comparison)] @@ -151,7 +151,6 @@ #![feature(slice_ptr_get)] #![feature(no_niche)] // rust-lang/rust#68303 #![feature(unsafe_block_in_unsafe_fn)] -#![deny(intra_doc_link_resolution_failure)] #![deny(unsafe_op_in_unsafe_fn)] #[prelude_import] diff --git a/library/core/src/option.rs b/library/core/src/option.rs index 5932f8e5856a7..3c7211fe040dc 100644 --- a/library/core/src/option.rs +++ b/library/core/src/option.rs @@ -380,7 +380,8 @@ impl Option { #[inline] #[track_caller] #[stable(feature = "rust1", since = "1.0.0")] - pub fn unwrap(self) -> T { + #[rustc_const_unstable(feature = "const_option", issue = "67441")] + pub const fn unwrap(self) -> T { match self { Some(val) => val, None => panic!("called `Option::unwrap()` on a `None` value"), diff --git a/library/core/src/slice/mod.rs b/library/core/src/slice/mod.rs index 9ed5a1f962215..93608a1ce4864 100644 --- a/library/core/src/slice/mod.rs +++ b/library/core/src/slice/mod.rs @@ -680,7 +680,7 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn windows(&self, size: usize) -> Windows<'_, T> { - assert!(size != 0); + assert_ne!(size, 0); Windows { v: self, size } } @@ -714,7 +714,7 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn chunks(&self, chunk_size: usize) -> Chunks<'_, T> { - assert!(chunk_size != 0); + assert_ne!(chunk_size, 0); Chunks { v: self, chunk_size } } @@ -752,7 +752,7 @@ impl [T] { #[stable(feature = "rust1", since = "1.0.0")] #[inline] pub fn chunks_mut(&mut self, chunk_size: usize) -> ChunksMut<'_, T> { - assert!(chunk_size != 0); + assert_ne!(chunk_size, 0); ChunksMut { v: self, chunk_size } } @@ -789,7 +789,7 @@ impl [T] { #[stable(feature = "chunks_exact", since = "1.31.0")] #[inline] pub fn chunks_exact(&self, chunk_size: usize) -> ChunksExact<'_, T> { - assert!(chunk_size != 0); + assert_ne!(chunk_size, 0); let rem = self.len() % chunk_size; let len = self.len() - rem; let (fst, snd) = self.split_at(len); @@ -834,13 +834,52 @@ impl [T] { #[stable(feature = "chunks_exact", since = "1.31.0")] #[inline] pub fn chunks_exact_mut(&mut self, chunk_size: usize) -> ChunksExactMut<'_, T> { - assert!(chunk_size != 0); + assert_ne!(chunk_size, 0); let rem = self.len() % chunk_size; let len = self.len() - rem; let (fst, snd) = self.split_at_mut(len); ChunksExactMut { v: fst, rem: snd, chunk_size } } + /// Returns an iterator over `N` elements of the slice at a time, starting at the + /// beginning of the slice. + /// + /// The chunks are slices and do not overlap. If `N` does not divide the length of the + /// slice, then the last up to `N-1` elements will be omitted and can be retrieved + /// from the `remainder` function of the iterator. + /// + /// This method is the const generic equivalent of [`chunks_exact`]. + /// + /// # Panics + /// + /// Panics if `N` is 0. This check will most probably get changed to a compile time + /// error before this method gets stabilized. + /// + /// # Examples + /// + /// ``` + /// #![feature(array_chunks)] + /// let slice = ['l', 'o', 'r', 'e', 'm']; + /// let mut iter = slice.array_chunks(); + /// assert_eq!(iter.next().unwrap(), &['l', 'o']); + /// assert_eq!(iter.next().unwrap(), &['r', 'e']); + /// assert!(iter.next().is_none()); + /// assert_eq!(iter.remainder(), &['m']); + /// ``` + /// + /// [`chunks_exact`]: #method.chunks_exact + #[unstable(feature = "array_chunks", issue = "74985")] + #[inline] + pub fn array_chunks(&self) -> ArrayChunks<'_, T, N> { + assert_ne!(N, 0); + let len = self.len() / N; + let (fst, snd) = self.split_at(len * N); + // SAFETY: We cast a slice of `len * N` elements into + // a slice of `len` many `N` elements chunks. + let array_slice: &[[T; N]] = unsafe { from_raw_parts(fst.as_ptr().cast(), len) }; + ArrayChunks { iter: array_slice.iter(), rem: snd } + } + /// Returns an iterator over `chunk_size` elements of the slice at a time, starting at the end /// of the slice. /// @@ -5432,6 +5471,110 @@ unsafe impl<'a, T> TrustedRandomAccess for ChunksExactMut<'a, T> { } } +/// An iterator over a slice in (non-overlapping) chunks (`N` elements at a +/// time), starting at the beginning of the slice. +/// +/// When the slice len is not evenly divided by the chunk size, the last +/// up to `chunk_size-1` elements will be omitted but can be retrieved from +/// the [`remainder`] function from the iterator. +/// +/// This struct is created by the [`array_chunks`] method on [slices]. +/// +/// [`array_chunks`]: ../../std/primitive.slice.html#method.array_chunks +/// [`remainder`]: ../../std/slice/struct.ArrayChunks.html#method.remainder +/// [slices]: ../../std/primitive.slice.html +#[derive(Debug)] +#[unstable(feature = "array_chunks", issue = "74985")] +pub struct ArrayChunks<'a, T: 'a, const N: usize> { + iter: Iter<'a, [T; N]>, + rem: &'a [T], +} + +impl<'a, T, const N: usize> ArrayChunks<'a, T, N> { + /// Returns the remainder of the original slice that is not going to be + /// returned by the iterator. The returned slice has at most `chunk_size-1` + /// elements. + #[unstable(feature = "array_chunks", issue = "74985")] + pub fn remainder(&self) -> &'a [T] { + self.rem + } +} + +// FIXME(#26925) Remove in favor of `#[derive(Clone)]` +#[unstable(feature = "array_chunks", issue = "74985")] +impl Clone for ArrayChunks<'_, T, N> { + fn clone(&self) -> Self { + ArrayChunks { iter: self.iter.clone(), rem: self.rem } + } +} + +#[unstable(feature = "array_chunks", issue = "74985")] +impl<'a, T, const N: usize> Iterator for ArrayChunks<'a, T, N> { + type Item = &'a [T; N]; + + #[inline] + fn next(&mut self) -> Option<&'a [T; N]> { + self.iter.next() + } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.iter.size_hint() + } + + #[inline] + fn count(self) -> usize { + self.iter.count() + } + + #[inline] + fn nth(&mut self, n: usize) -> Option { + self.iter.nth(n) + } + + #[inline] + fn last(self) -> Option { + self.iter.last() + } +} + +#[unstable(feature = "array_chunks", issue = "74985")] +impl<'a, T, const N: usize> DoubleEndedIterator for ArrayChunks<'a, T, N> { + #[inline] + fn next_back(&mut self) -> Option<&'a [T; N]> { + self.iter.next_back() + } + + #[inline] + fn nth_back(&mut self, n: usize) -> Option { + self.iter.nth_back(n) + } +} + +#[unstable(feature = "array_chunks", issue = "74985")] +impl ExactSizeIterator for ArrayChunks<'_, T, N> { + fn is_empty(&self) -> bool { + self.iter.is_empty() + } +} + +#[unstable(feature = "trusted_len", issue = "37572")] +unsafe impl TrustedLen for ArrayChunks<'_, T, N> {} + +#[unstable(feature = "array_chunks", issue = "74985")] +impl FusedIterator for ArrayChunks<'_, T, N> {} + +#[doc(hidden)] +#[unstable(feature = "array_chunks", issue = "74985")] +unsafe impl<'a, T, const N: usize> TrustedRandomAccess for ArrayChunks<'a, T, N> { + unsafe fn get_unchecked(&mut self, i: usize) -> &'a [T; N] { + unsafe { self.iter.get_unchecked(i) } + } + fn may_have_side_effect() -> bool { + false + } +} + /// An iterator over a slice in (non-overlapping) chunks (`chunk_size` elements at a /// time), starting at the end of the slice. /// diff --git a/library/core/tests/lib.rs b/library/core/tests/lib.rs index 47ed6db6c677b..6b28a815f033a 100644 --- a/library/core/tests/lib.rs +++ b/library/core/tests/lib.rs @@ -1,4 +1,5 @@ #![feature(alloc_layout_extra)] +#![feature(array_chunks)] #![feature(bool_to_option)] #![feature(bound_cloned)] #![feature(box_syntax)] diff --git a/library/core/tests/slice.rs b/library/core/tests/slice.rs index 8e240832c13b8..27cc7fce1daa3 100644 --- a/library/core/tests/slice.rs +++ b/library/core/tests/slice.rs @@ -473,6 +473,97 @@ fn test_chunks_exact_mut_zip() { assert_eq!(v1, [13, 14, 19, 20, 4]); } +#[test] +fn test_array_chunks_infer() { + let v: &[i32] = &[0, 1, 2, 3, 4, -4]; + let c = v.array_chunks(); + for &[a, b, c] in c { + assert_eq!(a + b + c, 3); + } + + let v2: &[i32] = &[0, 1, 2, 3, 4, 5, 6]; + let total = v2.array_chunks().map(|&[a, b]| a * b).sum::(); + assert_eq!(total, 2 * 3 + 4 * 5); +} + +#[test] +fn test_array_chunks_count() { + let v: &[i32] = &[0, 1, 2, 3, 4, 5]; + let c = v.array_chunks::<3>(); + assert_eq!(c.count(), 2); + + let v2: &[i32] = &[0, 1, 2, 3, 4]; + let c2 = v2.array_chunks::<2>(); + assert_eq!(c2.count(), 2); + + let v3: &[i32] = &[]; + let c3 = v3.array_chunks::<2>(); + assert_eq!(c3.count(), 0); +} + +#[test] +fn test_array_chunks_nth() { + let v: &[i32] = &[0, 1, 2, 3, 4, 5]; + let mut c = v.array_chunks::<2>(); + assert_eq!(c.nth(1).unwrap(), &[2, 3]); + assert_eq!(c.next().unwrap(), &[4, 5]); + + let v2: &[i32] = &[0, 1, 2, 3, 4, 5, 6]; + let mut c2 = v2.array_chunks::<3>(); + assert_eq!(c2.nth(1).unwrap(), &[3, 4, 5]); + assert_eq!(c2.next(), None); +} + +#[test] +fn test_array_chunks_nth_back() { + let v: &[i32] = &[0, 1, 2, 3, 4, 5]; + let mut c = v.array_chunks::<2>(); + assert_eq!(c.nth_back(1).unwrap(), &[2, 3]); + assert_eq!(c.next().unwrap(), &[0, 1]); + assert_eq!(c.next(), None); + + let v2: &[i32] = &[0, 1, 2, 3, 4]; + let mut c2 = v2.array_chunks::<3>(); + assert_eq!(c2.nth_back(0).unwrap(), &[0, 1, 2]); + assert_eq!(c2.next(), None); + assert_eq!(c2.next_back(), None); + + let v3: &[i32] = &[0, 1, 2, 3, 4]; + let mut c3 = v3.array_chunks::<10>(); + assert_eq!(c3.nth_back(0), None); +} + +#[test] +fn test_array_chunks_last() { + let v: &[i32] = &[0, 1, 2, 3, 4, 5]; + let c = v.array_chunks::<2>(); + assert_eq!(c.last().unwrap(), &[4, 5]); + + let v2: &[i32] = &[0, 1, 2, 3, 4]; + let c2 = v2.array_chunks::<2>(); + assert_eq!(c2.last().unwrap(), &[2, 3]); +} + +#[test] +fn test_array_chunks_remainder() { + let v: &[i32] = &[0, 1, 2, 3, 4]; + let c = v.array_chunks::<2>(); + assert_eq!(c.remainder(), &[4]); +} + +#[test] +fn test_array_chunks_zip() { + let v1: &[i32] = &[0, 1, 2, 3, 4]; + let v2: &[i32] = &[6, 7, 8, 9, 10]; + + let res = v1 + .array_chunks::<2>() + .zip(v2.array_chunks::<2>()) + .map(|(a, b)| a.iter().sum::() + b.iter().sum::()) + .collect::>(); + assert_eq!(res, vec![14, 22]); +} + #[test] fn test_rchunks_count() { let v: &[i32] = &[0, 1, 2, 3, 4, 5]; diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index b4951488fd86c..474765d863811 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -22,11 +22,15 @@ profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } hashbrown = { version = "0.6.2", default-features = false, features = ['rustc-dep-of-std'] } -[dependencies.backtrace_rs] -package = "backtrace" -version = "0.3.46" -default-features = false # without the libstd `backtrace` feature, stub out everything -features = [ "rustc-dep-of-std" ] # enable build support for integrating into libstd +# Dependencies of the `backtrace` crate +addr2line = { version = "0.13.0", optional = true, default-features = false } +rustc-demangle = { version = "0.1.4", features = ['rustc-dep-of-std'] } +miniz_oxide = { version = "0.4.0", optional = true, default-features = false } +[dependencies.object] +version = "0.20" +optional = true +default-features = false +features = ['read_core', 'elf', 'macho', 'pe'] [dev-dependencies] rand = "0.7" @@ -45,11 +49,12 @@ wasi = { version = "0.9.0", features = ['rustc-dep-of-std'], default-features = [features] backtrace = [ - "backtrace_rs/dbghelp", # backtrace/symbolize on MSVC - "backtrace_rs/libbacktrace", # symbolize on most platforms - "backtrace_rs/libunwind", # backtrace on most platforms - "backtrace_rs/dladdr", # symbolize on platforms w/o libbacktrace + "gimli-symbolize", + 'addr2line/rustc-dep-of-std', + 'object/rustc-dep-of-std', + 'miniz_oxide/rustc-dep-of-std', ] +gimli-symbolize = [] panic-unwind = ["panic_unwind"] profiler = ["profiler_builtins"] diff --git a/library/std/build.rs b/library/std/build.rs index 43a3327d84b61..83073cc77dd1a 100644 --- a/library/std/build.rs +++ b/library/std/build.rs @@ -88,4 +88,5 @@ fn main() { println!("cargo:rustc-cfg=feature=\"restricted-std\""); } println!("cargo:rustc-env=STD_ENV_ARCH={}", env::var("CARGO_CFG_TARGET_ARCH").unwrap()); + println!("cargo:rustc-cfg=backtrace_in_libstd"); } diff --git a/library/std/src/backtrace.rs b/library/std/src/backtrace.rs index 02e6811bc3f43..09f83ea5fca81 100644 --- a/library/std/src/backtrace.rs +++ b/library/std/src/backtrace.rs @@ -91,6 +91,7 @@ // `Backtrace`, but that's a relatively small price to pay relative to capturing // a backtrace or actually symbolizing it. +use crate::backtrace_rs::{self, BytesOrWideString}; use crate::env; use crate::ffi::c_void; use crate::fmt; @@ -98,8 +99,6 @@ use crate::sync::atomic::{AtomicUsize, Ordering::SeqCst}; use crate::sync::Mutex; use crate::sys_common::backtrace::{lock, output_filename}; use crate::vec::Vec; -use backtrace::BytesOrWideString; -use backtrace_rs as backtrace; /// A captured OS thread stack backtrace. /// @@ -150,7 +149,7 @@ struct BacktraceFrame { } enum RawFrame { - Actual(backtrace::Frame), + Actual(backtrace_rs::Frame), #[cfg(test)] Fake, } @@ -197,7 +196,7 @@ impl fmt::Debug for BacktraceSymbol { fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { write!(fmt, "{{ ")?; - if let Some(fn_name) = self.name.as_ref().map(|b| backtrace::SymbolName::new(b)) { + if let Some(fn_name) = self.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)) { write!(fmt, "fn: \"{:#}\"", fn_name)?; } else { write!(fmt, "fn: ")?; @@ -223,7 +222,7 @@ impl fmt::Debug for BytesOrWide { BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w), BytesOrWide::Wide(w) => BytesOrWideString::Wide(w), }, - backtrace::PrintFmt::Short, + backtrace_rs::PrintFmt::Short, crate::env::current_dir().as_ref().ok(), ) } @@ -305,7 +304,7 @@ impl Backtrace { let mut frames = Vec::new(); let mut actual_start = None; unsafe { - backtrace::trace_unsynchronized(|frame| { + backtrace_rs::trace_unsynchronized(|frame| { frames.push(BacktraceFrame { frame: RawFrame::Actual(frame.clone()), symbols: Vec::new(), @@ -356,9 +355,9 @@ impl fmt::Display for Backtrace { let full = fmt.alternate(); let (frames, style) = if full { - (&capture.frames[..], backtrace::PrintFmt::Full) + (&capture.frames[..], backtrace_rs::PrintFmt::Full) } else { - (&capture.frames[capture.actual_start..], backtrace::PrintFmt::Short) + (&capture.frames[capture.actual_start..], backtrace_rs::PrintFmt::Short) }; // When printing paths we try to strip the cwd if it exists, otherwise @@ -370,7 +369,7 @@ impl fmt::Display for Backtrace { output_filename(fmt, path, style, cwd.as_ref().ok()) }; - let mut f = backtrace::BacktraceFmt::new(fmt, style, &mut print_path); + let mut f = backtrace_rs::BacktraceFmt::new(fmt, style, &mut print_path); f.add_context()?; for frame in frames { let mut f = f.frame(); @@ -380,7 +379,7 @@ impl fmt::Display for Backtrace { for symbol in frame.symbols.iter() { f.print_raw( frame.frame.ip(), - symbol.name.as_ref().map(|b| backtrace::SymbolName::new(b)), + symbol.name.as_ref().map(|b| backtrace_rs::SymbolName::new(b)), symbol.filename.as_ref().map(|b| match b { BytesOrWide::Bytes(w) => BytesOrWideString::Bytes(w), BytesOrWide::Wide(w) => BytesOrWideString::Wide(w), @@ -415,7 +414,7 @@ impl Capture { RawFrame::Fake => unimplemented!(), }; unsafe { - backtrace::resolve_frame_unsynchronized(frame, |symbol| { + backtrace_rs::resolve_frame_unsynchronized(frame, |symbol| { symbols.push(BacktraceSymbol { name: symbol.name().map(|m| m.as_bytes().to_vec()), filename: symbol.filename_raw().map(|b| match b { diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c6e5b0a492ac8..c81b949af6566 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -212,7 +212,6 @@ #![warn(deprecated_in_future)] #![warn(missing_docs)] #![warn(missing_debug_implementations)] -#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings #![allow(explicit_outlives_requirements)] #![allow(unused_lifetimes)] // Tell the compiler to link to either panic_abort or panic_unwind @@ -511,6 +510,10 @@ mod panicking; // compiler pub mod rt; +#[path = "../../backtrace/src/lib.rs"] +#[allow(dead_code, unused_attributes)] +mod backtrace_rs; + // Pull in the `std_detect` crate directly into libstd. The contents of // `std_detect` are in a different repository: rust-lang/stdarch. // diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index 9542e7209b4cf..ab2a60103069d 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -171,7 +171,7 @@ fn default_hook(info: &PanicInfo<'_>) { // If this is a double panic, make sure that we print a backtrace // for this panic. Otherwise only print it if logging is enabled. let backtrace_env = if panic_count::get() >= 2 { - RustBacktrace::Print(backtrace_rs::PrintFmt::Full) + RustBacktrace::Print(crate::backtrace_rs::PrintFmt::Full) } else { backtrace::rust_backtrace_env() }; diff --git a/library/std/src/sys_common/backtrace.rs b/library/std/src/sys_common/backtrace.rs index e9b1e86d7ae49..d386a656e4ffd 100644 --- a/library/std/src/sys_common/backtrace.rs +++ b/library/std/src/sys_common/backtrace.rs @@ -1,3 +1,4 @@ +use crate::backtrace_rs::{self, BacktraceFmt, BytesOrWideString, PrintFmt}; use crate::borrow::Cow; /// Common code for printing the backtrace in the same way across the different /// supported platforms. @@ -9,8 +10,6 @@ use crate::path::{self, Path, PathBuf}; use crate::sync::atomic::{self, Ordering}; use crate::sys::mutex::Mutex; -use backtrace_rs::{BacktraceFmt, BytesOrWideString, PrintFmt}; - /// Max number of frames to print. const MAX_NB_FRAMES: usize = 100; diff --git a/rustfmt.toml b/rustfmt.toml index cb689098f8989..26cdcfff2a316 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -14,6 +14,7 @@ ignore = [ "src/test", # do not format submodules + "library/backtrace", "library/stdarch", "src/doc/book", "src/doc/edition-guide", diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 7f10d7895a5e7..a4a1d5193b9b9 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -1016,7 +1016,17 @@ impl Step for Src { let src_files = ["Cargo.lock"]; // This is the reduced set of paths which will become the rust-src component // (essentially libstd and all of its path dependencies). - copy_src_dirs(builder, &builder.src, &["library"], &[], &dst_src); + copy_src_dirs( + builder, + &builder.src, + &["library"], + &[ + // not needed and contains symlinks which rustup currently + // chokes on when unpacking. + "library/backtrace/crates", + ], + &dst_src, + ); for file in src_files.iter() { builder.copy(&builder.src.join(file), &dst_src.join(file)); } diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index 05af7210b1c68..2ead5d0a37f9c 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -393,7 +393,7 @@ impl Step for Miri { cargo.arg("--").arg("miri").arg("setup"); // Tell `cargo miri setup` where to find the sources. - cargo.env("XARGO_RUST_SRC", builder.src.join("src")); + cargo.env("XARGO_RUST_SRC", builder.src.join("library")); // Tell it where to find Miri. cargo.env("MIRI", &miri); // Debug things. diff --git a/src/ci/docker/host-x86_64/dist-i686-freebsd/Dockerfile b/src/ci/docker/host-x86_64/dist-i686-freebsd/Dockerfile index 7978bb7086965..14af9b9efe815 100644 --- a/src/ci/docker/host-x86_64/dist-i686-freebsd/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-i686-freebsd/Dockerfile @@ -29,5 +29,5 @@ ENV \ ENV HOSTS=i686-unknown-freebsd -ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs +ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh index c82031690ab6a..c6db200f8660f 100755 --- a/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh +++ b/src/ci/docker/host-x86_64/dist-various-2/build-wasi-toolchain.sh @@ -4,15 +4,15 @@ set -ex -# Originally from https://releases.llvm.org/9.0.0/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz -curl https://ci-mirrors.rust-lang.org/rustc/clang%2Bllvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04.tar.xz | \ +# Originally from https://github.com/llvm/llvm-project/releases/download/llvmorg-10.0.0/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz +curl https://ci-mirrors.rust-lang.org/rustc/clang%2Bllvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04.tar.xz | \ tar xJf - -export PATH=`pwd`/clang+llvm-9.0.0-x86_64-linux-gnu-ubuntu-14.04/bin:$PATH +export PATH=`pwd`/clang+llvm-10.0.0-x86_64-linux-gnu-ubuntu-18.04/bin:$PATH -git clone https://github.com/CraneStation/wasi-libc +git clone https://github.com/WebAssembly/wasi-libc cd wasi-libc -git reset --hard 9efc2f428358564fe64c374d762d0bfce1d92507 +git reset --hard 215adc8ac9f91eb055311acc72683fd2eb1ae15a make -j$(nproc) INSTALL_DIR=/wasm32-wasi install cd .. diff --git a/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile index 12170a3661487..2372c0dad0abf 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-freebsd/Dockerfile @@ -29,5 +29,5 @@ ENV \ ENV HOSTS=x86_64-unknown-freebsd -ENV RUST_CONFIGURE_ARGS --enable-extended --disable-docs +ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS diff --git a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile index c026506b10661..ab6515cd1fa95 100644 --- a/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-x86_64-musl/Dockerfile @@ -33,7 +33,6 @@ ENV HOSTS=x86_64-unknown-linux-musl ENV RUST_CONFIGURE_ARGS \ --musl-root-x86_64=/usr/local/x86_64-linux-musl \ --enable-extended \ - --disable-docs \ --enable-lld \ --set target.x86_64-unknown-linux-musl.crt-static=false \ --build $HOSTS diff --git a/src/doc/rustdoc/src/lints.md b/src/doc/rustdoc/src/lints.md index beb2556872df7..d1d6bc1c1fe69 100644 --- a/src/doc/rustdoc/src/lints.md +++ b/src/doc/rustdoc/src/lints.md @@ -11,7 +11,7 @@ can use them like any other lints by doing this: Here is the list of the lints provided by `rustdoc`: -## intra_doc_link_resolution_failure +## broken_intra_doc_links This lint **warns by default** and is **nightly-only**. This lint detects when an intra-doc link fails to get resolved. For example: diff --git a/src/doc/unstable-book/src/language-features/plugin.md b/src/doc/unstable-book/src/language-features/plugin.md index 1f010656bb854..3835113152762 100644 --- a/src/doc/unstable-book/src/language-features/plugin.md +++ b/src/doc/unstable-book/src/language-features/plugin.md @@ -45,42 +45,40 @@ that warns about any item named `lintme`. extern crate rustc_ast; // Load rustc as a plugin to get macros -#[macro_use] -extern crate rustc; extern crate rustc_driver; +#[macro_use] +extern crate rustc_lint; +#[macro_use] +extern crate rustc_session; -use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass, - EarlyLintPassObject, LintArray}; use rustc_driver::plugin::Registry; +use rustc_lint::{EarlyContext, EarlyLintPass, LintArray, LintContext, LintPass}; use rustc_ast::ast; - declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'"); -struct Pass; - -impl LintPass for Pass { - fn get_lints(&self) -> LintArray { - lint_array!(TEST_LINT) - } -} +declare_lint_pass!(Pass => [TEST_LINT]); impl EarlyLintPass for Pass { fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) { - if it.ident.as_str() == "lintme" { - cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'"); + if it.ident.name.as_str() == "lintme" { + cx.lint(TEST_LINT, |lint| { + lint.build("item is named 'lintme'").set_span(it.span).emit() + }); } } } #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { - reg.register_early_lint_pass(box Pass as EarlyLintPassObject); + reg.lint_store.register_lints(&[&TEST_LINT]); + reg.lint_store.register_early_pass(|| box Pass); } ``` Then code like ```rust,ignore +#![feature(plugin)] #![plugin(lint_plugin_test)] fn lintme() { } @@ -107,7 +105,7 @@ The components of a lint plugin are: Lint passes are syntax traversals, but they run at a late stage of compilation where type information is available. `rustc`'s [built-in -lints](https://github.com/rust-lang/rust/blob/master/src/librustc/lint/builtin.rs) +lints](https://github.com/rust-lang/rust/blob/master/src/librustc_session/lint/builtin.rs) mostly use the same infrastructure as lint plugins, and provide examples of how to access type information. diff --git a/src/etc/test-float-parse/runtests.py b/src/etc/test-float-parse/runtests.py index 7106078f897cf..218552a45972d 100644 --- a/src/etc/test-float-parse/runtests.py +++ b/src/etc/test-float-parse/runtests.py @@ -193,11 +193,12 @@ def interact(proc, queue): def main(): global MAILBOX - tests = [os.path.splitext(f)[0] for f in glob('*.rs') - if not f.startswith('_')] - listed = sys.argv[1:] - if listed: - tests = [test for test in tests if test in listed] + all_tests = [os.path.splitext(f)[0] for f in glob('*.rs') if not f.startswith('_')] + args = sys.argv[1:] + if args: + tests = [test for test in all_tests if test in args] + else + tests = all_tests if not tests: print("Error: No tests to run") sys.exit(1) diff --git a/src/librustc_ast/Cargo.toml b/src/librustc_ast/Cargo.toml index 6bd65fd5f96c7..a36f49bd4146b 100644 --- a/src/librustc_ast/Cargo.toml +++ b/src/librustc_ast/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_serialize = { path = "../librustc_serialize" } -log = "0.4" +log = { package = "tracing", version = "0.1" } scoped-tls = "1.0" rustc_span = { path = "../librustc_span" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_ast_lowering/Cargo.toml b/src/librustc_ast_lowering/Cargo.toml index d71eb4fcd5c27..51f34a1b78e97 100644 --- a/src/librustc_ast_lowering/Cargo.toml +++ b/src/librustc_ast_lowering/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_arena = { path = "../librustc_arena" } -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_hir = { path = "../librustc_hir" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_ast_passes/Cargo.toml b/src/librustc_ast_passes/Cargo.toml index e4d1d79abb2d6..c53089a4afc5c 100644 --- a/src/librustc_ast_passes/Cargo.toml +++ b/src/librustc_ast_passes/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" [dependencies] itertools = "0.8" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_ast_pretty/Cargo.toml b/src/librustc_ast_pretty/Cargo.toml index 6c076d2c5b866..4035346d35446 100644 --- a/src/librustc_ast_pretty/Cargo.toml +++ b/src/librustc_ast_pretty/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" doctest = false [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_span = { path = "../librustc_span" } rustc_ast = { path = "../librustc_ast" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_builtin_macros/Cargo.toml b/src/librustc_builtin_macros/Cargo.toml index fdb6c359052d0..c612781153e8f 100644 --- a/src/librustc_builtin_macros/Cargo.toml +++ b/src/librustc_builtin_macros/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_parse_format = { path = "../librustc_parse_format" } -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_codegen_llvm/Cargo.toml b/src/librustc_codegen_llvm/Cargo.toml index bedefcc30ed8c..ec4dfabdcc2f0 100644 --- a/src/librustc_codegen_llvm/Cargo.toml +++ b/src/librustc_codegen_llvm/Cargo.toml @@ -15,7 +15,7 @@ bitflags = "1.0" flate2 = "1.0" libc = "0.2" measureme = "0.7.1" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc-demangle = "0.1" rustc_attr = { path = "../librustc_attr" } diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index 236f7f696533d..728af7b0a8cd1 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -90,64 +90,69 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { args: &Vec>, caller_instance: ty::Instance<'tcx>, ) -> bool { + let mut is_codegen_intrinsic = true; + // Set `is_codegen_intrinsic` to `false` to bypass `codegen_intrinsic_call()`. + if self.tcx.sess.opts.debugging_opts.instrument_coverage { - // Add the coverage information from the MIR to the Codegen context. Some coverage - // intrinsics are used only to pass along the coverage information (returns `false` - // for `is_codegen_intrinsic()`), but `count_code_region` is also converted into an - // LLVM intrinsic to increment a coverage counter. - match intrinsic { - sym::count_code_region => { - use coverage::count_code_region_args::*; - self.add_counter_region( - caller_instance, - op_to_u64(&args[FUNCTION_SOURCE_HASH]), - op_to_u32(&args[COUNTER_ID]), - op_to_u32(&args[START_BYTE_POS]), - op_to_u32(&args[END_BYTE_POS]), - ); - return true; // Also inject the counter increment in the backend - } - sym::coverage_counter_add | sym::coverage_counter_subtract => { - use coverage::coverage_counter_expression_args::*; - self.add_counter_expression_region( - caller_instance, - op_to_u32(&args[EXPRESSION_ID]), - op_to_u32(&args[LEFT_ID]), - if intrinsic == sym::coverage_counter_add { - ExprKind::Add - } else { - ExprKind::Subtract - }, - op_to_u32(&args[RIGHT_ID]), - op_to_u32(&args[START_BYTE_POS]), - op_to_u32(&args[END_BYTE_POS]), - ); - return false; // Does not inject backend code + // If the intrinsic is from the local MIR, add the coverage information to the Codegen + // context, to be encoded into the local crate's coverage map. + if caller_instance.def_id().is_local() { + // FIXME(richkadel): Make sure to add coverage analysis tests on a crate with + // external crate dependencies, where: + // 1. Both binary and dependent crates are compiled with `-Zinstrument-coverage` + // 2. Only binary is compiled with `-Zinstrument-coverage` + // 3. Only dependent crates are compiled with `-Zinstrument-coverage` + match intrinsic { + sym::count_code_region => { + use coverage::count_code_region_args::*; + self.add_counter_region( + caller_instance, + op_to_u64(&args[FUNCTION_SOURCE_HASH]), + op_to_u32(&args[COUNTER_ID]), + op_to_u32(&args[START_BYTE_POS]), + op_to_u32(&args[END_BYTE_POS]), + ); + } + sym::coverage_counter_add | sym::coverage_counter_subtract => { + use coverage::coverage_counter_expression_args::*; + self.add_counter_expression_region( + caller_instance, + op_to_u32(&args[EXPRESSION_ID]), + op_to_u32(&args[LEFT_ID]), + if intrinsic == sym::coverage_counter_add { + ExprKind::Add + } else { + ExprKind::Subtract + }, + op_to_u32(&args[RIGHT_ID]), + op_to_u32(&args[START_BYTE_POS]), + op_to_u32(&args[END_BYTE_POS]), + ); + } + sym::coverage_unreachable => { + use coverage::coverage_unreachable_args::*; + self.add_unreachable_region( + caller_instance, + op_to_u32(&args[START_BYTE_POS]), + op_to_u32(&args[END_BYTE_POS]), + ); + } + _ => {} } - sym::coverage_unreachable => { - use coverage::coverage_unreachable_args::*; - self.add_unreachable_region( - caller_instance, - op_to_u32(&args[START_BYTE_POS]), - op_to_u32(&args[END_BYTE_POS]), - ); - return false; // Does not inject backend code + } + + // Only the `count_code_region` coverage intrinsic is translated into an actual LLVM + // intrinsic call (local or not); otherwise, set `is_codegen_intrinsic` to `false`. + match intrinsic { + sym::coverage_counter_add + | sym::coverage_counter_subtract + | sym::coverage_unreachable => { + is_codegen_intrinsic = false; } _ => {} } - } else { - // NOT self.tcx.sess.opts.debugging_opts.instrument_coverage - if intrinsic == sym::count_code_region { - // An external crate may have been pre-compiled with coverage instrumentation, and - // some references from the current crate to the external crate might carry along - // the call terminators to coverage intrinsics, like `count_code_region` (for - // example, when instantiating a generic function). If the current crate has - // `instrument_coverage` disabled, the `count_code_region` call terminators should - // be ignored. - return false; // Do not inject coverage counters inlined from external crates - } } - true // Unhandled intrinsics should be passed to `codegen_intrinsic_call()` + is_codegen_intrinsic } fn codegen_intrinsic_call( diff --git a/src/librustc_codegen_ssa/Cargo.toml b/src/librustc_codegen_ssa/Cargo.toml index e100e0095c92a..8fa0de37648f3 100644 --- a/src/librustc_codegen_ssa/Cargo.toml +++ b/src/librustc_codegen_ssa/Cargo.toml @@ -14,7 +14,7 @@ bitflags = "1.2.1" cc = "1.0.1" num_cpus = "1.0" memmap = "0.7" -log = "0.4.5" +log = { package = "tracing", version = "0.1" } libc = "0.2.50" jobserver = "0.1.11" tempfile = "3.1" diff --git a/src/librustc_codegen_ssa/coverageinfo/map.rs b/src/librustc_codegen_ssa/coverageinfo/map.rs index 1e36c90baafdf..72138065a90ba 100644 --- a/src/librustc_codegen_ssa/coverageinfo/map.rs +++ b/src/librustc_codegen_ssa/coverageinfo/map.rs @@ -86,7 +86,11 @@ impl Region { pub fn new(source_map: &SourceMap, start_byte_pos: u32, end_byte_pos: u32) -> Self { let start = source_map.lookup_char_pos(BytePos::from_u32(start_byte_pos)); let end = source_map.lookup_char_pos(BytePos::from_u32(end_byte_pos)); - assert_eq!(start.file.name, end.file.name); + assert_eq!( + start.file.name, end.file.name, + "Region start ({} -> {:?}) and end ({} -> {:?}) don't come from the same source file!", + start_byte_pos, start, end_byte_pos, end + ); Self { start, end } } diff --git a/src/librustc_data_structures/Cargo.toml b/src/librustc_data_structures/Cargo.toml index 1c2fb90b2d8b4..811d1e49626c4 100644 --- a/src/librustc_data_structures/Cargo.toml +++ b/src/librustc_data_structures/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] ena = "0.14" indexmap = "1" -log = "0.4" +log = { package = "tracing", version = "0.1" } jobserver_crate = { version = "0.1.13", package = "jobserver" } lazy_static = "1" once_cell = { version = "1", features = ["parking_lot"] } diff --git a/src/librustc_driver/Cargo.toml b/src/librustc_driver/Cargo.toml index 75d6592076655..6474a69b216a9 100644 --- a/src/librustc_driver/Cargo.toml +++ b/src/librustc_driver/Cargo.toml @@ -12,8 +12,8 @@ crate-type = ["dylib"] [dependencies] lazy_static = "1.0" libc = "0.2" -log = "0.4" -env_logger = { version = "0.7", default-features = false } +log = { package = "tracing", version = "0.1.18", features = ["release_max_level_info"] } +tracing-subscriber = { version = "0.2.10", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] } rustc_middle = { path = "../librustc_middle" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index ab4eac9440b41..7af640c109ed5 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1224,9 +1224,26 @@ pub fn install_ice_hook() { } /// This allows tools to enable rust logging without having to magically match rustc's -/// log crate version +/// log crate version. pub fn init_rustc_env_logger() { - env_logger::init_from_env("RUSTC_LOG"); + init_env_logger("RUSTC_LOG") +} + +/// This allows tools to enable rust logging without having to magically match rustc's +/// log crate version. In contrast to `init_rustc_env_logger` it allows you to choose an env var +/// other than `RUSTC_LOG`. +pub fn init_env_logger(env: &str) { + // Don't register a dispatcher if there's no filter to print anything + match std::env::var(env) { + Err(_) => return, + Ok(s) if s.is_empty() => return, + Ok(_) => {} + } + let builder = tracing_subscriber::FmtSubscriber::builder(); + + let builder = builder.with_env_filter(tracing_subscriber::EnvFilter::from_env(env)); + + builder.init() } pub fn main() -> ! { diff --git a/src/librustc_error_codes/error_codes/E0730.md b/src/librustc_error_codes/error_codes/E0730.md index c2a71ca5669a1..016b3f38aa310 100644 --- a/src/librustc_error_codes/error_codes/E0730.md +++ b/src/librustc_error_codes/error_codes/E0730.md @@ -1,6 +1,6 @@ An array without a fixed length was pattern-matched. -Example of erroneous code: +Erroneous code example: ```compile_fail,E0730 #![feature(const_generics)] @@ -14,14 +14,28 @@ fn is_123(x: [u32; N]) -> bool { } ``` -Ensure that the pattern is consistent with the size of the matched -array. Additional elements can be matched with `..`: +To fix this error, you have two solutions: + 1. Use an array with a fixed length. + 2. Use a slice. +Example with an array with a fixed length: + +``` +fn is_123(x: [u32; 3]) -> bool { // We use an array with a fixed size + match x { + [1, 2, ..] => true, // ok! + _ => false + } +} ``` -let r = &[1, 2, 3, 4]; -match r { - &[a, b, ..] => { // ok! - println!("a={}, b={}", a, b); + +Example with a slice: + +``` +fn is_123(x: &[u32]) -> bool { // We use a slice + match x { + [1, 2, ..] => true, // ok! + _ => false } } ``` diff --git a/src/librustc_error_codes/error_codes/E0734.md b/src/librustc_error_codes/error_codes/E0734.md index 7506c8e693ed8..4b8e89a70604d 100644 --- a/src/librustc_error_codes/error_codes/E0734.md +++ b/src/librustc_error_codes/error_codes/E0734.md @@ -1,6 +1,6 @@ A stability attribute has been used outside of the standard library. -Erroneous code examples: +Erroneous code example: ```compile_fail,E0734 #[rustc_deprecated(since = "b", reason = "text")] // invalid diff --git a/src/librustc_error_codes/error_codes/E0740.md b/src/librustc_error_codes/error_codes/E0740.md index 3777678518964..6240099a99f67 100644 --- a/src/librustc_error_codes/error_codes/E0740.md +++ b/src/librustc_error_codes/error_codes/E0740.md @@ -1,4 +1,4 @@ -A `union` cannot have fields with destructors. +A `union` was declared with fields with destructors. Erroneous code example: @@ -14,3 +14,5 @@ impl Drop for A { fn drop(&mut self) { println!("A"); } } ``` + +A `union` cannot have fields with destructors. diff --git a/src/librustc_error_codes/error_codes/E0741.md b/src/librustc_error_codes/error_codes/E0741.md index 0a8650282a374..91379bfe05c65 100644 --- a/src/librustc_error_codes/error_codes/E0741.md +++ b/src/librustc_error_codes/error_codes/E0741.md @@ -1,5 +1,6 @@ -Only structural-match types (that is, types that derive `PartialEq` and `Eq`) -may be used as the types of const generic parameters. +A non-structural-match type was used as the type of a const generic parameter. + +Erroneous code example: ```compile_fail,E0741 #![feature(const_generics)] @@ -9,12 +10,15 @@ struct A; struct B; // error! ``` -To fix this example, we derive `PartialEq` and `Eq`. +Only structural-match types (that is, types that derive `PartialEq` and `Eq`) +may be used as the types of const generic parameters. + +To fix the previous code example, we derive `PartialEq` and `Eq`: ``` #![feature(const_generics)] -#[derive(PartialEq, Eq)] +#[derive(PartialEq, Eq)] // We derive both traits here. struct A; struct B; // ok! diff --git a/src/librustc_error_codes/error_codes/E0743.md b/src/librustc_error_codes/error_codes/E0743.md index 1780fe59cbd69..ddd3136df0c39 100644 --- a/src/librustc_error_codes/error_codes/E0743.md +++ b/src/librustc_error_codes/error_codes/E0743.md @@ -8,10 +8,9 @@ Erroneous code example: fn foo2(x: u8, y: &...) {} // error! ``` -Only foreign functions can use the C-variadic type (`...`). -In such functions, `...` may only occur non-nested. -That is, `y: &'a ...` is not allowed. +Only foreign functions can use the C-variadic type (`...`). In such functions, +`...` may only occur non-nested. That is, `y: &'a ...` is not allowed. -A C-variadic type is used to give an undefined number -of parameters to a given function (like `printf` in C). -The equivalent in Rust would be to use macros directly. +A C-variadic type is used to give an undefined number of parameters to a given +function (like `printf` in C). The equivalent in Rust would be to use macros +directly (like `println!` for example). diff --git a/src/librustc_errors/Cargo.toml b/src/librustc_errors/Cargo.toml index 7f72161aff826..d0f04c3fe7647 100644 --- a/src/librustc_errors/Cargo.toml +++ b/src/librustc_errors/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" doctest = false [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_serialize = { path = "../librustc_serialize" } rustc_span = { path = "../librustc_span" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_expand/Cargo.toml b/src/librustc_expand/Cargo.toml index ef617acfe1314..bdf039c36abf6 100644 --- a/src/librustc_expand/Cargo.toml +++ b/src/librustc_expand/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] rustc_serialize = { path = "../librustc_serialize" } -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_span = { path = "../librustc_span" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_ast_passes = { path = "../librustc_ast_passes" } diff --git a/src/librustc_hir/Cargo.toml b/src/librustc_hir/Cargo.toml index 1b91d769c7047..4a404e176e148 100644 --- a/src/librustc_hir/Cargo.toml +++ b/src/librustc_hir/Cargo.toml @@ -18,5 +18,5 @@ rustc_span = { path = "../librustc_span" } rustc_serialize = { path = "../librustc_serialize" } rustc_ast = { path = "../librustc_ast" } lazy_static = "1" -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } diff --git a/src/librustc_incremental/Cargo.toml b/src/librustc_incremental/Cargo.toml index 7b3030fa1d9c1..60a87078d63cf 100644 --- a/src/librustc_incremental/Cargo.toml +++ b/src/librustc_incremental/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_graphviz = { path = "../librustc_graphviz" } -log = "0.4" +log = { package = "tracing", version = "0.1" } rand = "0.7" rustc_middle = { path = "../librustc_middle" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_infer/Cargo.toml b/src/librustc_infer/Cargo.toml index 06fc7ecf95f26..9d56fa223a9cb 100644 --- a/src/librustc_infer/Cargo.toml +++ b/src/librustc_infer/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_graphviz = { path = "../librustc_graphviz" } -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } diff --git a/src/librustc_interface/Cargo.toml b/src/librustc_interface/Cargo.toml index 112dc7037f588..5c7edc10dd5c7 100644 --- a/src/librustc_interface/Cargo.toml +++ b/src/librustc_interface/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] libc = "0.2" -log = "0.4" +log = { package = "tracing", version = "0.1" } rayon = { version = "0.3.0", package = "rustc-rayon" } smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_ast = { path = "../librustc_ast" } diff --git a/src/librustc_lint/Cargo.toml b/src/librustc_lint/Cargo.toml index 58c15257326ae..3ba1566023d28 100644 --- a/src/librustc_lint/Cargo.toml +++ b/src/librustc_lint/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_lint" path = "lib.rs" [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } unicode-security = "0.0.5" rustc_middle = { path = "../librustc_middle" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 06e7c2b6f3625..e32c8fbee6852 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -2209,7 +2209,7 @@ impl ClashingExternDeclarations { } (Slice(a_ty), Slice(b_ty)) => Self::structurally_same_type(cx, a_ty, b_ty, ckind), (RawPtr(a_tymut), RawPtr(b_tymut)) => { - a_tymut.mutbl == a_tymut.mutbl + a_tymut.mutbl == b_tymut.mutbl && Self::structurally_same_type(cx, &a_tymut.ty, &b_tymut.ty, ckind) } (Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => { diff --git a/src/librustc_lint/lib.rs b/src/librustc_lint/lib.rs index ab30d545edfc3..15a9affbff7e9 100644 --- a/src/librustc_lint/lib.rs +++ b/src/librustc_lint/lib.rs @@ -61,8 +61,8 @@ use rustc_hir::def_id::LocalDefId; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::{ - BARE_TRAIT_OBJECTS, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_OUTLIVES_REQUIREMENTS, - INTRA_DOC_LINK_RESOLUTION_FAILURE, INVALID_CODEBLOCK_ATTRIBUTES, MISSING_DOC_CODE_EXAMPLES, + BARE_TRAIT_OBJECTS, BROKEN_INTRA_DOC_LINKS, ELIDED_LIFETIMES_IN_PATHS, + EXPLICIT_OUTLIVES_REQUIREMENTS, INVALID_CODEBLOCK_ATTRIBUTES, MISSING_DOC_CODE_EXAMPLES, PRIVATE_DOC_TESTS, }; use rustc_span::symbol::{Ident, Symbol}; @@ -303,7 +303,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { add_lint_group!( "rustdoc", - INTRA_DOC_LINK_RESOLUTION_FAILURE, + BROKEN_INTRA_DOC_LINKS, INVALID_CODEBLOCK_ATTRIBUTES, MISSING_DOC_CODE_EXAMPLES, PRIVATE_DOC_TESTS @@ -318,6 +318,7 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) { store.register_renamed("async_idents", "keyword_idents"); store.register_renamed("exceeding_bitshifts", "arithmetic_overflow"); store.register_renamed("redundant_semicolon", "redundant_semicolons"); + store.register_renamed("intra_doc_link_resolution_failure", "broken_intra_doc_links"); store.register_removed("unknown_features", "replaced by an error"); store.register_removed("unsigned_negation", "replaced by negate_unsigned feature gate"); store.register_removed("negate_unsigned", "cast a signed value instead"); diff --git a/src/librustc_metadata/Cargo.toml b/src/librustc_metadata/Cargo.toml index 7bbe7567d2924..2c0e2aa39fd59 100644 --- a/src/librustc_metadata/Cargo.toml +++ b/src/librustc_metadata/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] flate2 = "1.0" libc = "0.2" -log = "0.4" +log = { package = "tracing", version = "0.1" } memmap = "0.7" smallvec = { version = "1.0", features = ["union", "may_dangle"] } rustc_middle = { path = "../librustc_middle" } diff --git a/src/librustc_metadata/creader.rs b/src/librustc_metadata/creader.rs index 25320a8d6a785..a4ccc8c74c849 100644 --- a/src/librustc_metadata/creader.rs +++ b/src/librustc_metadata/creader.rs @@ -248,9 +248,9 @@ impl<'a> CrateLoader<'a> { // Only use `--extern crate_name=path` here, not `--extern crate_name`. if let Some(mut files) = entry.files() { if files.any(|l| { - let l = fs::canonicalize(l).ok(); - source.dylib.as_ref().map(|p| &p.0) == l.as_ref() - || source.rlib.as_ref().map(|p| &p.0) == l.as_ref() + let l = fs::canonicalize(l).unwrap_or(l.clone().into()); + source.dylib.as_ref().map(|p| &p.0) == Some(&l) + || source.rlib.as_ref().map(|p| &p.0) == Some(&l) }) { ret = Some(cnum); } diff --git a/src/librustc_metadata/locator.rs b/src/librustc_metadata/locator.rs index 371ec4cd91148..8828b318d1ea6 100644 --- a/src/librustc_metadata/locator.rs +++ b/src/librustc_metadata/locator.rs @@ -426,20 +426,17 @@ impl<'a> CrateLocator<'a> { info!("lib candidate: {}", spf.path.display()); let (rlibs, rmetas, dylibs) = candidates.entry(hash.to_string()).or_default(); - fs::canonicalize(&spf.path) - .map(|p| { - if seen_paths.contains(&p) { - return FileDoesntMatch; - }; - seen_paths.insert(p.clone()); - match found_kind { - CrateFlavor::Rlib => rlibs.insert(p, kind), - CrateFlavor::Rmeta => rmetas.insert(p, kind), - CrateFlavor::Dylib => dylibs.insert(p, kind), - }; - FileMatches - }) - .unwrap_or(FileDoesntMatch) + let path = fs::canonicalize(&spf.path).unwrap_or_else(|_| spf.path.clone()); + if seen_paths.contains(&path) { + return FileDoesntMatch; + }; + seen_paths.insert(path.clone()); + match found_kind { + CrateFlavor::Rlib => rlibs.insert(path, kind), + CrateFlavor::Rmeta => rmetas.insert(path, kind), + CrateFlavor::Dylib => dylibs.insert(path, kind), + }; + FileMatches }); self.rejected_via_kind.extend(staticlibs); @@ -688,12 +685,13 @@ impl<'a> CrateLocator<'a> { && file.ends_with(&self.target.options.dll_suffix) { // Make sure there's at most one rlib and at most one dylib. + let loc = fs::canonicalize(&loc).unwrap_or_else(|_| loc.clone()); if loc.file_name().unwrap().to_str().unwrap().ends_with(".rlib") { - rlibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + rlibs.insert(loc, PathKind::ExternFlag); } else if loc.file_name().unwrap().to_str().unwrap().ends_with(".rmeta") { - rmetas.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + rmetas.insert(loc, PathKind::ExternFlag); } else { - dylibs.insert(fs::canonicalize(&loc).unwrap(), PathKind::ExternFlag); + dylibs.insert(loc, PathKind::ExternFlag); } } else { self.rejected_via_filename diff --git a/src/librustc_middle/Cargo.toml b/src/librustc_middle/Cargo.toml index 02d82c6793386..678fcfe65394b 100644 --- a/src/librustc_middle/Cargo.toml +++ b/src/librustc_middle/Cargo.toml @@ -13,7 +13,7 @@ doctest = false rustc_arena = { path = "../librustc_arena" } bitflags = "1.2.1" scoped-tls = "1.0" -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } rustc-rayon-core = "0.3.0" polonius-engine = "0.12.0" rustc_apfloat = { path = "../librustc_apfloat" } diff --git a/src/librustc_middle/mir/interpret/queries.rs b/src/librustc_middle/mir/interpret/queries.rs index d7c0be058599f..442e7f6b0f45e 100644 --- a/src/librustc_middle/mir/interpret/queries.rs +++ b/src/librustc_middle/mir/interpret/queries.rs @@ -18,7 +18,7 @@ impl<'tcx> TyCtxt<'tcx> { let substs = InternalSubsts::identity_for_item(self, def_id); let instance = ty::Instance::new(def_id, substs); let cid = GlobalId { instance, promoted: None }; - let param_env = self.param_env(def_id).with_reveal_all(); + let param_env = self.param_env(def_id).with_reveal_all_normalized(self); self.const_eval_global_id(param_env, cid, None) } diff --git a/src/librustc_middle/mir/interpret/value.rs b/src/librustc_middle/mir/interpret/value.rs index 9de2d17457ab1..2c76f0b5ad022 100644 --- a/src/librustc_middle/mir/interpret/value.rs +++ b/src/librustc_middle/mir/interpret/value.rs @@ -78,7 +78,7 @@ impl<'tcx> ConstValue<'tcx> { param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> Option { - let size = tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size; + let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size; self.try_to_bits(size) } diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index f857af28622d1..69f1366abf8ec 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -864,11 +864,17 @@ rustc_queries! { /// type-checking etc, and it does not normalize specializable /// associated types. This is almost always what you want, /// unless you are doing MIR optimizations, in which case you - /// might want to use `reveal_all()` method to change modes. query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> { desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) } } + /// Like `param_env`, but returns the `ParamEnv in `Reveal::All` mode. + /// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`, + /// as this method is more efficient. + query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> { + desc { |tcx| "computing revealed normalized predicates of `{}`", tcx.def_path_str(def_id) } + } + /// Trait selection queries. These are best used by invoking `ty.is_copy_modulo_regions()`, /// `ty.is_copy()`, etc, since that will prune the environment where possible. query is_copy_raw(env: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { @@ -1527,5 +1533,9 @@ rustc_queries! { ty::Instance::new(key.value.0.to_def_id(), key.value.2), } } + + query normalize_opaque_types(key: &'tcx ty::List>) -> &'tcx ty::List> { + desc { "normalizing opaque types in {:?}", key } + } } } diff --git a/src/librustc_middle/ty/consts.rs b/src/librustc_middle/ty/consts.rs index f3a863c3fce62..c0b5693dc594e 100644 --- a/src/librustc_middle/ty/consts.rs +++ b/src/librustc_middle/ty/consts.rs @@ -158,7 +158,7 @@ impl<'tcx> Const<'tcx> { ty: Ty<'tcx>, ) -> Option { assert_eq!(self.ty, ty); - let size = tcx.layout_of(param_env.with_reveal_all().and(ty)).ok()?.size; + let size = tcx.layout_of(param_env.with_reveal_all_normalized(tcx).and(ty)).ok()?.size; // if `ty` does not depend on generic parameters, use an empty param_env self.val.eval(tcx, param_env).try_to_bits(size) } diff --git a/src/librustc_middle/ty/consts/kind.rs b/src/librustc_middle/ty/consts/kind.rs index 75287ff7dace3..e8a1e714a8f43 100644 --- a/src/librustc_middle/ty/consts/kind.rs +++ b/src/librustc_middle/ty/consts/kind.rs @@ -96,12 +96,16 @@ impl<'tcx> ConstKind<'tcx> { if let ConstKind::Unevaluated(def, substs, promoted) = self { use crate::mir::interpret::ErrorHandled; - let param_env_and_substs = param_env.with_reveal_all().and(substs); - // HACK(eddyb) this erases lifetimes even though `const_eval_resolve` // also does later, but we want to do it before checking for // inference variables. - let param_env_and_substs = tcx.erase_regions(¶m_env_and_substs); + // Note that we erase regions *before* calling `with_reveal_all_normalized`, + // so that we don't try to invoke this query with + // any region variables. + let param_env_and_substs = tcx + .erase_regions(¶m_env) + .with_reveal_all_normalized(tcx) + .and(tcx.erase_regions(&substs)); // HACK(eddyb) when the query key would contain inference variables, // attempt using identity substs and `ParamEnv` instead, that will succeed diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d307131a99036..775d755444d7d 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -352,7 +352,7 @@ pub struct TypeckResults<'tcx> { pat_binding_modes: ItemLocalMap, /// Stores the types which were implicitly dereferenced in pattern binding modes - /// for later usage in HAIR lowering. For example, + /// for later usage in THIR lowering. For example, /// /// ``` /// match &&Some(5i32) { diff --git a/src/librustc_middle/ty/layout.rs b/src/librustc_middle/ty/layout.rs index 215f44819b5d1..143d3c4e1e92b 100644 --- a/src/librustc_middle/ty/layout.rs +++ b/src/librustc_middle/ty/layout.rs @@ -1903,7 +1903,7 @@ impl<'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'tcx>> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { - let param_env = self.param_env.with_reveal_all(); + let param_env = self.param_env.with_reveal_all_normalized(self.tcx); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let layout = self.tcx.layout_raw(param_env.and(ty))?; let layout = TyAndLayout { ty, layout }; @@ -1927,7 +1927,7 @@ impl LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'tcx>> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyAndLayout { - let param_env = self.param_env.with_reveal_all(); + let param_env = self.param_env.with_reveal_all_normalized(*self.tcx); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let layout = self.tcx.layout_raw(param_env.and(ty))?; let layout = TyAndLayout { ty, layout }; diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 6e77aab277720..bd45f866abc8b 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1,5 +1,5 @@ // ignore-tidy-filelength -pub use self::fold::{TypeFoldable, TypeVisitor}; +pub use self::fold::{TypeFoldable, TypeFolder, TypeVisitor}; pub use self::AssocItemContainer::*; pub use self::BorrowKind::*; pub use self::IntVarValue::*; @@ -1874,9 +1874,15 @@ impl<'tcx> ParamEnv<'tcx> { /// the desired behavior during codegen and certain other special /// contexts; normally though we want to use `Reveal::UserFacing`, /// which is the default. - pub fn with_reveal_all(mut self) -> Self { - self.packed_data |= 1; - self + /// All opaque types in the caller_bounds of the `ParamEnv` + /// will be normalized to their underlying types. + /// See PR #65989 and issue #65918 for more details + pub fn with_reveal_all_normalized(self, tcx: TyCtxt<'tcx>) -> Self { + if self.packed_data & 1 == 1 { + return self; + } + + ParamEnv::new(tcx.normalize_opaque_types(self.caller_bounds()), Reveal::All, self.def_id) } /// Returns this same environment but with no caller bounds. @@ -3116,6 +3122,7 @@ pub fn provide(providers: &mut ty::query::Providers) { context::provide(providers); erase_regions::provide(providers); layout::provide(providers); + util::provide(providers); super::util::bug::provide(providers); *providers = ty::query::Providers { trait_impls_of: trait_def::trait_impls_of_provider, diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index cb2b7a662cb4c..3f7a20bba2b9a 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -270,6 +270,17 @@ impl<'tcx> Key for Ty<'tcx> { } } +impl<'tcx> Key for &'tcx ty::List> { + type CacheSelector = DefaultCacheSelector; + + fn query_crate(&self) -> CrateNum { + LOCAL_CRATE + } + fn default_span(&self, _: TyCtxt<'_>) -> Span { + DUMMY_SP + } +} + impl<'tcx> Key for ty::ParamEnv<'tcx> { type CacheSelector = DefaultCacheSelector; diff --git a/src/librustc_middle/ty/util.rs b/src/librustc_middle/ty/util.rs index adba45facc9b4..db78fa535cf42 100644 --- a/src/librustc_middle/ty/util.rs +++ b/src/librustc_middle/ty/util.rs @@ -3,11 +3,12 @@ use crate::ich::NodeIdHashingMode; use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::mir::interpret::{sign_extend, truncate}; +use crate::ty::fold::TypeFolder; use crate::ty::layout::IntegerExt; use crate::ty::query::TyCtxtAt; use crate::ty::subst::{GenericArgKind, InternalSubsts, Subst, SubstsRef}; use crate::ty::TyKind::*; -use crate::ty::{self, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable}; +use crate::ty::{self, DefIdTree, GenericParamDefKind, List, Ty, TyCtxt, TypeFoldable}; use rustc_apfloat::Float as _; use rustc_ast::ast; use rustc_attr::{self as attr, SignedInt, UnsignedInt}; @@ -557,82 +558,84 @@ impl<'tcx> TyCtxt<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, ) -> Result, Ty<'tcx>> { - use crate::ty::fold::TypeFolder; - - struct OpaqueTypeExpander<'tcx> { - // Contains the DefIds of the opaque types that are currently being - // expanded. When we expand an opaque type we insert the DefId of - // that type, and when we finish expanding that type we remove the - // its DefId. - seen_opaque_tys: FxHashSet, - // Cache of all expansions we've seen so far. This is a critical - // optimization for some large types produced by async fn trees. - expanded_cache: FxHashMap<(DefId, SubstsRef<'tcx>), Ty<'tcx>>, - primary_def_id: DefId, - found_recursion: bool, - tcx: TyCtxt<'tcx>, - } - - impl<'tcx> OpaqueTypeExpander<'tcx> { - fn expand_opaque_ty( - &mut self, - def_id: DefId, - substs: SubstsRef<'tcx>, - ) -> Option> { - if self.found_recursion { - return None; - } - let substs = substs.fold_with(self); - if self.seen_opaque_tys.insert(def_id) { - let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) { - Some(expanded_ty) => expanded_ty, - None => { - let generic_ty = self.tcx.type_of(def_id); - let concrete_ty = generic_ty.subst(self.tcx, substs); - let expanded_ty = self.fold_ty(concrete_ty); - self.expanded_cache.insert((def_id, substs), expanded_ty); - expanded_ty - } - }; - self.seen_opaque_tys.remove(&def_id); - Some(expanded_ty) - } else { - // If another opaque type that we contain is recursive, then it - // will report the error, so we don't have to. - self.found_recursion = def_id == self.primary_def_id; - None - } - } - } - - impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { - fn tcx(&self) -> TyCtxt<'tcx> { - self.tcx - } - - fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { - if let ty::Opaque(def_id, substs) = t.kind { - self.expand_opaque_ty(def_id, substs).unwrap_or(t) - } else if t.has_opaque_types() { - t.super_fold_with(self) - } else { - t - } - } - } - let mut visitor = OpaqueTypeExpander { seen_opaque_tys: FxHashSet::default(), expanded_cache: FxHashMap::default(), - primary_def_id: def_id, + primary_def_id: Some(def_id), found_recursion: false, + check_recursion: true, tcx: self, }; + let expanded_type = visitor.expand_opaque_ty(def_id, substs).unwrap(); if visitor.found_recursion { Err(expanded_type) } else { Ok(expanded_type) } } } +struct OpaqueTypeExpander<'tcx> { + // Contains the DefIds of the opaque types that are currently being + // expanded. When we expand an opaque type we insert the DefId of + // that type, and when we finish expanding that type we remove the + // its DefId. + seen_opaque_tys: FxHashSet, + // Cache of all expansions we've seen so far. This is a critical + // optimization for some large types produced by async fn trees. + expanded_cache: FxHashMap<(DefId, SubstsRef<'tcx>), Ty<'tcx>>, + primary_def_id: Option, + found_recursion: bool, + /// Whether or not to check for recursive opaque types. + /// This is `true` when we're explicitly checking for opaque type + /// recursion, and 'false' otherwise to avoid unecessary work. + check_recursion: bool, + tcx: TyCtxt<'tcx>, +} + +impl<'tcx> OpaqueTypeExpander<'tcx> { + fn expand_opaque_ty(&mut self, def_id: DefId, substs: SubstsRef<'tcx>) -> Option> { + if self.found_recursion { + return None; + } + let substs = substs.fold_with(self); + if !self.check_recursion || self.seen_opaque_tys.insert(def_id) { + let expanded_ty = match self.expanded_cache.get(&(def_id, substs)) { + Some(expanded_ty) => expanded_ty, + None => { + let generic_ty = self.tcx.type_of(def_id); + let concrete_ty = generic_ty.subst(self.tcx, substs); + let expanded_ty = self.fold_ty(concrete_ty); + self.expanded_cache.insert((def_id, substs), expanded_ty); + expanded_ty + } + }; + if self.check_recursion { + self.seen_opaque_tys.remove(&def_id); + } + Some(expanded_ty) + } else { + // If another opaque type that we contain is recursive, then it + // will report the error, so we don't have to. + self.found_recursion = def_id == *self.primary_def_id.as_ref().unwrap(); + None + } + } +} + +impl<'tcx> TypeFolder<'tcx> for OpaqueTypeExpander<'tcx> { + fn tcx(&self) -> TyCtxt<'tcx> { + self.tcx + } + + fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> { + if let ty::Opaque(def_id, substs) = t.kind { + self.expand_opaque_ty(def_id, substs).unwrap_or(t) + } else if t.has_opaque_types() { + t.super_fold_with(self) + } else { + t + } + } +} + impl<'tcx> ty::TyS<'tcx> { /// Returns the maximum value for the given numeric type (including `char`s) /// or returns `None` if the type is not numeric. @@ -1142,3 +1145,24 @@ pub fn needs_drop_components( #[derive(Copy, Clone, Debug, HashStable, RustcEncodable, RustcDecodable)] pub struct AlwaysRequiresDrop; + +/// Normalizes all opaque types in the given value, replacing them +/// with their underlying types. +pub fn normalize_opaque_types( + tcx: TyCtxt<'tcx>, + val: &'tcx List>, +) -> &'tcx List> { + let mut visitor = OpaqueTypeExpander { + seen_opaque_tys: FxHashSet::default(), + expanded_cache: FxHashMap::default(), + primary_def_id: None, + found_recursion: false, + check_recursion: false, + tcx, + }; + val.fold_with(&mut visitor) +} + +pub fn provide(providers: &mut ty::query::Providers) { + *providers = ty::query::Providers { normalize_opaque_types, ..*providers } +} diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml index aebce78e4018b..f05c47e0ed626 100644 --- a/src/librustc_mir/Cargo.toml +++ b/src/librustc_mir/Cargo.toml @@ -13,7 +13,7 @@ doctest = false either = "1.5.0" rustc_graphviz = { path = "../librustc_graphviz" } itertools = "0.8" -log = "0.4" +log = { package = "tracing", version = "0.1" } log_settings = "0.1.1" polonius-engine = "0.12.0" rustc_middle = { path = "../librustc_middle" } diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 60cf21552e9e9..78f149f6451e6 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -8,11 +8,14 @@ use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar}; use rustc_middle::mir::CastKind; use rustc_middle::ty::adjustment::PointerCast; use rustc_middle::ty::layout::{IntegerExt, TyAndLayout}; -use rustc_middle::ty::{self, Ty, TypeAndMut, TypeFoldable}; +use rustc_middle::ty::{self, Ty, TypeAndMut}; use rustc_span::symbol::sym; use rustc_target::abi::{Integer, LayoutOf, Variants}; -use super::{truncate, FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, PlaceTy}; +use super::{ + truncate, util::ensure_monomorphic_enough, FnVal, ImmTy, Immediate, InterpCx, Machine, OpTy, + PlaceTy, +}; impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { pub fn cast( @@ -47,9 +50,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match src.layout.ty.kind { ty::FnDef(def_id, substs) => { // All reifications must be monomorphic, bail out otherwise. - if src.layout.ty.needs_subst() { - throw_inval!(TooGeneric); - } + ensure_monomorphic_enough(*self.tcx, src.layout.ty)?; if self.tcx.has_attr(def_id, sym::rustc_args_required_const) { span_bug!( @@ -89,9 +90,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match src.layout.ty.kind { ty::Closure(def_id, substs) => { // All reifications must be monomorphic, bail out otherwise. - if src.layout.ty.needs_subst() { - throw_inval!(TooGeneric); - } + ensure_monomorphic_enough(*self.tcx, src.layout.ty)?; let instance = ty::Instance::resolve_closure( *self.tcx, diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 630b2890835da..1e9be09781508 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -718,6 +718,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } ); + if unwinding && self.frame_idx() == 0 { + throw_ub_format!("unwinding past the topmost frame of the stack"); + } + ::log_settings::settings().indentation -= 1; let frame = self.stack_mut().pop().expect("tried to pop a stack frame, but there were none"); @@ -818,11 +822,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx> { // FIXME: should we tell the user that there was a local which was never written to? if let LocalValue::Live(Operand::Indirect(MemPlace { ptr, .. })) = local { - trace!("deallocating local"); // All locals have a backing allocation, even if the allocation is empty // due to the local having ZST type. let ptr = ptr.assert_ptr(); - trace!("{:?}", self.memory.dump_alloc(ptr.alloc_id)); + trace!("deallocating local: {:?}", self.memory.dump_alloc(ptr.alloc_id)); self.memory.deallocate_local(ptr)?; }; Ok(()) diff --git a/src/librustc_mir/interpret/intrinsics.rs b/src/librustc_mir/interpret/intrinsics.rs index 9a21fc427a3e3..b45045716d18c 100644 --- a/src/librustc_mir/interpret/intrinsics.rs +++ b/src/librustc_mir/interpret/intrinsics.rs @@ -12,11 +12,13 @@ use rustc_middle::mir::{ }; use rustc_middle::ty; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{Ty, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; use rustc_target::abi::{Abi, LayoutOf as _, Primitive, Size}; -use super::{CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy}; +use super::{ + util::ensure_monomorphic_enough, CheckInAllocMsg, ImmTy, InterpCx, Machine, OpTy, PlaceTy, +}; mod caller_location; mod type_name; @@ -54,9 +56,7 @@ crate fn eval_nullary_intrinsic<'tcx>( let name = tcx.item_name(def_id); Ok(match name { sym::type_name => { - if tp_ty.needs_subst() { - throw_inval!(TooGeneric); - } + ensure_monomorphic_enough(tcx, tp_ty)?; let alloc = type_name::alloc_type_name(tcx, tp_ty); ConstValue::Slice { data: alloc, start: 0, end: alloc.len() } } @@ -72,9 +72,7 @@ crate fn eval_nullary_intrinsic<'tcx>( ConstValue::from_machine_usize(n, &tcx) } sym::type_id => { - if tp_ty.needs_subst() { - throw_inval!(TooGeneric); - } + ensure_monomorphic_enough(tcx, tp_ty)?; ConstValue::from_u64(tcx.type_id_hash(tp_ty)) } sym::variant_count => { diff --git a/src/librustc_mir/interpret/mod.rs b/src/librustc_mir/interpret/mod.rs index 5de9b502a37c4..ebb061f48518b 100644 --- a/src/librustc_mir/interpret/mod.rs +++ b/src/librustc_mir/interpret/mod.rs @@ -12,6 +12,7 @@ mod place; mod step; mod terminator; mod traits; +mod util; mod validity; mod visitor; diff --git a/src/librustc_mir/interpret/traits.rs b/src/librustc_mir/interpret/traits.rs index 589da04d6a387..77f4593fa162c 100644 --- a/src/librustc_mir/interpret/traits.rs +++ b/src/librustc_mir/interpret/traits.rs @@ -1,9 +1,10 @@ use std::convert::TryFrom; use rustc_middle::mir::interpret::{InterpResult, Pointer, PointerArithmetic, Scalar}; -use rustc_middle::ty::{self, Instance, Ty, TypeFoldable}; +use rustc_middle::ty::{self, Instance, Ty}; use rustc_target::abi::{Align, LayoutOf, Size}; +use super::util::ensure_monomorphic_enough; use super::{FnVal, InterpCx, Machine, MemoryKind}; impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { @@ -23,9 +24,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let (ty, poly_trait_ref) = self.tcx.erase_regions(&(ty, poly_trait_ref)); // All vtables must be monomorphic, bail out otherwise. - if ty.needs_subst() || poly_trait_ref.needs_subst() { - throw_inval!(TooGeneric); - } + ensure_monomorphic_enough(*self.tcx, ty)?; + ensure_monomorphic_enough(*self.tcx, poly_trait_ref)?; if let Some(&vtable) = self.vtables.get(&(ty, poly_trait_ref)) { // This means we guarantee that there are no duplicate vtables, we will diff --git a/src/librustc_mir/interpret/util.rs b/src/librustc_mir/interpret/util.rs new file mode 100644 index 0000000000000..c0eac8a9305ee --- /dev/null +++ b/src/librustc_mir/interpret/util.rs @@ -0,0 +1,73 @@ +use rustc_middle::mir::interpret::InterpResult; +use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor}; +use std::convert::TryInto; + +/// Returns `true` if a used generic parameter requires substitution. +crate fn ensure_monomorphic_enough<'tcx, T>(tcx: TyCtxt<'tcx>, ty: T) -> InterpResult<'tcx> +where + T: TypeFoldable<'tcx>, +{ + debug!("ensure_monomorphic_enough: ty={:?}", ty); + if !ty.needs_subst() { + return Ok(()); + } + + struct UsedParamsNeedSubstVisitor<'tcx> { + tcx: TyCtxt<'tcx>, + }; + + impl<'tcx> TypeVisitor<'tcx> for UsedParamsNeedSubstVisitor<'tcx> { + fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> bool { + if !c.needs_subst() { + return false; + } + + match c.val { + ty::ConstKind::Param(..) => true, + _ => c.super_visit_with(self), + } + } + + fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool { + if !ty.needs_subst() { + return false; + } + + match ty.kind { + ty::Param(_) => true, + ty::Closure(def_id, substs) + | ty::Generator(def_id, substs, ..) + | ty::FnDef(def_id, substs) => { + let unused_params = self.tcx.unused_generic_params(def_id); + for (index, subst) in substs.into_iter().enumerate() { + let index = index + .try_into() + .expect("more generic parameters than can fit into a `u32`"); + let is_used = + unused_params.contains(index).map(|unused| !unused).unwrap_or(true); + // Only recurse when generic parameters in fns, closures and generators + // are used and require substitution. + if is_used && subst.needs_subst() { + // Just in case there are closures or generators within this subst, + // recurse. + if subst.super_visit_with(self) { + // Only return when we find a parameter so the remaining substs + // are not skipped. + return true; + } + } + } + false + } + _ => ty.super_visit_with(self), + } + } + } + + let mut vis = UsedParamsNeedSubstVisitor { tcx }; + if ty.visit_with(&mut vis) { + throw_inval!(TooGeneric); + } else { + Ok(()) + } +} diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index bfa9bb9e0f0e1..6a7653b60752d 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -193,7 +193,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) ); } let patch = { - let param_env = tcx.param_env(def_id).with_reveal_all(); + let param_env = tcx.param_env_reveal_all_normalized(def_id); let mut elaborator = DropShimElaborator { body: &body, patch: MirPatch::new(&body), tcx, param_env }; let dropee = tcx.mk_place_deref(dropee_ptr); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a1db06e6aa3de..8e2fd709d66f0 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -328,7 +328,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ) -> ConstPropagator<'mir, 'tcx> { let def_id = source.def_id(); let substs = &InternalSubsts::identity_for_item(tcx, def_id); - let param_env = tcx.param_env(def_id).with_reveal_all(); + let param_env = tcx.param_env_reveal_all_normalized(def_id); let span = tcx.def_span(def_id); let can_const_prop = CanConstProp::check(body); diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index d3bfd872d16c2..ad49090bfc50c 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -25,7 +25,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateDrops { debug!("elaborate_drops({:?} @ {:?})", src, body.span); let def_id = src.def_id(); - let param_env = tcx.param_env(src.def_id()).with_reveal_all(); + let param_env = tcx.param_env_reveal_all_normalized(src.def_id()); let move_data = match MoveData::gather_moves(body, tcx, param_env) { Ok(move_data) => move_data, Err((move_data, _)) => { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index c03be2a8fcd69..92ea162e419db 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -72,7 +72,7 @@ impl Inliner<'tcx> { let mut callsites = VecDeque::new(); - let param_env = self.tcx.param_env(self.source.def_id()).with_reveal_all(); + let param_env = self.tcx.param_env_reveal_all_normalized(self.source.def_id()); // Only do inlining into fn bodies. let id = self.tcx.hir().as_local_hir_id(self.source.def_id().expect_local()); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 59a8415ef96f0..f68473480630b 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -502,9 +502,47 @@ impl<'tcx> Validator<'_, 'tcx> { fn validate_place(&self, place: PlaceRef<'tcx>) -> Result<(), Unpromotable> { match place { PlaceRef { local, projection: [] } => self.validate_local(local), - PlaceRef { local: _, projection: [proj_base @ .., elem] } => { + PlaceRef { local, projection: [proj_base @ .., elem] } => { match *elem { - ProjectionElem::Deref | ProjectionElem::Downcast(..) => { + ProjectionElem::Deref => { + let mut not_promotable = true; + // This is a special treatment for cases like *&STATIC where STATIC is a + // global static variable. + // This pattern is generated only when global static variables are directly + // accessed and is qualified for promotion safely. + if let TempState::Defined { location, .. } = self.temps[local] { + let def_stmt = + self.body[location.block].statements.get(location.statement_index); + if let Some(Statement { + kind: + StatementKind::Assign(box (_, Rvalue::Use(Operand::Constant(c)))), + .. + }) = def_stmt + { + if let Some(did) = c.check_static_ptr(self.tcx) { + if let Some(hir::ConstContext::Static(..)) = self.const_kind { + // The `is_empty` predicate is introduced to exclude the case + // where the projection operations are [ .field, * ]. + // The reason is because promotion will be illegal if field + // accesses preceed the dereferencing. + // Discussion can be found at + // https://github.com/rust-lang/rust/pull/74945#discussion_r463063247 + // There may be opportunity for generalization, but this needs to be + // accounted for. + if proj_base.is_empty() + && !self.tcx.is_thread_local_static(did) + { + not_promotable = false; + } + } + } + } + } + if not_promotable { + return Err(Unpromotable); + } + } + ProjectionElem::Downcast(..) => { return Err(Unpromotable); } diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 491c37cbe06e8..9288d6e16f5e0 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -33,6 +33,7 @@ use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::TyCtxt; +use smallvec::SmallVec; use std::borrow::Cow; pub struct SimplifyCfg { @@ -172,9 +173,12 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } } - // Collapse a goto chain starting from `start` - fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) { - let mut terminator = match self.basic_blocks[*start] { + /// This function will return `None` if + /// * the block has statements + /// * the block has a terminator other than `goto` + /// * the block has no terminator (meaning some other part of the current optimization stole it) + fn take_terminator_if_simple_goto(&mut self, bb: BasicBlock) -> Option> { + match self.basic_blocks[bb] { BasicBlockData { ref statements, terminator: @@ -183,32 +187,45 @@ impl<'a, 'tcx> CfgSimplifier<'a, 'tcx> { } if statements.is_empty() => terminator.take(), // if `terminator` is None, this means we are in a loop. In that // case, let all the loop collapse to its entry. - _ => return, - }; - - let target = match terminator { - Some(Terminator { kind: TerminatorKind::Goto { ref mut target }, .. }) => { - self.collapse_goto_chain(target, changed); - *target - } - _ => unreachable!(), - }; - self.basic_blocks[*start].terminator = terminator; - - debug!("collapsing goto chain from {:?} to {:?}", *start, target); - - *changed |= *start != target; + _ => None, + } + } - if self.pred_count[*start] == 1 { - // This is the last reference to *start, so the pred-count to - // to target is moved into the current block. - self.pred_count[*start] = 0; - } else { - self.pred_count[target] += 1; - self.pred_count[*start] -= 1; + /// Collapse a goto chain starting from `start` + fn collapse_goto_chain(&mut self, start: &mut BasicBlock, changed: &mut bool) { + // Using `SmallVec` here, because in some logs on libcore oli-obk saw many single-element + // goto chains. We should probably benchmark different sizes. + let mut terminators: SmallVec<[_; 1]> = Default::default(); + let mut current = *start; + while let Some(terminator) = self.take_terminator_if_simple_goto(current) { + let target = match terminator { + Terminator { kind: TerminatorKind::Goto { target }, .. } => target, + _ => unreachable!(), + }; + terminators.push((current, terminator)); + current = target; } + let last = current; + *start = last; + while let Some((current, mut terminator)) = terminators.pop() { + let target = match terminator { + Terminator { kind: TerminatorKind::Goto { ref mut target }, .. } => target, + _ => unreachable!(), + }; + *target = last; + debug!("collapsing goto chain from {:?} to {:?}", current, target); - *start = target; + if self.pred_count[current] == 1 { + // This is the last reference to current, so the pred-count to + // to target is moved into the current block. + self.pred_count[current] = 0; + } else { + self.pred_count[*target] += 1; + self.pred_count[current] -= 1; + } + *changed = true; + self.basic_blocks[current].terminator = Some(terminator); + } } // merge a block with 1 `goto` predecessor to its parent diff --git a/src/librustc_mir/transform/validate.rs b/src/librustc_mir/transform/validate.rs index e794a6949d2f0..b8a74f09409ca 100644 --- a/src/librustc_mir/transform/validate.rs +++ b/src/librustc_mir/transform/validate.rs @@ -189,7 +189,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { // Normalize projections and things like that. // FIXME: We need to reveal_all, as some optimizations change types in ways // that require unfolding opaque types. - let param_env = self.param_env.with_reveal_all(); + let param_env = self.param_env.with_reveal_all_normalized(self.tcx); let src = self.tcx.normalize_erasing_regions(param_env, src); let dest = self.tcx.normalize_erasing_regions(param_env, dest); diff --git a/src/librustc_mir_build/Cargo.toml b/src/librustc_mir_build/Cargo.toml index 401a5009e3cf7..96059fa43e521 100644 --- a/src/librustc_mir_build/Cargo.toml +++ b/src/librustc_mir_build/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_arena = { path = "../librustc_arena" } -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_apfloat = { path = "../librustc_apfloat" } rustc_attr = { path = "../librustc_attr" } diff --git a/src/librustc_mir_build/build/block.rs b/src/librustc_mir_build/build/block.rs index 2be4136ad42a0..d1cbf209b06ce 100644 --- a/src/librustc_mir_build/build/block.rs +++ b/src/librustc_mir_build/build/block.rs @@ -1,7 +1,7 @@ use crate::build::matches::ArmHasGuard; use crate::build::ForGuard::OutsideGuard; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_hir as hir; use rustc_middle::mir::*; use rustc_session::lint::builtin::UNSAFE_OP_IN_UNSAFE_FN; @@ -176,7 +176,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let tail_result_is_ignored = destination_ty.is_unit() || this.block_context.currently_ignores_tail_results(); let span = match expr { - ExprRef::Hair(expr) => expr.span, + ExprRef::Thir(expr) => expr.span, ExprRef::Mirror(ref expr) => expr.span, }; this.block_context.push(BlockFrame::TailExpr { tail_result_is_ignored, span }); @@ -235,11 +235,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .push_unsafe_count .checked_sub(1) .unwrap_or_else(|| span_bug!(span, "unsafe count underflow")); - if self.push_unsafe_count == 0 { - Some(self.unpushed_unsafe) - } else { - None - } + if self.push_unsafe_count == 0 { Some(self.unpushed_unsafe) } else { None } } }; diff --git a/src/librustc_mir_build/build/expr/as_constant.rs b/src/librustc_mir_build/build/expr/as_constant.rs index 03ec0b48f8bfe..982aefcf6045c 100644 --- a/src/librustc_mir_build/build/expr/as_constant.rs +++ b/src/librustc_mir_build/build/expr/as_constant.rs @@ -1,7 +1,7 @@ //! See docs in build/expr/mod.rs use crate::build::Builder; -use crate::hair::*; +use crate::thir::*; use rustc_middle::mir::*; use rustc_middle::ty::CanonicalUserTypeAnnotation; diff --git a/src/librustc_mir_build/build/expr/as_operand.rs b/src/librustc_mir_build/build/expr/as_operand.rs index 5949fd1e22ce8..aac93f313f4e1 100644 --- a/src/librustc_mir_build/build/expr/as_operand.rs +++ b/src/librustc_mir_build/build/expr/as_operand.rs @@ -2,7 +2,7 @@ use crate::build::expr::category::Category; use crate::build::{BlockAnd, BlockAndExtension, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_middle::middle::region; use rustc_middle::mir::*; diff --git a/src/librustc_mir_build/build/expr/as_place.rs b/src/librustc_mir_build/build/expr/as_place.rs index e811d68d5a5f8..1e3e104c2bad6 100644 --- a/src/librustc_mir_build/build/expr/as_place.rs +++ b/src/librustc_mir_build/build/expr/as_place.rs @@ -3,7 +3,7 @@ use crate::build::expr::category::Category; use crate::build::ForGuard::{OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_middle::middle::region; use rustc_middle::mir::AssertKind::BoundsCheck; use rustc_middle::mir::*; diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index e2217fdfac036..9c5fddc6b77c0 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -4,7 +4,7 @@ use rustc_index::vec::Idx; use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_middle::middle::region; use rustc_middle::mir::AssertKind; use rustc_middle::mir::*; diff --git a/src/librustc_mir_build/build/expr/as_temp.rs b/src/librustc_mir_build/build/expr/as_temp.rs index 901dadd661278..a9cc0cc2f2475 100644 --- a/src/librustc_mir_build/build/expr/as_temp.rs +++ b/src/librustc_mir_build/build/expr/as_temp.rs @@ -2,7 +2,7 @@ use crate::build::scope::DropKind; use crate::build::{BlockAnd, BlockAndExtension, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_middle::middle::region; @@ -67,12 +67,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ExprKind::StaticRef { def_id, .. } => { assert!(!this.hir.tcx().is_thread_local_static(def_id)); local_decl.internal = true; - local_decl.local_info = Some(box LocalInfo::StaticRef { def_id, is_thread_local: false }); + local_decl.local_info = + Some(box LocalInfo::StaticRef { def_id, is_thread_local: false }); } ExprKind::ThreadLocalRef(def_id) => { assert!(this.hir.tcx().is_thread_local_static(def_id)); local_decl.internal = true; - local_decl.local_info = Some(box LocalInfo::StaticRef { def_id, is_thread_local: true }); + local_decl.local_info = + Some(box LocalInfo::StaticRef { def_id, is_thread_local: true }); } _ => {} } diff --git a/src/librustc_mir_build/build/expr/category.rs b/src/librustc_mir_build/build/expr/category.rs index fb4b7997b6a5a..9cabd186d8460 100644 --- a/src/librustc_mir_build/build/expr/category.rs +++ b/src/librustc_mir_build/build/expr/category.rs @@ -1,4 +1,4 @@ -use crate::hair::*; +use crate::thir::*; #[derive(Debug, PartialEq)] crate enum Category { diff --git a/src/librustc_mir_build/build/expr/into.rs b/src/librustc_mir_build/build/expr/into.rs index 36f8034336ba1..c3f54b39a3f38 100644 --- a/src/librustc_mir_build/build/expr/into.rs +++ b/src/librustc_mir_build/build/expr/into.rs @@ -2,7 +2,7 @@ use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_ast::ast::InlineAsmOptions; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -320,23 +320,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.unit() } ExprKind::InlineAsm { template, operands, options, line_spans } => { - use crate::hair; + use crate::thir; use rustc_middle::mir; let operands = operands .into_iter() .map(|op| match op { - hair::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In { + thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In { reg, value: unpack!(block = this.as_local_operand(block, expr)), }, - hair::InlineAsmOperand::Out { reg, late, expr } => { + thir::InlineAsmOperand::Out { reg, late, expr } => { mir::InlineAsmOperand::Out { reg, late, place: expr.map(|expr| unpack!(block = this.as_place(block, expr))), } } - hair::InlineAsmOperand::InOut { reg, late, expr } => { + thir::InlineAsmOperand::InOut { reg, late, expr } => { let place = unpack!(block = this.as_place(block, expr)); mir::InlineAsmOperand::InOut { reg, @@ -346,7 +346,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { out_place: Some(place), } } - hair::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => { + thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => { mir::InlineAsmOperand::InOut { reg, late, @@ -356,13 +356,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }), } } - hair::InlineAsmOperand::Const { expr } => mir::InlineAsmOperand::Const { + thir::InlineAsmOperand::Const { expr } => mir::InlineAsmOperand::Const { value: unpack!(block = this.as_local_operand(block, expr)), }, - hair::InlineAsmOperand::SymFn { expr } => { + thir::InlineAsmOperand::SymFn { expr } => { mir::InlineAsmOperand::SymFn { value: box this.as_constant(expr) } } - hair::InlineAsmOperand::SymStatic { def_id } => { + thir::InlineAsmOperand::SymStatic { def_id } => { mir::InlineAsmOperand::SymStatic { def_id } } }) diff --git a/src/librustc_mir_build/build/expr/stmt.rs b/src/librustc_mir_build/build/expr/stmt.rs index 49d6ce39ddfa4..f117689d940fd 100644 --- a/src/librustc_mir_build/build/expr/stmt.rs +++ b/src/librustc_mir_build/build/expr/stmt.rs @@ -1,11 +1,11 @@ use crate::build::scope::BreakableTarget; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_middle::middle::region; use rustc_middle::mir::*; impl<'a, 'tcx> Builder<'a, 'tcx> { - /// Builds a block of MIR statements to evaluate the HAIR `expr`. + /// Builds a block of MIR statements to evaluate the THIR `expr`. /// If the original expression was an AST statement, /// (e.g., `some().code(&here());`) then `opt_stmt_span` is the /// span of that statement (including its semicolon, if any). @@ -150,8 +150,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { break; } } - this.block_context - .push(BlockFrame::TailExpr { tail_result_is_ignored: true, span: expr.span }); + this.block_context.push(BlockFrame::TailExpr { + tail_result_is_ignored: true, + span: expr.span, + }); return Some(expr.span); } } diff --git a/src/librustc_mir_build/build/into.rs b/src/librustc_mir_build/build/into.rs index 0baa0c833a514..7264e495b84fd 100644 --- a/src/librustc_mir_build/build/into.rs +++ b/src/librustc_mir_build/build/into.rs @@ -5,7 +5,7 @@ //! latter `EvalInto` trait. use crate::build::{BlockAnd, Builder}; -use crate::hair::*; +use crate::thir::*; use rustc_middle::mir::*; pub(in crate::build) trait EvalInto<'tcx> { diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index 19948196f256f..77c0fe8dda534 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -9,15 +9,18 @@ use crate::build::scope::DropKind; use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard}; use crate::build::{BlockAnd, BlockAndExtension, Builder}; use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode}; -use crate::hair::{self, *}; -use rustc_data_structures::{fx::{FxHashMap, FxHashSet}, stack::ensure_sufficient_stack}; +use crate::thir::{self, *}; +use rustc_data_structures::{ + fx::{FxHashMap, FxHashSet}, + stack::ensure_sufficient_stack, +}; use rustc_hir::HirId; use rustc_index::bit_set::BitSet; use rustc_middle::middle::region; use rustc_middle::mir::*; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty}; -use rustc_span::Span; use rustc_span::symbol::Symbol; +use rustc_span::Span; use rustc_target::abi::VariantIdx; use smallvec::{smallvec, SmallVec}; @@ -395,7 +398,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .. }, ascription: - hair::pattern::Ascription { user_ty: pat_ascription_ty, variance: _, user_ty_span }, + thir::pattern::Ascription { user_ty: pat_ascription_ty, variance: _, user_ty_span }, } => { let place = self.storage_live_binding(block, var, irrefutable_pat.span, OutsideGuard, true); @@ -631,7 +634,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { PatKind::AscribeUserType { ref subpattern, - ascription: hair::pattern::Ascription { ref user_ty, user_ty_span, variance: _ }, + ascription: thir::pattern::Ascription { ref user_ty, user_ty_span, variance: _ }, } => { // This corresponds to something like // @@ -1982,16 +1985,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info, internal: false, is_block_tail: None, - local_info: Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(VarBindingForm { - binding_mode, - // hypothetically, `visit_primary_bindings` could try to unzip - // an outermost hir::Ty as we descend, matching up - // idents in pat; but complex w/ unclear UI payoff. - // Instead, just abandon providing diagnostic info. - opt_ty_info: None, - opt_match_place, - pat_span, - })))), + local_info: Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var( + VarBindingForm { + binding_mode, + // hypothetically, `visit_primary_bindings` could try to unzip + // an outermost hir::Ty as we descend, matching up + // idents in pat; but complex w/ unclear UI payoff. + // Instead, just abandon providing diagnostic info. + opt_ty_info: None, + opt_match_place, + pat_span, + }, + )))), }; let for_arm_body = self.local_decls.push(local); self.var_debug_info.push(VarDebugInfo { @@ -2009,7 +2014,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info, internal: false, is_block_tail: None, - local_info: Some(box LocalInfo::User(ClearCrossCrate::Set(BindingForm::RefForGuard))), + local_info: Some(box LocalInfo::User(ClearCrossCrate::Set( + BindingForm::RefForGuard, + ))), }); self.var_debug_info.push(VarDebugInfo { name, diff --git a/src/librustc_mir_build/build/matches/simplify.rs b/src/librustc_mir_build/build/matches/simplify.rs index 2917a771a2cf8..e584aeb922672 100644 --- a/src/librustc_mir_build/build/matches/simplify.rs +++ b/src/librustc_mir_build/build/matches/simplify.rs @@ -14,7 +14,7 @@ use crate::build::matches::{Ascription, Binding, Candidate, MatchPair}; use crate::build::Builder; -use crate::hair::{self, *}; +use crate::thir::{self, *}; use rustc_attr::{SignedInt, UnsignedInt}; use rustc_hir::RangeEnd; use rustc_middle::mir::interpret::truncate; @@ -108,7 +108,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match *match_pair.pattern.kind { PatKind::AscribeUserType { ref subpattern, - ascription: hair::pattern::Ascription { variance, user_ty, user_ty_span }, + ascription: thir::pattern::Ascription { variance, user_ty, user_ty_span }, } => { // Apply the type ascription to the value at `match_pair.place`, which is the // value being matched, taking the variance field into account. diff --git a/src/librustc_mir_build/build/matches/test.rs b/src/librustc_mir_build/build/matches/test.rs index 3e7bfc7d59b9b..158ad78a1bf36 100644 --- a/src/librustc_mir_build/build/matches/test.rs +++ b/src/librustc_mir_build/build/matches/test.rs @@ -7,8 +7,8 @@ use crate::build::matches::{Candidate, MatchPair, Test, TestKind}; use crate::build::Builder; -use crate::hair::pattern::compare_const_vals; -use crate::hair::*; +use crate::thir::pattern::compare_const_vals; +use crate::thir::*; use rustc_data_structures::fx::FxHashMap; use rustc_hir::RangeEnd; use rustc_index::bit_set::BitSet; @@ -443,7 +443,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { destination: Some((eq_result, eq_block)), cleanup: Some(cleanup), from_hir_call: false, - fn_span: source_info.span + fn_span: source_info.span, }, ); diff --git a/src/librustc_mir_build/build/matches/util.rs b/src/librustc_mir_build/build/matches/util.rs index 7d89a93129b1b..605396c5eb639 100644 --- a/src/librustc_mir_build/build/matches/util.rs +++ b/src/librustc_mir_build/build/matches/util.rs @@ -1,6 +1,6 @@ use crate::build::matches::MatchPair; use crate::build::Builder; -use crate::hair::*; +use crate::thir::*; use rustc_middle::mir::*; use rustc_middle::ty; use smallvec::SmallVec; diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 2549b90ddfa11..3c4587119cd55 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -1,7 +1,7 @@ use crate::build; use crate::build::scope::DropKind; -use crate::hair::cx::Cx; -use crate::hair::{BindingMode, LintLevel, PatKind}; +use crate::thir::cx::Cx; +use crate::thir::{BindingMode, LintLevel, PatKind}; use rustc_attr::{self as attr, UnwindAttr}; use rustc_errors::ErrorReported; use rustc_hir as hir; @@ -294,7 +294,7 @@ struct Builder<'a, 'tcx> { /// see the `scope` module for more details. scopes: scope::Scopes<'tcx>, - /// The block-context: each time we build the code within an hair::Block, + /// The block-context: each time we build the code within an thir::Block, /// we push a frame here tracking whether we are building a statement or /// if we are pushing the tail expression of the block. This is used to /// embed information in generated temps about whether they were created diff --git a/src/librustc_mir_build/build/scope.rs b/src/librustc_mir_build/build/scope.rs index b8df27094471f..2a03bb78c6b1a 100644 --- a/src/librustc_mir_build/build/scope.rs +++ b/src/librustc_mir_build/build/scope.rs @@ -1,6 +1,6 @@ /*! Managing the scope stack. The scopes are tied to lexical scopes, so as -we descend the HAIR, we push a scope on the stack, build its +we descend the THIR, we push a scope on the stack, build its contents, and then pop it off. Every scope is named by a `region::Scope`. @@ -83,12 +83,12 @@ should go to. */ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder, CFG}; -use crate::hair::{Expr, ExprRef, LintLevel}; -use rustc_middle::middle::region; -use rustc_middle::mir::*; +use crate::thir::{Expr, ExprRef, LintLevel}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; use rustc_hir::GeneratorKind; +use rustc_middle::middle::region; +use rustc_middle::mir::*; use rustc_span::{Span, DUMMY_SP}; use std::collections::hash_map::Entry; use std::mem; diff --git a/src/librustc_mir_build/lib.rs b/src/librustc_mir_build/lib.rs index ed154b9dc6f11..30545558933f7 100644 --- a/src/librustc_mir_build/lib.rs +++ b/src/librustc_mir_build/lib.rs @@ -17,13 +17,13 @@ extern crate log; extern crate rustc_middle; mod build; -mod hair; mod lints; +mod thir; use rustc_middle::ty::query::Providers; pub fn provide(providers: &mut Providers) { - providers.check_match = hair::pattern::check_match; - providers.lit_to_const = hair::constant::lit_to_const; + providers.check_match = thir::pattern::check_match; + providers.lit_to_const = thir::constant::lit_to_const; providers.mir_built = build::mir_built; } diff --git a/src/librustc_mir_build/hair/constant.rs b/src/librustc_mir_build/thir/constant.rs similarity index 100% rename from src/librustc_mir_build/hair/constant.rs rename to src/librustc_mir_build/thir/constant.rs diff --git a/src/librustc_mir_build/hair/cx/block.rs b/src/librustc_mir_build/thir/cx/block.rs similarity index 96% rename from src/librustc_mir_build/hair/cx/block.rs rename to src/librustc_mir_build/thir/cx/block.rs index a5381781d1d80..980888df7fee4 100644 --- a/src/librustc_mir_build/hair/cx/block.rs +++ b/src/librustc_mir_build/thir/cx/block.rs @@ -1,6 +1,6 @@ -use crate::hair::cx::to_ref::ToRef; -use crate::hair::cx::Cx; -use crate::hair::{self, *}; +use crate::thir::cx::to_ref::ToRef; +use crate::thir::cx::Cx; +use crate::thir::{self, *}; use rustc_hir as hir; use rustc_middle::middle::region; @@ -71,7 +71,7 @@ fn mirror_stmts<'a, 'tcx>( ty: pattern.ty, span: pattern.span, kind: Box::new(PatKind::AscribeUserType { - ascription: hair::pattern::Ascription { + ascription: thir::pattern::Ascription { user_ty: PatTyProj::from_user_type(user_ty), user_ty_span: ty.span, variance: ty::Variance::Covariant, diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/thir/cx/expr.rs similarity index 99% rename from src/librustc_mir_build/hair/cx/expr.rs rename to src/librustc_mir_build/thir/cx/expr.rs index 6e1d8a8fc4012..ea41a66b3e43d 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/thir/cx/expr.rs @@ -1,8 +1,8 @@ -use crate::hair::cx::block; -use crate::hair::cx::to_ref::ToRef; -use crate::hair::cx::Cx; -use crate::hair::util::UserAnnotatedTyHelpers; -use crate::hair::*; +use crate::thir::cx::block; +use crate::thir::cx::to_ref::ToRef; +use crate::thir::cx::Cx; +use crate::thir::util::UserAnnotatedTyHelpers; +use crate::thir::*; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_index::vec::Idx; @@ -1020,7 +1020,7 @@ fn overloaded_place<'a, 'tcx>( // line up (this is because `*x` and `x[y]` represent places): let recv_ty = match args[0] { - ExprRef::Hair(e) => cx.typeck_results().expr_ty_adjusted(e), + ExprRef::Thir(e) => cx.typeck_results().expr_ty_adjusted(e), ExprRef::Mirror(ref e) => e.ty, }; diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/thir/cx/mod.rs similarity index 98% rename from src/librustc_mir_build/hair/cx/mod.rs rename to src/librustc_mir_build/thir/cx/mod.rs index 2694cde14fde7..21736df7b0710 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/thir/cx/mod.rs @@ -1,9 +1,9 @@ //! This module contains the functionality to convert from the wacky tcx data -//! structures into the HAIR. The `builder` is generally ignorant of the tcx, +//! structures into the THIR. The `builder` is generally ignorant of the tcx, //! etc., and instead goes through the `Cx` for most of its work. -use crate::hair::util::UserAnnotatedTyHelpers; -use crate::hair::*; +use crate::thir::util::UserAnnotatedTyHelpers; +use crate::thir::*; use rustc_ast::ast; use rustc_ast::attr; diff --git a/src/librustc_mir_build/hair/cx/to_ref.rs b/src/librustc_mir_build/thir/cx/to_ref.rs similarity index 93% rename from src/librustc_mir_build/hair/cx/to_ref.rs rename to src/librustc_mir_build/thir/cx/to_ref.rs index 6cf8122e200db..53a988ebb79e2 100644 --- a/src/librustc_mir_build/hair/cx/to_ref.rs +++ b/src/librustc_mir_build/thir/cx/to_ref.rs @@ -1,4 +1,4 @@ -use crate::hair::*; +use crate::thir::*; use rustc_hir as hir; @@ -11,7 +11,7 @@ impl<'tcx> ToRef for &'tcx hir::Expr<'tcx> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { - ExprRef::Hair(self) + ExprRef::Thir(self) } } @@ -19,7 +19,7 @@ impl<'tcx> ToRef for &'tcx &'tcx hir::Expr<'tcx> { type Output = ExprRef<'tcx>; fn to_ref(self) -> ExprRef<'tcx> { - ExprRef::Hair(&**self) + ExprRef::Thir(&**self) } } diff --git a/src/librustc_mir_build/hair/mod.rs b/src/librustc_mir_build/thir/mod.rs similarity index 95% rename from src/librustc_mir_build/hair/mod.rs rename to src/librustc_mir_build/thir/mod.rs index ccff510f2d4e5..b6ce7e0b41e54 100644 --- a/src/librustc_mir_build/hair/mod.rs +++ b/src/librustc_mir_build/thir/mod.rs @@ -1,5 +1,5 @@ -//! The MIR is built from some high-level abstract IR -//! (HAIR). This section defines the HAIR along with a trait for +//! The MIR is built from some typed high-level IR +//! (THIR). This section defines the THIR along with a trait for //! accessing it. The intention is to allow MIR construction to be //! unit-tested and separated from the Rust source and compiler data //! structures. @@ -99,18 +99,18 @@ crate enum StmtKind<'tcx> { #[cfg(target_arch = "x86_64")] rustc_data_structures::static_assert_size!(Expr<'_>, 168); -/// The Hair trait implementor lowers their expressions (`&'tcx H::Expr`) +/// The Thir trait implementor lowers their expressions (`&'tcx H::Expr`) /// into instances of this `Expr` enum. This lowering can be done /// basically as lazily or as eagerly as desired: every recursive /// reference to an expression in this enum is an `ExprRef<'tcx>`, which /// may in turn be another instance of this enum (boxed), or else an /// unlowered `&'tcx H::Expr`. Note that instances of `Expr` are very -/// short-lived. They are created by `Hair::to_expr`, analyzed and +/// short-lived. They are created by `Thir::to_expr`, analyzed and /// converted into MIR, and then discarded. /// /// If you compare `Expr` to the full compiler AST, you will see it is /// a good bit simpler. In fact, a number of the more straight-forward -/// MIR simplifications are already done in the impl of `Hair`. For +/// MIR simplifications are already done in the impl of `Thir`. For /// example, method calls and overloaded operators are absent: they are /// expected to be converted into `Expr::Call` instances. #[derive(Clone, Debug)] @@ -302,7 +302,7 @@ crate enum ExprKind<'tcx> { #[derive(Clone, Debug)] crate enum ExprRef<'tcx> { - Hair(&'tcx hir::Expr<'tcx>), + Thir(&'tcx hir::Expr<'tcx>), Mirror(Box>), } @@ -342,7 +342,7 @@ crate enum LogicalOp { impl<'tcx> ExprRef<'tcx> { crate fn span(&self) -> Span { match self { - ExprRef::Hair(expr) => expr.span, + ExprRef::Thir(expr) => expr.span, ExprRef::Mirror(expr) => expr.span, } } @@ -385,7 +385,7 @@ crate enum InlineAsmOperand<'tcx> { // The Mirror trait /// "Mirroring" is the process of converting from a HIR type into one -/// of the HAIR types defined in this file. This is basically a "on +/// of the THIR types defined in this file. This is basically a "on /// the fly" desugaring step that hides a lot of the messiness in the /// tcx. For example, the mirror of a `&'tcx hir::Expr` is an /// `Expr<'tcx>`. @@ -394,7 +394,7 @@ crate enum InlineAsmOperand<'tcx> { /// + e2`, the references to the inner expressions `e1` and `e2` are /// `ExprRef<'tcx>` instances, and they may or may not be eagerly /// mirrored. This allows a single AST node from the compiler to -/// expand into one or more Hair nodes, which lets the Hair nodes be +/// expand into one or more Thir nodes, which lets the Thir nodes be /// simpler. crate trait Mirror<'tcx> { type Output; @@ -415,7 +415,7 @@ impl<'tcx> Mirror<'tcx> for ExprRef<'tcx> { fn make_mirror(self, hir: &mut Cx<'_, 'tcx>) -> Expr<'tcx> { match self { - ExprRef::Hair(h) => h.make_mirror(hir), + ExprRef::Thir(h) => h.make_mirror(hir), ExprRef::Mirror(m) => *m, } } diff --git a/src/librustc_mir_build/hair/pattern/_match.rs b/src/librustc_mir_build/thir/pattern/_match.rs similarity index 100% rename from src/librustc_mir_build/hair/pattern/_match.rs rename to src/librustc_mir_build/thir/pattern/_match.rs diff --git a/src/librustc_mir_build/hair/pattern/check_match.rs b/src/librustc_mir_build/thir/pattern/check_match.rs similarity index 100% rename from src/librustc_mir_build/hair/pattern/check_match.rs rename to src/librustc_mir_build/thir/pattern/check_match.rs diff --git a/src/librustc_mir_build/hair/pattern/const_to_pat.rs b/src/librustc_mir_build/thir/pattern/const_to_pat.rs similarity index 100% rename from src/librustc_mir_build/hair/pattern/const_to_pat.rs rename to src/librustc_mir_build/thir/pattern/const_to_pat.rs diff --git a/src/librustc_mir_build/hair/pattern/mod.rs b/src/librustc_mir_build/thir/pattern/mod.rs similarity index 98% rename from src/librustc_mir_build/hair/pattern/mod.rs rename to src/librustc_mir_build/thir/pattern/mod.rs index a5c87bc963f49..bdefaadfdfe56 100644 --- a/src/librustc_mir_build/hair/pattern/mod.rs +++ b/src/librustc_mir_build/thir/pattern/mod.rs @@ -6,7 +6,7 @@ mod const_to_pat; pub(crate) use self::check_match::check_match; -use crate::hair::util::UserAnnotatedTyHelpers; +use crate::thir::util::UserAnnotatedTyHelpers; use rustc_ast::ast; use rustc_errors::struct_span_err; @@ -16,7 +16,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator; use rustc_hir::RangeEnd; use rustc_index::vec::Idx; use rustc_middle::mir::interpret::{get_slice_bytes, sign_extend, ConstValue}; -use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; +use rustc_middle::mir::interpret::{ErrorHandled, LitToConstError, LitToConstInput}; use rustc_middle::mir::UserTypeProjection; use rustc_middle::mir::{BorrowKind, Field, Mutability}; use rustc_middle::ty::subst::{GenericArg, SubstsRef}; @@ -402,7 +402,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { // // `vec![&&Option, &Option]`. // - // Applying the adjustments, we want to instead output `&&Some(n)` (as a HAIR pattern). So + // Applying the adjustments, we want to instead output `&&Some(n)` (as a THIR pattern). So // we wrap the unadjusted pattern in `PatKind::Deref` repeatedly, consuming the // adjustments in *reverse order* (last-in-first-out, so that the last `Deref` inserted // gets the least-dereferenced type). @@ -776,7 +776,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { // Use `Reveal::All` here because patterns are always monomorphic even if their function // isn't. - let param_env_reveal_all = self.param_env.with_reveal_all(); + let param_env_reveal_all = self.param_env.with_reveal_all_normalized(self.tcx); let substs = self.typeck_results.node_substs(id); let instance = match ty::Instance::resolve(self.tcx, param_env_reveal_all, def_id, substs) { Ok(Some(i)) => i, @@ -834,6 +834,12 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { pattern } } + Err(ErrorHandled::TooGeneric) => { + // While `Reported | Linted` cases will have diagnostics emitted already + // it is not true for TooGeneric case, so we need to give user more information. + self.tcx.sess.span_err(span, "constant pattern depends on a generic parameter"); + pat_from_kind(PatKind::Wild) + } Err(_) => { self.tcx.sess.span_err(span, "could not evaluate constant pattern"); pat_from_kind(PatKind::Wild) diff --git a/src/librustc_mir_build/hair/util.rs b/src/librustc_mir_build/thir/util.rs similarity index 100% rename from src/librustc_mir_build/hair/util.rs rename to src/librustc_mir_build/thir/util.rs diff --git a/src/librustc_parse/Cargo.toml b/src/librustc_parse/Cargo.toml index 7164c67880863..f214ec020cbec 100644 --- a/src/librustc_parse/Cargo.toml +++ b/src/librustc_parse/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] bitflags = "1.0" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } diff --git a/src/librustc_passes/Cargo.toml b/src/librustc_passes/Cargo.toml index 69048cbf24a30..d9fa435e3ad68 100644 --- a/src/librustc_passes/Cargo.toml +++ b/src/librustc_passes/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_passes" path = "lib.rs" [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_passes/layout_test.rs b/src/librustc_passes/layout_test.rs index 2419e6965968e..55a6d3f76457e 100644 --- a/src/librustc_passes/layout_test.rs +++ b/src/librustc_passes/layout_test.rs @@ -82,8 +82,10 @@ impl LayoutTest<'tcx> { } sym::debug => { - let normalized_ty = - self.tcx.normalize_erasing_regions(param_env.with_reveal_all(), ty); + let normalized_ty = self.tcx.normalize_erasing_regions( + param_env.with_reveal_all_normalized(self.tcx), + ty, + ); self.tcx.sess.span_err( item.span, &format!("layout_of({:?}) = {:#?}", normalized_ty, *ty_layout), diff --git a/src/librustc_privacy/Cargo.toml b/src/librustc_privacy/Cargo.toml index 6110d2ef7fc9a..6f543e71b4281 100644 --- a/src/librustc_privacy/Cargo.toml +++ b/src/librustc_privacy/Cargo.toml @@ -17,4 +17,4 @@ rustc_typeck = { path = "../librustc_typeck" } rustc_session = { path = "../librustc_session" } rustc_span = { path = "../librustc_span" } rustc_data_structures = { path = "../librustc_data_structures" } -log = "0.4" +log = { package = "tracing", version = "0.1" } diff --git a/src/librustc_query_system/Cargo.toml b/src/librustc_query_system/Cargo.toml index 73d50f84fe836..64af9c5f1a152 100644 --- a/src/librustc_query_system/Cargo.toml +++ b/src/librustc_query_system/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_arena = { path = "../librustc_arena" } -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } rustc-rayon-core = "0.3.0" rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } diff --git a/src/librustc_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml index 6f6104c3d6932..1cb49132ead9c 100644 --- a/src/librustc_resolve/Cargo.toml +++ b/src/librustc_resolve/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] bitflags = "1.2.1" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_ast = { path = "../librustc_ast" } rustc_arena = { path = "../librustc_arena" } rustc_middle = { path = "../librustc_middle" } diff --git a/src/librustc_save_analysis/Cargo.toml b/src/librustc_save_analysis/Cargo.toml index 5948c88054ded..7a5ae0ace3ae6 100644 --- a/src/librustc_save_analysis/Cargo.toml +++ b/src/librustc_save_analysis/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_save_analysis" path = "lib.rs" [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_ast = { path = "../librustc_ast" } rustc_ast_pretty = { path = "../librustc_ast_pretty" } diff --git a/src/librustc_session/Cargo.toml b/src/librustc_session/Cargo.toml index abce7359c0ed7..35c227df8500a 100644 --- a/src/librustc_session/Cargo.toml +++ b/src/librustc_session/Cargo.toml @@ -11,7 +11,7 @@ path = "lib.rs" [dependencies] bitflags = "1.2.1" getopts = "0.2" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_session/filesearch.rs b/src/librustc_session/filesearch.rs index 27396c524f4e6..504490d938cfa 100644 --- a/src/librustc_session/filesearch.rs +++ b/src/librustc_session/filesearch.rs @@ -117,28 +117,22 @@ pub fn make_target_lib_path(sysroot: &Path, target_triple: &str) -> PathBuf { pub fn get_or_default_sysroot() -> PathBuf { // Follow symlinks. If the resolved path is relative, make it absolute. - fn canonicalize(path: Option) -> Option { - path.and_then(|path| { - match fs::canonicalize(&path) { - // See comments on this target function, but the gist is that - // gcc chokes on verbatim paths which fs::canonicalize generates - // so we try to avoid those kinds of paths. - Ok(canon) => Some(fix_windows_verbatim_for_gcc(&canon)), - Err(e) => panic!("failed to get realpath: {}", e), - } - }) + fn canonicalize(path: PathBuf) -> PathBuf { + let path = fs::canonicalize(&path).unwrap_or(path); + // See comments on this target function, but the gist is that + // gcc chokes on verbatim paths which fs::canonicalize generates + // so we try to avoid those kinds of paths. + fix_windows_verbatim_for_gcc(&path) } match env::current_exe() { - Ok(exe) => match canonicalize(Some(exe)) { - Some(mut p) => { - p.pop(); - p.pop(); - p - } - None => panic!("can't determine value for sysroot"), - }, - Err(ref e) => panic!(format!("failed to get current_exe: {}", e)), + Ok(exe) => { + let mut p = canonicalize(exe); + p.pop(); + p.pop(); + p + } + Err(e) => panic!("failed to get current_exe: {}", e), } } diff --git a/src/librustc_session/lint/builtin.rs b/src/librustc_session/lint/builtin.rs index aa2a133952f8f..144a06a4916bd 100644 --- a/src/librustc_session/lint/builtin.rs +++ b/src/librustc_session/lint/builtin.rs @@ -398,7 +398,7 @@ declare_lint! { } declare_lint! { - pub INTRA_DOC_LINK_RESOLUTION_FAILURE, + pub BROKEN_INTRA_DOC_LINKS, Warn, "failures in resolving intra-doc link targets" } @@ -601,7 +601,7 @@ declare_lint_pass! { ABSOLUTE_PATHS_NOT_STARTING_WITH_CRATE, UNSTABLE_NAME_COLLISIONS, IRREFUTABLE_LET_PATTERNS, - INTRA_DOC_LINK_RESOLUTION_FAILURE, + BROKEN_INTRA_DOC_LINKS, INVALID_CODEBLOCK_ATTRIBUTES, MISSING_CRATE_LEVEL_DOCS, MISSING_DOC_CODE_EXAMPLES, diff --git a/src/librustc_span/Cargo.toml b/src/librustc_span/Cargo.toml index 2a7a774872525..2db417ce0e129 100644 --- a/src/librustc_span/Cargo.toml +++ b/src/librustc_span/Cargo.toml @@ -18,6 +18,6 @@ rustc_arena = { path = "../librustc_arena" } scoped-tls = "1.0" unicode-width = "0.1.4" cfg-if = "0.1.2" -log = "0.4" +log = { package = "tracing", version = "0.1" } sha-1 = "0.8" md-5 = "0.8" diff --git a/src/librustc_symbol_mangling/Cargo.toml b/src/librustc_symbol_mangling/Cargo.toml index d670ababe9f12..757d86bd95afd 100644 --- a/src/librustc_symbol_mangling/Cargo.toml +++ b/src/librustc_symbol_mangling/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" doctest = false [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } punycode = "0.4.0" rustc-demangle = "0.1.16" diff --git a/src/librustc_symbol_mangling/v0.rs b/src/librustc_symbol_mangling/v0.rs index 676fee590b3c5..56ee492de87ab 100644 --- a/src/librustc_symbol_mangling/v0.rs +++ b/src/librustc_symbol_mangling/v0.rs @@ -271,7 +271,7 @@ impl Printer<'tcx> for SymbolMangler<'tcx> { let key = self.tcx.def_key(impl_def_id); let parent_def_id = DefId { index: key.parent.unwrap(), ..impl_def_id }; - let mut param_env = self.tcx.param_env(impl_def_id).with_reveal_all(); + let mut param_env = self.tcx.param_env_reveal_all_normalized(impl_def_id); if !substs.is_empty() { param_env = param_env.subst(self.tcx, substs); } diff --git a/src/librustc_target/Cargo.toml b/src/librustc_target/Cargo.toml index c73490e451320..21796e8498568 100644 --- a/src/librustc_target/Cargo.toml +++ b/src/librustc_target/Cargo.toml @@ -10,7 +10,7 @@ path = "lib.rs" [dependencies] bitflags = "1.2.1" -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_macros = { path = "../librustc_macros" } rustc_serialize = { path = "../librustc_serialize" } diff --git a/src/librustc_trait_selection/Cargo.toml b/src/librustc_trait_selection/Cargo.toml index fd11a85a9c406..c43fe3f2c0c89 100644 --- a/src/librustc_trait_selection/Cargo.toml +++ b/src/librustc_trait_selection/Cargo.toml @@ -11,7 +11,7 @@ doctest = false [dependencies] rustc_parse_format = { path = "../librustc_parse_format" } -log = { version = "0.4", features = ["release_max_level_info", "std"] } +log = { package = "tracing", version = "0.1" } rustc_attr = { path = "../librustc_attr" } rustc_middle = { path = "../librustc_middle" } rustc_ast = { path = "../librustc_ast" } diff --git a/src/librustc_traits/Cargo.toml b/src/librustc_traits/Cargo.toml index 079b9b10fd090..f8487982e3d49 100644 --- a/src/librustc_traits/Cargo.toml +++ b/src/librustc_traits/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_traits" path = "lib.rs" [dependencies] -log = { version = "0.4" } +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_hir = { path = "../librustc_hir" } diff --git a/src/librustc_ty/Cargo.toml b/src/librustc_ty/Cargo.toml index b6db75e44f971..6cdb353000278 100644 --- a/src/librustc_ty/Cargo.toml +++ b/src/librustc_ty/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_ty" path = "lib.rs" [dependencies] -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_errors = { path = "../librustc_errors" } diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 324ae4ec29e9b..1e0c4055af3c5 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -137,7 +137,7 @@ fn resolve_associated_item<'tcx>( }); let substs = tcx.infer_ctxt().enter(|infcx| { - let param_env = param_env.with_reveal_all(); + let param_env = param_env.with_reveal_all_normalized(tcx); let substs = rcvr_substs.rebase_onto(tcx, trait_def_id, impl_data.substs); let substs = translate_substs( &infcx, diff --git a/src/librustc_ty/ty.rs b/src/librustc_ty/ty.rs index 7f954dacf3e89..dfb28b473ff26 100644 --- a/src/librustc_ty/ty.rs +++ b/src/librustc_ty/ty.rs @@ -276,6 +276,10 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause) } +fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { + tcx.param_env(def_id).with_reveal_all_normalized(tcx) +} + fn crate_disambiguator(tcx: TyCtxt<'_>, crate_num: CrateNum) -> CrateDisambiguator { assert_eq!(crate_num, LOCAL_CRATE); tcx.sess.local_crate_disambiguator() @@ -502,6 +506,7 @@ pub fn provide(providers: &mut ty::query::Providers) { adt_sized_constraint, def_span, param_env, + param_env_reveal_all_normalized, trait_of_item, crate_disambiguator, original_crate_name, diff --git a/src/librustc_typeck/Cargo.toml b/src/librustc_typeck/Cargo.toml index 93b503c976be4..963deda162d62 100644 --- a/src/librustc_typeck/Cargo.toml +++ b/src/librustc_typeck/Cargo.toml @@ -12,7 +12,7 @@ doctest = false [dependencies] rustc_arena = { path = "../librustc_arena" } -log = "0.4" +log = { package = "tracing", version = "0.1" } rustc_middle = { path = "../librustc_middle" } rustc_attr = { path = "../librustc_attr" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index ae2cf6daf5350..e69102d1995d3 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -678,6 +678,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { .collect::>(); for ((span, empty_where), obligations) in type_params.into_iter() { restrict_type_params = true; + // #74886: Sort here so that the output is always the same. + let mut obligations = obligations.into_iter().collect::>(); + obligations.sort(); err.span_suggestion_verbose( span, &format!( @@ -688,7 +691,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { format!( "{} {}", if empty_where { " where" } else { "," }, - obligations.into_iter().collect::>().join(", ") + obligations.join(", ") ), Applicability::MaybeIncorrect, ); diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index 42170bc199cbc..9c7ea34bf51b6 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -345,7 +345,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { debug!("inspecting {:?}", expected); debug!("current discriminant is Ref, inserting implicit deref"); - // Preserve the reference type. We'll need it later during HAIR lowering. + // Preserve the reference type. We'll need it later during THIR lowering. pat_adjustments.push(expected); expected = inner_ty; diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index cae09267994e3..b810c9824ce66 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -161,6 +161,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { self.add_constraints_from_sig(current_item, tcx.fn_sig(def_id), self.covariant); } + ty::Error(_) => {} _ => { span_bug!( tcx.def_span(def_id), diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 3547b45dfa71f..4f751decc8090 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -508,7 +508,7 @@ impl Options { let output_format = match matches.opt_str("output-format") { Some(s) => match OutputFormat::try_from(s.as_str()) { Ok(o) => { - if o.is_json() && !show_coverage { + if o.is_json() && !(show_coverage || nightly_options::is_nightly_build()) { diag.struct_err("json output format isn't supported for doc generation") .emit(); return Err(1); @@ -626,7 +626,9 @@ fn check_deprecated_options(matches: &getopts::Matches, diag: &rustc_errors::Han for flag in deprecated_flags.iter() { if matches.opt_present(flag) { - if *flag == "output-format" && matches.opt_present("show-coverage") { + if *flag == "output-format" + && (matches.opt_present("show-coverage") || nightly_options::is_nightly_build()) + { continue; } let mut err = diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 2c2ebc9291b98..cbd0ca0de6414 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -315,7 +315,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt let cpath = Some(input.clone()); let input = Input::File(input); - let intra_link_resolution_failure_name = lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE.name; + let intra_link_resolution_failure_name = lint::builtin::BROKEN_INTRA_DOC_LINKS.name; let missing_docs = rustc_lint::builtin::MISSING_DOCS.name; let missing_doc_example = rustc_lint::builtin::MISSING_DOC_CODE_EXAMPLES.name; let private_doc_tests = rustc_lint::builtin::PRIVATE_DOC_TESTS.name; diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs new file mode 100644 index 0000000000000..14f87ec2aa9bb --- /dev/null +++ b/src/librustdoc/json/mod.rs @@ -0,0 +1,47 @@ +use crate::clean; +use crate::config::{RenderInfo, RenderOptions}; +use crate::error::Error; +use crate::formats::cache::Cache; +use crate::formats::FormatRenderer; + +use rustc_span::edition::Edition; + +#[derive(Clone)] +pub struct JsonRenderer {} + +impl FormatRenderer for JsonRenderer { + fn init( + _krate: clean::Crate, + _options: RenderOptions, + _render_info: RenderInfo, + _edition: Edition, + _cache: &mut Cache, + ) -> Result<(Self, clean::Crate), Error> { + unimplemented!() + } + + fn item(&mut self, _item: clean::Item, _cache: &Cache) -> Result<(), Error> { + unimplemented!() + } + + fn mod_item_in( + &mut self, + _item: &clean::Item, + _item_name: &str, + _cache: &Cache, + ) -> Result<(), Error> { + unimplemented!() + } + + fn mod_item_out(&mut self, _item_name: &str) -> Result<(), Error> { + unimplemented!() + } + + fn after_krate(&mut self, _krate: &clean::Crate, _cache: &Cache) -> Result<(), Error> { + unimplemented!() + } + + fn after_run(&mut self, _diag: &rustc_errors::Handler) -> Result<(), Error> { + unimplemented!() + } +} diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 65bc089faf428..002c5f967105d 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -14,7 +14,6 @@ #![feature(never_type)] #![recursion_limit = "256"] -extern crate env_logger; #[macro_use] extern crate lazy_static; extern crate rustc_ast; @@ -68,6 +67,7 @@ mod error; mod fold; crate mod formats; pub mod html; +mod json; mod markdown; mod passes; mod test; @@ -89,7 +89,8 @@ pub fn main() { }; rustc_driver::set_sigpipe_handler(); rustc_driver::install_ice_hook(); - env_logger::init_from_env("RUSTDOC_LOG"); + rustc_driver::init_env_logger("RUSTDOC_LOG"); + let res = std::thread::Builder::new() .stack_size(thread_stack_size) .spawn(move || get_args().map(|args| main_args(&args)).unwrap_or(1)) @@ -450,6 +451,28 @@ fn wrap_return(diag: &rustc_errors::Handler, res: Result<(), String>) -> i32 { } } +fn run_renderer( + krate: clean::Crate, + renderopts: config::RenderOptions, + render_info: config::RenderInfo, + diag: &rustc_errors::Handler, + edition: rustc_span::edition::Edition, +) -> i32 { + match formats::run_format::(krate, renderopts, render_info, &diag, edition) { + Ok(_) => rustc_driver::EXIT_SUCCESS, + Err(e) => { + let mut msg = diag.struct_err(&format!("couldn't generate documentation: {}", e.error)); + let file = e.file.display().to_string(); + if file.is_empty() { + msg.emit() + } else { + msg.note(&format!("failed to create or modify \"{}\"", file)).emit() + } + rustc_driver::EXIT_FAILURE + } + } +} + fn main_options(options: config::Options) -> i32 { let diag = core::new_handler(options.error_format, None, &options.debugging_options); @@ -480,6 +503,7 @@ fn main_options(options: config::Options) -> i32 { let result = rustc_driver::catch_fatal_errors(move || { let crate_name = options.crate_name.clone(); let crate_version = options.crate_version.clone(); + let output_format = options.output_format; let (mut krate, renderinfo, renderopts) = core::run_core(options); info!("finished with rustc"); @@ -502,20 +526,12 @@ fn main_options(options: config::Options) -> i32 { info!("going to format"); let (error_format, edition, debugging_options) = diag_opts; let diag = core::new_handler(error_format, None, &debugging_options); - match formats::run_format::( - krate, renderopts, renderinfo, &diag, edition, - ) { - Ok(_) => rustc_driver::EXIT_SUCCESS, - Err(e) => { - let mut msg = - diag.struct_err(&format!("couldn't generate documentation: {}", e.error)); - let file = e.file.display().to_string(); - if file.is_empty() { - msg.emit() - } else { - msg.note(&format!("failed to create or modify \"{}\"", file)).emit() - } - rustc_driver::EXIT_FAILURE + match output_format { + None | Some(config::OutputFormat::Html) => { + run_renderer::(krate, renderopts, renderinfo, &diag, edition) + } + Some(config::OutputFormat::Json) => { + run_renderer::(krate, renderopts, renderinfo, &diag, edition) } } }); diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 418238181e9b8..bf7a43236e061 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -867,46 +867,40 @@ fn report_diagnostic( let attrs = &item.attrs; let sp = span_of_attrs(attrs).unwrap_or(item.source.span()); - cx.tcx.struct_span_lint_hir( - lint::builtin::INTRA_DOC_LINK_RESOLUTION_FAILURE, - hir_id, - sp, - |lint| { - let mut diag = lint.build(msg); - - let span = link_range - .as_ref() - .and_then(|range| super::source_span_for_markdown_range(cx, dox, range, attrs)); - - if let Some(link_range) = link_range { - if let Some(sp) = span { - diag.set_span(sp); - } else { - // blah blah blah\nblah\nblah [blah] blah blah\nblah blah - // ^ ~~~~ - // | link_range - // last_new_line_offset - let last_new_line_offset = - dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); - let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); - - // Print the line containing the `link_range` and manually mark it with '^'s. - diag.note(&format!( - "the link appears in this line:\n\n{line}\n\ + cx.tcx.struct_span_lint_hir(lint::builtin::BROKEN_INTRA_DOC_LINKS, hir_id, sp, |lint| { + let mut diag = lint.build(msg); + + let span = link_range + .as_ref() + .and_then(|range| super::source_span_for_markdown_range(cx, dox, range, attrs)); + + if let Some(link_range) = link_range { + if let Some(sp) = span { + diag.set_span(sp); + } else { + // blah blah blah\nblah\nblah [blah] blah blah\nblah blah + // ^ ~~~~ + // | link_range + // last_new_line_offset + let last_new_line_offset = dox[..link_range.start].rfind('\n').map_or(0, |n| n + 1); + let line = dox[last_new_line_offset..].lines().next().unwrap_or(""); + + // Print the line containing the `link_range` and manually mark it with '^'s. + diag.note(&format!( + "the link appears in this line:\n\n{line}\n\ {indicator: $DIR/deny-intra-link-resolution-failure.rs:1:9 | -LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-doc-alias-ice.rs b/src/test/rustdoc-ui/intra-doc-alias-ice.rs index 9657d573d5016..c053e378e7147 100644 --- a/src/test/rustdoc-ui/intra-doc-alias-ice.rs +++ b/src/test/rustdoc-ui/intra-doc-alias-ice.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub type TypeAlias = usize; diff --git a/src/test/rustdoc-ui/intra-doc-alias-ice.stderr b/src/test/rustdoc-ui/intra-doc-alias-ice.stderr index d2b2b90a4e50d..f1c07e31cd753 100644 --- a/src/test/rustdoc-ui/intra-doc-alias-ice.stderr +++ b/src/test/rustdoc-ui/intra-doc-alias-ice.stderr @@ -7,8 +7,8 @@ LL | /// [broken cross-reference](TypeAlias::hoge) note: the lint level is defined here --> $DIR/intra-doc-alias-ice.rs:1:9 | -LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-link-span-ice-55723.rs b/src/test/rustdoc-ui/intra-link-span-ice-55723.rs index 95388003f8470..7764a6df6ee77 100644 --- a/src/test/rustdoc-ui/intra-link-span-ice-55723.rs +++ b/src/test/rustdoc-ui/intra-link-span-ice-55723.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // An error in calculating spans while reporting intra-doc link resolution errors caused rustdoc to // attempt to slice in the middle of a multibyte character. See diff --git a/src/test/rustdoc-ui/intra-link-span-ice-55723.stderr b/src/test/rustdoc-ui/intra-link-span-ice-55723.stderr index 156e214a79ff0..6b0ff8f116295 100644 --- a/src/test/rustdoc-ui/intra-link-span-ice-55723.stderr +++ b/src/test/rustdoc-ui/intra-link-span-ice-55723.stderr @@ -7,8 +7,8 @@ LL | /// (arr[i]) note: the lint level is defined here --> $DIR/intra-link-span-ice-55723.rs:1:9 | -LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to previous error diff --git a/src/test/rustdoc-ui/intra-links-ambiguity.rs b/src/test/rustdoc-ui/intra-links-ambiguity.rs index 7316fcdad6772..d1597cdca66ab 100644 --- a/src/test/rustdoc-ui/intra-links-ambiguity.rs +++ b/src/test/rustdoc-ui/intra-links-ambiguity.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] #![allow(non_camel_case_types)] #![allow(non_upper_case_globals)] diff --git a/src/test/rustdoc-ui/intra-links-ambiguity.stderr b/src/test/rustdoc-ui/intra-links-ambiguity.stderr index 7b9821b3d047a..35262c1b6122e 100644 --- a/src/test/rustdoc-ui/intra-links-ambiguity.stderr +++ b/src/test/rustdoc-ui/intra-links-ambiguity.stderr @@ -7,8 +7,8 @@ LL | /// [`ambiguous`] is ambiguous. note: the lint level is defined here --> $DIR/intra-links-ambiguity.rs:1:9 | -LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ help: to link to the struct, prefix with the item type | LL | /// [`struct@ambiguous`] is ambiguous. diff --git a/src/test/rustdoc-ui/intra-links-anchors.rs b/src/test/rustdoc-ui/intra-links-anchors.rs index 7e61bd725359a..ccefd2e6fabb5 100644 --- a/src/test/rustdoc-ui/intra-links-anchors.rs +++ b/src/test/rustdoc-ui/intra-links-anchors.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // A few tests on anchors. diff --git a/src/test/rustdoc-ui/intra-links-anchors.stderr b/src/test/rustdoc-ui/intra-links-anchors.stderr index ef33d8f3e06fe..e737b84320d94 100644 --- a/src/test/rustdoc-ui/intra-links-anchors.stderr +++ b/src/test/rustdoc-ui/intra-links-anchors.stderr @@ -7,8 +7,8 @@ LL | /// Or maybe [Foo::f#hola]. note: the lint level is defined here --> $DIR/intra-links-anchors.rs:1:9 | -LL | #![deny(intra_doc_link_resolution_failure)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ error: `hello#people#!` contains multiple anchors --> $DIR/intra-links-anchors.rs:31:28 diff --git a/src/test/rustdoc-ui/intra-links-private.private.stderr b/src/test/rustdoc-ui/intra-links-private.private.stderr index a2148b82f819a..77c4b67a6528f 100644 --- a/src/test/rustdoc-ui/intra-links-private.private.stderr +++ b/src/test/rustdoc-ui/intra-links-private.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] | ^^^^^^^^^ this item is private | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/intra-links-private.public.stderr b/src/test/rustdoc-ui/intra-links-private.public.stderr index 56742406992fc..312a78e8c3ec7 100644 --- a/src/test/rustdoc-ui/intra-links-private.public.stderr +++ b/src/test/rustdoc-ui/intra-links-private.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `DocMe` links to private item `DontDocMe` LL | /// docs [DontDocMe] | ^^^^^^^^^ this item is private | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/intra-links-warning-crlf.stderr b/src/test/rustdoc-ui/intra-links-warning-crlf.stderr index bc31264c170ea..1e3a26fadfa9f 100644 --- a/src/test/rustdoc-ui/intra-links-warning-crlf.stderr +++ b/src/test/rustdoc-ui/intra-links-warning-crlf.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `error` LL | /// [error] | ^^^^^ unresolved link | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `error1` diff --git a/src/test/rustdoc-ui/intra-links-warning.stderr b/src/test/rustdoc-ui/intra-links-warning.stderr index 81931399c240a..53f2476295ebb 100644 --- a/src/test/rustdoc-ui/intra-links-warning.stderr +++ b/src/test/rustdoc-ui/intra-links-warning.stderr @@ -4,7 +4,7 @@ warning: unresolved link to `Foo::baz` LL | //! Test with [Foo::baz], [Bar::foo], ... | ^^^^^^^^ unresolved link | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` warning: unresolved link to `Bar::foo` diff --git a/src/test/rustdoc-ui/issue-74134.private.stderr b/src/test/rustdoc-ui/issue-74134.private.stderr index 9c5cdf0117cab..58772109140ca 100644 --- a/src/test/rustdoc-ui/issue-74134.private.stderr +++ b/src/test/rustdoc-ui/issue-74134.private.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = note: this link resolves only because you passed `--document-private-items`, but will break without warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/issue-74134.public.stderr b/src/test/rustdoc-ui/issue-74134.public.stderr index ff2951d864e64..b5bea190941e6 100644 --- a/src/test/rustdoc-ui/issue-74134.public.stderr +++ b/src/test/rustdoc-ui/issue-74134.public.stderr @@ -4,7 +4,7 @@ warning: public documentation for `public_item` links to private item `PrivateTy LL | /// [`PrivateType`] | ^^^^^^^^^^^^^ this item is private | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default = note: this link will resolve properly if you pass `--document-private-items` warning: 1 warning emitted diff --git a/src/test/rustdoc-ui/lint-group.stderr b/src/test/rustdoc-ui/lint-group.stderr index ad923c714da4d..04296d2e44a7c 100644 --- a/src/test/rustdoc-ui/lint-group.stderr +++ b/src/test/rustdoc-ui/lint-group.stderr @@ -39,7 +39,7 @@ note: the lint level is defined here | LL | #![deny(rustdoc)] | ^^^^^^^ - = note: `#[deny(intra_doc_link_resolution_failure)]` implied by `#[deny(rustdoc)]` + = note: `#[deny(broken_intra_doc_links)]` implied by `#[deny(rustdoc)]` = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` error: aborting due to 3 previous errors diff --git a/src/test/rustdoc-ui/reference-link-has-one-warning.stderr b/src/test/rustdoc-ui/reference-link-has-one-warning.stderr index 5bbc62b76dd04..a1eeb60f1785a 100644 --- a/src/test/rustdoc-ui/reference-link-has-one-warning.stderr +++ b/src/test/rustdoc-ui/reference-link-has-one-warning.stderr @@ -4,7 +4,7 @@ warning: `[with#anchor#error]` has an issue with the link anchor. LL | /// docs [label][with#anchor#error] | ^^^^^^^^^^^^^^^^^ only one `#` is allowed in a link | - = note: `#[warn(intra_doc_link_resolution_failure)]` on by default + = note: `#[warn(broken_intra_doc_links)]` on by default warning: 1 warning emitted diff --git a/src/test/rustdoc/intra-doc-crate/additional_doc.rs b/src/test/rustdoc/intra-doc-crate/additional_doc.rs index adfa7f5754eb9..837390b3c7161 100644 --- a/src/test/rustdoc/intra-doc-crate/additional_doc.rs +++ b/src/test/rustdoc/intra-doc-crate/additional_doc.rs @@ -1,6 +1,6 @@ // aux-build:additional_doc.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate my_rand; diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/additional_doc.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/additional_doc.rs index 8b8793e75ed59..849d25687337b 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/additional_doc.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/additional_doc.rs @@ -1,5 +1,5 @@ #![crate_name = "my_rand"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub trait RngCore {} /// Rng extends [`RngCore`]. diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/hidden.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/hidden.rs index 23e38523a4f91..b543ae764c05b 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/hidden.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/hidden.rs @@ -1,5 +1,5 @@ #![crate_name = "hidden_dep"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] #[doc(hidden)] pub mod __reexport { diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/intra-doc-basic.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/intra-doc-basic.rs index 2ee5835a7df84..5342baecbc4b8 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/intra-doc-basic.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/intra-doc-basic.rs @@ -1,5 +1,5 @@ #![crate_name = "a"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub struct Foo; diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/macro_inner.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/macro_inner.rs index abd41fec13016..a94f9e5dcca2e 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/macro_inner.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/macro_inner.rs @@ -1,5 +1,5 @@ #![crate_name = "macro_inner"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub struct Foo; diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/module.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/module.rs index 5d63d7e37b64d..b7e3913f108f7 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/module.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/module.rs @@ -1,5 +1,5 @@ #![crate_name = "module_inner"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] /// [SomeType] links to [bar] pub struct SomeType; pub trait SomeTrait {} diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-inner.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-inner.rs index 3a22d13e673ac..8ae0f6c16b3d8 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-inner.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-inner.rs @@ -1,5 +1,5 @@ #![crate_name = "a"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub mod bar { pub struct Bar; diff --git a/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-outer.rs b/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-outer.rs index b8ca4e44e1f16..d90c529e38552 100644 --- a/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-outer.rs +++ b/src/test/rustdoc/intra-doc-crate/auxiliary/submodule-outer.rs @@ -1,5 +1,5 @@ #![crate_name = "bar"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub trait Foo { /// [`Bar`] [`Baz`] diff --git a/src/test/rustdoc/intra-doc-crate/basic.rs b/src/test/rustdoc/intra-doc-crate/basic.rs index a245a0f84539c..6ab9140c3c385 100644 --- a/src/test/rustdoc/intra-doc-crate/basic.rs +++ b/src/test/rustdoc/intra-doc-crate/basic.rs @@ -1,6 +1,6 @@ // aux-build:intra-doc-basic.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // from https://github.com/rust-lang/rust/issues/65983 extern crate a; diff --git a/src/test/rustdoc/intra-doc-crate/hidden.rs b/src/test/rustdoc/intra-doc-crate/hidden.rs index e3d2af16db19c..9c9d4c649455e 100644 --- a/src/test/rustdoc/intra-doc-crate/hidden.rs +++ b/src/test/rustdoc/intra-doc-crate/hidden.rs @@ -1,6 +1,6 @@ // aux-build:hidden.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // tests https://github.com/rust-lang/rust/issues/73363 diff --git a/src/test/rustdoc/intra-doc-crate/macro.rs b/src/test/rustdoc/intra-doc-crate/macro.rs index 72fd57b6b0c7f..311b16dff13bc 100644 --- a/src/test/rustdoc/intra-doc-crate/macro.rs +++ b/src/test/rustdoc/intra-doc-crate/macro.rs @@ -2,7 +2,7 @@ // aux-build:macro_inner.rs // aux-build:proc_macro.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate macro_inner; extern crate proc_macro_inner; diff --git a/src/test/rustdoc/intra-doc-crate/module.rs b/src/test/rustdoc/intra-doc-crate/module.rs index 67fa7293f37fb..9039e344f7b00 100644 --- a/src/test/rustdoc/intra-doc-crate/module.rs +++ b/src/test/rustdoc/intra-doc-crate/module.rs @@ -1,7 +1,7 @@ // outer.rs // aux-build: module.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate module_inner; // @has 'module/bar/index.html' '//a[@href="../../module_inner/trait.SomeTrait.html"]' 'SomeTrait' // @has 'module/bar/index.html' '//a[@href="../../module_inner/struct.SomeType.html"]' 'SomeType' diff --git a/src/test/rustdoc/intra-doc-crate/submodule-inner.rs b/src/test/rustdoc/intra-doc-crate/submodule-inner.rs index b4b615bf9edad..e1465816368bf 100644 --- a/src/test/rustdoc/intra-doc-crate/submodule-inner.rs +++ b/src/test/rustdoc/intra-doc-crate/submodule-inner.rs @@ -1,6 +1,6 @@ // aux-build:submodule-inner.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate a; diff --git a/src/test/rustdoc/intra-doc-crate/submodule-outer.rs b/src/test/rustdoc/intra-doc-crate/submodule-outer.rs index 6b30ef8b3dec8..45f561328f279 100644 --- a/src/test/rustdoc/intra-doc-crate/submodule-outer.rs +++ b/src/test/rustdoc/intra-doc-crate/submodule-outer.rs @@ -1,6 +1,6 @@ // aux-build:submodule-outer.rs // edition:2018 -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate bar as bar_; diff --git a/src/test/rustdoc/intra-doc-crate/traits.rs b/src/test/rustdoc/intra-doc-crate/traits.rs index 617331236902d..07f9fb6331333 100644 --- a/src/test/rustdoc/intra-doc-crate/traits.rs +++ b/src/test/rustdoc/intra-doc-crate/traits.rs @@ -3,7 +3,7 @@ // aux-build:traits.rs // build-aux-docs // ignore-tidy-line-length -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate inner; use inner::SomeTrait; diff --git a/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs b/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs index 65187f48539a4..bd733e1023033 100644 --- a/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs +++ b/src/test/rustdoc/intra-doc-link-mod-ambiguity.rs @@ -1,6 +1,6 @@ // ignore-tidy-linelength -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub fn foo() { diff --git a/src/test/rustdoc/intra-link-extern-crate.rs b/src/test/rustdoc/intra-link-extern-crate.rs index bbe3edaea8cb2..193bca704bfbd 100644 --- a/src/test/rustdoc/intra-link-extern-crate.rs +++ b/src/test/rustdoc/intra-link-extern-crate.rs @@ -4,6 +4,6 @@ // though they would never actually get displayed. This tripped intra-doc-link resolution failures, // for items that aren't under our control, and not actually getting documented! -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate inner; diff --git a/src/test/rustdoc/intra-link-in-bodies.rs b/src/test/rustdoc/intra-link-in-bodies.rs index 4c693907226ad..ec965a99dc240 100644 --- a/src/test/rustdoc/intra-link-in-bodies.rs +++ b/src/test/rustdoc/intra-link-in-bodies.rs @@ -1,6 +1,6 @@ // we need to make sure that intra-doc links on trait impls get resolved in the right scope -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub mod inner { pub struct SomethingOutOfScope; diff --git a/src/test/rustdoc/intra-link-libstd-re-export.rs b/src/test/rustdoc/intra-link-libstd-re-export.rs index 6f239292ec200..d0af3aec66097 100644 --- a/src/test/rustdoc/intra-link-libstd-re-export.rs +++ b/src/test/rustdoc/intra-link-libstd-re-export.rs @@ -1,3 +1,3 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub use std::*; diff --git a/src/test/rustdoc/intra-link-prim-methods-external-core.rs b/src/test/rustdoc/intra-link-prim-methods-external-core.rs index e09d36594edf9..c8ef4c015997b 100644 --- a/src/test/rustdoc/intra-link-prim-methods-external-core.rs +++ b/src/test/rustdoc/intra-link-prim-methods-external-core.rs @@ -4,7 +4,7 @@ // ignore-windows // ignore-tidy-linelength -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] #![feature(no_core, lang_items)] #![no_core] #![crate_type = "rlib"] diff --git a/src/test/rustdoc/intra-link-prim-methods-local.rs b/src/test/rustdoc/intra-link-prim-methods-local.rs index d24cd2cbb5e20..d448acf7f9682 100644 --- a/src/test/rustdoc/intra-link-prim-methods-local.rs +++ b/src/test/rustdoc/intra-link-prim-methods-local.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] #![feature(no_core, lang_items)] #![no_core] #![crate_type = "rlib"] diff --git a/src/test/rustdoc/intra-link-prim-methods.rs b/src/test/rustdoc/intra-link-prim-methods.rs index 76636b80b5eb5..94c80c996c1e0 100644 --- a/src/test/rustdoc/intra-link-prim-methods.rs +++ b/src/test/rustdoc/intra-link-prim-methods.rs @@ -1,4 +1,4 @@ -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // ignore-tidy-linelength diff --git a/src/test/rustdoc/intra-link-prim-precedence.rs b/src/test/rustdoc/intra-link-prim-precedence.rs index d7ebb73b3be7d..5f10c1ec4a75c 100644 --- a/src/test/rustdoc/intra-link-prim-precedence.rs +++ b/src/test/rustdoc/intra-link-prim-precedence.rs @@ -1,5 +1,5 @@ // ignore-tidy-linelength -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] pub mod char {} diff --git a/src/test/rustdoc/intra-link-private.rs b/src/test/rustdoc/intra-link-private.rs index c99b4d70684aa..cf8bc0b15869f 100644 --- a/src/test/rustdoc/intra-link-private.rs +++ b/src/test/rustdoc/intra-link-private.rs @@ -2,7 +2,7 @@ // These failures were legitimate, but not truly relevant - the docs in question couldn't be // checked for accuracy anyway. -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] /// ooh, i'm a [rebel] just for kicks struct SomeStruct; diff --git a/src/test/rustdoc/intra-link-proc-macro.rs b/src/test/rustdoc/intra-link-proc-macro.rs index 7b6ea5d60f853..7a8403255edb6 100644 --- a/src/test/rustdoc/intra-link-proc-macro.rs +++ b/src/test/rustdoc/intra-link-proc-macro.rs @@ -1,6 +1,6 @@ // aux-build:intra-link-proc-macro-macro.rs // build-aux-docs -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] extern crate intra_link_proc_macro_macro; diff --git a/src/test/rustdoc/intra-links-external-traits.rs b/src/test/rustdoc/intra-links-external-traits.rs index d6b4a8ad58ad7..de76f29476c66 100644 --- a/src/test/rustdoc/intra-links-external-traits.rs +++ b/src/test/rustdoc/intra-links-external-traits.rs @@ -2,7 +2,7 @@ // ignore-cross-compile #![crate_name = "outer"] -#![deny(intra_doc_link_resolution_failure)] +#![deny(broken_intra_doc_links)] // using a trait that has intra-doc links on it from another crate (whether re-exporting or just // implementing it) used to give spurious resolution failure warnings diff --git a/src/test/rustdoc/through-proc-macro.rs b/src/test/rustdoc/through-proc-macro.rs index 348c9eea2dcbf..613410871f0d1 100644 --- a/src/test/rustdoc/through-proc-macro.rs +++ b/src/test/rustdoc/through-proc-macro.rs @@ -1,6 +1,6 @@ // aux-build:through-proc-macro-aux.rs // build-aux-docs -#![warn(intra_doc_link_resolution_failure)] +#![warn(broken_intra_doc_links)] extern crate some_macros; #[some_macros::second] diff --git a/src/test/ui/const-generics/nested-type.rs b/src/test/ui/const-generics/nested-type.rs new file mode 100644 index 0000000000000..12ea850c8f686 --- /dev/null +++ b/src/test/ui/const-generics/nested-type.rs @@ -0,0 +1,18 @@ +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct Foo; + + impl Foo { + fn value() -> usize { + N + } + } + + Foo::<17>::value() +}]>; + +fn main() {} diff --git a/src/test/ui/const-generics/nested-type.stderr b/src/test/ui/const-generics/nested-type.stderr new file mode 100644 index 0000000000000..da0e8032404fc --- /dev/null +++ b/src/test/ui/const-generics/nested-type.stderr @@ -0,0 +1,159 @@ +error[E0391]: cycle detected when computing type of `Foo` + --> $DIR/nested-type.rs:4:1 + | +LL | struct Foo $DIR/nested-type.rs:4:18 + | +LL | struct Foo $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires const-evaluating `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires type-checking `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`... + --> $DIR/nested-type.rs:7:5 + | +LL | struct Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which requires computing the variances for items in this crate... + = note: ...which again requires computing type of `Foo`, completing the cycle +note: cycle used when collecting item types in top-level module + --> $DIR/nested-type.rs:1:1 + | +LL | / #![feature(const_generics)] +LL | | #![allow(incomplete_features)] +LL | | +LL | | struct Foo $DIR/nested-type.rs:4:1 + | +LL | struct Foo $DIR/nested-type.rs:4:18 + | +LL | struct Foo $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires const-evaluating `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires type-checking `Foo::{{constant}}#0`... + --> $DIR/nested-type.rs:4:26 + | +LL | struct Foo; +... | +LL | | Foo::<17>::value() +LL | | }]>; + | |_^ +note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`... + --> $DIR/nested-type.rs:7:5 + | +LL | struct Foo; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + = note: ...which requires computing the variances for items in this crate... + = note: ...which again requires computing type of `Foo`, completing the cycle +note: cycle used when collecting item types in top-level module + --> $DIR/nested-type.rs:1:1 + | +LL | / #![feature(const_generics)] +LL | | #![allow(incomplete_features)] +LL | | +LL | | struct Foo::None.unwrap(); //~ NOTE + +fn main() { + println!("{}", FOO); + println!("{}", BAR); +} diff --git a/src/test/ui/consts/const-unwrap.stderr b/src/test/ui/consts/const-unwrap.stderr new file mode 100644 index 0000000000000..7f2c1f4151097 --- /dev/null +++ b/src/test/ui/consts/const-unwrap.stderr @@ -0,0 +1,20 @@ +error: any use of this value will cause an error + --> $SRC_DIR/core/src/option.rs:LL:COL + | +LL | None => panic!("called `Option::unwrap()` on a `None` value"), + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | | + | the evaluated program panicked at 'called `Option::unwrap()` on a `None` value', $DIR/const-unwrap.rs:9:38 + | inside `std::option::Option::::unwrap` at $SRC_DIR/core/src/macros/mod.rs:LL:COL + | inside `BAR` at $DIR/const-unwrap.rs:9:18 + | + ::: $DIR/const-unwrap.rs:9:1 + | +LL | const BAR: i32 = Option::::None.unwrap(); + | ---------------------------------------------- + | + = note: `#[deny(const_err)]` on by default + = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + diff --git a/src/test/ui/consts/const_constructor/const-construct-call.rs b/src/test/ui/consts/const_constructor/const-construct-call.rs index d883d3fa6e40e..d3e6cf78bc93b 100644 --- a/src/test/ui/consts/const_constructor/const-construct-call.rs +++ b/src/test/ui/consts/const_constructor/const-construct-call.rs @@ -6,7 +6,7 @@ #![cfg_attr(const_fn, feature(const_fn))] -// Ctor(..) is transformed to Ctor { 0: ... } in HAIR lowering, so directly +// Ctor(..) is transformed to Ctor { 0: ... } in THIR lowering, so directly // calling constructors doesn't require them to be const. type ExternalType = std::panic::AssertUnwindSafe<(Option, Result)>; diff --git a/src/test/ui/consts/issue-73976-polymorphic.rs b/src/test/ui/consts/issue-73976-polymorphic.rs index 7cf20296062ab..518036c9dbeec 100644 --- a/src/test/ui/consts/issue-73976-polymorphic.rs +++ b/src/test/ui/consts/issue-73976-polymorphic.rs @@ -17,8 +17,8 @@ impl GetTypeId { const fn check_type_id() -> bool { matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) - //~^ ERROR could not evaluate constant pattern - //~| ERROR could not evaluate constant pattern + //~^ ERROR constant pattern depends on a generic parameter + //~| ERROR constant pattern depends on a generic parameter } pub struct GetTypeNameLen(T); @@ -29,8 +29,8 @@ impl GetTypeNameLen { const fn check_type_name_len() -> bool { matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE) - //~^ ERROR could not evaluate constant pattern - //~| ERROR could not evaluate constant pattern + //~^ ERROR constant pattern depends on a generic parameter + //~| ERROR constant pattern depends on a generic parameter } fn main() { diff --git a/src/test/ui/consts/issue-73976-polymorphic.stderr b/src/test/ui/consts/issue-73976-polymorphic.stderr index 971573e14aad8..250f1536d85fc 100644 --- a/src/test/ui/consts/issue-73976-polymorphic.stderr +++ b/src/test/ui/consts/issue-73976-polymorphic.stderr @@ -1,22 +1,22 @@ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:19:37 | LL | matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:31:42 | LL | matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:19:37 | LL | matches!(GetTypeId::::VALUE, GetTypeId::::VALUE) | ^^^^^^^^^^^^^^^^^^^^^ -error: could not evaluate constant pattern +error: constant pattern depends on a generic parameter --> $DIR/issue-73976-polymorphic.rs:31:42 | LL | matches!(GetTypeNameLen::::VALUE, GetTypeNameLen::::VALUE) diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.rs b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs similarity index 100% rename from src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.rs rename to src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs diff --git a/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr similarity index 69% rename from src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr rename to src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr index b536e1b5548d0..12ad86429613b 100644 --- a/src/test/ui/half-open-range-patterns/half-open-range-pats-hair-lower-empty.stderr +++ b/src/test/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr @@ -1,155 +1,155 @@ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:12:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:12:11 | LL | m!(0, ..core::u8::MIN); | ^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:15:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11 | LL | m!(0, ..core::u16::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:18:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:18:11 | LL | m!(0, ..core::u32::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:21:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:21:11 | LL | m!(0, ..core::u64::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:24:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11 | LL | m!(0, ..core::u128::MIN); | ^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:28:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11 | LL | m!(0, ..core::i8::MIN); | ^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:31:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:31:11 | LL | m!(0, ..core::i16::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:34:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:34:11 | LL | m!(0, ..core::i32::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:37:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:37:11 | LL | m!(0, ..core::i64::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:40:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:40:11 | LL | m!(0, ..core::i128::MIN); | ^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:44:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:44:14 | LL | m!(0f32, ..core::f32::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:47:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:47:14 | LL | m!(0f64, ..core::f64::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:51:13 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:51:13 | LL | m!('a', ..'\u{0}'); | ^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:12:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:12:11 | LL | m!(0, ..core::u8::MIN); | ^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:15:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:15:11 | LL | m!(0, ..core::u16::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:18:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:18:11 | LL | m!(0, ..core::u32::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:21:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:21:11 | LL | m!(0, ..core::u64::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:24:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:24:11 | LL | m!(0, ..core::u128::MIN); | ^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:28:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:28:11 | LL | m!(0, ..core::i8::MIN); | ^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:31:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:31:11 | LL | m!(0, ..core::i16::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:34:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:34:11 | LL | m!(0, ..core::i32::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:37:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:37:11 | LL | m!(0, ..core::i64::MIN); | ^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:40:11 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:40:11 | LL | m!(0, ..core::i128::MIN); | ^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:44:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:44:14 | LL | m!(0f32, ..core::f32::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:47:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:47:14 | LL | m!(0f64, ..core::f64::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-hair-lower-empty.rs:51:13 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:51:13 | LL | m!('a', ..'\u{0}'); | ^^^^^^^^^ diff --git a/src/test/ui/issues/issue-74614.rs b/src/test/ui/issues/issue-74614.rs index f5e8deb29fbc8..8b0c00b135519 100644 --- a/src/test/ui/issues/issue-74614.rs +++ b/src/test/ui/issues/issue-74614.rs @@ -1,3 +1,4 @@ +// compile-flags:-Zpolymorphize=on // build-pass fn test() { diff --git a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.rs b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.rs index 1479791719313..993954b450e37 100644 --- a/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.rs +++ b/src/test/ui/pattern/bindings-after-at/borrowck-pat-by-move-and-ref-inverse-promotion.rs @@ -1,5 +1,5 @@ // Test that `by_move_binding @ pat_with_by_ref_bindings` is prevented even with promotion. -// Currently this logic exists in HAIR match checking as opposed to borrowck. +// Currently this logic exists in THIR match checking as opposed to borrowck. #![feature(bindings_after_at)] #![feature(move_ref_pattern)] diff --git a/src/test/ui/pattern/const-pat-ice.stderr b/src/test/ui/pattern/const-pat-ice.stderr index 6e87e5c6912c3..2aa0824f30186 100644 --- a/src/test/ui/pattern/const-pat-ice.stderr +++ b/src/test/ui/pattern/const-pat-ice.stderr @@ -1,4 +1,4 @@ -thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir_build/hair/pattern/_match.rs:LL:CC +thread 'rustc' panicked at 'assertion failed: rows.iter().all(|r| r.len() == v.len())', src/librustc_mir_build/thir/pattern/_match.rs:LL:CC note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace error: internal compiler error: unexpected panic diff --git a/src/test/ui/polymorphization/issue-74636.rs b/src/test/ui/polymorphization/issue-74636.rs new file mode 100644 index 0000000000000..4c532f451e373 --- /dev/null +++ b/src/test/ui/polymorphization/issue-74636.rs @@ -0,0 +1,16 @@ +// compile-flags:-Zpolymorphize=on +// build-pass + +use std::any::TypeId; + +pub fn foo(_: T) -> TypeId { + TypeId::of::() +} + +fn outer() { + foo(|| ()); +} + +fn main() { + outer::(); +} diff --git a/src/test/ui/statics/static-promotion.rs b/src/test/ui/statics/static-promotion.rs new file mode 100644 index 0000000000000..bd8910bdb3f3f --- /dev/null +++ b/src/test/ui/statics/static-promotion.rs @@ -0,0 +1,34 @@ +// check-pass + +// Use of global static variables in literal values should be allowed for +// promotion. +// This test is to demonstrate the issue raised in +// https://github.com/rust-lang/rust/issues/70584 + +// Literal values were previously promoted into local static values when +// other global static variables are used. + +struct A(&'static T); +struct B { + x: &'static T, +} +static STR: &'static [u8] = b"hi"; +static C: A>> = { + A(&B { + x: &B { x: STR }, + }) +}; + +pub struct Slice(&'static [i32]); + +static CONTENT: i32 = 42; +pub static CONTENT_MAP: Slice = Slice(&[CONTENT]); + +pub static FOO: (i32, i32) = (42, 43); +pub static CONTENT_MAP2: Slice = Slice(&[FOO.0]); + +fn main() { + assert_eq!(b"hi", C.0.x.x); + assert_eq!(&[42], CONTENT_MAP.0); + assert_eq!(&[42], CONTENT_MAP2.0); +} diff --git a/src/tools/cargo b/src/tools/cargo index 974eb438da8ce..2d5c2381e4e50 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit 974eb438da8ced6e3becda2bbf63d9b643eacdeb +Subproject commit 2d5c2381e4e50484bf281fc1bfe19743aa9eb37a diff --git a/src/tools/clippy/clippy_lints/src/utils/mod.rs b/src/tools/clippy/clippy_lints/src/utils/mod.rs index 655b1133cf74f..3f8e15d90297d 100644 --- a/src/tools/clippy/clippy_lints/src/utils/mod.rs +++ b/src/tools/clippy/clippy_lints/src/utils/mod.rs @@ -883,7 +883,7 @@ pub fn is_ctor_or_promotable_const_function(cx: &LateContext<'_>, expr: &Expr<'_ } /// Returns `true` if a pattern is refutable. -// TODO: should be implemented using rustc/mir_build/hair machinery +// TODO: should be implemented using rustc/mir_build/thir machinery pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { fn is_enum_variant(cx: &LateContext<'_>, qpath: &QPath<'_>, id: HirId) -> bool { matches!( diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml index 338a167de3fe5..bd4c5949800f6 100644 --- a/src/tools/compiletest/Cargo.toml +++ b/src/tools/compiletest/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" diff = "0.1.10" env_logger = { version = "0.7", default-features = false } getopts = "0.2" -log = "0.4" +log = { package = "tracing", version = "0.1" } regex = "1.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index c4292d041d051..bd9f8fb045025 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -1,7 +1,7 @@ #![feature(rustc_private)] -extern crate env_logger; extern crate rustc_ast; +extern crate rustc_driver; extern crate rustc_span; use std::cell::RefCell; @@ -282,7 +282,7 @@ fn parse_args() -> (OutputFormat, PathBuf) { } fn main() { - env_logger::init(); + rustc_driver::init_env_logger("RUST_LOG"); let (format, dst) = parse_args(); let result = rustc_ast::with_default_session_globals(move || main_with_result(format, &dst)); if let Err(e) = result { diff --git a/src/tools/miri b/src/tools/miri index 515287f114b54..55bdb31746530 160000 --- a/src/tools/miri +++ b/src/tools/miri @@ -1 +1 @@ -Subproject commit 515287f114b546a72d4a1fe8ffe1dbc20dedf13d +Subproject commit 55bdb3174653039f47362742f8dc941bfc086e8f diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index e50d27f8006d8..55e17466a881e 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -17,6 +17,7 @@ const LICENSES: &[&str] = &[ "MIT", "Unlicense/MIT", "Unlicense OR MIT", + "0BSD OR MIT OR Apache-2.0", // adler license ]; /// These are exceptions to Rust's permissive licensing policy, and @@ -36,7 +37,6 @@ const EXCEPTIONS: &[(&str, &str)] = &[ ("ryu", "Apache-2.0 OR BSL-1.0"), // rls/cargo/... (because of serde) ("bytesize", "Apache-2.0"), // cargo ("im-rc", "MPL-2.0+"), // cargo - ("adler32", "BSD-3-Clause AND Zlib"), // cargo dep that isn't used ("constant_time_eq", "CC0-1.0"), // rustfmt ("sized-chunks", "MPL-2.0+"), // cargo via im-rc ("bitmaps", "MPL-2.0+"), // cargo via im-rc @@ -57,7 +57,8 @@ const RESTRICTED_DEPENDENCY_CRATES: &[&str] = &["rustc_middle", "rustc_codegen_l /// This list is here to provide a speed-bump to adding a new dependency to /// rustc. Please check with the compiler team before adding an entry. const PERMITTED_DEPENDENCIES: &[&str] = &[ - "adler32", + "addr2line", + "adler", "aho-corasick", "annotate-snippets", "ansi_term", @@ -65,7 +66,6 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "atty", "autocfg", "backtrace", - "backtrace-sys", "bitflags", "block-buffer", "block-padding", @@ -98,6 +98,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "generic-array", "getopts", "getrandom", + "gimli", "hashbrown", "hermit-abi", "humantime", @@ -119,6 +120,7 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "miniz_oxide", "nodrop", "num_cpus", + "object", "once_cell", "opaque-debug", "parking_lot", @@ -164,6 +166,9 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[ "termcolor", "termize", "thread_local", + "tracing", + "tracing-attributes", + "tracing-core", "typenum", "unicode-normalization", "unicode-script", diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 08b2fccd73f5c..19218cbd66a8a 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -51,6 +51,7 @@ pub mod unstable_book; fn filter_dirs(path: &Path) -> bool { let skip = [ "src/llvm-project", + "library/backtrace", "library/stdarch", "src/tools/cargo", "src/tools/clippy",