Skip to content

Commit b8fb890

Browse files
committed
Auto merge of rust-lang#120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkin
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](rust-lang#120363).
2 parents 31b551f + 4d93edf commit b8fb890

20 files changed

+86
-73
lines changed

tests/ui-toml/undocumented_unsafe_blocks/undocumented_unsafe_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//@[disabled] rustc-env:CLIPPY_CONF_DIR=tests/ui-toml/undocumented_unsafe_blocks/disabled
55

66
#![warn(clippy::undocumented_unsafe_blocks, clippy::unnecessary_safety_comment)]
7-
#![allow(deref_nullptr, clippy::let_unit_value, clippy::missing_safety_doc)]
7+
#![allow(deref_nullptr, non_local_definitions, clippy::let_unit_value, clippy::missing_safety_doc)]
88
#![feature(lint_reasons)]
99

1010
extern crate proc_macro_unsafe;

tests/ui/bool_comparison.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::needless_if)]
1+
#![allow(non_local_definitions, clippy::needless_if)]
22
#![warn(clippy::bool_comparison)]
33
#![allow(clippy::non_canonical_partial_ord_impl)]
44

tests/ui/bool_comparison.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::needless_if)]
1+
#![allow(non_local_definitions, clippy::needless_if)]
22
#![warn(clippy::bool_comparison)]
33
#![allow(clippy::non_canonical_partial_ord_impl)]
44

tests/ui/crashes/ice-4760.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(non_local_definitions)]
2+
13
const COUNT: usize = 2;
24
struct Thing;
35
trait Dummy {}

tests/ui/crashes/ice-6179.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
44
#![warn(clippy::use_self)]
55
#![allow(dead_code, clippy::let_with_type_underscore)]
6+
#![allow(non_local_definitions)]
67

78
struct Foo;
89

tests/ui/explicit_into_iter_loop.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(non_local_definitions)]
12
#![warn(clippy::explicit_into_iter_loop)]
23

34
fn main() {

tests/ui/explicit_into_iter_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(non_local_definitions)]
12
#![warn(clippy::explicit_into_iter_loop)]
23

