diff options
| author | Michael Goulet <michael@errs.io> | 2022-12-27 12:33:34 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-27 12:33:34 -0800 |
| commit | a9fdeddafd8c5ce08dd8d61a86201ae9e1e71046 (patch) | |
| tree | 98b05a2bb5bb36407c6697975aa5af18ecab47b7 /src | |
| parent | 4b668a1feed45b3061fbf0d1d42fb1a695c0d4b3 (diff) | |
| parent | 7e84273b7fcaa0f6578c97fd71e27453ef300c31 (diff) | |
| download | rust-a9fdeddafd8c5ce08dd8d61a86201ae9e1e71046.tar.gz rust-a9fdeddafd8c5ce08dd8d61a86201ae9e1e71046.zip | |
Rollup merge of #105765 - estebank:range-typo, r=compiler-errors
Detect likely `.` -> `..` typo in method calls Fix #65015.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/suggestions/method-access-to-range-literal-typo.rs | 30 | ||||
| -rw-r--r-- | src/test/ui/suggestions/method-access-to-range-literal-typo.stderr | 48 |
2 files changed, 78 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..ac662edafe6 --- /dev/null +++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.rs @@ -0,0 +1,30 @@ +fn as_ref() -> Option<Vec<u8>> { + None +} +struct Type { + option: Option<Vec<u8>> +} +trait Trait { + fn foo(&self) -> Vec<u8>; +} +impl Trait for Option<Vec<u8>> { + fn foo(&self) -> Vec<u8> { + vec![1, 2, 3] + } +} + +impl Type { + fn method(&self) -> Option<Vec<u8>> { + self.option..as_ref().map(|x| x) + //~^ ERROR E0308 + } + fn method2(&self) -> &u8 { + self.option..foo().get(0) + //~^ 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..c84f9467891 --- /dev/null +++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr @@ -0,0 +1,48 @@ +error[E0425]: cannot find function `foo` in this scope + --> $DIR/method-access-to-range-literal-typo.rs:22:22 + | +LL | self.option..foo().get(0) + | ^^^ not found in this scope + | +help: you might have meant to write `.` instead of `..` + | +LL - self.option..foo().get(0) +LL + self.option.foo().get(0) + | + +error[E0308]: mismatched types + --> $DIR/method-access-to-range-literal-typo.rs:18: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 likely meant to write a method call instead of a range + | +LL - self.option..as_ref().map(|x| x) +LL + self.option.as_ref().map(|x| x) + | + +error[E0308]: mismatched types + --> $DIR/method-access-to-range-literal-typo.rs:22:9 + | +LL | fn method2(&self) -> &u8 { + | --- expected `&u8` because of return type +LL | self.option..foo().get(0) + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&u8`, found struct `Range` + | + = note: expected reference `&u8` + found struct `std::ops::Range<Option<Vec<u8>>>` +help: you likely meant to write a method call instead of a range + | +LL - self.option..foo().get(0) +LL + self.option.foo().get(0) + | + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0308, E0425. +For more information about an error, try `rustc --explain E0308`. |
