about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-02-22 02:01:53 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-02-24 00:59:38 +0100
commitfa2a792491ed28530146ee55a46128c05a8026ad (patch)
tree4fc69b8061150c0978f88451eba057003ecffce7
parent6d0e58bff88f620c1a4f641a627f046bf4cde4ad (diff)
downloadrust-fa2a792491ed28530146ee55a46128c05a8026ad.tar.gz
rust-fa2a792491ed28530146ee55a46128c05a8026ad.zip
add `Span` to `ast::Defaultness::Default`.
-rw-r--r--src/librustc_ast_lowering/item.rs12
-rw-r--r--src/librustc_ast_passes/ast_validation.rs12
-rw-r--r--src/librustc_ast_passes/feature_gate.rs4
-rw-r--r--src/librustc_ast_pretty/pprust.rs2
-rw-r--r--src/librustc_parse/parser/item.rs2
-rw-r--r--src/librustc_save_analysis/sig.rs2
-rw-r--r--src/libsyntax/ast.rs2
-rw-r--r--src/test/ui/parser/assoc-static-semantic-fail.stderr8
-rw-r--r--src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr24
-rw-r--r--src/test/ui/specialization/defaultimpl/validation.rs2
-rw-r--r--src/test/ui/specialization/defaultimpl/validation.stderr8
11 files changed, 48 insertions, 30 deletions
diff --git a/src/librustc_ast_lowering/item.rs b/src/librustc_ast_lowering/item.rs
index 1a19fab0265..3d6926df58d 100644
--- a/src/librustc_ast_lowering/item.rs
+++ b/src/librustc_ast_lowering/item.rs
@@ -810,13 +810,9 @@ impl<'hir> LoweringContext<'_, 'hir> {
             }
             AssocItemKind::Macro(..) => unimplemented!(),
         };
-        hir::TraitItemRef {
-            id: hir::TraitItemId { hir_id: self.lower_node_id(i.id) },
-            ident: i.ident,
-            span: i.span,
-            defaultness: self.lower_defaultness(Defaultness::Default, has_default),
-            kind,
-        }
+        let id = hir::TraitItemId { hir_id: self.lower_node_id(i.id) };
+        let defaultness = hir::Defaultness::Default { has_value: has_default };
+        hir::TraitItemRef { id, ident: i.ident, span: i.span, defaultness, kind }
     }
 
     /// Construct `ExprKind::Err` for the given `span`.
@@ -948,7 +944,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
 
     fn lower_defaultness(&self, d: Defaultness, has_value: bool) -> hir::Defaultness {
         match d {
-            Defaultness::Default => hir::Defaultness::Default { has_value: has_value },
+            Defaultness::Default(_) => hir::Defaultness::Default { has_value },
             Defaultness::Final => {
                 assert!(has_value);
                 hir::Defaultness::Final
diff --git a/src/librustc_ast_passes/ast_validation.rs b/src/librustc_ast_passes/ast_validation.rs
index a9844a7059e..d385ea1a4a6 100644
--- a/src/librustc_ast_passes/ast_validation.rs
+++ b/src/librustc_ast_passes/ast_validation.rs
@@ -400,9 +400,11 @@ impl<'a> AstValidator<'a> {
     }
 
     fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
-        if let Defaultness::Default = defaultness {
+        if let Defaultness::Default(def_span) = defaultness {
+            let span = self.session.source_map().def_span(span);
             self.err_handler()
                 .struct_span_err(span, "`default` is only allowed on items in `impl` definitions")
+                .span_label(def_span, "`default` because of this")
                 .emit();
         }
     }
@@ -863,10 +865,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
                 if polarity == ImplPolarity::Negative {
                     self.err_handler().span_err(item.span, "inherent impls cannot be negative");
                 }
-                if defaultness == Defaultness::Default {
+                if let Defaultness::Default(def_span) = defaultness {
+                    let span = self.session.source_map().def_span(item.span);
                     self.err_handler()
-                        .struct_span_err(item.span, "inherent impls cannot be default")
-                        .note("only trait implementations may be annotated with default")
+                        .struct_span_err(span, "inherent impls cannot be `default`")
+                        .span_label(def_span, "`default` because of this")
+                        .note("only trait implementations may be annotated with `default`")
                         .emit();
                 }
                 if let Const::Yes(span) = constness {
diff --git a/src/librustc_ast_passes/feature_gate.rs b/src/librustc_ast_passes/feature_gate.rs
index 5bddae0d49e..586539d9b5e 100644
--- a/src/librustc_ast_passes/feature_gate.rs
+++ b/src/librustc_ast_passes/feature_gate.rs
@@ -349,7 +349,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
                     );
                 }
 
-                if let ast::Defaultness::Default = defaultness {
+                if let ast::Defaultness::Default(_) = defaultness {
                     gate_feature_post!(&self, specialization, i.span, "specialization is unstable");
                 }
             }
@@ -543,7 +543,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
     }
 
     fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
-        if i.defaultness == ast::Defaultness::Default {
+        if let ast::Defaultness::Default(_) = i.defaultness {
             gate_feature_post!(&self, specialization, i.span, "specialization is unstable");
         }
 
diff --git a/src/librustc_ast_pretty/pprust.rs b/src/librustc_ast_pretty/pprust.rs
index 548ae6e7e63..abe3165df4b 100644
--- a/src/librustc_ast_pretty/pprust.rs
+++ b/src/librustc_ast_pretty/pprust.rs
@@ -1389,7 +1389,7 @@ impl<'a> State<'a> {
     }
 
     crate fn print_defaultness(&mut self, defaultness: ast::Defaultness) {
-        if let ast::Defaultness::Default = defaultness {
+        if let ast::Defaultness::Default(_) = defaultness {
             self.word_nbsp("default");
         }
     }
diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs
index 328cf11c532..a6e4900bc62 100644
--- a/src/librustc_parse/parser/item.rs
+++ b/src/librustc_parse/parser/item.rs
@@ -547,7 +547,7 @@ impl<'a> Parser<'a> {
             )
         {
             self.bump(); // `default`
-            Defaultness::Default
+            Defaultness::Default(self.prev_span)
         } else {
             Defaultness::Final
         }
diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs
index 2c07ed0571b..a7a10c0be0d 100644
--- a/src/librustc_save_analysis/sig.rs
+++ b/src/librustc_save_analysis/sig.rs
@@ -502,7 +502,7 @@ impl Sig for ast::Item {
                 items: _,
             } => {
                 let mut text = String::new();
-                if let ast::Defaultness::Default = defaultness {
+                if let ast::Defaultness::Default(_) = defaultness {
                     text.push_str("default ");
                 }
                 if let ast::Unsafe::Yes(_) = unsafety {
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 849950e939a..bcf94d19613 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -2106,7 +2106,7 @@ pub enum Const {
 /// For details see the [RFC #2532](https://github.com/rust-lang/rfcs/pull/2532).
 #[derive(Copy, Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, HashStable_Generic)]
 pub enum Defaultness {
-    Default,
+    Default(Span),
     Final,
 }
 
diff --git a/src/test/ui/parser/assoc-static-semantic-fail.stderr b/src/test/ui/parser/assoc-static-semantic-fail.stderr
index d02e2855c7e..dfd0053fda2 100644
--- a/src/test/ui/parser/assoc-static-semantic-fail.stderr
+++ b/src/test/ui/parser/assoc-static-semantic-fail.stderr
@@ -74,13 +74,17 @@ error: `default` is only allowed on items in `impl` definitions
   --> $DIR/assoc-static-semantic-fail.rs:24:5
    |
 LL |     default static TC: u8 = 0;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^^^^^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/assoc-static-semantic-fail.rs:27:5
    |
 LL |     pub(crate) default static TD: u8;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |     ^^^^^^^^^^^-------^^^^^^^^^^^^^^^
+   |                |
+   |                `default` because of this
 
 error[E0449]: unnecessary visibility qualifier
   --> $DIR/assoc-static-semantic-fail.rs:27:5
diff --git a/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr b/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
index 54111df3423..6bb946d5b64 100644
--- a/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
+++ b/src/test/ui/parser/trait-item-with-defaultness-fail-semantic.stderr
@@ -2,37 +2,49 @@ error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
    |
 LL |     default const A: u8;
-   |     ^^^^^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
    |
 LL |     default const B: u8 = 0;
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^^^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
    |
 LL |     default type D;
-   |     ^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
    |
 LL |     default type C: Ord;
-   |     ^^^^^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:10:5
    |
 LL |     default fn f1();
-   |     ^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: `default` is only allowed on items in `impl` definitions
   --> $DIR/trait-item-with-defaultness-fail-semantic.rs:11:5
    |
 LL |     default fn f2() {}
-   |     ^^^^^^^^^^^^^^^^^^
+   |     -------^^^^^^^^
+   |     |
+   |     `default` because of this
 
 error: aborting due to 6 previous errors
 
diff --git a/src/test/ui/specialization/defaultimpl/validation.rs b/src/test/ui/specialization/defaultimpl/validation.rs
index cf5d6628054..26b3f1ec414 100644
--- a/src/test/ui/specialization/defaultimpl/validation.rs
+++ b/src/test/ui/specialization/defaultimpl/validation.rs
@@ -4,7 +4,7 @@
 struct S;
 struct Z;
 
-default impl S {} //~ ERROR inherent impls cannot be default
+default impl S {} //~ ERROR inherent impls cannot be `default`
 
 default unsafe impl Send for S {} //~ ERROR impls of auto traits cannot be default
 default impl !Send for Z {} //~ ERROR impls of auto traits cannot be default
diff --git a/src/test/ui/specialization/defaultimpl/validation.stderr b/src/test/ui/specialization/defaultimpl/validation.stderr
index 14a06c39088..03b1ef69ca0 100644
--- a/src/test/ui/specialization/defaultimpl/validation.stderr
+++ b/src/test/ui/specialization/defaultimpl/validation.stderr
@@ -1,10 +1,12 @@
-error: inherent impls cannot be default
+error: inherent impls cannot be `default`
   --> $DIR/validation.rs:7:1
    |
 LL | default impl S {}
-   | ^^^^^^^^^^^^^^^^^
+   | -------^^^^^^^
+   | |
+   | `default` because of this
    |
-   = note: only trait implementations may be annotated with default
+   = note: only trait implementations may be annotated with `default`
 
 error: impls of auto traits cannot be default
   --> $DIR/validation.rs:9:1