34
fn main() {

tests/ui/explicit_into_iter_loop.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: it is more concise to loop over containers instead of using explicit iteration methods
2-
--> $DIR/explicit_into_iter_loop.rs:9:18
2+
--> $DIR/explicit_into_iter_loop.rs:10:18
33
|
44
LL | for _ in iterator.into_iter() {}
55
| ^^^^^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `iterator`
@@ -8,31 +8,31 @@ LL | for _ in iterator.into_iter() {}
88
= help: to override `-D warnings` add `#[allow(clippy::explicit_into_iter_loop)]`
99

1010
error: it is more concise to loop over containers instead of using explicit iteration methods
11-
--> $DIR/explicit_into_iter_loop.rs:22:14
11+
--> $DIR/explicit_into_iter_loop.rs:23:14
1212
|
1313
LL | for _ in t.into_iter() {}
1414
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `&t`
1515

1616
error: it is more concise to loop over containers instead of using explicit iteration methods
17-
--> $DIR/explicit_into_iter_loop.rs:25:14
17+
--> $DIR/explicit_into_iter_loop.rs:26:14
1818
|
1919
LL | for _ in r.into_iter() {}
2020
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `r`
2121

2222
error: it is more concise to loop over containers instead of using explicit iteration methods
23-
--> $DIR/explicit_into_iter_loop.rs:33:14
23+
--> $DIR/explicit_into_iter_loop.rs:34:14
2424
|
2525
LL | for _ in mr.into_iter() {}
2626
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&*mr`
2727

2828
error: it is more concise to loop over containers instead of using explicit iteration methods
29-
--> $DIR/explicit_into_iter_loop.rs:45:14
29+
--> $DIR/explicit_into_iter_loop.rs:46:14
3030
|
3131
LL | for _ in u.into_iter() {}
3232
| ^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut u`
3333

3434
error: it is more concise to loop over containers instead of using explicit iteration methods
35-
--> $DIR/explicit_into_iter_loop.rs:48:14
35+
--> $DIR/explicit_into_iter_loop.rs:49:14
3636
|
3737
LL | for _ in mr.into_iter() {}
3838
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut *mr`

tests/ui/explicit_iter_loop.fixed

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
clippy::needless_borrow,
66
clippy::deref_addrof,
77
clippy::unnecessary_mut_passed,
8-
dead_code
8+
dead_code,
9+
non_local_definitions,
910
)]
1011

1112
use core::slice;

tests/ui/explicit_iter_loop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
clippy::needless_borrow,
66
clippy::deref_addrof,
77
clippy::unnecessary_mut_passed,
8-
dead_code
8+
dead_code,
9+
non_local_definitions,
910
)]
1011

1112
use core::slice;

tests/ui/explicit_iter_loop.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: it is more concise to loop over references to containers instead of using explicit iteration methods
2-
--> $DIR/explicit_iter_loop.rs:17:14
2+
--> $DIR/explicit_iter_loop.rs:18:14
33
|
44
LL | for _ in vec.iter() {}
55
| ^^^^^^^^^^ help: to write this more concisely, try: `&vec`
@@ -11,103 +11,103 @@ LL | #![deny(clippy::explicit_iter_loop)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: it is more concise to loop over references to containers instead of using explicit iteration methods
14-
--> $DIR/explicit_iter_loop.rs:18:14
14+
--> $DIR/explicit_iter_loop.rs:19:14
1515
|
1616
LL | for _ in vec.iter_mut() {}
1717
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&mut vec`
1818

1919
error: it is more concise to loop over references to containers instead of using explicit iteration methods
20-
--> $DIR/explicit_iter_loop.rs:21:14
20+
--> $DIR/explicit_iter_loop.rs:22:14
2121
|
2222
LL | for _ in rvec.iter() {}
2323
| ^^^^^^^^^^^ help: to write this more concisely, try: `rvec`
2424

2525
error: it is more concise to loop over references to containers instead of using explicit iteration methods
26-
--> $DIR/explicit_iter_loop.rs:30:14
26+
--> $DIR/explicit_iter_loop.rs:31:14
2727
|
2828
LL | for _ in [1, 2, 3].iter() {}
2929
| ^^^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[1, 2, 3]`
3030

3131
error: it is more concise to loop over references to containers instead of using explicit iteration methods
32-
--> $DIR/explicit_iter_loop.rs:34:14
32+
--> $DIR/explicit_iter_loop.rs:35:14
3333
|
3434
LL | for _ in [0; 32].iter() {}
3535
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 32]`
3636

3737
error: it is more concise to loop over references to containers instead of using explicit iteration methods
38-
--> $DIR/explicit_iter_loop.rs:35:14
38+
--> $DIR/explicit_iter_loop.rs:36:14
3939
|
4040
LL | for _ in [0; 33].iter() {}
4141
| ^^^^^^^^^^^^^^ help: to write this more concisely, try: `&[0; 33]`
4242

4343
error: it is more concise to loop over references to containers instead of using explicit iteration methods
44-
--> $DIR/explicit_iter_loop.rs:38:14
44+
--> $DIR/explicit_iter_loop.rs:39:14
4545
|
4646
LL | for _ in ll.iter() {}
4747
| ^^^^^^^^^ help: to write this more concisely, try: `&ll`
4848

4949
error: it is more concise to loop over references to containers instead of using explicit iteration methods
50-
--> $DIR/explicit_iter_loop.rs:40:14
50+
--> $DIR/explicit_iter_loop.rs:41:14
5151
|
5252
LL | for _ in rll.iter() {}
5353
| ^^^^^^^^^^ help: to write this more concisely, try: `rll`
5454

5555
error: it is more concise to loop over references to containers instead of using explicit iteration methods
56-
--> $DIR/explicit_iter_loop.rs:43:14
56+
--> $DIR/explicit_iter_loop.rs:44:14
5757
|
5858
LL | for _ in vd.iter() {}
5959
| ^^^^^^^^^ help: to write this more concisely, try: `&vd`
6060

6161
error: it is more concise to loop over references to containers instead of using explicit iteration methods
62-
--> $DIR/explicit_iter_loop.rs:45:14
62+
--> $DIR/explicit_iter_loop.rs:46:14
6363
|
6464
LL | for _ in rvd.iter() {}
6565
| ^^^^^^^^^^ help: to write this more concisely, try: `rvd`
6666

6767
error: it is more concise to loop over references to containers instead of using explicit iteration methods
68-
--> $DIR/explicit_iter_loop.rs:48:14
68+
--> $DIR/explicit_iter_loop.rs:49:14
6969
|
7070
LL | for _ in bh.iter() {}
7171
| ^^^^^^^^^ help: to write this more concisely, try: `&bh`
7272

7373
error: it is more concise to loop over references to containers instead of using explicit iteration methods
74-
--> $DIR/explicit_iter_loop.rs:51:14
74+
--> $DIR/explicit_iter_loop.rs:52:14
7575
|
7676
LL | for _ in hm.iter() {}
7777
| ^^^^^^^^^ help: to write this more concisely, try: `&hm`
7878

7979
error: it is more concise to loop over references to containers instead of using explicit iteration methods
80-
--> $DIR/explicit_iter_loop.rs:54:14
80+
--> $DIR/explicit_iter_loop.rs:55:14
8181
|
8282
LL | for _ in bt.iter() {}
8383
| ^^^^^^^^^ help: to write this more concisely, try: `&bt`
8484

8585
error: it is more concise to loop over references to containers instead of using explicit iteration methods
86-
--> $DIR/explicit_iter_loop.rs:57:14
86+
--> $DIR/explicit_iter_loop.rs:58:14
8787
|
8888
LL | for _ in hs.iter() {}
8989
| ^^^^^^^^^ help: to write this more concisely, try: `&hs`
9090

9191
error: it is more concise to loop over references to containers instead of using explicit iteration methods
92-
--> $DIR/explicit_iter_loop.rs:60:14
92+
--> $DIR/explicit_iter_loop.rs:61:14
9393
|
9494
LL | for _ in bs.iter() {}
9595
| ^^^^^^^^^ help: to write this more concisely, try: `&bs`
9696

9797
error: it is more concise to loop over references to containers instead of using explicit iteration methods
98-
--> $DIR/explicit_iter_loop.rs:149:14
98+
--> $DIR/explicit_iter_loop.rs:150:14
9999
|
100100
LL | for _ in x.iter() {}
101101
| ^^^^^^^^ help: to write this more concisely, try: `&x`
102102

103103
error: it is more concise to loop over references to containers instead of using explicit iteration methods
104-
--> $DIR/explicit_iter_loop.rs:150:14
104+
--> $DIR/explicit_iter_loop.rs:151:14
105105
|
106106
LL | for _ in x.iter_mut() {}
107107
| ^^^^^^^^^^^^ help: to write this more concisely, try: `&mut x`
108108

109109
error: it is more concise to loop over references to containers instead of using explicit iteration methods
110-
--> $DIR/explicit_iter_loop.rs:153:14
110+
--> $DIR/explicit_iter_loop.rs:154:14
111111
|
112112
LL | for _ in r.iter() {}
113113
| ^^^^^^^^ help: to write this more concisely, try: `r`

tests/ui/from_over_into.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(type_alias_impl_trait)]
22
#![warn(clippy::from_over_into)]
3+
#![allow(non_local_definitions)]
34
#![allow(unused)]
45

