From 975bc18481879b69603674266a5239ecb579f928 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Thu, 5 Aug 2021 11:58:52 -0500 Subject: Make Arguments constructors unsafe --- src/test/pretty/dollar-crate.pp | 10 ++-- src/test/pretty/issue-4264.pp | 56 +++++++++++++---------- src/test/ui/attributes/key-value-expansion.stderr | 16 ++++--- 3 files changed, 49 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/test/pretty/dollar-crate.pp b/src/test/pretty/dollar-crate.pp index f4be3c1c63a..4eccba06b13 100644 --- a/src/test/pretty/dollar-crate.pp +++ b/src/test/pretty/dollar-crate.pp @@ -10,9 +10,11 @@ extern crate std; fn main() { { - ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], - &match () { - () => [], - })); + ::std::io::_print(match match () { () => [], } { + ref args => unsafe { + ::core::fmt::Arguments::new_v1(&["rust\n"], + args) + } + }); }; } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 199aee05622..a21ea520121 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -32,29 +32,39 @@ pub fn bar() ({ ({ let res = ((::alloc::fmt::format as - for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1 - as - fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test" - as - &str)] - as - [&str; 1]) - as - &[&str; 1]), - (&(match (() - as - ()) - { - () - => - ([] - as - [ArgumentV1; 0]), - } - as - [ArgumentV1; 0]) - as - &[ArgumentV1; 0])) + for<'r> fn(Arguments<'r>) -> String {format})((match (match (() + as + ()) + { + () + => + ([] + as + [ArgumentV1; 0]), + } + as + [ArgumentV1; 0]) + { + ref args + => + unsafe + { + ((::core::fmt::Arguments::new_v1 + as + unsafe fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test" + as + &str)] + as + [&str; 1]) + as + &[&str; 1]), + (args + as + &[ArgumentV1; 0])) + as + Arguments) + } + } as Arguments)) as String); diff --git a/src/test/ui/attributes/key-value-expansion.stderr b/src/test/ui/attributes/key-value-expansion.stderr index 31e93ef54f2..03ca515265c 100644 --- a/src/test/ui/attributes/key-value-expansion.stderr +++ b/src/test/ui/attributes/key-value-expansion.stderr @@ -17,12 +17,16 @@ LL | bug!(); error: unexpected token: `{ let res = - ::alloc::fmt::format(::core::fmt::Arguments::new_v1(&[""], - &match (&"u8",) { - (arg0,) => - [::core::fmt::ArgumentV1::new(arg0, - ::core::fmt::Display::fmt)], - })); + ::alloc::fmt::format(match match (&"u8",) { + (arg0,) => + [::core::fmt::ArgumentV1::new(arg0, + ::core::fmt::Display::fmt)], + } { + ref args => unsafe { + ::core::fmt::Arguments::new_v1(&[""], + args) + } + }); res }.as_str()` --> $DIR/key-value-expansion.rs:48:23 -- cgit 1.4.1-3-g733a5 From 46377c48a400bc39110fb9a930c2c200ceac7cd2 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Mon, 7 Jun 2021 17:43:35 -0500 Subject: Add unnecessary unsafe test --- .../ui/unsafe/unsafe-around-compiler-generated-unsafe.mir.stderr | 8 +++++++- src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.rs | 3 +++ .../ui/unsafe/unsafe-around-compiler-generated-unsafe.thir.stderr | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.mir.stderr b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.mir.stderr index 29bd84cd0db..62199e5a2ec 100644 --- a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.mir.stderr +++ b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.mir.stderr @@ -10,5 +10,11 @@ note: the lint level is defined here LL | #![deny(unused_unsafe)] | ^^^^^^^^^^^^^ -error: aborting due to previous error +error: unnecessary `unsafe` block + --> $DIR/unsafe-around-compiler-generated-unsafe.rs:13:5 + | +LL | unsafe { println!("foo"); } + | ^^^^^^ unnecessary `unsafe` block + +error: aborting due to 2 previous errors diff --git a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.rs b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.rs index e9c7efb9e8b..c1a32764039 100644 --- a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.rs +++ b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.rs @@ -8,4 +8,7 @@ fn main() { let _ = async { unsafe { async {}.await; } //~ ERROR unnecessary `unsafe` }; + + // `format_args!` expands with a compiler-generated unsafe block + unsafe { println!("foo"); } //~ ERROR unnecessary `unsafe` } diff --git a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.thir.stderr b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.thir.stderr index 29bd84cd0db..62199e5a2ec 100644 --- a/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.thir.stderr +++ b/src/test/ui/unsafe/unsafe-around-compiler-generated-unsafe.thir.stderr @@ -10,5 +10,11 @@ note: the lint level is defined here LL | #![deny(unused_unsafe)] | ^^^^^^^^^^^^^ -error: aborting due to previous error +error: unnecessary `unsafe` block + --> $DIR/unsafe-around-compiler-generated-unsafe.rs:13:5 + | +LL | unsafe { println!("foo"); } + | ^^^^^^ unnecessary `unsafe` block + +error: aborting due to 2 previous errors -- cgit 1.4.1-3-g733a5 From 51979ac1c710f334d3a13379b0279599b2f14fdc Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sat, 3 Jul 2021 13:06:51 -0500 Subject: Fix a debuginfo test --- src/test/debuginfo/rc_arc.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/debuginfo/rc_arc.rs b/src/test/debuginfo/rc_arc.rs index 55cddf7c6c6..144a746062d 100644 --- a/src/test/debuginfo/rc_arc.rs +++ b/src/test/debuginfo/rc_arc.rs @@ -75,5 +75,7 @@ fn main() { let a1 = Arc::clone(&a); let w2 = Arc::downgrade(&a); - print!(""); // #break + zzz(); // #break } + +fn zzz() { () } -- cgit 1.4.1-3-g733a5 From d3097fc496d2fb87f988618a24f133026229120c Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Fri, 16 Jul 2021 08:54:08 -0500 Subject: clippy: Fix format_args expansion parsing --- src/tools/clippy/clippy_utils/src/higher.rs | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/tools/clippy/clippy_utils/src/higher.rs b/src/tools/clippy/clippy_utils/src/higher.rs index 29b698e56e3..6437363bad7 100644 --- a/src/tools/clippy/clippy_utils/src/higher.rs +++ b/src/tools/clippy/clippy_utils/src/higher.rs @@ -485,12 +485,28 @@ impl FormatArgsExpn<'tcx> { if let ExpnKind::Macro(_, name) = expr.span.ctxt().outer_expn_data().kind; let name = name.as_str(); if name.ends_with("format_args") || name.ends_with("format_args_nl"); - if let ExprKind::Call(_, args) = expr.kind; - if let Some((strs_ref, args, fmt_expr)) = match args { + + if let ExprKind::Match(inner_match, [arm], _) = expr.kind; + + // `match match`, if you will + if let ExprKind::Match(args, [inner_arm], _) = inner_match.kind; + if let ExprKind::Tup(value_args) = args.kind; + if let Some(value_args) = value_args + .iter() + .map(|e| match e.kind { + ExprKind::AddrOf(_, _, e) => Some(e), + _ => None, + }) + .collect(); + if let ExprKind::Array(args) = inner_arm.body.kind; + + if let ExprKind::Block(Block { stmts: [], expr: Some(expr), .. }, _) = arm.body.kind; + if let ExprKind::Call(_, call_args) = expr.kind; + if let Some((strs_ref, fmt_expr)) = match call_args { // Arguments::new_v1 - [strs_ref, args] => Some((strs_ref, args, None)), + [strs_ref, _] => Some((strs_ref, None)), // Arguments::new_v1_formatted - [strs_ref, args, fmt_expr] => Some((strs_ref, args, Some(fmt_expr))), + [strs_ref, _, fmt_expr] => Some((strs_ref, Some(fmt_expr))), _ => None, }; if let ExprKind::AddrOf(BorrowKind::Ref, _, strs_arr) = strs_ref.kind; @@ -506,17 +522,6 @@ impl FormatArgsExpn<'tcx> { None }) .collect(); - if let ExprKind::AddrOf(BorrowKind::Ref, _, args) = args.kind; - if let ExprKind::Match(args, [arm], _) = args.kind; - if let ExprKind::Tup(value_args) = args.kind; - if let Some(value_args) = value_args - .iter() - .map(|e| match e.kind { - ExprKind::AddrOf(_, _, e) => Some(e), - _ => None, - }) - .collect(); - if let ExprKind::Array(args) = arm.body.kind; then { Some(FormatArgsExpn { format_string_span: strs_ref.span, -- cgit 1.4.1-3-g733a5 From b1e07b82dcef6d31556a92cb75d825bce6032519 Mon Sep 17 00:00:00 2001 From: Cameron Steffen Date: Sun, 15 Aug 2021 19:18:18 -0500 Subject: Fix a coverage-reports test --- .../coverage-reports/expected_show_coverage.issue-84561.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt index f24f7c69404..b35f3f54de9 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.issue-84561.txt @@ -31,15 +31,15 @@ 24| 1| println!("{:?}", Foo(1)); 25| 1| 26| 1| assert_ne!(Foo(0), Foo(5), "{}", if is_true { "true message" } else { "false message" }); - ^0 ^0 ^0 + ^0 ^0 ^0 ^0 27| 1| assert_ne!( 28| | Foo(0) 29| | , 30| | Foo(5) 31| | , 32| 0| "{}" - 33| 0| , - 34| 0| if + 33| | , + 34| | if 35| 0| is_true 36| | { 37| 0| "true message" -- cgit 1.4.1-3-g733a5