rust icon indicating copy to clipboard operation
rust copied to clipboard

Suggest to use . instead of :: when accessing a method of an object

Open chenyukang opened this issue 3 years ago • 1 comments

Fixes #101749 Fixes #101542

chenyukang avatar Sep 18 '22 11:09 chenyukang

r? @TaKO8Ki

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Sep 18 '22 11:09 rust-highfive

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] src/test/ui/resolve/bad-module.rs stdout ----
diff of stderr:

10 LL |     let foo = foo::bar::baz();
12 
- error: aborting due to 2 previous errors
- error: aborting due to 2 previous errors
+ error[E0434]: `foo` is not a crate or module, maybe you meant to call instance method
+    |
+    |
+ LL |     let foo = foo::bar::baz();
+    |
+ warning: ident is defined at here
+   --> $DIR/bad-module.rs:2:9
+    |
+    |
+ LL |     let foo = thing::len(Vec::new());
14 
- For more information about this error, try `rustc --explain E0433`.
+ error: aborting due to 3 previous errors
+ 
---
To only update this specific test, also pass `--test-args resolve/bad-module.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/resolve/bad-module.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/bad-module" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/bad-module/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0433]: failed to resolve: use of undeclared crate or module `thing`
   |
   |
LL |     let foo = thing::len(Vec::new());
   |               ^^^^^ use of undeclared crate or module `thing`
error[E0433]: failed to resolve: use of undeclared crate or module `foo`
  --> /checkout/src/test/ui/resolve/bad-module.rs:5:15
   |
   |
LL |     let foo = foo::bar::baz();


error[E0434]: `foo` is not a crate or module, maybe you meant to call instance method
   |
   |
LL |     let foo = foo::bar::baz();
   |
warning: ident is defined at here
  --> /checkout/src/test/ui/resolve/bad-module.rs:2:9
   |
   |
LL |     let foo = thing::len(Vec::new());

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0433, E0434.
---
---- [ui] src/test/ui/resolve/issue-101749.rs stdout ----
diff of stderr:

3    |
4 LL |     println!("{}", rect1::area());
5    |                    ^^^^^ use of undeclared crate or module `rect1`
+ 
+ error[E0434]: need to fix call instance method: area#0
6    |
6    |
- help: `rect1` is not a crate or module, maybe you meant to call instance method
+ LL |     println!("{}", rect1::area());
8    |
8    |
- LL |     println!("{}", rect1.area());
+ warning: ident is defined at here
+   --> $DIR/issue-101749.rs:18:9
+    |
+    |
+ LL |     let rect1 = Rectangle::new(width, height);
11 
- error: aborting due to previous error
+ error: aborting due to 2 previous errors
13 
---
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/issue-101749.stderr
diff of fixed:

16     let width = 3;
17     let height = 4;
18     let rect1 = Rectangle::new(width, height);
-     println!("{}", rect1.area());
+     println!("{}", rect1::area());
20     //~^ ERROR failed to resolve: use of undeclared crate or module `rect1`
22 


The actual fixed differed from the expected fixed.
The actual fixed differed from the expected fixed.
Actual fixed saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/issue-101749.fixed
To only update this specific test, also pass `--test-args resolve/issue-101749.rs`

error: 2 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/resolve/issue-101749.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0433]: failed to resolve: use of undeclared crate or module `rect1`
   |
   |
LL |     println!("{}", rect1::area());
   |                    ^^^^^ use of undeclared crate or module `rect1`

error[E0434]: need to fix call instance method: area#0
   |
   |
LL |     println!("{}", rect1::area());
   |
warning: ident is defined at here
  --> /checkout/src/test/ui/resolve/issue-101749.rs:18:9
   |
   |
LL |     let rect1 = Rectangle::new(width, height);

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0433, E0434.

rust-log-analyzer avatar Oct 28 '22 19:10 rust-log-analyzer

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] src/test/ui/resolve/issue-101749.rs stdout ----
diff of stderr:

4 LL |     let _ = rect::area();
5    |             ^^^^ use of undeclared crate or module `rect`
6 
- error: `rect` is not a crate or module
-   --> $DIR/issue-101749.rs:18:13
-    |
- LL |     let _ = rect::area();
-    |
-    |
- warning: ident `rect` is defined at here
-   --> $DIR/issue-101749.rs:16:9
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
-    |
- LL |     let rect = Rectangle::new(3, 4);
- help: maybe you meant to call instance method
-    |
-    |
- LL |     let _ = rect.area();
- 
- error: aborting due to 2 previous errors
+ error: aborting due to previous error
24 
---
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/issue-101749.stderr
diff of fixed:

15 fn main() {
16     let rect = Rectangle::new(3, 4);
17     //~^ WARNING ident `rect` is defined at here
-     let _ = rect.area();
+     let _ = rect::area();
19     //~^ ERROR failed to resolve: use of undeclared crate or module `rect`
20     //~| ERROR `rect` is not a crate or module


The actual fixed differed from the expected fixed.
The actual fixed differed from the expected fixed.
Actual fixed saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/issue-101749.fixed
To only update this specific test, also pass `--test-args resolve/issue-101749.rs`

error: 2 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/resolve/issue-101749.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/resolve/issue-101749/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0433]: failed to resolve: use of undeclared crate or module `rect`
   |
   |
LL |     let _ = rect::area();
   |             ^^^^ use of undeclared crate or module `rect`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.
------------------------------------------

rust-log-analyzer avatar Oct 30 '22 04:10 rust-log-analyzer

:umbrella: The latest upstream changes (presumably #103978) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Nov 04 '22 22:11 bors

Hi @TaKO8Ki, Any more suggestion on this PR?

chenyukang avatar Nov 20 '22 11:11 chenyukang

:umbrella: The latest upstream changes (presumably #104655) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Nov 21 '22 02:11 bors

Sorry for taking so long to review this even though I was cc'd. I gave this some reviews, let me know what you think @chenyukang. I like the idea of the diagnostic, though.

compiler-errors avatar Nov 22 '22 01:11 compiler-errors

r? @compiler-errors

compiler-errors avatar Nov 22 '22 06:11 compiler-errors

@chenyukang make sure to do:

@rustbot ready

When you're ready to review. Otherwise I might not see this, haha.

compiler-errors avatar Nov 26 '22 22:11 compiler-errors

@compiler-errors thanks for reminder! 😁

chenyukang avatar Nov 27 '22 01:11 chenyukang

Thanks, this looks pretty good. I will give one last review once you fix the typo. Please ping me if I forget.

Updated, thanks!

chenyukang avatar Dec 03 '22 14:12 chenyukang

@bors r+

compiler-errors avatar Dec 04 '22 14:12 compiler-errors

:pushpin: Commit fb004e9a95793b7672d55b2984d65d4ac00a3cfc has been approved by compiler-errors

It is now in the queue for this repository.

bors avatar Dec 04 '22 14:12 bors

:hourglass: Testing commit fb004e9a95793b7672d55b2984d65d4ac00a3cfc with merge 0f0d5d716a00c1f29cfbf240e12bdccc4f9b9a94...

bors avatar Dec 04 '22 19:12 bors