Skip to content

Commit 73cd2cd

Browse files
merge test
1 parent aff9c01 commit 73cd2cd

File tree

4 files changed

+105
-107
lines changed

4 files changed

+105
-107
lines changed

tests/ui/doc/missing_panics_doc.rs

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/ui/doc/missing_panics_doc.stderr

Lines changed: 0 additions & 75 deletions
This file was deleted.

tests/ui/missing_panics_doc.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,35 @@ pub fn debug_assertions() {
151151
debug_assert_eq!(1, 2);
152152
debug_assert_ne!(1, 2);
153153
}
154+
155+
// all function must be triggered the lint.
156+
// `pub` is required, because the lint does not consider unreachable items
157+
pub mod issue10240 {
158+
pub fn option_unwrap<T>(v: &[T]) -> &T {
159+
let o: Option<&T> = v.last();
160+
o.unwrap()
161+
}
162+
163+
pub fn option_expect<T>(v: &[T]) -> &T {
164+
let o: Option<&T> = v.last();
165+
o.expect("passed an empty thing")
166+
}
167+
168+
pub fn result_unwrap<T>(v: &[T]) -> &T {
169+
let res: Result<&T, &str> = v.last().ok_or("oh noes");
170+
res.unwrap()
171+
}
172+
173+
pub fn result_expect<T>(v: &[T]) -> &T {
174+
let res: Result<&T, &str> = v.last().ok_or("oh noes");
175+
res.expect("passed an empty thing")
176+
}
177+
178+
pub fn last_unwrap(v: &[u32]) -> u32 {
179+
*v.last().unwrap()
180+
}
181+
182+
pub fn last_expect(v: &[u32]) -> u32 {
183+
*v.last().expect("passed an empty thing")
184+
}
185+
}

tests/ui/missing_panics_doc.stderr

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,77 @@ note: first possible panic found here
8383
LL | assert_ne!(x, 0);
8484
| ^^^^^^^^^^^^^^^^
8585

86-
error: aborting due to 7 previous errors
86+
error: docs for function which may panic missing `# Panics` section
87+
--> $DIR/missing_panics_doc.rs:158:5
88+
|
89+
LL | pub fn option_unwrap<T>(v: &[T]) -> &T {
90+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
91+
|
92+
note: first possible panic found here
93+
--> $DIR/missing_panics_doc.rs:160:9
94+
|
95+
LL | o.unwrap()
96+
| ^^^^^^^^^^
97+
98+
error: docs for function which may panic missing `# Panics` section
99+
--> $DIR/missing_panics_doc.rs:163:5
100+
|
101+
LL | pub fn option_expect<T>(v: &[T]) -> &T {
102+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
103+
|
104+
note: first possible panic found here
105+
--> $DIR/missing_panics_doc.rs:165:9
106+
|
107+
LL | o.expect("passed an empty thing")
108+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
109+
110+
error: docs for function which may panic missing `# Panics` section
111+
--> $DIR/missing_panics_doc.rs:168:5
112+
|
113+
LL | pub fn result_unwrap<T>(v: &[T]) -> &T {
114+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115+
|
116+
note: first possible panic found here
117+
--> $DIR/missing_panics_doc.rs:170:9
118+
|
119+
LL | res.unwrap()
120+
| ^^^^^^^^^^^^
121+
122+
error: docs for function which may panic missing `# Panics` section
123+
--> $DIR/missing_panics_doc.rs:173:5
124+
|
125+
LL | pub fn result_expect<T>(v: &[T]) -> &T {
126+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
127+
|
128+
note: first possible panic found here
129+
--> $DIR/missing_panics_doc.rs:175:9
130+
|
131+
LL | res.expect("passed an empty thing")
132+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
133+
134+
error: docs for function which may panic missing `# Panics` section
135+
--> $DIR/missing_panics_doc.rs:178:5
136+
|
137+
LL | pub fn last_unwrap(v: &[u32]) -> u32 {
138+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
139+
|
140+
note: first possible panic found here
141+
--> $DIR/missing_panics_doc.rs:179:10
142+
|
143+
LL | *v.last().unwrap()
144+
| ^^^^^^^^^^^^^^^^^
145+
146+
error: docs for function which may panic missing `# Panics` section
147+
--> $DIR/missing_panics_doc.rs:182:5
148+
|
149+
LL | pub fn last_expect(v: &[u32]) -> u32 {
150+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
151+
|
152+
note: first possible panic found here
153+
--> $DIR/missing_panics_doc.rs:183:10
154+
|
155+
LL | *v.last().expect("passed an empty thing")
156+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157+
158+
error: aborting due to 13 previous errors
87159

0 commit comments

Comments
 (0)