diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2022-12-15 16:24:42 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2022-12-26 18:27:40 -0800 |
| commit | c9381fc334cb8db62fdb5a8f75807ebdff3d6e15 (patch) | |
| tree | 9026bc26002c1bfccaa4d7189c14cd9e528700cd /src/test | |
| parent | caa64e5b5e7605a1c1428b2a402021bef83f3e1e (diff) | |
| download | rust-c9381fc334cb8db62fdb5a8f75807ebdff3d6e15.tar.gz rust-c9381fc334cb8db62fdb5a8f75807ebdff3d6e15.zip | |
Detect likely `.` -> `..` typo in method calls
Fix #65015.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/method-access-to-range-literal-typo.rs | 22 | ||||
| -rw-r--r-- | src/test/ui/suggestions/method-access-to-range-literal-typo.stderr | 45 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/method-access-to-range-literal-typo.rs b/src/test/ui/suggestions/method-access-to-range-literal-typo.rs new file mode 100644 index 00000000000..545f9c597fd --- /dev/null +++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.rs @@ -0,0 +1,22 @@ +fn as_ref() -> Option<Vec<u8>> { + None +} +struct Type { + option: Option<Vec<u8>> +} + +impl Type { + fn method(&self) -> Option<Vec<u8>> { + self.option..as_ref().map(|x| x) + //~^ ERROR E0308 + } + fn method2(&self) -> Option<Vec<u8>> { + self.option..foo().map(|x| x) + //~^ ERROR E0425 + //~| ERROR E0308 + } +} + +fn main() { + let _ = Type { option: None }.method(); +} diff --git a/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr b/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr new file mode 100644 index 00000000000..becc825b6cf --- /dev/null +++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr @@ -0,0 +1,45 @@ +error[E0425]: cannot find function `foo` in this scope + --> $DIR/method-access-to-range-literal-typo.rs:14:22 + | +LL | self.option..foo().map(|x| x) + | ^^^ not found in this scope + | +help: you might have meant to write a method call instead of a range + | +LL | self.option.foo().map(|x| x) + | ~ + +error[E0308]: mismatched types + --> $DIR/method-access-to-range-literal-typo.rs:10:9 + | +LL | fn method(&self) -> Option<Vec<u8>> { + | --------------- expected `Option<Vec<u8>>` because of return type +LL | self.option..as_ref().map(|x| x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found struct `Range` + | + = note: expected enum `Option<_>` + found struct `std::ops::Range<Option<_>>` +help: you might have meant to write a method call instead of a range + | +LL | self.option.as_ref().map(|x| x) + | ~ + +error[E0308]: mismatched types + --> $DIR/method-access-to-range-literal-typo.rs:14:9 + | +LL | fn method2(&self) -> Option<Vec<u8>> { + | --------------- expected `Option<Vec<u8>>` because of return type +LL | self.option..foo().map(|x| x) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found struct `Range` + | + = note: expected enum `Option<_>` + found struct `std::ops::Range<Option<_>>` +help: you might have meant to write a method call instead of a range + | +LL | self.option.foo().map(|x| x) + | ~ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0425. +For more information about an error, try `rustc --explain E0308`. |
