Skip to content

borrow checker error message has wrong pointer type with trait Test<'a> #14098

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
erickt opened this issue May 10, 2014 · 3 comments
Closed

borrow checker error message has wrong pointer type with trait Test<'a> #14098

erickt opened this issue May 10, 2014 · 3 comments
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@erickt
Copy link
Contributor

erickt commented May 10, 2014

creduce found this error:

trait Test<'a> {
    fn method(&'a mut self);
}

fn run_test<'a>(test: &'a mut Test<'a>) {
    test.method();
    test.method();
}

fn main() {}

With this error:

ice.rs:7:5: 7:9 error: cannot borrow `*test` as mutable more than once at a time
ice.rs:7     test.method();
             ^~~~
ice.rs:6:5: 6:9 note: previous borrow of `*test` occurs here; the mutable borrow prevents subsequent moves, borrows, or modification of `*test` until the borrow ends
ice.rs:6     test.method();
             ^~~~
ice.rs:8:2: 8:2 note: previous borrow ends here
ice.rs:5 fn run_test<'a>(test: &'a mut Test<'a>) {
ice.rs:6     test.method();
ice.rs:7     test.method();
ice.rs:8 }
         ^
error: aborting due to previous error

One thing that makes this case potentially interesting though is that if you remove the lifetime from the trait the error goes away:

trait Test {
    fn method<'a>(&'a mut self);
}

fn run_test<'a>(test: &'a mut Test) {
    test.method();
    test.method();
}

fn main() {}

@nikomatsakis: Is this second case an error? Or is it supposed to happen?

@steveklabnik
Copy link
Member

Triage: still an error.

@durka
Copy link
Contributor

durka commented Sep 9, 2016

There doesn't seem to be a bug here.

@Mark-Simulacrum
Copy link
Member

Closing, I agree that there doesn't seem to be an error here.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
…er, r=Veykril

Support DidChangeWorkspaceFolders notifications

This PR enables the `WorkspaceFoldersServerCapabilities` capability for rust-analyzer and implemented support for the associated [`DidChangeWorkspaceFolders`](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWorkspaceFolders) notification to allow clients to update the list of `workspaceFolders` sent during initialization.

## Motivation

This allows clients which lazily autodiscover their workspace roots (like the [helix editor](https://github.com/helix-editor/helix) once [my PR](helix-editor/helix#5748) lands) avoid spawning multiple instances of RA. Right now such clients are forced to either:

* greedily discover all LSP roots in the workspace (precludes the ability to respond to new workspace roots)
* spawn multiple instance of rust-analyzer (one for each root)
* restart rust-analyzer whenever a new workspace is added

Some example use-cases are shown [here](helix-editor/helix#5748 (comment)).

This PR will also improve support for VSCode (and Atom) multi workspaces.

## Implementation

The implementation was fairly straightforward as `rust-analyzer` already supports dynamically reloading workspaces, for example on configuration changes. Furthermore, rust-analyzer also already supports auto-discovering internal workspace from the `workspaceFolders` key in the initialization request. Therefore, the necessary logic just needed to be moved to a central place and reused.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants