Skip to content

use dyn syntax in error messages #49277

New issue

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

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

Already on GitHub? # to your account

Closed
nikomatsakis opened this issue Mar 22, 2018 · 0 comments
Closed

use dyn syntax in error messages #49277

nikomatsakis opened this issue Mar 22, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nikomatsakis
Copy link
Contributor

We have not yet stabilized dyn Trait (see #49218), but once we do, we should start using it in error messages. So for example this test:

#![feature(dyn_trait)]
use std::fmt::{Debug, Display};
fn main() {
    let x: Box<dyn Debug> = Box::new(1);
    let _: Box<dyn Display> = x;
}

should print

error[E0308]: mismatched types
 --> src/main.rs:5:31
  |
5 |     let _: Box<dyn Display> = x;
  |                               ^ expected trait `std::fmt::Display`, found trait `std::fmt::Debug`
  |
  = note: expected type `std::boxed::Box<dyn std::fmt::Display>`
             found type `std::boxed::Box<dyn std::fmt::Debug>`
@nikomatsakis nikomatsakis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 22, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Jun 24, 2018
The `dyn Trait` syntax was stabilized in 199ee32. Resolves rust-lang#49277.
pietroalbini added a commit to pietroalbini/rust that referenced this issue Jun 26, 2018
add `dyn ` to display of dynamic (trait) types

~~I'm not sure we want the `dyn` in the E0277 "trait bound [...] is not satisfied" messages ("bound" sounds like a different thing in contrast to the names of specific trait-object types like `Box<dyn Trait>`), but I'm finding the code I would need to change that hard to follow—the [display object seems to](https://github.com/rust-lang/rust/blob/f0805a4421449bd6fe3096d63820fbebe2bfcd1d/src/librustc/traits/error_reporting.rs#L600) be a [`Predicate::Trait`](https://github.com/rust-lang/rust/blob/f0805a4421449bd6fe3096d63820fbebe2bfcd1d/src/librustc/ty/mod.rs#L962) variant, whose [`Display` implementation](https://github.com/rust-lang/rust/blob/f0805a4421449bd6fe3096d63820fbebe2bfcd1d/src/librustc/util/ppaux.rs#L1309) calls `.print` on its `PolyTraitPredicate` member, [which is a type alias](https://github.com/rust-lang/rust/blob/f0805a4421449bd6fe3096d63820fbebe2bfcd1d/src/librustc/ty/mod.rs#L1112) for `ty::Binder<TraitPredicate<'tcx>>`, whose [`Display` implementation](https://github.com/rust-lang/rust/blob/f0805a4421449bd6fe3096d63820fbebe2bfcd1d/src/librustc/util/ppaux.rs#L975-L985) ... _&c._— so maybe it's time to pull-request this and see what reviewers think.~~

 Resolves rust-lang#49277 (?).

r? @nikomatsakis
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints 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

1 participant