Skip to content

"can't qualify macro invocation with pub" error can fire without any macro invocations #63255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
little-arhat opened this issue Aug 4, 2019 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@little-arhat
Copy link

With #63180 in effect, code using existential type produces confusing error:

error: can't qualify macro invocation with `pub`
 --> src/mixer.rs:6:1
  |
6 | pub existential type T: MotorCtrl;
  | ^^^
  |
  = help: try adjusting the macro to put `pub` inside the invocation

The actual fix is to change

pub existential type T: MotorCtrl; to pub type T = impl MotorCtrl; and to enable type_alias_impl_trait feature, instead of existential_type.

@little-arhat little-arhat changed the title Confusing error message regarding existential type Confusing error message "can't qualify macro invocation with pub" when existential type is used Aug 4, 2019
@Centril
Copy link
Contributor

Centril commented Aug 4, 2019

I don't think it is worth having special cased diagnostics for existential type.

@little-arhat
Copy link
Author

@Centril true, it wasn't stabilized anyway. But I think it's good to have this issue here to help people googling an error.

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Aug 4, 2019
@estebank estebank added the A-parser Area: The lexing & parsing of Rust source code to an AST label Aug 4, 2019
@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. and removed requires-nightly This issue requires a nightly compiler in some way. labels Aug 5, 2019
@jonas-schievink
Copy link
Contributor

The same issue occurs when using pub auto unsafe trait instead of the correct pub unsafe auto trait:

pub auto unsafe trait SingleCoreSend {}
error: can't qualify macro invocation with `pub`
 --> src/lib.rs:1:1
  |
1 | pub auto unsafe trait SingleCoreSend {}
  | ^^^
  |
  = help: try adjusting the macro to put `pub` inside the invocation

error: expected one of `!` or `::`, found `unsafe`
 --> src/lib.rs:1:10
  |
1 | pub auto unsafe trait SingleCoreSend {}
  |          ^^^^^^ expected one of `!` or `::` here

error: aborting due to 2 previous errors

Note that this happens even when the feature is turned off.

@jonas-schievink jonas-schievink added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Oct 29, 2019
@birkenfeld
Copy link
Contributor

Also seen with functions and a simple typo:

pub asyn fn test() {}

Error:

error: can't qualify macro invocation with `pub`
 --> src/main.rs:1:1
  |
1 | pub asyn fn test() {}
  | ^^^
  |
  = help: try adjusting the macro to put `pub` inside the invocation

error: expected one of `!` or `::`, found keyword `fn`
 --> src/main.rs:1:10
  |
1 | pub asyn fn test() {}
  |          ^^ expected one of `!` or `::`

I'm not sure how the parser gets the idea that a macro was coming there...

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` labels Dec 15, 2019
@jonas-schievink jonas-schievink changed the title Confusing error message "can't qualify macro invocation with pub" when existential type is used "can't qualify macro invocation with pub" error can fire without any macro invocations Dec 15, 2019
@ChrisJefferson
Copy link
Contributor

Just as another practical example, I wrote (having a C++ brain hiccup) pub typedef mytype = usize;, which produced the same message about macros and confused me until I found typedef isn't a macro, or in fact anything.

@jonas-schievink jonas-schievink added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed P-low Low priority labels Jan 29, 2020
@gihrig
Copy link

gihrig commented Mar 10, 2020

I don't think it is worth having special cased diagnostics for existential type.

But the error goes well beyond existential:

A missing const will trigger this error:

pub mod DEFAULT_BBOX {
  pub mod _northEast {
    pub lat: f64 = 48.82099347817258;
    pub lng: f64 = 9.299583435058596;
  }
error: can't qualify macro invocation with `pub`
  --> src/constants/Map.rs:11:5
   |
11 |     pub lat: f64 = 48.82099347817258;
   |     ^^^
   |
   = help: try adjusting the macro to put `pub` inside the invocation

The problem of course, is that the correct code is:

    pub const lat: f64 = ...

$ rustc -V
rustc 1.43.0-nightly (58b8343 2020-02-05)

macOS 10.14.6

@Centril
Copy link
Contributor

Centril commented Mar 18, 2020

Today you get:

error: visibility `pub` is not followed by an item
 --> src/lib.rs:1:1
  |
1 | pub existential type T: MotorCtrl;
  | ^^^ the visibility
  |
  = help: you likely meant to define an item, e.g., `pub fn foo() {}`

error: expected item, found `existential`
 --> src/lib.rs:1:5
  |
1 | pub existential type T: MotorCtrl;
  |     ^^^^^^^^^^^ expected item

...which seems good enough.

@Centril Centril closed this as completed Mar 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The lexing & parsing of Rust source code to an AST C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants