]> git.lizzy.rs Git - rust.git/commitdiff
Improve error message for unstable default body
authorMaybe Waffle <waffle.lapkin@gmail.com>
Mon, 20 Jun 2022 12:07:14 +0000 (16:07 +0400)
committerMaybe Waffle <waffle.lapkin@gmail.com>
Tue, 26 Jul 2022 11:40:04 +0000 (15:40 +0400)
Cargo.lock
compiler/rustc_typeck/Cargo.toml
compiler/rustc_typeck/src/check/check.rs
compiler/rustc_typeck/src/check/mod.rs
src/test/ui/stability-attribute/default-body-stability-err.rs
src/test/ui/stability-attribute/default-body-stability-err.stderr

index ed3e30342f2f61f475891338e7564cd2cb8ecb48..bb7598bbf3e6fc37992e59715ffca57a2ba7a7ac 100644 (file)
@@ -4616,6 +4616,7 @@ dependencies = [
  "rustc_attr",
  "rustc_data_structures",
  "rustc_errors",
+ "rustc_feature",
  "rustc_graphviz",
  "rustc_hir",
  "rustc_hir_pretty",
index faf52e2695a33507a26a659741d934e2453ea7ea..cae29c1d3c5f938a2b103d103a962c2b790d77ca 100644 (file)
@@ -30,3 +30,4 @@ rustc_ty_utils = { path = "../rustc_ty_utils" }
 rustc_lint = { path = "../rustc_lint" }
 rustc_serialize = { path = "../rustc_serialize" }
 rustc_type_ir = { path = "../rustc_type_ir" }
+rustc_feature = { path = "../rustc_feature" }
index 6254825d96dc8fd54a9492036d0eacbac61ca7e9..0293bf7803a660efb8ebba3697625f9477d17a0e 100644 (file)
@@ -1112,17 +1112,14 @@ fn check_impl_items_against_trait<'tcx>(
 
             if !is_implemented_here {
                 match tcx.eval_default_body_stability(trait_item_id, full_impl_span) {
-                    EvalResult::Deny { feature, reason, issue, is_soft, .. } => {
-                        default_body_is_unstable(
-                            tcx,
-                            full_impl_span,
-                            trait_item_id,
-                            feature,
-                            reason,
-                            issue,
-                            is_soft,
-                        )
-                    }
+                    EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable(
+                        tcx,
+                        full_impl_span,
+                        trait_item_id,
+                        feature,
+                        reason,
+                        issue,
+                    ),
 
                     // Unmarked default bodies are considered stable (at least for now).
                     EvalResult::Allow | EvalResult::Unmarked => {}
index acd7e76fe2598ac58c8ca8baf649065ddfac74c5..b5201c737dfe3a07c50082a3034f2028ee13867c 100644 (file)
@@ -99,7 +99,6 @@
 pub use fn_ctxt::*;
 use hir::def::CtorOf;
 pub use inherited::{Inherited, InheritedBuilder};
-use rustc_middle::middle::stability::report_unstable;
 
 use crate::astconv::AstConv;
 use crate::check::gather_locals::GatherLocalsVisitor;
@@ -667,19 +666,32 @@ fn missing_items_must_implement_one_of_err(
 fn default_body_is_unstable(
     tcx: TyCtxt<'_>,
     impl_span: Span,
-    _item_did: DefId,
+    item_did: DefId,
     feature: Symbol,
     reason: Option<Symbol>,
     issue: Option<NonZeroU32>,
-    is_soft: bool,
 ) {
-    let soft_handler = |lint, span, msg: &_| {
-        tcx.struct_span_lint_hir(lint, hir::CRATE_HIR_ID, span, |lint| {
-            lint.build(msg).emit();
-        })
+    let missing_item_name = &tcx.associated_item(item_did).name;
+    let use_of_unstable_library_feature_note = match reason {
+        Some(r) => format!("use of unstable library feature '{feature}': {r}"),
+        None => format!("use of unstable library feature '{feature}'"),
     };
 
-    report_unstable(tcx.sess, feature, reason, issue, None, is_soft, impl_span, soft_handler)
+    let mut err = struct_span_err!(
+        tcx.sess,
+        impl_span,
+        E0046,
+        "not all trait items implemented, missing: `{missing_item_name}`",
+    );
+    err.note(format!("default implementation of `{missing_item_name}` is unstable"));
+    err.note(use_of_unstable_library_feature_note);
+    rustc_session::parse::add_feature_diagnostics_for_issue(
+        &mut err,
+        &tcx.sess.parse_sess,
+        feature,
+        rustc_feature::GateIssue::Library(issue),
+    );
+    err.emit();
 }
 
 /// Re-sugar `ty::GenericPredicates` in a way suitable to be used in structured suggestions.
index 8f970d0c9f6617407f2e88ac808c6946f4558363..ecb281bccf604d1ed3173ee309f47b5fae92c4f9 100644 (file)
@@ -8,11 +8,11 @@
 struct Type;
 
 impl JustTrait for Type {}
-//~^ ERROR use of unstable library feature 'fun_default_body'
-//~| ERROR use of unstable library feature 'constant_default_body'
+//~^ ERROR not all trait items implemented, missing: `CONSTANT` [E0046]
+//~| ERROR not all trait items implemented, missing: `fun` [E0046]
 
 impl Equal for Type {
-    //~^ ERROR use of unstable library feature 'eq_default_body'
+    //~^ ERROR not all trait items implemented, missing: `eq` [E0046]
     fn neq(&self, other: &Self) -> bool {
         false
     }
index 6abf68bbcae5328958c2bb856b717e21fb2df8ec..ef666f30fc2a294fd5a3a4b6715aada8adee7f17 100644 (file)
@@ -1,20 +1,24 @@
-error[E0658]: use of unstable library feature 'constant_default_body'
+error[E0046]: not all trait items implemented, missing: `CONSTANT`
   --> $DIR/default-body-stability-err.rs:10:1
    |
 LL | impl JustTrait for Type {}
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
+   = note: default implementation of `CONSTANT` is unstable
+   = note: use of unstable library feature 'constant_default_body'
    = help: add `#![feature(constant_default_body)]` to the crate attributes to enable
 
-error[E0658]: use of unstable library feature 'fun_default_body'
+error[E0046]: not all trait items implemented, missing: `fun`
   --> $DIR/default-body-stability-err.rs:10:1
    |
 LL | impl JustTrait for Type {}
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
+   = note: default implementation of `fun` is unstable
+   = note: use of unstable library feature 'fun_default_body'
    = help: add `#![feature(fun_default_body)]` to the crate attributes to enable
 
-error[E0658]: use of unstable library feature 'eq_default_body'
+error[E0046]: not all trait items implemented, missing: `eq`
   --> $DIR/default-body-stability-err.rs:14:1
    |
 LL | / impl Equal for Type {
@@ -25,8 +29,10 @@ LL | |     }
 LL | | }
    | |_^
    |
+   = note: default implementation of `eq` is unstable
+   = note: use of unstable library feature 'eq_default_body'
    = help: add `#![feature(eq_default_body)]` to the crate attributes to enable
 
 error: aborting due to 3 previous errors
 
-For more information about this error, try `rustc --explain E0658`.
+For more information about this error, try `rustc --explain E0046`.