Skip to content

Conversation

@rmehri01
Copy link
Contributor

On parse errors where we just parsed &raw we can suggest using a raw reference adding mut or const after, though raw is contextual so it might not always be accurate.

Example:

mod foo {
    pub static A: i32 = 0;
}

fn get_ref() -> *const i32 {
    &raw foo::A
}
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `foo`
  --> $DIR/return-expr.rs:11:10
   |
LL |     &raw foo::A
   |          ^^^ expected one of 8 possible tokens
   |
help: you might have meant to use a raw reference
   |
LL |     &raw mut foo::A
   |          +++
LL |     &raw const foo::A
   |          +++++

error: aborting due to 1 previous error

Closes #133231

@rustbot
Copy link
Collaborator

rustbot commented Jan 20, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 20, 2025
@rust-log-analyzer
Copy link
Collaborator

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

Click to see the possible cause of the failure (guessed by this bot)
#22 exporting to docker image format
#22 sending tarball 28.1s done
#22 DONE 34.9s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
   Compiling rustc_middle v0.0.0 (/checkout/compiler/rustc_middle)
error: using `Symbol::intern` on a string literal
    --> compiler/rustc_parse/src/parser/diagnostics.rs:1311:37
     |
1311 |             && *p == Symbol::intern("raw")
     |
     = help: consider adding the symbol to `compiler/rustc_span/src/symbol.rs`
     = note: requested on the command line with `-D rustc::symbol-intern-string-literal`

Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that this approach is both not general enough, and generalizing it further would require sprinkling around suggest_add_mut_or_const_in_raw_ref into too many places in the parser.

We basically have to add a recovery to every path where we could have &raw X, right? For example, this doesn't currently work in function argument position, or the LHS of an assignment (not a let), or in a struct constructor.

@rmehri01
Copy link
Contributor Author

I fear that this approach is both not general enough, and generalizing it further would require sprinkling around suggest_add_mut_or_const_in_raw_ref into too many places in the parser.

We basically have to add a recovery to every path where we could have &raw X, right? For example, this doesn't currently work in function argument position, or the LHS of an assignment (not a let), or in a struct constructor.

I see, I was pretty much just just copying recover_missing_dot since it seemed similar, is there a better way to go about this?

@fee1-dead fee1-dead added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 22, 2025
@rmehri01 rmehri01 closed this Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terse parse error on &raw expr

5 participants