Improve error
This commit is contained in:
parent
2c1429ca5e
commit
a2b1347bbb
@ -46,7 +46,7 @@
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_errors::{struct_span_err, Applicability};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Namespace, PartialRes, PerNS, Res};
|
||||
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId, CRATE_DEF_ID};
|
||||
@ -2785,9 +2785,14 @@ fn maybe_lint_bare_trait(&mut self, span: Span, id: NodeId, is_global: bool) {
|
||||
)
|
||||
} else {
|
||||
let msg = "trait objects must include the `dyn` keyword";
|
||||
let label = "`dyn` keyword should be added before this trait";
|
||||
let label = "add `dyn` keyword before this trait";
|
||||
let mut err = struct_span_err!(self.sess, span, E0782, "{}", msg,);
|
||||
err.span_label(span, label);
|
||||
err.span_suggestion_verbose(
|
||||
span.shrink_to_lo(),
|
||||
label,
|
||||
String::from("dyn "),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ The range pattern `...` is no longer allowed.
|
||||
|
||||
Erroneous code example:
|
||||
|
||||
```edition2021,compile_fail,E782
|
||||
```edition2021,compile_fail,E783
|
||||
match 2u8 {
|
||||
0...9 => println!("Got a number less than 10"), // error!
|
||||
_ => println!("Got a number 10 or more"),
|
||||
|
@ -2,19 +2,34 @@ error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/dyn-2021-edition-error.rs:6:14
|
||||
|
|
||||
LL | let _x: &SomeTrait = todo!();
|
||||
| ^^^^^^^^^ `dyn` keyword should be added before this trait
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: add `dyn` keyword before this trait
|
||||
|
|
||||
LL | let _x: &dyn SomeTrait = todo!();
|
||||
| ^^^
|
||||
|
||||
error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/dyn-2021-edition-error.rs:3:17
|
||||
|
|
||||
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
|
||||
| ^^^^^^^^^ `dyn` keyword should be added before this trait
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: add `dyn` keyword before this trait
|
||||
|
|
||||
LL | fn function(x: &dyn SomeTrait, y: Box<SomeTrait>) {
|
||||
| ^^^
|
||||
|
||||
error[E0782]: trait objects must include the `dyn` keyword
|
||||
--> $DIR/dyn-2021-edition-error.rs:3:35
|
||||
|
|
||||
LL | fn function(x: &SomeTrait, y: Box<SomeTrait>) {
|
||||
| ^^^^^^^^^ `dyn` keyword should be added before this trait
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: add `dyn` keyword before this trait
|
||||
|
|
||||
LL | fn function(x: &SomeTrait, y: Box<dyn SomeTrait>) {
|
||||
| ^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user