diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/unwrap_or_else_default.fixed | 37 | ||||
| -rw-r--r-- | tests/ui/unwrap_or_else_default.rs | 37 | ||||
| -rw-r--r-- | tests/ui/unwrap_or_else_default.stderr | 50 |
3 files changed, 123 insertions, 1 deletions
diff --git a/tests/ui/unwrap_or_else_default.fixed b/tests/ui/unwrap_or_else_default.fixed index 08b89a18bbb..e6b6ab359df 100644 --- a/tests/ui/unwrap_or_else_default.fixed +++ b/tests/ui/unwrap_or_else_default.fixed @@ -74,4 +74,41 @@ fn unwrap_or_else_default() { empty_string.unwrap_or_default(); } +fn type_certainty(option: Option<Vec<u64>>) { + option.unwrap_or_default().push(1); + + let option: std::option::Option<std::vec::Vec<u64>> = None; + option.unwrap_or_default().push(1); + + let option: Option<Vec<u64>> = None; + option.unwrap_or_default().push(1); + + let option = std::option::Option::<std::vec::Vec<u64>>::None; + option.unwrap_or_default().push(1); + + let option = Option::<Vec<u64>>::None; + option.unwrap_or_default().push(1); + + let option = std::option::Option::None::<std::vec::Vec<u64>>; + option.unwrap_or_default().push(1); + + let option = Option::None::<Vec<u64>>; + option.unwrap_or_default().push(1); + + let option = None::<Vec<u64>>; + option.unwrap_or_default().push(1); + + // should not be changed: type annotation with infer, unconcretized initializer + let option: Option<Vec<_>> = None; + option.unwrap_or_else(Vec::new).push(1); + + // should not be changed: no type annotation, unconcretized initializer + let option = Option::None; + option.unwrap_or_else(Vec::new).push(1); + + // should not be changed: no type annotation, unconcretized initializer + let option = None; + option.unwrap_or_else(Vec::new).push(1); +} + fn main() {} diff --git a/tests/ui/unwrap_or_else_default.rs b/tests/ui/unwrap_or_else_default.rs index ad2a744908f..38fa2e4595d 100644 --- a/tests/ui/unwrap_or_else_default.rs +++ b/tests/ui/unwrap_or_else_default.rs @@ -74,4 +74,41 @@ fn unwrap_or_else_default() { empty_string.unwrap_or_else(|| "".to_string()); } +fn type_certainty(option: Option<Vec<u64>>) { + option.unwrap_or_else(Vec::new).push(1); + + let option: std::option::Option<std::vec::Vec<u64>> = None; + option.unwrap_or_else(Vec::new).push(1); + + let option: Option<Vec<u64>> = None; + option.unwrap_or_else(Vec::new).push(1); + + let option = std::option::Option::<std::vec::Vec<u64>>::None; + option.unwrap_or_else(Vec::new).push(1); + + let option = Option::<Vec<u64>>::None; + option.unwrap_or_else(Vec::new).push(1); + + let option = std::option::Option::None::<std::vec::Vec<u64>>; + option.unwrap_or_else(Vec::new).push(1); + + let option = Option::None::<Vec<u64>>; + option.unwrap_or_else(Vec::new).push(1); + + let option = None::<Vec<u64>>; + option.unwrap_or_else(Vec::new).push(1); + + // should not be changed: type annotation with infer, unconcretized initializer + let option: Option<Vec<_>> = None; + option.unwrap_or_else(Vec::new).push(1); + + // should not be changed: no type annotation, unconcretized initializer + let option = Option::None; + option.unwrap_or_else(Vec::new).push(1); + + // should not be changed: no type annotation, unconcretized initializer + let option = None; + option.unwrap_or_else(Vec::new).push(1); +} + fn main() {} diff --git a/tests/ui/unwrap_or_else_default.stderr b/tests/ui/unwrap_or_else_default.stderr index d2b9212223f..a6815e8f916 100644 --- a/tests/ui/unwrap_or_else_default.stderr +++ b/tests/ui/unwrap_or_else_default.stderr @@ -36,5 +36,53 @@ error: use of `.unwrap_or_else(..)` to construct default value LL | empty_string.unwrap_or_else(|| "".to_string()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `empty_string.unwrap_or_default()` -error: aborting due to 6 previous errors +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:78:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:81:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:84:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:87:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:90:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:93:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:96:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: use of `.unwrap_or_else(..)` to construct default value + --> $DIR/unwrap_or_else_default.rs:99:5 + | +LL | option.unwrap_or_else(Vec::new).push(1); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `option.unwrap_or_default()` + +error: aborting due to 14 previous errors |
