Skip to content
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

Add dyn to areas of core. #2538

Merged
merged 2 commits into from
Jun 18, 2019
Merged

Add dyn to areas of core. #2538

merged 2 commits into from
Jun 18, 2019

Conversation

kitsonk
Copy link
Contributor

@kitsonk kitsonk commented Jun 17, 2019

Nightly Rust complains with the following:

error: trait objects without an explicit `dyn` are deprecated
  --> ../../core/isolate.rs:71:19
   |
71 | type DispatchFn = Fn(&[u8], Option<PinnedBuf>) -> Op;
   |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Fn(&[u8], Option<PinnedBuf>) -> Op`
   |
   = note: `-D bare-trait-objects` implied by `-D warnings`

error: trait objects without an explicit `dyn` are deprecated
  --> ../../core/isolate.rs:74:20
   |
74 | type DynImportFn = Fn(&str, &str) -> DynImportFuture;
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `dyn`: `dyn Fn(&str, &str) -> DynImportFuture`

error: trait objects without an explicit `dyn` are deprecated
   --> ../../core/modules.rs:598:32
    |
598 |     fn cause(&self) -> Option<&Error> {
    |                                ^^^^^ help: use `dyn`: `dyn Error`

error: aborting due to 3 previous errors

This patch fixes it and should be supported by earlier versions of Rust. (I had to update to a recent version of nightly because master has something that is triggering a bug in RLS, updating to a more recent version of nightly fixed that).

@95th
Copy link
Contributor

95th commented Jun 17, 2019

One more error on Nightly (2019-06-17):

error[E0283]: type annotations required: cannot resolve `std::string::String: std::convert::AsRef<_>`
  --> ../../cli\repl.rs:97:44
   |
97 |         self.editor.add_history_entry(line.as_ref());
   |                                            ^^^^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0283`.
ninja: build stopped: subcommand failed.

Fix:

self.editor.add_history_entry(&line);

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 18, 2019

In my other branch @ry suggested:

self.editor.add_history_entry(line.clone());

which is now reflected in this PR and rebased on master.

@95th
Copy link
Contributor

95th commented Jun 18, 2019

I think cloning is not required because if you look at the rustyline's History implementation, it calls line.into which creates a new instance from the passed reference anyways.

@@ -94,7 +94,7 @@ impl Repl {
.editor
.readline(&prompt)
.map(|line| {
self.editor.add_history_entry(line.as_ref());
self.editor.add_history_entry(line.clone());
Copy link
Member

Choose a reason for hiding this comment

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

Hm I'm not sure what was happening on the other branch - I had to make that change to get it to compile locally... but if this is passing CI, I think it would be better left as is.

Copy link
Member

Choose a reason for hiding this comment

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

Otherwise LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it to &line in the other branch and you pushed a commit to line.clone().

@95th
Copy link
Contributor

95th commented Jun 18, 2019

@kitsonk &line doesn't work in current stable and as_ref doesn't in nightly. Looks like a bug in Rust.

EDIT:
(Apparantly this is expected behavior as per rust-lang/rust#59825)

@95th
Copy link
Contributor

95th commented Jun 18, 2019

For now, we can use verbose turbofish, which works on both:

self.editor.add_history_entry(AsRef::<str>::as_ref(&line))

@kitsonk
Copy link
Contributor Author

kitsonk commented Jun 18, 2019

@95th What is wrong with clone? It works in both. Probably best not to leak the reference anyways. The lifetime of line is suspect IMO.

@95th
Copy link
Contributor

95th commented Jun 18, 2019

@kitsonk Nothing wrong. Just that the cloned instance is discarded in the method. I guess clone is fine here because it works without much noise.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

LGTM - not sure what the deal with the as_ref is but the clone works and is very far from a hot path.

@ry ry merged commit ed390a5 into denoland:master Jun 18, 2019
@kitsonk kitsonk deleted the dyn_fix branch August 2, 2022 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants