diff --git a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs index 9c362a5e20791973fa3d360b6d26b6211fe7c63f..f4751e591bf3ce65984531014a7df239a0a133eb 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/find_anon_type.rs @@ -62,7 +62,7 @@ fn find_component_for_bound_region( &self, arg: &'tcx hir::Ty, br: &ty::BoundRegion, - ) -> Option<(&'tcx hir::Ty)> { + ) -> Option<&'tcx hir::Ty> { let mut nested_visitor = FindNestedTypeVisitor { tcx: self.tcx(), bound_region: *br, diff --git a/src/librustc_data_structures/owning_ref/mod.rs b/src/librustc_data_structures/owning_ref/mod.rs index b835b1706b85f5cf3651a94bc6f4c489517d4a4e..0213eb4f2a2a4027f281f067ea6fbe8a601a1331 100644 --- a/src/librustc_data_structures/owning_ref/mod.rs +++ b/src/librustc_data_structures/owning_ref/mod.rs @@ -1046,14 +1046,14 @@ unsafe impl CloneStableAddress for OwningRef where O: CloneStableAddress {} unsafe impl Send for OwningRef - where O: Send, for<'a> (&'a T): Send {} + where O: Send, for<'a> &'a T: Send {} unsafe impl Sync for OwningRef - where O: Sync, for<'a> (&'a T): Sync {} + where O: Sync, for<'a> &'a T: Sync {} unsafe impl Send for OwningRefMut - where O: Send, for<'a> (&'a mut T): Send {} + where O: Send, for<'a> &'a mut T: Send {} unsafe impl Sync for OwningRefMut - where O: Sync, for<'a> (&'a mut T): Sync {} + where O: Sync, for<'a> &'a mut T: Sync {} impl Debug for dyn Erased { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 3b3995832cb4cb1f9663c6bad8ae604fbc8e3a7e..7a168baacaf8152314bef6c89f6b078abd22deac 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -603,6 +603,25 @@ fn check_param(&mut self, cx: &EarlyContext<'_>, param: &ast::Param) { fn check_arm(&mut self, cx: &EarlyContext<'_>, arm: &ast::Arm) { self.check_unused_parens_pat(cx, &arm.pat, false, false); } + + fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) { + if let &ast::TyKind::Paren(ref r) = &ty.kind { + match &r.kind { + &ast::TyKind::TraitObject(..) => {} + &ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {} + _ => { + let pattern_text = if let Ok(snippet) = cx.sess().source_map() + .span_to_snippet(ty.span) { + snippet + } else { + pprust::ty_to_string(ty) + }; + + Self::remove_outer_parens(cx, ty.span, &pattern_text, "type", (false, false)); + } + } + } + } } declare_lint! { diff --git a/src/librustc_mir/borrow_check/prefixes.rs b/src/librustc_mir/borrow_check/prefixes.rs index a46a1cc5647a9e597988d78254fba7e9ab39de69..1be1fcef61b6e4024ff2cf4af9780dca59cb02bd 100644 --- a/src/librustc_mir/borrow_check/prefixes.rs +++ b/src/librustc_mir/borrow_check/prefixes.rs @@ -29,7 +29,7 @@ pub(super) struct Prefixes<'cx, 'tcx> { body: &'cx Body<'tcx>, tcx: TyCtxt<'tcx>, kind: PrefixSet, - next: Option<(PlaceRef<'cx, 'tcx>)>, + next: Option>, } #[derive(Copy, Clone, PartialEq, Eq, Debug)] diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index ff50051ef504043d673d3f3bdec1466093fa0850..941c81eaff2645c5b9022279d065fbefcb0dee14 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1818,7 +1818,7 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> { type Item = &'a K; #[inline] - fn next(&mut self) -> Option<(&'a K)> { + fn next(&mut self) -> Option<&'a K> { self.inner.next().map(|(k, _)| k) } #[inline] @@ -1841,7 +1841,7 @@ impl<'a, K, V> Iterator for Values<'a, K, V> { type Item = &'a V; #[inline] - fn next(&mut self) -> Option<(&'a V)> { + fn next(&mut self) -> Option<&'a V> { self.inner.next().map(|(_, v)| v) } #[inline] @@ -1864,7 +1864,7 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> { type Item = &'a mut V; #[inline] - fn next(&mut self) -> Option<(&'a mut V)> { + fn next(&mut self) -> Option<&'a mut V> { self.inner.next().map(|(_, v)| v) } #[inline] diff --git a/src/test/ui/alignment-gep-tup-like-1.rs b/src/test/ui/alignment-gep-tup-like-1.rs index c51c56b08992618171b902bf53459b47d9be0426..adbd05ed8c1757593995a802f856518ad7ae3d6e 100644 --- a/src/test/ui/alignment-gep-tup-like-1.rs +++ b/src/test/ui/alignment-gep-tup-like-1.rs @@ -28,7 +28,7 @@ fn f(a: A, b: u16) -> Box+'static> { box Invoker { a: a, b: b, - } as (Box+'static>) + } as Box+'static> } pub fn main() { diff --git a/src/test/ui/as-precedence.rs b/src/test/ui/as-precedence.rs index a9f6fceb08ff093a10ca1bd3328e216ad717e905..feb0cb30ccaccf49f057db73e9f492e52e538db7 100644 --- a/src/test/ui/as-precedence.rs +++ b/src/test/ui/as-precedence.rs @@ -1,5 +1,6 @@ // run-pass +#[allow(unused_parens)] fn main() { assert_eq!(3 as usize * 3, 9); assert_eq!(3 as (usize) * 3, 9); diff --git a/src/test/ui/close-over-big-then-small-data.rs b/src/test/ui/close-over-big-then-small-data.rs index 40e5f500df4a833131639aab8755d0406f46f1a9..4d6edf4ecb0f330522ce374a08209a48c3a10210 100644 --- a/src/test/ui/close-over-big-then-small-data.rs +++ b/src/test/ui/close-over-big-then-small-data.rs @@ -30,7 +30,7 @@ fn f(a: A, b: u16) -> Box+'static> { box Invoker { a: a, b: b, - } as (Box+'static>) + } as Box+'static> } pub fn main() { diff --git a/src/test/ui/functions-closures/closure-to-fn-coercion.rs b/src/test/ui/functions-closures/closure-to-fn-coercion.rs index 4f43c2bb53847bddace7107c8529ac4c7a1bd2de..87ba488b5aef2459f3df3d79e0456112cdf5ea3c 100644 --- a/src/test/ui/functions-closures/closure-to-fn-coercion.rs +++ b/src/test/ui/functions-closures/closure-to-fn-coercion.rs @@ -10,7 +10,7 @@ |v: &mut u32| *v += 3, |v: &mut u32| *v += 4, ]; -fn func_specific() -> (fn() -> u32) { +fn func_specific() -> fn() -> u32 { || return 42 } diff --git a/src/test/ui/lint/lint-unnecessary-parens.rs b/src/test/ui/lint/lint-unnecessary-parens.rs index 811bc87eb0e2eee5afe81311b39301f29fa79d37..9f42b855a870d7b4e44abb0e86f4e23c3a6ef5a7 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.rs +++ b/src/test/ui/lint/lint-unnecessary-parens.rs @@ -13,6 +13,18 @@ fn bar(y: bool) -> X { return (X { y }); //~ ERROR unnecessary parentheses around `return` value } +fn unused_parens_around_return_type() -> (u32) { //~ ERROR unnecessary parentheses around type + panic!() +} + +trait Trait { + fn test(&self); +} + +fn passes_unused_parens_lint() -> &'static (dyn Trait) { + panic!() +} + fn main() { foo(); bar((true)); //~ ERROR unnecessary parentheses around function argument diff --git a/src/test/ui/lint/lint-unnecessary-parens.stderr b/src/test/ui/lint/lint-unnecessary-parens.stderr index 83b247a4a60534ef7b8bc4aca0a0349367735e19..adc1069b64d62b98d3144f40d9419ba94047af6a 100644 --- a/src/test/ui/lint/lint-unnecessary-parens.stderr +++ b/src/test/ui/lint/lint-unnecessary-parens.stderr @@ -16,26 +16,32 @@ error: unnecessary parentheses around `return` value LL | return (X { y }); | ^^^^^^^^^ help: remove these parentheses +error: unnecessary parentheses around type + --> $DIR/lint-unnecessary-parens.rs:16:42 + | +LL | fn unused_parens_around_return_type() -> (u32) { + | ^^^^^ help: remove these parentheses + error: unnecessary parentheses around function argument - --> $DIR/lint-unnecessary-parens.rs:18:9 + --> $DIR/lint-unnecessary-parens.rs:30:9 | LL | bar((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `if` condition - --> $DIR/lint-unnecessary-parens.rs:20:8 + --> $DIR/lint-unnecessary-parens.rs:32:8 | LL | if (true) {} | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `while` condition - --> $DIR/lint-unnecessary-parens.rs:21:11 + --> $DIR/lint-unnecessary-parens.rs:33:11 | LL | while (true) {} | ^^^^^^ help: remove these parentheses warning: denote infinite loops with `loop { ... }` - --> $DIR/lint-unnecessary-parens.rs:21:5 + --> $DIR/lint-unnecessary-parens.rs:33:5 | LL | while (true) {} | ^^^^^^^^^^^^ help: use `loop` @@ -43,46 +49,46 @@ LL | while (true) {} = note: `#[warn(while_true)]` on by default error: unnecessary parentheses around `match` head expression - --> $DIR/lint-unnecessary-parens.rs:23:11 + --> $DIR/lint-unnecessary-parens.rs:35:11 | LL | match (true) { | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around `let` head expression - --> $DIR/lint-unnecessary-parens.rs:26:16 + --> $DIR/lint-unnecessary-parens.rs:38:16 | LL | if let 1 = (1) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around `let` head expression - --> $DIR/lint-unnecessary-parens.rs:27:19 + --> $DIR/lint-unnecessary-parens.rs:39:19 | LL | while let 1 = (2) {} | ^^^ help: remove these parentheses error: unnecessary parentheses around method argument - --> $DIR/lint-unnecessary-parens.rs:41:24 + --> $DIR/lint-unnecessary-parens.rs:53:24 | LL | X { y: false }.foo((true)); | ^^^^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:43:18 + --> $DIR/lint-unnecessary-parens.rs:55:18 | LL | let mut _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:44:10 + --> $DIR/lint-unnecessary-parens.rs:56:10 | LL | _a = (0); | ^^^ help: remove these parentheses error: unnecessary parentheses around assigned value - --> $DIR/lint-unnecessary-parens.rs:45:11 + --> $DIR/lint-unnecessary-parens.rs:57:11 | LL | _a += (1); | ^^^ help: remove these parentheses -error: aborting due to 12 previous errors +error: aborting due to 13 previous errors diff --git a/src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed b/src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed index 89607af260a5258e795576acac33b085c34204fd..0f26a975a370f30963a4078afc7f8e51433fbfcf 100644 --- a/src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed +++ b/src/test/ui/single-use-lifetime/zero-uses-in-fn.fixed @@ -15,7 +15,7 @@ fn october<'b, T>(s: &'b T) -> &'b T { s } -fn november<'a>(s: &'a str) -> (&'a str) { +fn november<'a>(s: &'a str) -> &'a str { //~^ ERROR lifetime parameter `'b` never used //~| HELP elide the unused lifetime s diff --git a/src/test/ui/single-use-lifetime/zero-uses-in-fn.rs b/src/test/ui/single-use-lifetime/zero-uses-in-fn.rs index be0bdb9b6285102ea40b2d906e6eec041595ef95..7f9504fe5a90a5f3156c779a9caa141b5254f6df 100644 --- a/src/test/ui/single-use-lifetime/zero-uses-in-fn.rs +++ b/src/test/ui/single-use-lifetime/zero-uses-in-fn.rs @@ -15,7 +15,7 @@ fn october<'a, 'b, T>(s: &'b T) -> &'b T { s } -fn november<'a, 'b>(s: &'a str) -> (&'a str) { +fn november<'a, 'b>(s: &'a str) -> &'a str { //~^ ERROR lifetime parameter `'b` never used //~| HELP elide the unused lifetime s diff --git a/src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr b/src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr index 2ccba796d4229ebe319526d3280ee26057a72bea..b9c3bd89748fff17879ba018a07cb0bbd2b0e8a3 100644 --- a/src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr +++ b/src/test/ui/single-use-lifetime/zero-uses-in-fn.stderr @@ -21,7 +21,7 @@ LL | fn october<'a, 'b, T>(s: &'b T) -> &'b T { error: lifetime parameter `'b` never used --> $DIR/zero-uses-in-fn.rs:18:17 | -LL | fn november<'a, 'b>(s: &'a str) -> (&'a str) { +LL | fn november<'a, 'b>(s: &'a str) -> &'a str { | --^^ | | | help: elide the unused lifetime