Skip to content

Don't ICE on missing Unsize impl - #72194

Merged
bors merged 1 commit into
rust-lang:masterfrom
cofibrant:dispatch-from-dyn-ice
May 14, 2020
Merged

Don't ICE on missing Unsize impl#72194
bors merged 1 commit into
rust-lang:masterfrom
cofibrant:dispatch-from-dyn-ice

Conversation

@cofibrant

@cofibrantcofibrant commented May 14, 2020

Copy link
Copy Markdown
Contributor

Previously code of the form

#![feature(unsize, dispatch_from_dyn)]use std::marker::Unsize;use std::ops::DispatchFromDyn;pubstructFoo<'a,T: ?Sized>{_inner:&'a&'aT,}impl<'a,T: ?Sized + Unsize<U>,U: ?Sized>DispatchFromDyn<Foo<'a,U>>forFoo<'a,T>{}

would generate an ICE due to the missing Unsize impl being run through the suggest_change_mut suggestion. This PR adds an early exit and a pointer to the appropriate docs regarding Unsize instead:

error[E0277]: the trait bound `&'a T: std::marker::Unsize<&'a U>` is not satisfied
--> src/test/ui/issues/issue-71036.rs:11:1
|
11 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unsize<&'a U>` is not implemented for `&'a T`
|
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
= note: required because of the requirements on the impl of `std::ops::DispatchFromDyn<&'a &'a U>` for `&'a &'a T`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

r? @estebank

Resolves#71036

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2020
Comment threadsrc/librustc_trait_selection/traits/error_reporting/mod.rs Outdated
Comment threadsrc/librustc_trait_selection/traits/error_reporting/mod.rs Outdated

@estebankestebank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me after niko's requests!

let is_from = format!("{}", trait_ref.print_only_trait_path())
.starts_with("std::convert::From<");
let is_unsize =
{ Some(trait_ref.def_id()) == self.tcx.lang_items().unsize_trait() };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are the braces needed? Have you ran x.py fmt?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Not strictly necessary, but I ran ./x.py fmt

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I can remove if you think that's better?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Na, if it's fine with fmt it's fine with me.

@estebank

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@bors

bors commented May 14, 2020

Copy link
Copy Markdown
Collaborator

📌 Commit f6aa161 has been approved by estebank

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 14, 2020
RalfJung added a commit to RalfJung/rust that referenced this pull request May 14, 2020
…tebank
Don't ICE on missing `Unsize` impl
Previously code of the form
```rust
#![feature(unsize, dispatch_from_dyn)]
use std::marker::Unsize;
use std::ops::DispatchFromDyn;
pub struct Foo<'a, T: ?Sized> {
_inner: &'a &'a T,
}
impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {}
```
would generate an ICE due to the missing `Unsize` impl being run through the `suggest_change_mut` suggestion. This PR adds an early exit and a pointer to the appropriate docs regarding `Unsize` instead:
```
error[E0277]: the trait bound `&'a T: std::marker::Unsize<&'a U>` is not satisfied
--> src/test/ui/issues/issue-71036.rs:11:1
|
11 | impl<'a, T: ?Sized + Unsize<U>, U: ?Sized> DispatchFromDyn<Foo<'a, U>> for Foo<'a, T> {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::marker::Unsize<&'a U>` is not implemented for `&'a T`
|
= note: all implementations of `Unsize` are provided automatically by the compiler, see <https://doc.rust-lang.org/stable/std/marker/trait.Unsize.html> for more information
= note: required because of the requirements on the impl of `std::ops::DispatchFromDyn<&'a &'a U>` for `&'a &'a T`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
```
r? @estebankResolvesrust-lang#71036
@RalfJungRalfJung mentioned this pull request May 14, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request May 14, 2020
Rollup of 8 pull requests
Successful merges:
- rust-lang#71910 (Fix unused_parens false positive when using binary operations)
- rust-lang#72087 (Fix hang in lexical_region_resolve)
- rust-lang#72126 (Change `WorkProduct::saved_files` to an `Option`.)
- rust-lang#72127 (add long error explanation for E0228)
- rust-lang#72141 (Warn against thread::sleep in async fn)
- rust-lang#72170 (use `require_lang_item` over `unwrap`.)
- rust-lang#72191 (Clean up E0589 explanation)
- rust-lang#72194 (Don't ICE on missing `Unsize` impl)
Failed merges:
r? @ghost
@bors
bors merged commit 7b5bc61 into rust-lang:masterMay 14, 2020
@cofibrant
cofibrant deleted the dispatch-from-dyn-ice branch May 14, 2020 23:58
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compiler panics while trying to implement DispatchFromDyn

5 participants

@cofibrant@estebank@bors@nikomatsakis@rust-highfive