From 03f2cf24637e7536eeffeb8ff7010687f48e1031 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 8 Jul 2021 00:05:38 -0700 Subject: [PATCH 01/23] Make `--force-warns` a normal lint level option --- compiler/rustc_lint/src/levels.rs | 17 +++++------- compiler/rustc_session/src/config.rs | 39 +++++++++------------------ compiler/rustc_session/src/options.rs | 1 - src/librustdoc/config.rs | 2 +- 4 files changed, 20 insertions(+), 39 deletions(-) diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index bc6956f579783..4edf76170701e 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -104,23 +104,18 @@ impl<'s> LintLevelsBuilder<'s> { Err(_) => continue, // errors handled in check_lint_name_cmdline above }; for id in ids { + // ForceWarn and Forbid cannot be overriden + match specs.get(&id) { + Some((Level::ForceWarn | Level::Forbid, _)) => continue, + _ => (), + } + self.check_gated_lint(id, DUMMY_SP); let src = LintLevelSource::CommandLine(lint_flag_val, orig_level); specs.insert(id, (level, src)); } } - for lint_name in &sess.opts.force_warns { - store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn, self.crate_attrs); - let lints = store - .find_lints(lint_name) - .unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids")); - for id in lints { - let src = LintLevelSource::CommandLine(Symbol::intern(lint_name), Level::ForceWarn); - specs.insert(id, (Level::ForceWarn, src)); - } - } - self.cur = self.sets.list.push(LintSet { specs, parent: COMMAND_LINE }); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 88eaa7fe32924..a75b79048e6a8 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -677,7 +677,6 @@ impl Default for Options { optimize: OptLevel::No, debuginfo: DebugInfo::None, lint_opts: Vec::new(), - force_warns: Vec::new(), lint_cap: None, describe_lints: false, output_types: OutputTypes(BTreeMap::new()), @@ -1170,20 +1169,20 @@ pub fn get_cmd_lint_options( matches: &getopts::Matches, error_format: ErrorOutputType, debugging_opts: &DebuggingOptions, -) -> (Vec<(String, lint::Level)>, bool, Option, Vec) { +) -> (Vec<(String, lint::Level)>, bool, Option) { let mut lint_opts_with_position = vec![]; let mut describe_lints = false; - for level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid] { - for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { - let arg_pos = if let lint::Forbid = level { - // HACK: forbid is always specified last, so it can't be overridden. - // FIXME: remove this once is - // fixed and `forbid` works as expected. - usize::MAX - } else { - passed_arg_pos - }; + if !debugging_opts.unstable_options && matches.opt_present("force-warns") { + early_error( + error_format, + "the `-Z unstable-options` flag must also be passed to enable \ + the flag `--force-warns=lints`", + ); + } + + for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] { + for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) { if lint_name == "help" { describe_lints = true; } else { @@ -1204,18 +1203,7 @@ pub fn get_cmd_lint_options( .unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap))) }); - if !debugging_opts.unstable_options && matches.opt_present("force-warns") { - early_error( - error_format, - "the `-Z unstable-options` flag must also be passed to enable \ - the flag `--force-warns=lints`", - ); - } - - let force_warns = - matches.opt_strs("force-warns").into_iter().map(|name| name.replace('-', "_")).collect(); - - (lint_opts, describe_lints, lint_cap, force_warns) + (lint_opts, describe_lints, lint_cap) } /// Parses the `--color` flag. @@ -1953,7 +1941,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { .unwrap_or_else(|e| early_error(error_format, &e[..])); let mut debugging_opts = DebuggingOptions::build(matches, error_format); - let (lint_opts, describe_lints, lint_cap, force_warns) = + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format, &debugging_opts); check_debug_option_stability(&debugging_opts, error_format, json_rendered); @@ -2127,7 +2115,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options { optimize: opt_level, debuginfo, lint_opts, - force_warns, lint_cap, describe_lints, output_types, diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 4c40d0c367eca..00da62b1d074f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -135,7 +135,6 @@ top_level_options!( debuginfo: DebugInfo [TRACKED], lint_opts: Vec<(String, lint::Level)> [TRACKED], lint_cap: Option [TRACKED], - force_warns: Vec [TRACKED], describe_lints: bool [UNTRACKED], output_types: OutputTypes [TRACKED], search_paths: Vec [UNTRACKED], diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 4cf647a81ae4b..d601d948555fb 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -628,7 +628,7 @@ impl Options { let generate_redirect_map = matches.opt_present("generate-redirect-map"); let show_type_layout = matches.opt_present("show-type-layout"); - let (lint_opts, describe_lints, lint_cap, _) = + let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format, &debugging_opts); Ok(Options { From 07f1e6152c5aab4490975d53e2da442a4e827fc5 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Mon, 28 Jun 2021 17:42:55 -0400 Subject: [PATCH 02/23] Add natvis for NonZero and Wrapping types --- src/etc/natvis/libcore.natvis | 41 ++++++++ src/test/debuginfo/numeric-types.rs | 142 ++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 src/test/debuginfo/numeric-types.rs diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index c8196d5c713b2..7eaba42e2f77d 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -1,5 +1,46 @@ + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + {__0} + + + + {__0} + + {{ Unique {pointer} }} diff --git a/src/test/debuginfo/numeric-types.rs b/src/test/debuginfo/numeric-types.rs new file mode 100644 index 0000000000000..8e03a2947ea45 --- /dev/null +++ b/src/test/debuginfo/numeric-types.rs @@ -0,0 +1,142 @@ +// only-cdb +// compile-flags:-g + +// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}` and `Wrapping` in +// `libcore.natvis`. + +// === CDB TESTS ================================================================================== +// cdb-command: g + +// cdb-command: dx nz_i8 +// cdb-check:nz_i8 : 11 [Type: core::num::nonzero::NonZeroI8] +// cdb-check: [] [Type: core::num::nonzero::NonZeroI8] + +// cdb-command: dx nz_i16 +// cdb-check:nz_i16 : 22 [Type: core::num::nonzero::NonZeroI16] +// cdb-check: [] [Type: core::num::nonzero::NonZeroI16] + +// cdb-command: dx nz_i32 +// cdb-check:nz_i32 : 33 [Type: core::num::nonzero::NonZeroI32] +// cdb-check: [] [Type: core::num::nonzero::NonZeroI32] + +// cdb-command: dx nz_i64 +// cdb-check:nz_i64 : 44 [Type: core::num::nonzero::NonZeroI64] +// cdb-check: [] [Type: core::num::nonzero::NonZeroI64] + +// 128-bit integers don't seem to work in CDB +// cdb-command: dx nz_i128 +// cdb-check: [] [Type: core::num::nonzero::NonZeroI128] + +// cdb-command: dx nz_isize +// cdb-check:nz_isize : 66 [Type: core::num::nonzero::NonZeroIsize] +// cdb-check: [] [Type: core::num::nonzero::NonZeroIsize] + +// cdb-command: dx nz_u8 +// cdb-check:nz_u8 : 0x4d [Type: core::num::nonzero::NonZeroU8] +// cdb-check: [] [Type: core::num::nonzero::NonZeroU8] + +// cdb-command: dx nz_u16 +// cdb-check:nz_u16 : 0x58 [Type: core::num::nonzero::NonZeroU16] +// cdb-check: [] [Type: core::num::nonzero::NonZeroU16] + +// cdb-command: dx nz_u32 +// cdb-check:nz_u32 : 0x63 [Type: core::num::nonzero::NonZeroU32] +// cdb-check: [] [Type: core::num::nonzero::NonZeroU32] + +// cdb-command: dx nz_u64 +// cdb-check:nz_u64 : 0x64 [Type: core::num::nonzero::NonZeroU64] +// cdb-check: [] [Type: core::num::nonzero::NonZeroU64] + +// 128-bit integers don't seem to work in CDB +// cdb-command: dx nz_u128 +// cdb-check: [] [Type: core::num::nonzero::NonZeroU128] + +// cdb-command: dx nz_usize +// cdb-check:nz_usize : 0x7a [Type: core::num::nonzero::NonZeroUsize] +// cdb-check: [] [Type: core::num::nonzero::NonZeroUsize] + +// cdb-command: dx w_i8 +// cdb-check:w_i8 : 10 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_i16 +// cdb-check:w_i16 : 20 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_i32 +// cdb-check:w_i32 : 30 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_i64 +// cdb-check:w_i64 : 40 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// 128-bit integers don't seem to work in CDB +// cdb-command: dx w_i128 +// cdb-check:w_i128 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_isize +// cdb-check:w_isize : 60 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_u8 +// cdb-check:w_u8 : 0x46 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_u16 +// cdb-check:w_u16 : 0x50 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_u32 +// cdb-check:w_u32 : 0x5a [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_u64 +// cdb-check:w_u64 : 0x64 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// 128-bit integers don't seem to work in CDB +// cdb-command: dx w_u128 +// cdb-check:w_u128 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +// cdb-command: dx w_usize +// cdb-check:w_usize : 0x78 [Type: core::num::wrapping::Wrapping] +// cdb-check: [] [Type: core::num::wrapping::Wrapping] + +use std::num::*; + +fn main() { + let nz_i8 = NonZeroI8::new(11).unwrap(); + let nz_i16 = NonZeroI16::new(22).unwrap(); + let nz_i32 = NonZeroI32::new(33).unwrap(); + let nz_i64 = NonZeroI64::new(44).unwrap(); + let nz_i128 = NonZeroI128::new(55).unwrap(); + let nz_isize = NonZeroIsize::new(66).unwrap(); + + let nz_u8 = NonZeroU8::new(77).unwrap(); + let nz_u16 = NonZeroU16::new(88).unwrap(); + let nz_u32 = NonZeroU32::new(99).unwrap(); + let nz_u64 = NonZeroU64::new(100).unwrap(); + let nz_u128 = NonZeroU128::new(111).unwrap(); + let nz_usize = NonZeroUsize::new(122).unwrap(); + + let w_i8 = Wrapping(10i8); + let w_i16 = Wrapping(20i16); + let w_i32 = Wrapping(30i32); + let w_i64 = Wrapping(40i64); + let w_i128 = Wrapping(50i128); + let w_isize = Wrapping(60isize); + + let w_u8 = Wrapping(70u8); + let w_u16 = Wrapping(80u16); + let w_u32 = Wrapping(90u32); + let w_u64 = Wrapping(100u64); + let w_u128 = Wrapping(110u128); + let w_usize = Wrapping(120usize); + + zzz(); // #break +} + +fn zzz() { } From 9740dcc82f39c2a7f1700ebbb2f0edb53388a44b Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 29 Jun 2021 10:45:41 -0400 Subject: [PATCH 03/23] Add natvis for Atomic types --- src/etc/natvis/libcore.natvis | 36 ++++++++++++++- src/test/debuginfo/numeric-types.rs | 68 ++++++++++++++++++++++++++++- 2 files changed, 101 insertions(+), 3 deletions(-) diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 7eaba42e2f77d..b5899cf9319d8 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -61,4 +61,38 @@ *pointer - \ No newline at end of file + + + {(bool)v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + + {v.value} + + diff --git a/src/test/debuginfo/numeric-types.rs b/src/test/debuginfo/numeric-types.rs index 8e03a2947ea45..2eae9239b6118 100644 --- a/src/test/debuginfo/numeric-types.rs +++ b/src/test/debuginfo/numeric-types.rs @@ -1,8 +1,8 @@ // only-cdb // compile-flags:-g -// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}` and `Wrapping` in -// `libcore.natvis`. +// Tests the visualizations for `NonZero{I,U}{8,16,32,64,128,size}`, `Wrapping` and +// `Atomic{Bool,I8,I16,I32,I64,Isize,U8,U16,U32,U64,Usize}` located in `libcore.natvis`. // === CDB TESTS ================================================================================== // cdb-command: g @@ -105,7 +105,56 @@ // cdb-check:w_usize : 0x78 [Type: core::num::wrapping::Wrapping] // cdb-check: [] [Type: core::num::wrapping::Wrapping] +// cdb-command: dx a_bool_t +// cdb-check:a_bool_t : true [Type: core::sync::atomic::AtomicBool] +// cdb-check: [] [Type: core::sync::atomic::AtomicBool] + +// cdb-command: dx a_bool_f +// cdb-check:a_bool_f : false [Type: core::sync::atomic::AtomicBool] +// cdb-check: [] [Type: core::sync::atomic::AtomicBool] + +// cdb-command: dx a_i8 +// cdb-check:a_i8 : 2 [Type: core::sync::atomic::AtomicI8] +// cdb-check: [] [Type: core::sync::atomic::AtomicI8] + +// cdb-command: dx a_i16 +// cdb-check:a_i16 : 4 [Type: core::sync::atomic::AtomicI16] +// cdb-check: [] [Type: core::sync::atomic::AtomicI16] + +// cdb-command: dx a_i32 +// cdb-check:a_i32 : 8 [Type: core::sync::atomic::AtomicI32] +// cdb-check: [] [Type: core::sync::atomic::AtomicI32] + +// cdb-command: dx a_i64 +// cdb-check:a_i64 : 16 [Type: core::sync::atomic::AtomicI64] +// cdb-check: [] [Type: core::sync::atomic::AtomicI64] + +// cdb-command: dx a_isize +// cdb-check:a_isize : 32 [Type: core::sync::atomic::AtomicIsize] +// cdb-check: [] [Type: core::sync::atomic::AtomicIsize] + +// cdb-command: dx a_u8 +// cdb-check:a_u8 : 0x40 [Type: core::sync::atomic::AtomicU8] +// cdb-check: [] [Type: core::sync::atomic::AtomicU8] + +// cdb-command: dx a_u16 +// cdb-check:a_u16 : 0x80 [Type: core::sync::atomic::AtomicU16] +// cdb-check: [] [Type: core::sync::atomic::AtomicU16] + +// cdb-command: dx a_u32 +// cdb-check:a_u32 : 0x100 [Type: core::sync::atomic::AtomicU32] +// cdb-check: [] [Type: core::sync::atomic::AtomicU32] + +// cdb-command: dx a_u64 +// cdb-check:a_u64 : 0x200 [Type: core::sync::atomic::AtomicU64] +// cdb-check: [] [Type: core::sync::atomic::AtomicU64] + +// cdb-command: dx a_usize +// cdb-check:a_usize : 0x400 [Type: core::sync::atomic::AtomicUsize] +// cdb-check: [] [Type: core::sync::atomic::AtomicUsize] + use std::num::*; +use std::sync::atomic::*; fn main() { let nz_i8 = NonZeroI8::new(11).unwrap(); @@ -136,6 +185,21 @@ fn main() { let w_u128 = Wrapping(110u128); let w_usize = Wrapping(120usize); + let a_bool_t = AtomicBool::new(true); + let a_bool_f = AtomicBool::new(false); + + let a_i8 = AtomicI8::new(2); + let a_i16 = AtomicI16::new(4); + let a_i32 = AtomicI32::new(8); + let a_i64 = AtomicI64::new(16); + let a_isize = AtomicIsize::new(32); + + let a_u8 = AtomicU8::new(64); + let a_u16 = AtomicU16::new(128); + let a_u32 = AtomicU32::new(256); + let a_u64 = AtomicU64::new(512); + let a_usize = AtomicUsize::new(1024); + zzz(); // #break } From cad42e0d330d8d3476f2217fe4f14f2f5e34e691 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 29 Jun 2021 15:32:03 -0400 Subject: [PATCH 04/23] Add natvis for cell types --- src/etc/natvis/libcore.natvis | 34 +++++++++++++ src/test/debuginfo/mutable-locs.rs | 77 +++++++++++++++++++++++++----- src/test/debuginfo/rwlock-read.rs | 6 +-- 3 files changed, 102 insertions(+), 15 deletions(-) diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index b5899cf9319d8..96459adb6b8ac 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -1,5 +1,39 @@ + + {value.value} + + value.value + + + + {value} + + value + + + + {value} + + value + + + + {value.value} + + "Unborrowed",sb + "Immutably borrowed",sb + "Mutably borrowed",sb + value.value + + + + {value} + + value + + + {__0} diff --git a/src/test/debuginfo/mutable-locs.rs b/src/test/debuginfo/mutable-locs.rs index 428a7e8d9c09b..688483e43e4db 100644 --- a/src/test/debuginfo/mutable-locs.rs +++ b/src/test/debuginfo/mutable-locs.rs @@ -9,26 +9,64 @@ // cdb-command: g // cdb-command:dx static_c,d -// cdb-check:static_c,d [Type: core::cell::Cell] -// cdb-check: [...] value [Type: core::cell::UnsafeCell] +// cdb-check:static_c,d : 10 [Type: core::cell::Cell] +// cdb-check: [] [Type: core::cell::Cell] // cdb-command: dx static_c.value,d -// cdb-check:static_c.value,d [Type: core::cell::UnsafeCell] -// cdb-check: [...] value : 10 [Type: int] +// cdb-check:static_c.value,d : 10 [Type: core::cell::UnsafeCell] +// cdb-check: [] [Type: core::cell::UnsafeCell] // cdb-command: dx dynamic_c,d -// cdb-check:dynamic_c,d [Type: core::cell::RefCell] -// cdb-check: [...] borrow [Type: core::cell::Cell] -// cdb-check: [...] value [Type: core::cell::UnsafeCell] +// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell] +// cdb-check: [] [Type: core::cell::RefCell] +// cdb-check: [Borrow state] : Unborrowed // cdb-command: dx dynamic_c.value,d -// cdb-check:dynamic_c.value,d [Type: core::cell::UnsafeCell] -// cdb-check: [...] value : 15 [Type: int] +// cdb-check:dynamic_c.value,d : 15 [Type: core::cell::UnsafeCell] +// cdb-check: [] [Type: core::cell::UnsafeCell] // cdb-command: dx b,d -// cdb-check:b,d [Type: core::cell::RefMut] -// cdb-check: [...] value : [...] : 42 [Type: int *] -// cdb-check: [...] borrow [Type: core::cell::BorrowRefMut] +// cdb-check:b,d : 42 [Type: core::cell::RefMut] +// cdb-check: [] [Type: core::cell::RefMut] +// cdb-check: 42 [Type: int] + +// cdb-command: g + +// cdb-command: dx dynamic_c,d +// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell] +// cdb-check: [] [Type: core::cell::RefCell] +// cdb-check: [Borrow state] : Immutably borrowed + +// cdb-command: dx r_borrow,d +// cdb-check:r_borrow,d : 15 [Type: core::cell::Ref] +// cdb-check: [] [Type: core::cell::Ref] +// cdb-check: 15 [Type: int] + +// cdb-command: g + +// cdb-command: dx dynamic_c,d +// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell] +// cdb-check: [] [Type: core::cell::RefCell] +// cdb-check: [Borrow state] : Unborrowed + +// cdb-command: g + +// cdb-command: dx dynamic_c,d +// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell] +// cdb-check: [] [Type: core::cell::RefCell] +// cdb-check: [Borrow state] : Mutably borrowed + +// cdb-command: dx r_borrow_mut,d +// cdb-check:r_borrow_mut,d : 15 [Type: core::cell::RefMut] +// cdb-check: [] [Type: core::cell::RefMut] +// cdb-check: 15 [Type: int] + +// cdb-command: g + +// cdb-command: dx dynamic_c,d +// cdb-check:dynamic_c,d : 15 [Type: core::cell::RefCell] +// cdb-check: [] [Type: core::cell::RefCell] +// cdb-check: [Borrow state] : Unborrowed #![allow(unused_variables)] @@ -46,6 +84,21 @@ fn main() { *b = 42; zzz(); // #break + + // Check that `RefCell`'s borrow state visualizes correctly + { + let r_borrow = dynamic_c.borrow(); + zzz(); // #break + } + + zzz(); // #break + + { + let r_borrow_mut = dynamic_c.borrow_mut(); + zzz(); // #break + } + + zzz(); // #break } fn zzz() {()} diff --git a/src/test/debuginfo/rwlock-read.rs b/src/test/debuginfo/rwlock-read.rs index ac652c8ccf4cc..e1c10a4d37fc3 100644 --- a/src/test/debuginfo/rwlock-read.rs +++ b/src/test/debuginfo/rwlock-read.rs @@ -11,15 +11,15 @@ // cdb-command:dx l // cdb-check:l [Type: std::sync::rwlock::RwLock] // cdb-check: [...] poison [Type: std::sync::poison::Flag] -// cdb-check: [...] data [Type: core::cell::UnsafeCell] +// cdb-check: [...] data : 0 [Type: core::cell::UnsafeCell] // // cdb-command:dx r // cdb-check:r [Type: std::sync::rwlock::RwLockReadGuard] // cdb-check: [...] lock : [...] [Type: std::sync::rwlock::RwLock *] // // cdb-command:dx r.lock->data,d -// cdb-check:r.lock->data,d [Type: core::cell::UnsafeCell] -// cdb-check: [...] value : 0 [Type: int] +// cdb-check:r.lock->data,d : 0 [Type: core::cell::UnsafeCell] +// cdb-check: [] [Type: core::cell::UnsafeCell] #[allow(unused_variables)] From 8f1eec37545c276b0cfaa60d38b4778e1bba7214 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 29 Jun 2021 16:41:44 -0400 Subject: [PATCH 05/23] Fixup natvis for NonNull and Unique types Remove the Shared type natvis since it no longer exists --- src/etc/natvis/libcore.natvis | 19 ++++++------------- src/test/debuginfo/marker-types.rs | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 13 deletions(-) create mode 100644 src/test/debuginfo/marker-types.rs diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 96459adb6b8ac..04e72c706b4b7 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -75,24 +75,17 @@ {__0} - - {{ Unique {pointer} }} - - pointer - - - - - {{ Shared {pointer} }} + + NonNull({(void*) pointer}: {pointer}) - pointer + pointer - - {(void*) pointer} + + Unique({(void*)pointer}: {pointer}) - *pointer + pointer diff --git a/src/test/debuginfo/marker-types.rs b/src/test/debuginfo/marker-types.rs new file mode 100644 index 0000000000000..43e45d8f282e8 --- /dev/null +++ b/src/test/debuginfo/marker-types.rs @@ -0,0 +1,21 @@ +// only-cdb +// compile-flags:-g + +// === CDB TESTS ================================================================================== + +// cdb-command: g + +// cdb-command: dx nonnull +// cdb-check:nonnull : NonNull(0x[...]: 0xc) [Type: core::ptr::non_null::NonNull] +// cdb-check: [] [Type: core::ptr::non_null::NonNull] +// cdb-checK: 0xc [Type: unsigned int] + +use std::ptr::NonNull; + +fn main() { + let nonnull: NonNull<_> = (&12u32).into(); + + zzz(); // #break +} + +fn zzz() { } From f2aba34eea86a1e3c1ebdd0b8f7adfc730169518 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Tue, 29 Jun 2021 17:04:23 -0400 Subject: [PATCH 06/23] Add natvis for Range types --- src/etc/natvis/libcore.natvis | 16 ++++++++++++++ src/test/debuginfo/range-types.rs | 36 ++++++++++++++++--------------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 04e72c706b4b7..624495fb5acbc 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -75,6 +75,22 @@ {__0} + + ({start}..{end}) + + + ({start}..) + + + ({start}..={end}) + + + (..{end}) + + + (..={end}) + + NonNull({(void*) pointer}: {pointer}) diff --git a/src/test/debuginfo/range-types.rs b/src/test/debuginfo/range-types.rs index c0288b6ba80e0..7362a50a03015 100644 --- a/src/test/debuginfo/range-types.rs +++ b/src/test/debuginfo/range-types.rs @@ -9,26 +9,27 @@ // cdb-command: g // cdb-command: dx r1,d -// cdb-check:r1,d [Type: core::ops::range::Range] -// cdb-check: [...] start : 3 [Type: int] -// cdb-check: [...] end : 5 [Type: int] +// cdb-check:r1,d : (3..5) [Type: core::ops::range::Range] +// cdb-check: [] [Type: core::ops::range::Range] // cdb-command: dx r2,d -// cdb-check:r2,d [Type: core::ops::range::RangeFrom] -// cdb-check: [...] start : 2 [Type: int] +// cdb-check:r2,d : (2..) [Type: core::ops::range::RangeFrom] +// cdb-check: [] [Type: core::ops::range::RangeFrom] // cdb-command: dx r3,d -// cdb-check:r3,d [Type: core::ops::range::RangeInclusive] -// cdb-check: [...] start : 1 [Type: int] -// cdb-check: [...] end : 4 [Type: int] -// cdb-check: [...] exhausted : false [Type: bool] +// cdb-check:r3,d : (1..=4) [Type: core::ops::range::RangeInclusive] +// cdb-check: [] [Type: core::ops::range::RangeInclusive] // cdb-command: dx r4,d -// cdb-check:r4,d [Type: core::ops::range::RangeToInclusive] -// cdb-check: [...] end : 3 [Type: int] +// cdb-check:r4,d : (..10) [Type: core::ops::range::RangeTo] +// cdb-check: [] [Type: core::ops::range::RangeTo] // cdb-command: dx r5,d -// cdb-check:r5,d [Type: core::ops::range::RangeFull] +// cdb-check:r5,d : (..=3) [Type: core::ops::range::RangeToInclusive] +// cdb-check: [] [Type: core::ops::range::RangeToInclusive] + +// cdb-command: dx r6,d +// cdb-check:r6,d [Type: core::ops::range::RangeFull] #[allow(unused_variables)] @@ -36,11 +37,12 @@ use std::ops::{Range, RangeFrom, RangeFull, RangeInclusive, RangeToInclusive}; fn main() { - let r1 = Range{start: 3, end: 5}; - let r2 = RangeFrom{start: 2}; - let r3 = RangeInclusive::new(1, 4); - let r4 = RangeToInclusive{end: 3}; - let r5 = RangeFull{}; + let r1 = (3..5); + let r2 = (2..); + let r3 = (1..=4); + let r4 = (..10); + let r5 = (..=3); + let r6 = (..); zzz(); // #break } From 691ee054d5bb8e0a95fd0486a7167bd8889ebba7 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 30 Jun 2021 12:08:58 -0400 Subject: [PATCH 07/23] Add natvis for Duration, ManuallyDrop and Pin types --- src/etc/natvis/libcore.natvis | 22 ++++++++++++++++++++++ src/test/debuginfo/duration-type.rs | 22 ++++++++++++++++++++++ src/test/debuginfo/marker-types.rs | 18 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/test/debuginfo/duration-type.rs diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index 624495fb5acbc..abac2cefa3886 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -34,6 +34,13 @@ + + {value} + + value + + + {__0} @@ -91,6 +98,13 @@ (..={end}) + + Pin({(void*)pointer}: {pointer}) + + pointer + + + NonNull({(void*) pointer}: {pointer}) @@ -138,4 +152,12 @@ {v.value} + + + {secs,d}s {nanos,d}ns + + secs + nanos + + diff --git a/src/test/debuginfo/duration-type.rs b/src/test/debuginfo/duration-type.rs new file mode 100644 index 0000000000000..3a7f9f78b5fed --- /dev/null +++ b/src/test/debuginfo/duration-type.rs @@ -0,0 +1,22 @@ +// only-cdb +// compile-flags:-g + +// === CDB TESTS ================================================================================== + +// cdb-command: g + +// cdb-command: dx duration +// cdb-check:duration : 5s 12ns [Type: core::time::Duration] +// cdb-check: [] [Type: core::time::Duration] +// cdb-check: seconds : 0x5 [Type: unsigned __int64] +// cdb-check: nanoseconds : 0xc [Type: unsigned int] + +use std::time::Duration; + +fn main() { + let duration = Duration::new(5, 12); + + zzz(); // #break +} + +fn zzz() { } diff --git a/src/test/debuginfo/marker-types.rs b/src/test/debuginfo/marker-types.rs index 43e45d8f282e8..de4e8311a4fc3 100644 --- a/src/test/debuginfo/marker-types.rs +++ b/src/test/debuginfo/marker-types.rs @@ -10,11 +10,29 @@ // cdb-check: [] [Type: core::ptr::non_null::NonNull] // cdb-checK: 0xc [Type: unsigned int] +// cdb-command: dx manuallydrop +// cdb-check:manuallydrop : 12345 [Type: core::mem::manually_drop::ManuallyDrop] +// cdb-check: [] [Type: core::mem::manually_drop::ManuallyDrop] + +// cdb-command: dx pin +// cdb-check:pin : Pin(0x[...]: "this") [Type: core::pin::Pin >] +// cdb-check: [] [Type: core::pin::Pin >] +// cdb-check: [len] : 0x4 [Type: unsigned __int64] +// cdb-check: [capacity] : 0x4 [Type: unsigned __int64] +// cdb-check: [chars] + +use std::mem::ManuallyDrop; +use std::pin::Pin; use std::ptr::NonNull; fn main() { let nonnull: NonNull<_> = (&12u32).into(); + let manuallydrop = ManuallyDrop::new(12345i32); + + let mut s = "this".to_string(); + let pin = Pin::new(&mut s); + zzz(); // #break } From a6a82c66d4fc3be10861ad6885ff0ab239c203ad Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 30 Jun 2021 17:23:44 -0400 Subject: [PATCH 08/23] Add/improve visualizations for liballoc types --- src/etc/natvis/liballoc.natvis | 10 ++++++++++ src/test/debuginfo/pretty-std.rs | 26 +++++++++++++++++++++++++- src/test/debuginfo/rc_arc.rs | 13 +++++++++++-- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/etc/natvis/liballoc.natvis b/src/etc/natvis/liballoc.natvis index 9cc60fc7b47e5..707643152c946 100644 --- a/src/etc/natvis/liballoc.natvis +++ b/src/etc/natvis/liballoc.natvis @@ -57,16 +57,26 @@ + {ptr.pointer->value} ptr.pointer->value + ptr.pointer->strong + + {ptr.pointer->value} + + ptr.pointer->value + + + {ptr.pointer->data} ptr.pointer->data + ptr.pointer->strong diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 7ed76beb8c6d9..a2074c43dfaca 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -129,10 +129,24 @@ // NOTE: cdb fails to interpret debug info of Option enums on i686. // cdb-check:some_string [Type: enum$, 1, [...], Some>] +// cdb-command: dx linkedlist +// cdb-check:linkedlist : { len=0x2 } [Type: alloc::collections::linked_list::LinkedList] +// cdb-check: [] [Type: alloc::collections::linked_list::LinkedList] +// cdb-check: [0x0] : 128 [Type: int] +// cdb-check: [0x1] : 42 [Type: int] + +// cdb-command: dx vecdeque +// cdb-check:vecdeque : { len=0x2 } [Type: alloc::collections::vec_deque::VecDeque] +// cdb-check: [] [Type: alloc::collections::vec_deque::VecDeque] +// cdb-check: [len] : 0x2 +// cdb-check: [capacity] : 0x8 [Type: unsigned __int64] +// cdb-check: [0x0] : 90 [Type: int] +// cdb-check: [0x1] : 20 [Type: int] + #![allow(unused_variables)] +use std::collections::{LinkedList, VecDeque}; use std::ffi::OsString; - fn main() { // &[] @@ -156,6 +170,16 @@ fn main() { let some_string = Some("IAMA optional string!".to_owned()); + // LinkedList + let mut linkedlist = LinkedList::new(); + linkedlist.push_back(42); + linkedlist.push_front(128); + + // VecDeque + let mut vecdeque = VecDeque::new(); + vecdeque.push_back(20); + vecdeque.push_front(90); + zzz(); // #break } diff --git a/src/test/debuginfo/rc_arc.rs b/src/test/debuginfo/rc_arc.rs index 6e558bd3c13aa..24623bc972e9f 100644 --- a/src/test/debuginfo/rc_arc.rs +++ b/src/test/debuginfo/rc_arc.rs @@ -29,22 +29,31 @@ // cdb-command:dx r,d // cdb-check:r,d : 42 [Type: alloc::rc::Rc] +// cdb-check: [] [Type: alloc::rc::Rc] +// cdb-check: [Reference count] : 2 [Type: core::cell::Cell] // cdb-command:dx r1,d // cdb-check:r1,d : 42 [Type: alloc::rc::Rc] +// cdb-check: [] [Type: alloc::rc::Rc] +// cdb-check: [Reference count] : 2 [Type: core::cell::Cell] // cdb-command:dx w1,d -// cdb-check:w1,d [Type: alloc::rc::Weak] -// cdb-check: [...] ptr : [...] [Type: core::ptr::non_null::NonNull >] +// cdb-check:w1,d : 42 [Type: alloc::rc::Weak] +// cdb-check: [] [Type: alloc::rc::Weak] // cdb-command:dx a,d // cdb-check:a,d : 42 [Type: alloc::sync::Arc] +// cdb-check: [] [Type: alloc::sync::Arc] +// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] // cdb-command:dx a1,d // cdb-check:a1,d : 42 [Type: alloc::sync::Arc] +// cdb-check: [] [Type: alloc::sync::Arc] +// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] // cdb-command:dx w2,d // cdb-check:w2,d : 42 [Type: alloc::sync::Weak] +// cdb-check: [] [Type: alloc::sync::Weak] use std::rc::Rc; use std::sync::Arc; From 85002741a26d6fdf6578e33aaaeace7c04c6254a Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Thu, 1 Jul 2021 15:57:12 -0400 Subject: [PATCH 09/23] Add visualizer for OsString and fixup other string visualizers --- src/etc/natvis/intrinsic.natvis | 4 ++-- src/etc/natvis/libstd.natvis | 16 +++++++++++++++- src/test/debuginfo/pretty-std.rs | 5 +++-- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/etc/natvis/intrinsic.natvis b/src/etc/natvis/intrinsic.natvis index 52e5d37c83fbd..558536fa613a5 100644 --- a/src/etc/natvis/intrinsic.natvis +++ b/src/etc/natvis/intrinsic.natvis @@ -1,8 +1,8 @@ - {data_ptr,[length]s8} - data_ptr,[length]s8 + {(char*)data_ptr,[length]s8} + (char*)data_ptr,[length]s8 length diff --git a/src/etc/natvis/libstd.natvis b/src/etc/natvis/libstd.natvis index 3ccd2e9c30ed5..25094fc8409e1 100644 --- a/src/etc/natvis/libstd.natvis +++ b/src/etc/natvis/libstd.natvis @@ -74,7 +74,7 @@ - {inner.data_ptr,s} + {(char*)inner.data_ptr} @@ -101,4 +101,18 @@ + + + {(char*)inner.inner.bytes.buf.ptr.pointer,[inner.inner.bytes.len]} + + + + + inner.inner.bytes.len + (char*)inner.inner.bytes.buf.ptr.pointer + + + + + diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index a2074c43dfaca..51325cd4249ad 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -111,8 +111,9 @@ // cdb-check: [11] : 33 '!' [Type: char] // cdb-command: dx os_string -// cdb-check:os_string [Type: [...]::OsString] -// NOTE: OsString doesn't have a .natvis entry yet. +// cdb-check:os_string : "IAMA OS string 😃" [Type: std::ffi::os_str::OsString] +// cdb-check: [] [Type: std::ffi::os_str::OsString] +// cdb-check: [chars] // cdb-command: dx some // cdb-check:some : Some [Type: enum$ >] From eb3a52778d2848afbc3701481b9c83fe5c153ade Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 8 Jul 2021 20:07:47 -0700 Subject: [PATCH 10/23] Address review comments --- compiler/rustc_lint/src/levels.rs | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_lint/src/levels.rs b/compiler/rustc_lint/src/levels.rs index 4edf76170701e..069fa41fa886a 100644 --- a/compiler/rustc_lint/src/levels.rs +++ b/compiler/rustc_lint/src/levels.rs @@ -26,8 +26,6 @@ use rustc_span::symbol::{sym, Symbol}; use rustc_span::{source_map::MultiSpan, Span, DUMMY_SP}; use tracing::debug; -use std::cmp; - fn lint_levels(tcx: TyCtxt<'_>, (): ()) -> LintLevelMap { let store = unerased_lint_store(tcx); let crate_attrs = tcx.hir().attrs(CRATE_HIR_ID); @@ -91,12 +89,6 @@ impl<'s> LintLevelsBuilder<'s> { for &(ref lint_name, level) in &sess.opts.lint_opts { store.check_lint_name_cmdline(sess, &lint_name, level, self.crate_attrs); let orig_level = level; - - // If the cap is less than this specified level, e.g., if we've got - // `--cap-lints allow` but we've also got `-D foo` then we ignore - // this specification as the lint cap will set it to allow anyway. - let level = cmp::min(level, self.sets.lint_cap); - let lint_flag_val = Symbol::intern(lint_name); let ids = match store.find_lints(&lint_name) { @@ -105,9 +97,8 @@ impl<'s> LintLevelsBuilder<'s> { }; for id in ids { // ForceWarn and Forbid cannot be overriden - match specs.get(&id) { - Some((Level::ForceWarn | Level::Forbid, _)) => continue, - _ => (), + if let Some((Level::ForceWarn | Level::Forbid, _)) = specs.get(&id) { + continue; } self.check_gated_lint(id, DUMMY_SP); From dbdce6ee6ab91d940e184628744a6988f42a0af0 Mon Sep 17 00:00:00 2001 From: inquisitivecrystal <22333129+inquisitivecrystal@users.noreply.github.com> Date: Thu, 8 Jul 2021 21:35:26 -0700 Subject: [PATCH 11/23] Add tests for command line lint control --- .../lint/cli-lint-override.forbid_warn.stderr | 11 +++++++++++ .../cli-lint-override.force_warn_deny.stderr | 11 +++++++++++ src/test/ui/lint/cli-lint-override.rs | 17 +++++++++++++++++ .../ui/lint/cli-lint-override.warn_deny.stderr | 11 +++++++++++ src/test/ui/lint/cli-unknown-force-warn.rs | 7 +++++++ src/test/ui/lint/cli-unknown-force-warn.stderr | 15 +++++++++++++++ 6 files changed, 72 insertions(+) create mode 100644 src/test/ui/lint/cli-lint-override.forbid_warn.stderr create mode 100644 src/test/ui/lint/cli-lint-override.force_warn_deny.stderr create mode 100644 src/test/ui/lint/cli-lint-override.rs create mode 100644 src/test/ui/lint/cli-lint-override.warn_deny.stderr create mode 100644 src/test/ui/lint/cli-unknown-force-warn.rs create mode 100644 src/test/ui/lint/cli-unknown-force-warn.stderr diff --git a/src/test/ui/lint/cli-lint-override.forbid_warn.stderr b/src/test/ui/lint/cli-lint-override.forbid_warn.stderr new file mode 100644 index 0000000000000..ff4dc4abc74a1 --- /dev/null +++ b/src/test/ui/lint/cli-lint-override.forbid_warn.stderr @@ -0,0 +1,11 @@ +error: extern declarations without an explicit ABI are deprecated + --> $DIR/cli-lint-override.rs:12:1 + | +LL | extern fn foo() {} + | ^^^^^^^^^^^^^^^ ABI should be specified here + | + = note: requested on the command line with `-F missing-abi` + = help: the default ABI is C + +error: aborting due to previous error + diff --git a/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr b/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr new file mode 100644 index 0000000000000..50c58ea6e151a --- /dev/null +++ b/src/test/ui/lint/cli-lint-override.force_warn_deny.stderr @@ -0,0 +1,11 @@ +warning: extern declarations without an explicit ABI are deprecated + --> $DIR/cli-lint-override.rs:12:1 + | +LL | extern fn foo() {} + | ^^^^^^^^^^^^^^^ ABI should be specified here + | + = note: requested on the command line with `--force-warns missing-abi` + = help: the default ABI is C + +warning: 1 warning emitted + diff --git a/src/test/ui/lint/cli-lint-override.rs b/src/test/ui/lint/cli-lint-override.rs new file mode 100644 index 0000000000000..6814c15e65686 --- /dev/null +++ b/src/test/ui/lint/cli-lint-override.rs @@ -0,0 +1,17 @@ +// Tests that subsequent lints specified via the command line override +// each other, except for ForceWarn and Forbid, which cannot be overriden. +// +// revisions: warn_deny forbid_warn force_warn_deny +// +//[warn_deny] compile-flags: --warn missing_abi --deny missing_abi +//[forbid_warn] compile-flags: --warn missing_abi --forbid missing_abi +//[force_warn_deny] compile-flags: -Z unstable-options --force-warns missing_abi --allow missing_abi +//[force_warn_deny] check-pass + + +extern fn foo() {} +//[warn_deny]~^ ERROR extern declarations without an explicit ABI are deprecated +//[forbid_warn]~^^ ERROR extern declarations without an explicit ABI are deprecated +//[force_warn_deny]~^^^ WARN extern declarations without an explicit ABI are deprecated + +fn main() {} diff --git a/src/test/ui/lint/cli-lint-override.warn_deny.stderr b/src/test/ui/lint/cli-lint-override.warn_deny.stderr new file mode 100644 index 0000000000000..2d869adfd37e3 --- /dev/null +++ b/src/test/ui/lint/cli-lint-override.warn_deny.stderr @@ -0,0 +1,11 @@ +error: extern declarations without an explicit ABI are deprecated + --> $DIR/cli-lint-override.rs:12:1 + | +LL | extern fn foo() {} + | ^^^^^^^^^^^^^^^ ABI should be specified here + | + = note: requested on the command line with `-D missing-abi` + = help: the default ABI is C + +error: aborting due to previous error + diff --git a/src/test/ui/lint/cli-unknown-force-warn.rs b/src/test/ui/lint/cli-unknown-force-warn.rs new file mode 100644 index 0000000000000..201161296baf4 --- /dev/null +++ b/src/test/ui/lint/cli-unknown-force-warn.rs @@ -0,0 +1,7 @@ +// Checks that rustc correctly errors when passed an invalid lint with +// `--force-warns`. This is a regression test for issue #86958. +// +// compile-flags: -Z unstable-options --force-warns foo-qux +// error-pattern: unknown lint: `foo_qux` + +fn main() {} diff --git a/src/test/ui/lint/cli-unknown-force-warn.stderr b/src/test/ui/lint/cli-unknown-force-warn.stderr new file mode 100644 index 0000000000000..3a9aebb996c93 --- /dev/null +++ b/src/test/ui/lint/cli-unknown-force-warn.stderr @@ -0,0 +1,15 @@ +error[E0602]: unknown lint: `foo_qux` + | + = note: requested on the command line with `--force-warns foo_qux` + +error[E0602]: unknown lint: `foo_qux` + | + = note: requested on the command line with `--force-warns foo_qux` + +error[E0602]: unknown lint: `foo_qux` + | + = note: requested on the command line with `--force-warns foo_qux` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0602`. From d1852e10545c65cec73ea296436840e67309d82c Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 9 Jul 2021 12:52:28 -0400 Subject: [PATCH 12/23] Respond to review feedback --- src/etc/natvis/liballoc.natvis | 1 + src/etc/natvis/libcore.natvis | 4 ++-- src/etc/natvis/libstd.natvis | 2 ++ src/test/debuginfo/duration-type.rs | 4 ++-- src/test/debuginfo/marker-types.rs | 4 ++-- src/test/debuginfo/pretty-std.rs | 2 +- 6 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/etc/natvis/liballoc.natvis b/src/etc/natvis/liballoc.natvis index 707643152c946..b9454573de8ea 100644 --- a/src/etc/natvis/liballoc.natvis +++ b/src/etc/natvis/liballoc.natvis @@ -48,6 +48,7 @@ vec.len vec.buf.cap + {(char*)vec.buf.ptr.pointer,[vec.len]s8} vec.len diff --git a/src/etc/natvis/libcore.natvis b/src/etc/natvis/libcore.natvis index abac2cefa3886..fa8ee2d70bbab 100644 --- a/src/etc/natvis/libcore.natvis +++ b/src/etc/natvis/libcore.natvis @@ -156,8 +156,8 @@ {secs,d}s {nanos,d}ns - secs - nanos + secs,d + nanos,d diff --git a/src/etc/natvis/libstd.natvis b/src/etc/natvis/libstd.natvis index 25094fc8409e1..c7be0167de9fd 100644 --- a/src/etc/natvis/libstd.natvis +++ b/src/etc/natvis/libstd.natvis @@ -77,6 +77,7 @@ {(char*)inner.data_ptr} + {(char*)inner.data_ptr} inner.length @@ -106,6 +107,7 @@ {(char*)inner.inner.bytes.buf.ptr.pointer,[inner.inner.bytes.len]} + {(char*)inner.inner.bytes.buf.ptr.pointer,[inner.inner.bytes.len]} inner.inner.bytes.len diff --git a/src/test/debuginfo/duration-type.rs b/src/test/debuginfo/duration-type.rs index 3a7f9f78b5fed..bc0266d644ec1 100644 --- a/src/test/debuginfo/duration-type.rs +++ b/src/test/debuginfo/duration-type.rs @@ -8,8 +8,8 @@ // cdb-command: dx duration // cdb-check:duration : 5s 12ns [Type: core::time::Duration] // cdb-check: [] [Type: core::time::Duration] -// cdb-check: seconds : 0x5 [Type: unsigned __int64] -// cdb-check: nanoseconds : 0xc [Type: unsigned int] +// cdb-check: seconds : 5 [Type: unsigned __int64] +// cdb-check: nanoseconds : 12 [Type: unsigned int] use std::time::Duration; diff --git a/src/test/debuginfo/marker-types.rs b/src/test/debuginfo/marker-types.rs index de4e8311a4fc3..52d70bda908d5 100644 --- a/src/test/debuginfo/marker-types.rs +++ b/src/test/debuginfo/marker-types.rs @@ -8,7 +8,7 @@ // cdb-command: dx nonnull // cdb-check:nonnull : NonNull(0x[...]: 0xc) [Type: core::ptr::non_null::NonNull] // cdb-check: [] [Type: core::ptr::non_null::NonNull] -// cdb-checK: 0xc [Type: unsigned int] +// cdb-check: 0xc [Type: unsigned int] // cdb-command: dx manuallydrop // cdb-check:manuallydrop : 12345 [Type: core::mem::manually_drop::ManuallyDrop] @@ -19,7 +19,7 @@ // cdb-check: [] [Type: core::pin::Pin >] // cdb-check: [len] : 0x4 [Type: unsigned __int64] // cdb-check: [capacity] : 0x4 [Type: unsigned __int64] -// cdb-check: [chars] +// cdb-check: [chars] : "this" use std::mem::ManuallyDrop; use std::pin::Pin; diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 51325cd4249ad..303f0114b1734 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -113,7 +113,7 @@ // cdb-command: dx os_string // cdb-check:os_string : "IAMA OS string 😃" [Type: std::ffi::os_str::OsString] // cdb-check: [] [Type: std::ffi::os_str::OsString] -// cdb-check: [chars] +// cdb-check: [chars] : "IAMA OS string 😃" // cdb-command: dx some // cdb-check:some : Some [Type: enum$ >] From 10b536fc7133eb6dcbde3fa25dfd0b6c89a5e32c Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Sun, 11 Jul 2021 16:26:29 -0400 Subject: [PATCH 13/23] ExprUseVisitor: treat ByValue use of Copy types as ImmBorrow --- compiler/rustc_typeck/src/check/upvar.rs | 5 ++-- compiler/rustc_typeck/src/expr_use_visitor.rs | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 9a39a32f6d5d3..7e3bc785c07c5 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -1535,10 +1535,9 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> { place_with_id, diag_expr_id, mode ); - // Copy type being used as ByValue are equivalent to ImmBorrow and don't require any - // escalation. + // Copy types in ByValue scenarios need should be treated as ImmBorrows match mode { - euv::ConsumeMode::Copy => return, + euv::ConsumeMode::Copy => unreachable!(), euv::ConsumeMode::Move => {} }; diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index f174941279484..bc34525662f5d 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -144,7 +144,13 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { debug!("delegate_consume(place_with_id={:?})", place_with_id); let mode = copy_or_move(&self.mc, place_with_id); - self.delegate.consume(place_with_id, diag_expr_id, mode); + + match mode { + ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id, mode), + ConsumeMode::Copy => { + self.delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) + } + } } fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) { @@ -653,9 +659,18 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { delegate.borrow(place, discr_place.hir_id, bk); } ty::BindByValue(..) => { - let mode = copy_or_move(mc, &place); debug!("walk_pat binding consuming pat"); - delegate.consume(place, discr_place.hir_id, mode); + let mode = copy_or_move(mc, &place); + match mode { + ConsumeMode::Move => { + delegate.consume(place, discr_place.hir_id, mode) + } + ConsumeMode::Copy => delegate.borrow( + place, + discr_place.hir_id, + ty::BorrowKind::ImmBorrow, + ), + } } } } @@ -773,8 +788,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { match capture_info.capture_kind { ty::UpvarCapture::ByValue(_) => { - let mode = copy_or_move(&self.mc, &place_with_id); - self.delegate.consume(&place_with_id, place_with_id.hir_id, mode); + self.delegate_consume(&place_with_id, place_with_id.hir_id); } ty::UpvarCapture::ByRef(upvar_borrow) => { self.delegate.borrow( From 14fdf8a115da7e88721dcbef6b35d8c6eab074f2 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Mon, 12 Jul 2021 13:26:01 -0400 Subject: [PATCH 14/23] Add test for `Unique`, weak ref counts and ref counts for `Weak` --- src/etc/natvis/liballoc.natvis | 6 ++++++ src/test/debuginfo/marker-types.rs | 12 +++++++++++- src/test/debuginfo/rc_arc.rs | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/etc/natvis/liballoc.natvis b/src/etc/natvis/liballoc.natvis index b9454573de8ea..d001f40fccbc7 100644 --- a/src/etc/natvis/liballoc.natvis +++ b/src/etc/natvis/liballoc.natvis @@ -64,12 +64,15 @@ ptr.pointer->value ptr.pointer->strong + ptr.pointer->weak {ptr.pointer->value} ptr.pointer->value + ptr.pointer->strong + ptr.pointer->weak @@ -78,12 +81,15 @@ ptr.pointer->data ptr.pointer->strong + ptr.pointer->weak {ptr.pointer->data} ptr.pointer->data + ptr.pointer->strong + ptr.pointer->weak diff --git a/src/test/debuginfo/marker-types.rs b/src/test/debuginfo/marker-types.rs index 52d70bda908d5..f27a5d20c70db 100644 --- a/src/test/debuginfo/marker-types.rs +++ b/src/test/debuginfo/marker-types.rs @@ -21,9 +21,17 @@ // cdb-check: [capacity] : 0x4 [Type: unsigned __int64] // cdb-check: [chars] : "this" +// cdb-command: dx unique +// cdb-check:unique : Unique(0x[...]: (0x2a, 4321)) [Type: core::ptr::unique::Unique >] +// cdb-check: [] [Type: core::ptr::unique::Unique >] +// cdb-check: [0] : 0x2a [Type: unsigned __int64] +// cdb-check: [1] : 4321 [Type: int] + +#![feature(ptr_internals)] + use std::mem::ManuallyDrop; use std::pin::Pin; -use std::ptr::NonNull; +use std::ptr::{NonNull, Unique}; fn main() { let nonnull: NonNull<_> = (&12u32).into(); @@ -33,6 +41,8 @@ fn main() { let mut s = "this".to_string(); let pin = Pin::new(&mut s); + let unique: Unique<_> = (&mut (42u64, 4321i32)).into(); + zzz(); // #break } diff --git a/src/test/debuginfo/rc_arc.rs b/src/test/debuginfo/rc_arc.rs index 24623bc972e9f..55cddf7c6c6b4 100644 --- a/src/test/debuginfo/rc_arc.rs +++ b/src/test/debuginfo/rc_arc.rs @@ -31,29 +31,37 @@ // cdb-check:r,d : 42 [Type: alloc::rc::Rc] // cdb-check: [] [Type: alloc::rc::Rc] // cdb-check: [Reference count] : 2 [Type: core::cell::Cell] +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell] // cdb-command:dx r1,d // cdb-check:r1,d : 42 [Type: alloc::rc::Rc] // cdb-check: [] [Type: alloc::rc::Rc] // cdb-check: [Reference count] : 2 [Type: core::cell::Cell] +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell] // cdb-command:dx w1,d // cdb-check:w1,d : 42 [Type: alloc::rc::Weak] // cdb-check: [] [Type: alloc::rc::Weak] +// cdb-check: [Reference count] : 2 [Type: core::cell::Cell] +// cdb-check: [Weak reference count] : 2 [Type: core::cell::Cell] // cdb-command:dx a,d // cdb-check:a,d : 42 [Type: alloc::sync::Arc] // cdb-check: [] [Type: alloc::sync::Arc] // cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] // cdb-command:dx a1,d // cdb-check:a1,d : 42 [Type: alloc::sync::Arc] // cdb-check: [] [Type: alloc::sync::Arc] // cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] // cdb-command:dx w2,d // cdb-check:w2,d : 42 [Type: alloc::sync::Weak] // cdb-check: [] [Type: alloc::sync::Weak] +// cdb-check: [Reference count] : 2 [Type: core::sync::atomic::AtomicUsize] +// cdb-check: [Weak reference count] : 2 [Type: core::sync::atomic::AtomicUsize] use std::rc::Rc; use std::sync::Arc; From 36f51c96dc4f48ad50663f44980afe3fb529bd2c Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 14 Jul 2021 00:27:39 -0400 Subject: [PATCH 15/23] Add test for copy type in move closure --- .../2229_closure_analysis/move_closure.rs | 15 ++++++++ .../2229_closure_analysis/move_closure.stderr | 35 ++++++++++++++++++- .../run_pass/move_closure.rs | 13 +++++++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.rs b/src/test/ui/closures/2229_closure_analysis/move_closure.rs index 3b284eadbd0e3..0e7abf64fab06 100644 --- a/src/test/ui/closures/2229_closure_analysis/move_closure.rs +++ b/src/test/ui/closures/2229_closure_analysis/move_closure.rs @@ -195,6 +195,21 @@ fn box_mut_2() { //~| NOTE: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow } +// Test that move closures can take ownership of Copy type +fn returned_closure_owns_copy_type_data() -> impl Fn() -> i32 { + let x = 10; + + let c = #[rustc_capture_analysis] move || x; + //~^ ERROR: attributes on expressions are experimental + //~| NOTE: see issue #15701 + //~| First Pass analysis includes: + //~| NOTE: Capturing x[] -> ImmBorrow + //~| Min Capture analysis includes: + //~| NOTE: Min Capture x[] -> ByValue + + c +} + fn main() { simple_move_closure(); simple_ref(); diff --git a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr b/src/test/ui/closures/2229_closure_analysis/move_closure.stderr index c8e2708feee31..82ed99f9444d3 100644 --- a/src/test/ui/closures/2229_closure_analysis/move_closure.stderr +++ b/src/test/ui/closures/2229_closure_analysis/move_closure.stderr @@ -88,6 +88,39 @@ LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10; = note: see issue #15701 for more information = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable +error[E0658]: attributes on expressions are experimental + --> $DIR/move_closure.rs:202:13 + | +LL | let c = #[rustc_capture_analysis] move || x; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #15701 for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + +error: First Pass analysis includes: + --> $DIR/move_closure.rs:202:39 + | +LL | let c = #[rustc_capture_analysis] move || x; + | ^^^^^^^^^ + | +note: Capturing x[] -> ImmBorrow + --> $DIR/move_closure.rs:202:47 + | +LL | let c = #[rustc_capture_analysis] move || x; + | ^ + +error: Min Capture analysis includes: + --> $DIR/move_closure.rs:202:39 + | +LL | let c = #[rustc_capture_analysis] move || x; + | ^^^^^^^^^ + | +note: Min Capture x[] -> ByValue + --> $DIR/move_closure.rs:202:47 + | +LL | let c = #[rustc_capture_analysis] move || x; + | ^ + error: First Pass analysis includes: --> $DIR/move_closure.rs:15:5 | @@ -424,6 +457,6 @@ note: Min Capture p_foo[Deref,Deref,(0, 0)] -> UniqueImmBorrow LL | let c = #[rustc_capture_analysis] move || p_foo.x += 10; | ^^^^^^^ -error: aborting due to 30 previous errors +error: aborting due to 33 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs b/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs index 65c8a5a7850fe..e1b61e85ec192 100644 --- a/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs +++ b/src/test/ui/closures/2229_closure_analysis/run_pass/move_closure.rs @@ -3,6 +3,8 @@ // Test that move closures compile properly with `capture_disjoint_fields` enabled. +#![allow(unused)] + fn simple_ref() { let mut s = 10; let ref_s = &mut s; @@ -92,6 +94,15 @@ fn data_moved_but_not_fn_once() { c(); } +// Test that move closures can take ownership of Copy type +fn returned_closure_owns_copy_type_data() -> impl Fn() -> i32 { + let x = 10; + + let c = move || x; + + c +} + fn main() { simple_ref(); struct_contains_ref_to_another_struct(); @@ -100,4 +111,6 @@ fn main() { disjoint_via_ref(); data_moved_but_not_fn_once(); + + returned_closure_owns_copy_type_data(); } From 6c3774eec4947c1bffbf7c374119ea2b46f96960 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 14 Jul 2021 02:21:08 -0400 Subject: [PATCH 16/23] ExprUseVisitor::Delegate consume only when moving --- compiler/rustc_typeck/src/check/upvar.rs | 26 ++++--------------- compiler/rustc_typeck/src/expr_use_visitor.rs | 23 +++++----------- src/tools/clippy/clippy_lints/src/escape.rs | 9 +++---- .../clippy_lints/src/loops/mut_range_bound.rs | 4 +-- .../src/needless_pass_by_value.rs | 6 ++--- src/tools/clippy/clippy_utils/src/usage.rs | 4 +-- 6 files changed, 21 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_typeck/src/check/upvar.rs b/compiler/rustc_typeck/src/check/upvar.rs index 7e3bc785c07c5..39874f48eb014 100644 --- a/compiler/rustc_typeck/src/check/upvar.rs +++ b/compiler/rustc_typeck/src/check/upvar.rs @@ -1528,19 +1528,11 @@ impl<'a, 'tcx> InferBorrowKind<'a, 'tcx> { &mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId, - mode: euv::ConsumeMode, ) { debug!( - "adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})", - place_with_id, diag_expr_id, mode + "adjust_upvar_borrow_kind_for_consume(place_with_id={:?}, diag_expr_id={:?})", + place_with_id, diag_expr_id ); - - // Copy types in ByValue scenarios need should be treated as ImmBorrows - match mode { - euv::ConsumeMode::Copy => unreachable!(), - euv::ConsumeMode::Move => {} - }; - let tcx = self.fcx.tcx; let upvar_id = if let PlaceBase::Upvar(upvar_id) = place_with_id.place.base { upvar_id @@ -1715,22 +1707,14 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'tcx> { } } - fn consume( - &mut self, - place_with_id: &PlaceWithHirId<'tcx>, - diag_expr_id: hir::HirId, - mode: euv::ConsumeMode, - ) { - debug!( - "consume(place_with_id={:?}, diag_expr_id={:?}, mode={:?})", - place_with_id, diag_expr_id, mode - ); + fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { + debug!("consume(place_with_id={:?}, diag_expr_id={:?})", place_with_id, diag_expr_id); if !self.capture_information.contains_key(&place_with_id.place) { self.init_capture_info_for_place(&place_with_id, diag_expr_id); } - self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id, mode); + self.adjust_upvar_borrow_kind_for_consume(&place_with_id, diag_expr_id); } fn borrow( diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index bc34525662f5d..dceeac48d6a3d 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -2,8 +2,6 @@ //! normal visitor, which just walks the entire body in one shot, the //! `ExprUseVisitor` determines how expressions are being used. -pub use self::ConsumeMode::*; - // Export these here so that Clippy can use them. pub use rustc_middle::hir::place::{Place, PlaceBase, PlaceWithHirId, Projection}; @@ -28,19 +26,14 @@ use crate::mem_categorization as mc; /// This trait defines the callbacks you can expect to receive when /// employing the ExprUseVisitor. pub trait Delegate<'tcx> { - // The value found at `place` is either copied or moved, depending + // The value found at `place` is moved, depending // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`. // // The parameter `diag_expr_id` indicates the HIR id that ought to be used for // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic // id will be the id of the expression `expr` but the place itself will have // the id of the binding in the pattern `pat`. - fn consume( - &mut self, - place_with_id: &PlaceWithHirId<'tcx>, - diag_expr_id: hir::HirId, - mode: ConsumeMode, - ); + fn consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId); // The value found at `place` is being borrowed with kind `bk`. // `diag_expr_id` is the id used for diagnostics (see `consume` for more details). @@ -60,7 +53,7 @@ pub trait Delegate<'tcx> { } #[derive(Copy, Clone, PartialEq, Debug)] -pub enum ConsumeMode { +enum ConsumeMode { Copy, // reference to x where x has a type that copies Move, // reference to x where x has a type that moves } @@ -146,7 +139,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let mode = copy_or_move(&self.mc, place_with_id); match mode { - ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id, mode), + ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id), ConsumeMode::Copy => { self.delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) } @@ -662,9 +655,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { debug!("walk_pat binding consuming pat"); let mode = copy_or_move(mc, &place); match mode { - ConsumeMode::Move => { - delegate.consume(place, discr_place.hir_id, mode) - } + ConsumeMode::Move => delegate.consume(place, discr_place.hir_id), ConsumeMode::Copy => delegate.borrow( place, discr_place.hir_id, @@ -812,8 +803,8 @@ fn copy_or_move<'a, 'tcx>( place_with_id.place.ty(), mc.tcx().hir().span(place_with_id.hir_id), ) { - Move + ConsumeMode::Move } else { - Copy + ConsumeMode::Copy } } diff --git a/src/tools/clippy/clippy_lints/src/escape.rs b/src/tools/clippy/clippy_lints/src/escape.rs index 3581ab41906f4..5f400d079da2f 100644 --- a/src/tools/clippy/clippy_lints/src/escape.rs +++ b/src/tools/clippy/clippy_lints/src/escape.rs @@ -11,7 +11,7 @@ use rustc_span::source_map::Span; use rustc_span::symbol::kw; use rustc_target::abi::LayoutOf; use rustc_target::spec::abi::Abi; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; #[derive(Copy, Clone)] pub struct BoxedLocal { @@ -133,13 +133,10 @@ fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool { } impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> { - fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, mode: ConsumeMode) { + fn consume(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId) { if cmt.place.projections.is_empty() { if let PlaceBase::Local(lid) = cmt.place.base { - if let ConsumeMode::Move = mode { - // moved out or in. clearly can't be localized - self.set.remove(&lid); - } + self.set.remove(&lid); let map = &self.cx.tcx.hir(); if let Some(Node::Binding(_)) = map.find(cmt.hir_id) { if self.set.contains(&lid) { diff --git a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs index d07b5a93b67c0..1e54a1e2de165 100644 --- a/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs +++ b/src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs @@ -7,7 +7,7 @@ use rustc_infer::infer::TyCtxtInferExt; use rustc_lint::LateContext; use rustc_middle::{mir::FakeReadCause, ty}; use rustc_span::source_map::Span; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; pub(super) fn check(cx: &LateContext<'_>, arg: &Expr<'_>, body: &Expr<'_>) { if let Some(higher::Range { @@ -82,7 +82,7 @@ struct MutatePairDelegate<'a, 'tcx> { } impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { diff --git a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs index e33a33e238633..57fd03f4e12a6 100644 --- a/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs +++ b/src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs @@ -326,10 +326,8 @@ impl MovedVariablesCtxt { } impl<'tcx> euv::Delegate<'tcx> for MovedVariablesCtxt { - fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId, mode: euv::ConsumeMode) { - if let euv::ConsumeMode::Move = mode { - self.move_common(cmt); - } + fn consume(&mut self, cmt: &euv::PlaceWithHirId<'tcx>, _: HirId) { + self.move_common(cmt); } fn borrow(&mut self, _: &euv::PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {} diff --git a/src/tools/clippy/clippy_utils/src/usage.rs b/src/tools/clippy/clippy_utils/src/usage.rs index 2c55021ac8837..82e4b30006804 100644 --- a/src/tools/clippy/clippy_utils/src/usage.rs +++ b/src/tools/clippy/clippy_utils/src/usage.rs @@ -10,7 +10,7 @@ use rustc_lint::LateContext; use rustc_middle::hir::map::Map; use rustc_middle::mir::FakeReadCause; use rustc_middle::ty; -use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; +use rustc_typeck::expr_use_visitor::{Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId}; /// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined. pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) -> Option { @@ -67,7 +67,7 @@ impl<'tcx> MutVarsDelegate { } impl<'tcx> Delegate<'tcx> for MutVarsDelegate { - fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId, _: ConsumeMode) {} + fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {} fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, bk: ty::BorrowKind) { if let ty::BorrowKind::MutBorrow = bk { From 6e357bce5db7c14aa132acc6707a685d978b2efa Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Wed, 14 Jul 2021 16:50:11 -0400 Subject: [PATCH 17/23] Fix tests for i686 --- src/test/debuginfo/marker-types.rs | 4 ++-- src/test/debuginfo/pretty-std.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/debuginfo/marker-types.rs b/src/test/debuginfo/marker-types.rs index f27a5d20c70db..8373d7856bb37 100644 --- a/src/test/debuginfo/marker-types.rs +++ b/src/test/debuginfo/marker-types.rs @@ -17,8 +17,8 @@ // cdb-command: dx pin // cdb-check:pin : Pin(0x[...]: "this") [Type: core::pin::Pin >] // cdb-check: [] [Type: core::pin::Pin >] -// cdb-check: [len] : 0x4 [Type: unsigned __int64] -// cdb-check: [capacity] : 0x4 [Type: unsigned __int64] +// cdb-check: [len] : 0x4 [Type: unsigned [...]] +// cdb-check: [capacity] : 0x4 [Type: unsigned [...]] // cdb-check: [chars] : "this" // cdb-command: dx unique diff --git a/src/test/debuginfo/pretty-std.rs b/src/test/debuginfo/pretty-std.rs index 303f0114b1734..d5a6e148b7a66 100644 --- a/src/test/debuginfo/pretty-std.rs +++ b/src/test/debuginfo/pretty-std.rs @@ -140,7 +140,7 @@ // cdb-check:vecdeque : { len=0x2 } [Type: alloc::collections::vec_deque::VecDeque] // cdb-check: [] [Type: alloc::collections::vec_deque::VecDeque] // cdb-check: [len] : 0x2 -// cdb-check: [capacity] : 0x8 [Type: unsigned __int64] +// cdb-check: [capacity] : 0x8 [Type: unsigned [...]] // cdb-check: [0x0] : 90 [Type: int] // cdb-check: [0x1] : 20 [Type: int] From 4b10218055871933095b648d4fd5816433606508 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Wed, 14 Jul 2021 16:17:04 -0500 Subject: [PATCH 18/23] Remove refs from pat slices --- compiler/rustc_ast_lowering/src/expr.rs | 19 +++++++++---- compiler/rustc_ast_lowering/src/lib.rs | 27 ++++++++++++------ compiler/rustc_ast_lowering/src/pat.rs | 28 +++++++++++-------- compiler/rustc_hir/src/hir.rs | 16 +++++------ .../rustc_mir_build/src/thir/pattern/mod.rs | 8 +++--- compiler/rustc_typeck/src/check/pat.rs | 10 +++---- src/librustdoc/clean/utils.rs | 17 ++++------- src/tools/clippy/clippy_lints/src/format.rs | 2 +- .../clippy_lints/src/manual_unwrap_or.rs | 4 +-- src/tools/clippy/clippy_lints/src/matches.rs | 2 +- .../clippy_lints/src/option_if_let_else.rs | 2 +- .../clippy_lints/src/pattern_type_mismatch.rs | 2 +- src/tools/clippy/clippy_utils/src/lib.rs | 18 ++++++------ 13 files changed, 86 insertions(+), 69 deletions(-) diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index eb8e92f07eacc..7fecf537cfbd3 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1067,6 +1067,15 @@ impl<'hir> LoweringContext<'_, 'hir> { eq_sign_span: Span, assignments: &mut Vec>, ) -> &'hir hir::Pat<'hir> { + self.arena.alloc(self.destructure_assign_mut(lhs, eq_sign_span, assignments)) + } + + fn destructure_assign_mut( + &mut self, + lhs: &Expr, + eq_sign_span: Span, + assignments: &mut Vec>, + ) -> hir::Pat<'hir> { match &lhs.kind { // Underscore pattern. ExprKind::Underscore => { @@ -1080,7 +1089,7 @@ impl<'hir> LoweringContext<'_, 'hir> { let (before, after) = pats.split_at(i); hir::PatKind::Slice( before, - Some(self.pat_without_dbm(span, hir::PatKind::Wild)), + Some(self.arena.alloc(self.pat_without_dbm(span, hir::PatKind::Wild))), after, ) } else { @@ -1165,14 +1174,14 @@ impl<'hir> LoweringContext<'_, 'hir> { let tuple_pat = hir::PatKind::Tuple(&[], Some(0)); return self.pat_without_dbm(lhs.span, tuple_pat); } else { - return self.destructure_assign(e, eq_sign_span, assignments); + return self.destructure_assign_mut(e, eq_sign_span, assignments); } } _ => {} } // Treat all other cases as normal lvalue. let ident = Ident::new(sym::lhs, lhs.span); - let (pat, binding) = self.pat_ident(lhs.span, ident); + let (pat, binding) = self.pat_ident_mut(lhs.span, ident); let ident = self.expr_ident(lhs.span, ident, binding); let assign = hir::ExprKind::Assign(self.lower_expr(lhs), ident, eq_sign_span); let expr = self.expr(lhs.span, assign, ThinVec::new()); @@ -1191,7 +1200,7 @@ impl<'hir> LoweringContext<'_, 'hir> { ctx: &str, eq_sign_span: Span, assignments: &mut Vec>, - ) -> (&'hir [&'hir hir::Pat<'hir>], Option<(usize, Span)>) { + ) -> (&'hir [hir::Pat<'hir>], Option<(usize, Span)>) { let mut rest = None; let elements = self.arena.alloc_from_iter(elements.iter().enumerate().filter_map(|(i, e)| { @@ -1204,7 +1213,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } None } else { - Some(self.destructure_assign(e, eq_sign_span, assignments)) + Some(self.destructure_assign_mut(e, eq_sign_span, assignments)) } })); (elements, rest) diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index b787158c34368..a8d6a99cbeb4c 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -2577,21 +2577,35 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.pat_ident_binding_mode(span, ident, hir::BindingAnnotation::Unannotated) } + fn pat_ident_mut(&mut self, span: Span, ident: Ident) -> (hir::Pat<'hir>, hir::HirId) { + self.pat_ident_binding_mode_mut(span, ident, hir::BindingAnnotation::Unannotated) + } + fn pat_ident_binding_mode( &mut self, span: Span, ident: Ident, bm: hir::BindingAnnotation, ) -> (&'hir hir::Pat<'hir>, hir::HirId) { + let (pat, hir_id) = self.pat_ident_binding_mode_mut(span, ident, bm); + (self.arena.alloc(pat), hir_id) + } + + fn pat_ident_binding_mode_mut( + &mut self, + span: Span, + ident: Ident, + bm: hir::BindingAnnotation, + ) -> (hir::Pat<'hir>, hir::HirId) { let hir_id = self.next_id(); ( - self.arena.alloc(hir::Pat { + hir::Pat { hir_id, kind: hir::PatKind::Binding(bm, hir_id, ident.with_span_pos(span), None), span, default_binding_modes: true, - }), + }, hir_id, ) } @@ -2609,13 +2623,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }) } - fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> { - self.arena.alloc(hir::Pat { - hir_id: self.next_id(), - kind, - span, - default_binding_modes: false, - }) + fn pat_without_dbm(&mut self, span: Span, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> { + hir::Pat { hir_id: self.next_id(), kind, span, default_binding_modes: false } } fn ty_path( diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index 66e623528f3bd..d81ddd2c082e7 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -10,7 +10,11 @@ use rustc_span::symbol::Ident; use rustc_span::{source_map::Spanned, Span}; impl<'a, 'hir> LoweringContext<'a, 'hir> { - crate fn lower_pat(&mut self, mut pattern: &Pat) -> &'hir hir::Pat<'hir> { + crate fn lower_pat(&mut self, pattern: &Pat) -> &'hir hir::Pat<'hir> { + self.arena.alloc(self.lower_pat_mut(pattern)) + } + + crate fn lower_pat_mut(&mut self, mut pattern: &Pat) -> hir::Pat<'hir> { ensure_sufficient_stack(|| { // loop here to avoid recursion let node = loop { @@ -34,7 +38,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } PatKind::Or(ref pats) => { break hir::PatKind::Or( - self.arena.alloc_from_iter(pats.iter().map(|x| self.lower_pat(x))), + self.arena.alloc_from_iter(pats.iter().map(|x| self.lower_pat_mut(x))), ); } PatKind::Path(ref qself, ref path) => { @@ -101,7 +105,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &mut self, pats: &[P], ctx: &str, - ) -> (&'hir [&'hir hir::Pat<'hir>], Option) { + ) -> (&'hir [hir::Pat<'hir>], Option) { let mut elems = Vec::with_capacity(pats.len()); let mut rest = None; @@ -140,7 +144,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } // It was not a sub-tuple pattern so lower it normally. - elems.push(self.lower_pat(pat)); + elems.push(self.lower_pat_mut(pat)); } for (_, pat) in iter { @@ -149,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // ...but there was one again, so error. self.ban_extra_rest_pat(pat.span, rest.unwrap().1, ctx); } else { - elems.push(self.lower_pat(pat)); + elems.push(self.lower_pat_mut(pat)); } } @@ -189,11 +193,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { // Record, lower it to `$binding_mode $ident @ _`, and stop here. PatKind::Ident(ref bm, ident, Some(ref sub)) if sub.is_rest() => { prev_rest_span = Some(sub.span); - slice = Some(lower_rest_sub(self, pat, bm, ident, sub)); + slice = Some(self.arena.alloc(lower_rest_sub(self, pat, bm, ident, sub))); break; } // It was not a subslice pattern so lower it normally. - _ => before.push(self.lower_pat(pat)), + _ => before.push(self.lower_pat_mut(pat)), } } @@ -214,7 +218,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.ban_extra_rest_pat(rest_span, prev_rest_span.unwrap(), "slice"); } else { // Lower the pattern normally. - after.push(self.lower_pat(pat)); + after.push(self.lower_pat_mut(pat)); } } @@ -268,17 +272,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } fn pat_wild_with_node_id_of(&mut self, p: &Pat) -> &'hir hir::Pat<'hir> { - self.pat_with_node_id_of(p, hir::PatKind::Wild) + self.arena.alloc(self.pat_with_node_id_of(p, hir::PatKind::Wild)) } /// Construct a `Pat` with the `HirId` of `p.id` lowered. - fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> &'hir hir::Pat<'hir> { - self.arena.alloc(hir::Pat { + fn pat_with_node_id_of(&mut self, p: &Pat, kind: hir::PatKind<'hir>) -> hir::Pat<'hir> { + hir::Pat { hir_id: self.lower_node_id(p.id), kind, span: p.span, default_binding_modes: true, - }) + } } /// Emit a friendly error for extra `..` patterns in a tuple/tuple struct/slice pattern. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a7ce92ea57917..4b2679e164aac 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -808,13 +808,13 @@ impl<'hir> Pat<'hir> { } use PatKind::*; - match &self.kind { + match self.kind { Wild | Lit(_) | Range(..) | Binding(.., None) | Path(_) => true, Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_short_(it), Struct(_, fields, _) => fields.iter().all(|field| field.pat.walk_short_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().all(|p| p.walk_short_(it)), Slice(before, slice, after) => { - before.iter().chain(slice.iter()).chain(after.iter()).all(|p| p.walk_short_(it)) + before.iter().chain(slice).chain(after.iter()).all(|p| p.walk_short_(it)) } } } @@ -836,13 +836,13 @@ impl<'hir> Pat<'hir> { } use PatKind::*; - match &self.kind { + match self.kind { Wild | Lit(_) | Range(..) | Binding(.., None) | Path(_) => {} Box(s) | Ref(s, _) | Binding(.., Some(s)) => s.walk_(it), Struct(_, fields, _) => fields.iter().for_each(|field| field.pat.walk_(it)), TupleStruct(_, s, _) | Tuple(s, _) | Or(s) => s.iter().for_each(|p| p.walk_(it)), Slice(before, slice, after) => { - before.iter().chain(slice.iter()).chain(after.iter()).for_each(|p| p.walk_(it)) + before.iter().chain(slice).chain(after.iter()).for_each(|p| p.walk_(it)) } } } @@ -940,11 +940,11 @@ pub enum PatKind<'hir> { /// A tuple struct/variant pattern `Variant(x, y, .., z)`. /// If the `..` pattern fragment is present, then `Option` denotes its position. /// `0 <= position <= subpats.len()` - TupleStruct(QPath<'hir>, &'hir [&'hir Pat<'hir>], Option), + TupleStruct(QPath<'hir>, &'hir [Pat<'hir>], Option), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. - Or(&'hir [&'hir Pat<'hir>]), + Or(&'hir [Pat<'hir>]), /// A path pattern for an unit struct/variant or a (maybe-associated) constant. Path(QPath<'hir>), @@ -952,7 +952,7 @@ pub enum PatKind<'hir> { /// A tuple pattern (e.g., `(a, b)`). /// If the `..` pattern fragment is present, then `Option` denotes its position. /// `0 <= position <= subpats.len()` - Tuple(&'hir [&'hir Pat<'hir>], Option), + Tuple(&'hir [Pat<'hir>], Option), /// A `box` pattern. Box(&'hir Pat<'hir>), @@ -975,7 +975,7 @@ pub enum PatKind<'hir> { /// ``` /// PatKind::Slice([Binding(a), Binding(b)], Some(Wild), [Binding(c), Binding(d)]) /// ``` - Slice(&'hir [&'hir Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [&'hir Pat<'hir>]), + Slice(&'hir [Pat<'hir>], Option<&'hir Pat<'hir>>, &'hir [Pat<'hir>]), } #[derive(Copy, Clone, PartialEq, Encodable, Debug, HashStable_Generic)] diff --git a/compiler/rustc_mir_build/src/thir/pattern/mod.rs b/compiler/rustc_mir_build/src/thir/pattern/mod.rs index 3ea76fb99d531..046f41400366d 100644 --- a/compiler/rustc_mir_build/src/thir/pattern/mod.rs +++ b/compiler/rustc_mir_build/src/thir/pattern/mod.rs @@ -325,7 +325,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { fn lower_tuple_subpats( &mut self, - pats: &'tcx [&'tcx hir::Pat<'tcx>], + pats: &'tcx [hir::Pat<'tcx>], expected_len: usize, gap_pos: Option, ) -> Vec> { @@ -338,7 +338,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { .collect() } - fn lower_patterns(&mut self, pats: &'tcx [&'tcx hir::Pat<'tcx>]) -> Vec> { + fn lower_patterns(&mut self, pats: &'tcx [hir::Pat<'tcx>]) -> Vec> { pats.iter().map(|p| self.lower_pattern(p)).collect() } @@ -350,9 +350,9 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> { &mut self, span: Span, ty: Ty<'tcx>, - prefix: &'tcx [&'tcx hir::Pat<'tcx>], + prefix: &'tcx [hir::Pat<'tcx>], slice: &'tcx Option<&'tcx hir::Pat<'tcx>>, - suffix: &'tcx [&'tcx hir::Pat<'tcx>], + suffix: &'tcx [hir::Pat<'tcx>], ) -> PatKind<'tcx> { let prefix = self.lower_patterns(prefix); let slice = self.lower_opt_pattern(slice); diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 2879614d0c808..981a040e66072 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -864,7 +864,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { &self, pat: &'tcx Pat<'tcx>, qpath: &'tcx hir::QPath<'tcx>, - subpats: &'tcx [&'tcx Pat<'tcx>], + subpats: &'tcx [Pat<'tcx>], ddpos: Option, expected: Ty<'tcx>, def_bm: BindingMode, @@ -982,7 +982,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pat_span: Span, res: Res, qpath: &hir::QPath<'_>, - subpats: &'tcx [&'tcx Pat<'tcx>], + subpats: &'tcx [Pat<'tcx>], fields: &'tcx [ty::FieldDef], expected: Ty<'tcx>, had_err: bool, @@ -1112,7 +1112,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_tuple( &self, span: Span, - elements: &'tcx [&'tcx Pat<'tcx>], + elements: &'tcx [Pat<'tcx>], ddpos: Option, expected: Ty<'tcx>, def_bm: BindingMode, @@ -1746,9 +1746,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_slice( &self, span: Span, - before: &'tcx [&'tcx Pat<'tcx>], + before: &'tcx [Pat<'tcx>], slice: Option<&'tcx Pat<'tcx>>, - after: &'tcx [&'tcx Pat<'tcx>], + after: &'tcx [Pat<'tcx>], expected: Ty<'tcx>, def_bm: BindingMode, ti: TopInfo<'tcx>, diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 7ae602c8033f8..dea016a467d64 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -260,17 +260,12 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { PatKind::Wild | PatKind::Struct(..) => return kw::Underscore, PatKind::Binding(_, _, ident, _) => return ident.name, PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p), - PatKind::Or(ref pats) => pats - .iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(" | "), + PatKind::Or(ref pats) => { + pats.iter().map(|p| name_from_pat(p).to_string()).collect::>().join(" | ") + } PatKind::Tuple(ref elts, _) => format!( "({})", - elts.iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(", ") + elts.iter().map(|p| name_from_pat(p).to_string()).collect::>().join(", ") ), PatKind::Box(ref p) => return name_from_pat(&**p), PatKind::Ref(ref p, _) => return name_from_pat(&**p), @@ -282,9 +277,9 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { } PatKind::Range(..) => return kw::Underscore, PatKind::Slice(ref begin, ref mid, ref end) => { - let begin = begin.iter().map(|p| name_from_pat(&**p).to_string()); + let begin = begin.iter().map(|p| name_from_pat(p).to_string()); let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter(); - let end = end.iter().map(|p| name_from_pat(&**p).to_string()); + let end = end.iter().map(|p| name_from_pat(p).to_string()); format!("[{}]", begin.chain(mid).chain(end).collect::>().join(", ")) } }) diff --git a/src/tools/clippy/clippy_lints/src/format.rs b/src/tools/clippy/clippy_lints/src/format.rs index c2b055ed6488e..81e5e63860397 100644 --- a/src/tools/clippy/clippy_lints/src/format.rs +++ b/src/tools/clippy/clippy_lints/src/format.rs @@ -92,7 +92,7 @@ fn on_argumentv1_new<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, arms: & if let PatKind::Tuple(pats, None) = arms[0].pat.kind; if pats.len() == 1; then { - let ty = cx.typeck_results().pat_ty(pats[0]).peel_refs(); + let ty = cx.typeck_results().pat_ty(&pats[0]).peel_refs(); if *ty.kind() != rustc_middle::ty::Str && !is_type_diagnostic_item(cx, ty, sym::string_type) { return None; } diff --git a/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs b/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs index 18038dd781943..9d8d77cf8f089 100644 --- a/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs +++ b/src/tools/clippy/clippy_lints/src/manual_unwrap_or.rs @@ -61,13 +61,13 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { if let Some((idx, or_arm)) = arms.iter().enumerate().find(|(_, arm)| { match arm.pat.kind { PatKind::Path(ref qpath) => is_lang_ctor(cx, qpath, OptionNone), - PatKind::TupleStruct(ref qpath, &[pat], _) => + PatKind::TupleStruct(ref qpath, [pat], _) => matches!(pat.kind, PatKind::Wild) && is_lang_ctor(cx, qpath, ResultErr), _ => false, } }); let unwrap_arm = &arms[1 - idx]; - if let PatKind::TupleStruct(ref qpath, &[unwrap_pat], _) = unwrap_arm.pat.kind; + if let PatKind::TupleStruct(ref qpath, [unwrap_pat], _) = unwrap_arm.pat.kind; if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk); if let PatKind::Binding(_, binding_hir_id, ..) = unwrap_pat.kind; if path_to_local_id(unwrap_arm.body, binding_hir_id); diff --git a/src/tools/clippy/clippy_lints/src/matches.rs b/src/tools/clippy/clippy_lints/src/matches.rs index f1e3492c4ecc5..b6adfdfb9267a 100644 --- a/src/tools/clippy/clippy_lints/src/matches.rs +++ b/src/tools/clippy/clippy_lints/src/matches.rs @@ -625,7 +625,7 @@ impl<'tcx> LateLintPass<'tcx> for Matches { if let PatKind::TupleStruct( QPath::Resolved(None, variant_name), args, _) = arms[0].pat.kind; if args.len() == 1; - if let PatKind::Binding(_, arg, ..) = strip_pat_refs(args[0]).kind; + if let PatKind::Binding(_, arg, ..) = strip_pat_refs(&args[0]).kind; let body = remove_blocks(arms[0].body); if path_to_local_id(body, arg); diff --git a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs index b6af4175edfda..b2be35bdddb38 100644 --- a/src/tools/clippy/clippy_lints/src/option_if_let_else.rs +++ b/src/tools/clippy/clippy_lints/src/option_if_let_else.rs @@ -132,7 +132,7 @@ fn detect_option_if_let_else<'tcx>( if !is_else_clause(cx.tcx, expr); if arms.len() == 2; if !is_result_ok(cx, cond_expr); // Don't lint on Result::ok because a different lint does it already - if let PatKind::TupleStruct(struct_qpath, &[inner_pat], _) = &arms[0].pat.kind; + if let PatKind::TupleStruct(struct_qpath, [inner_pat], _) = &arms[0].pat.kind; if is_lang_ctor(cx, struct_qpath, OptionSome); if let PatKind::Binding(bind_annotation, _, id, _) = &inner_pat.kind; if !contains_return_break_continue_macro(arms[0].body); diff --git a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs index 9bab783998aa5..ea4065d371b81 100644 --- a/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs +++ b/src/tools/clippy/clippy_lints/src/pattern_type_mismatch.rs @@ -258,7 +258,7 @@ fn get_variant<'a>(adt_def: &'a AdtDef, qpath: &QPath<'_>) -> Option<&'a Variant fn find_first_mismatch_in_tuple<'tcx, I>( cx: &LateContext<'tcx>, - pats: &[&Pat<'_>], + pats: &[Pat<'_>], ty_iter_src: I, ) -> Option<(Span, Mutability, Level)> where diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index 2f10472180f5e..1ba9bb90ce8fe 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -255,7 +255,7 @@ pub fn in_macro(span: Span) -> bool { } /// Checks if given pattern is a wildcard (`_`) -pub fn is_wild<'tcx>(pat: &impl std::ops::Deref>) -> bool { +pub fn is_wild(pat: &Pat<'_>) -> bool { matches!(pat.kind, PatKind::Wild) } @@ -1023,8 +1023,8 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { ) } - fn are_refutable<'a, I: Iterator>>(cx: &LateContext<'_>, mut i: I) -> bool { - i.any(|pat| is_refutable(cx, pat)) + fn are_refutable<'a, I: IntoIterator>>(cx: &LateContext<'_>, i: I) -> bool { + i.into_iter().any(|pat| is_refutable(cx, pat)) } match pat.kind { @@ -1035,23 +1035,23 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { PatKind::Path(ref qpath) => is_enum_variant(cx, qpath, pat.hir_id), PatKind::Or(pats) => { // TODO: should be the honest check, that pats is exhaustive set - are_refutable(cx, pats.iter().map(|pat| &**pat)) + are_refutable(cx, pats) }, - PatKind::Tuple(pats, _) => are_refutable(cx, pats.iter().map(|pat| &**pat)), + PatKind::Tuple(pats, _) => are_refutable(cx, pats), PatKind::Struct(ref qpath, fields, _) => { is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, fields.iter().map(|field| &*field.pat)) }, PatKind::TupleStruct(ref qpath, pats, _) => { - is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats.iter().map(|pat| &**pat)) + is_enum_variant(cx, qpath, pat.hir_id) || are_refutable(cx, pats) }, - PatKind::Slice(head, ref middle, tail) => { + PatKind::Slice(head, middle, tail) => { match &cx.typeck_results().node_type(pat.hir_id).kind() { rustc_ty::Slice(..) => { // [..] is the only irrefutable slice pattern. !head.is_empty() || middle.is_none() || !tail.is_empty() }, rustc_ty::Array(..) => { - are_refutable(cx, head.iter().chain(middle).chain(tail.iter()).map(|pat| &**pat)) + are_refutable(cx, head.iter().chain(middle).chain(tail.iter())) }, _ => { // unreachable!() @@ -1066,7 +1066,7 @@ pub fn is_refutable(cx: &LateContext<'_>, pat: &Pat<'_>) -> bool { /// the function once on the given pattern. pub fn recurse_or_patterns<'tcx, F: FnMut(&'tcx Pat<'tcx>)>(pat: &'tcx Pat<'tcx>, mut f: F) { if let PatKind::Or(pats) = pat.kind { - pats.iter().copied().for_each(f); + pats.iter().for_each(f); } else { f(pat); } From c4ac8369e2ec05a9c8234608b8bd2a33832b3929 Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Thu, 15 Jul 2021 00:54:18 -0400 Subject: [PATCH 19/23] PR feedback --- compiler/rustc_typeck/src/expr_use_visitor.rs | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index dceeac48d6a3d..eaa6ce82906b3 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -29,6 +29,10 @@ pub trait Delegate<'tcx> { // The value found at `place` is moved, depending // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`. // + // Use of a `Copy` type in a ByValue context is considered a use + // by `ImmBorrow` and `borrow` is called instead. + // + // // The parameter `diag_expr_id` indicates the HIR id that ought to be used for // diagnostics. Around pattern matching such as `let pat = expr`, the diagnostic // id will be the id of the expression `expr` but the place itself will have @@ -134,16 +138,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } fn delegate_consume(&mut self, place_with_id: &PlaceWithHirId<'tcx>, diag_expr_id: hir::HirId) { - debug!("delegate_consume(place_with_id={:?})", place_with_id); - - let mode = copy_or_move(&self.mc, place_with_id); - - match mode { - ConsumeMode::Move => self.delegate.consume(place_with_id, diag_expr_id), - ConsumeMode::Copy => { - self.delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) - } - } + delegate_consume(&self.mc, self.delegate, place_with_id, diag_expr_id) } fn consume_exprs(&mut self, exprs: &[hir::Expr<'_>]) { @@ -653,15 +648,7 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { } ty::BindByValue(..) => { debug!("walk_pat binding consuming pat"); - let mode = copy_or_move(mc, &place); - match mode { - ConsumeMode::Move => delegate.consume(place, discr_place.hir_id), - ConsumeMode::Copy => delegate.borrow( - place, - discr_place.hir_id, - ty::BorrowKind::ImmBorrow, - ), - } + delegate_consume(mc, *delegate, place, discr_place.hir_id); } } } @@ -808,3 +795,23 @@ fn copy_or_move<'a, 'tcx>( ConsumeMode::Copy } } + +// - If a place is used in a `ByValue` context then move it if it's not a `Copy` type. +// - If the place that is a `Copy` type consider it a `ImmBorrow`. +fn delegate_consume<'a, 'tcx>( + mc: &mc::MemCategorizationContext<'a, 'tcx>, + delegate: &mut (dyn Delegate<'tcx> + 'a), + place_with_id: &PlaceWithHirId<'tcx>, + diag_expr_id: hir::HirId, +) { + debug!("delegate_consume(place_with_id={:?})", place_with_id); + + let mode = copy_or_move(&mc, place_with_id); + + match mode { + ConsumeMode::Move => delegate.consume(place_with_id, diag_expr_id), + ConsumeMode::Copy => { + delegate.borrow(place_with_id, diag_expr_id, ty::BorrowKind::ImmBorrow) + } + } +} From 75291ee92453bb97a36d999dfce4bb7e0fea27c9 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 15 Jul 2021 04:13:20 -0400 Subject: [PATCH 20/23] Update compiler/rustc_typeck/src/expr_use_visitor.rs --- compiler/rustc_typeck/src/expr_use_visitor.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index eaa6ce82906b3..a2bb420a90109 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -30,7 +30,9 @@ pub trait Delegate<'tcx> { // on `mode`. Where `diag_expr_id` is the id used for diagnostics for `place`. // // Use of a `Copy` type in a ByValue context is considered a use - // by `ImmBorrow` and `borrow` is called instead. + // by `ImmBorrow` and `borrow` is called instead. This is because + // a shared borrow is the "minimum access" that would be needed + // to perform a copy. // // // The parameter `diag_expr_id` indicates the HIR id that ought to be used for From d49f977ed9fef7bc0734693eb6f6b1f41b72735e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Sat, 20 Mar 2021 00:00:00 +0000 Subject: [PATCH 21/23] Layout error instead of an ICE for packed and aligned types --- compiler/rustc_middle/src/ty/layout.rs | 9 +++++++-- src/test/ui/conflicting-repr-hints.rs | 11 +++++++++++ src/test/ui/conflicting-repr-hints.stderr | 16 +++++++++++++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index dbb5064c4f546..e089b2526078c 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -312,7 +312,8 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { let dl = self.data_layout(); let pack = repr.pack; if pack.is_some() && repr.align.is_some() { - bug!("struct cannot be packed and aligned"); + self.tcx.sess.delay_span_bug(DUMMY_SP, "struct cannot be packed and aligned"); + return Err(LayoutError::Unknown(ty)); } let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align }; @@ -808,7 +809,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { if def.is_union() { if def.repr.pack.is_some() && def.repr.align.is_some() { - bug!("union cannot be packed and aligned"); + self.tcx.sess.delay_span_bug( + tcx.def_span(def.did), + "union cannot be packed and aligned", + ); + return Err(LayoutError::Unknown(ty)); } let mut align = diff --git a/src/test/ui/conflicting-repr-hints.rs b/src/test/ui/conflicting-repr-hints.rs index 09dade20992ba..ed82b6a742c8d 100644 --- a/src/test/ui/conflicting-repr-hints.rs +++ b/src/test/ui/conflicting-repr-hints.rs @@ -66,4 +66,15 @@ union Z { i: i32, } +#[repr(packed, align(0x100))] +pub struct S(u16); //~ ERROR type has conflicting packed and align representation hints + +#[repr(packed, align(0x100))] +pub union U { //~ ERROR type has conflicting packed and align representation hints + u: u16 +} + +static B: U = U { u: 0 }; +static A: S = S(0); + fn main() {} diff --git a/src/test/ui/conflicting-repr-hints.stderr b/src/test/ui/conflicting-repr-hints.stderr index 0b78532c73751..0f32fc0481bc6 100644 --- a/src/test/ui/conflicting-repr-hints.stderr +++ b/src/test/ui/conflicting-repr-hints.stderr @@ -74,7 +74,21 @@ LL | | i: i32, LL | | } | |_^ -error: aborting due to 10 previous errors +error[E0587]: type has conflicting packed and align representation hints + --> $DIR/conflicting-repr-hints.rs:70:1 + | +LL | pub struct S(u16); + | ^^^^^^^^^^^^^^^^^^ + +error[E0587]: type has conflicting packed and align representation hints + --> $DIR/conflicting-repr-hints.rs:73:1 + | +LL | / pub union U { +LL | | u: u16 +LL | | } + | |_^ + +error: aborting due to 12 previous errors Some errors have detailed explanations: E0566, E0587, E0634. For more information about an error, try `rustc --explain E0566`. From 59103d1a25ce41321a4d7d304123bb019da11612 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 15 Jul 2021 18:19:07 +0200 Subject: [PATCH 22/23] Fix layout overflow in type declaration --- src/librustdoc/html/static/css/rustdoc.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 208e8f723f407..017ce0a494eb3 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -247,6 +247,9 @@ code, pre, a.test-arrow { pre { padding: 14px; } +.type-decl pre { + overflow-x: auto; +} .source .content pre { padding: 20px; From 25e74037e8c1fda12cc83833d6e49feccb665e0f Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 15 Jul 2021 18:19:25 +0200 Subject: [PATCH 23/23] Add regression test for type declaration layout overflow --- src/test/rustdoc-gui/src/lib2/lib.rs | 7 +++++++ src/test/rustdoc-gui/type-declation-overflow.goml | 8 ++++++++ 2 files changed, 15 insertions(+) create mode 100644 src/test/rustdoc-gui/type-declation-overflow.goml diff --git a/src/test/rustdoc-gui/src/lib2/lib.rs b/src/test/rustdoc-gui/src/lib2/lib.rs index ec8ab339e2804..0466909479b67 100644 --- a/src/test/rustdoc-gui/src/lib2/lib.rs +++ b/src/test/rustdoc-gui/src/lib2/lib.rs @@ -47,3 +47,10 @@ pub mod sub_mod { /// ``` pub struct Foo; } + +pub mod long_trait { + use std::ops::DerefMut; + + pub trait ALongNameBecauseItHelpsTestingTheCurrentProblem: DerefMut + + From + Send + Sync + AsRef + 'static {} +} diff --git a/src/test/rustdoc-gui/type-declation-overflow.goml b/src/test/rustdoc-gui/type-declation-overflow.goml new file mode 100644 index 0000000000000..0a316e220a42c --- /dev/null +++ b/src/test/rustdoc-gui/type-declation-overflow.goml @@ -0,0 +1,8 @@ +// This test ensures that the type declaration content overflow is handled inside the
 directly.
+goto: file://|DOC_PATH|/lib2/long_trait/trait.ALongNameBecauseItHelpsTestingTheCurrentProblem.html
+// We set a fixed size so there is no chance of "random" resize.
+size: (1100, 800)
+// Logically, the  scroll width should be the width of the window.
+assert-property: ("body", {"scrollWidth": "1100"})
+// However, since there is overflow in the type declaration, its scroll width is bigger.
+assert-property: (".type-decl pre", {"scrollWidth": "1324"})