56
// this should throw an error

tests/ui/from_over_into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![feature(type_alias_impl_trait)]
22
#![warn(clippy::from_over_into)]
3+
#![allow(non_local_definitions)]
34
#![allow(unused)]
45

56
// this should throw an error

tests/ui/from_over_into.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
2-
--> $DIR/from_over_into.rs:8:1
2+
--> $DIR/from_over_into.rs:9:1
33
|
44
LL | impl Into<StringWrapper> for String {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -14,7 +14,7 @@ LL ~ StringWrapper(val)
1414
|
1515

1616
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
17-
--> $DIR/from_over_into.rs:16:1
17+
--> $DIR/from_over_into.rs:17:1
1818
|
1919
LL | impl Into<SelfType> for String {
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -27,7 +27,7 @@ LL ~ SelfType(String::new())
2727
|
2828

2929
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
30-
--> $DIR/from_over_into.rs:31:1
30+
--> $DIR/from_over_into.rs:32:1
3131
|
3232
LL | impl Into<SelfKeywords> for X {
3333
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -42,7 +42,7 @@ LL ~ let _: X = val;
4242
|
4343

4444
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
45-
--> $DIR/from_over_into.rs:43:1
45+
--> $DIR/from_over_into.rs:44:1
4646
|
4747
LL | impl core::convert::Into<bool> for crate::ExplicitPaths {
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -60,7 +60,7 @@ LL ~ val.0
6060
|
6161

6262
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
63-
--> $DIR/from_over_into.rs:63:1
63+
--> $DIR/from_over_into.rs:64:1
6464
|
6565
LL | impl Into<String> for PathInExpansion {
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -74,7 +74,7 @@ LL ~ fn from(val: PathInExpansion) -> Self {
7474
|
7575

7676
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
77-
--> $DIR/from_over_into.rs:85:5
77+
--> $DIR/from_over_into.rs:86:5
7878
|
7979
LL | impl<T> Into<FromOverInto<T>> for Vec<T> {
8080
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -87,7 +87,7 @@ LL ~ FromOverInto(val)
8787
|
8888

8989
error: an implementation of `From` is preferred since it gives you `Into<_>` for free where the reverse isn't true
90-
--> $DIR/from_over_into.rs:95:5
90+
--> $DIR/from_over_into.rs:96:5
9191
|
9292
LL | impl Into<()> for Hello {
9393
| ^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/manual_str_repeat.fixed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(non_local_definitions)]
12
#![warn(clippy::manual_str_repeat)]
23

34
use std::borrow::Cow;

tests/ui/manual_str_repeat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![allow(non_local_definitions)]
12
#![warn(clippy::manual_str_repeat)]
23

34
use std::borrow::Cow;

tests/ui/manual_str_repeat.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: manual implementation of `str::repeat` using iterators
2-
--> $DIR/manual_str_repeat.rs:7:21
2+
--> $DIR/manual_str_repeat.rs:8:21
33
|
44
LL | let _: String = std::iter::repeat("test").take(10).collect();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)`
@@ -8,55 +8,55 @@ LL | let _: String = std::iter::repeat("test").take(10).collect();
88
= help: to override `-D warnings` add `#[allow(clippy::manual_str_repeat)]`
99

1010
error: manual implementation of `str::repeat` using iterators
11-
--> $DIR/manual_str_repeat.rs:8:21
11+
--> $DIR/manual_str_repeat.rs:9:21
1212
|
1313
LL | let _: String = std::iter::repeat('x').take(10).collect();
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"x".repeat(10)`
1515

1616
error: manual implementation of `str::repeat` using iterators
17-
--> $DIR/manual_str_repeat.rs:9:21
17+
--> $DIR/manual_str_repeat.rs:10:21
1818
|
1919
LL | let _: String = std::iter::repeat('\'').take(10).collect();
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"'".repeat(10)`
2121

2222
error: manual implementation of `str::repeat` using iterators
23-
--> $DIR/manual_str_repeat.rs:10:21
23+
--> $DIR/manual_str_repeat.rs:11:21
2424
|
2525
LL | let _: String = std::iter::repeat('"').take(10).collect();
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"\"".repeat(10)`
2727

2828
error: manual implementation of `str::repeat` using iterators
29-
--> $DIR/manual_str_repeat.rs:14:13
29+
--> $DIR/manual_str_repeat.rs:15:13
3030
|
3131
LL | let _ = repeat(x).take(count + 2).collect::<String>();
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count + 2)`
3333

3434
error: manual implementation of `str::repeat` using iterators
35-
--> $DIR/manual_str_repeat.rs:23:21
35+
--> $DIR/manual_str_repeat.rs:24:21
3636
|
3737
LL | let _: String = repeat(*x).take(count).collect();
3838
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `(*x).repeat(count)`
3939

4040
error: manual implementation of `str::repeat` using iterators
41-
--> $DIR/manual_str_repeat.rs:32:21
41+
--> $DIR/manual_str_repeat.rs:33:21
4242
|
4343
LL | let _: String = repeat(x).take(count).collect();
4444
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)`
4545

4646
error: manual implementation of `str::repeat` using iterators
47-
--> $DIR/manual_str_repeat.rs:44:21
47+
--> $DIR/manual_str_repeat.rs:45:21
4848
|
4949
LL | let _: String = repeat(Cow::Borrowed("test")).take(count).collect();
5050
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Cow::Borrowed("test").repeat(count)`
5151

5252
error: manual implementation of `str::repeat` using iterators
53-
--> $DIR/manual_str_repeat.rs:47:21
53+
--> $DIR/manual_str_repeat.rs:48:21
5454
|
5555
LL | let _: String = repeat(x).take(count).collect();
5656
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `x.repeat(count)`
5757

5858
error: manual implementation of `str::repeat` using iterators
59-
--> $DIR/manual_str_repeat.rs:62:21
59+
--> $DIR/manual_str_repeat.rs:63:21
6060
|
6161
LL | let _: String = std::iter::repeat("test").take(10).collect();
6262
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `"test".repeat(10)`

0 commit comments

Comments
 (0)