|
1 | 1 | use crate::ast::{self, AssocTyConstraint, AssocTyConstraintKind, NodeId}; |
2 | 2 | use crate::ast::{GenericParam, GenericParamKind, PatKind, RangeEnd, VariantData}; |
3 | 3 | use crate::attr; |
4 | | -use crate::sess::ParseSess; |
| 4 | +use crate::sess::{feature_err, leveled_feature_err, GateStrength, ParseSess}; |
5 | 5 | use crate::visit::{self, FnKind, Visitor}; |
6 | 6 |
|
7 | 7 | use rustc_data_structures::fx::FxHashMap; |
8 | 8 | use rustc_error_codes::*; |
9 | | -use rustc_errors::{error_code, struct_span_err, Applicability, DiagnosticBuilder, Handler}; |
10 | | -use rustc_feature::{find_feature_issue, GateIssue}; |
| 9 | +use rustc_errors::{error_code, struct_span_err, Applicability, Handler}; |
11 | 10 | use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP}; |
12 | | -use rustc_feature::{Feature, Features, State as FeatureState, UnstableFeatures}; |
| 11 | +use rustc_feature::{Feature, Features, GateIssue, State as FeatureState, UnstableFeatures}; |
13 | 12 | use rustc_feature::{ |
14 | 13 | ACCEPTED_FEATURES, ACTIVE_FEATURES, REMOVED_FEATURES, STABLE_REMOVED_FEATURES, |
15 | 14 | }; |
16 | 15 | use rustc_span::edition::{Edition, ALL_EDITIONS}; |
17 | 16 | use rustc_span::source_map::Spanned; |
18 | 17 | use rustc_span::symbol::{sym, Symbol}; |
19 | | -use rustc_span::{MultiSpan, Span, DUMMY_SP}; |
| 18 | +use rustc_span::{Span, DUMMY_SP}; |
20 | 19 |
|
21 | 20 | use log::debug; |
22 | 21 |
|
@@ -53,70 +52,6 @@ pub fn check_attribute(attr: &ast::Attribute, parse_sess: &ParseSess, features: |
53 | 52 | PostExpansionVisitor { parse_sess, features }.visit_attribute(attr) |
54 | 53 | } |
55 | 54 |
|
56 | | -#[derive(Debug, Copy, Clone, PartialEq)] |
57 | | -pub enum GateStrength { |
58 | | - /// A hard error. (Most feature gates should use this.) |
59 | | - Hard, |
60 | | - /// Only a warning. (Use this only as backwards-compatibility demands.) |
61 | | - Soft, |
62 | | -} |
63 | | - |
64 | | -pub fn feature_err<'a>( |
65 | | - sess: &'a ParseSess, |
66 | | - feature: Symbol, |
67 | | - span: impl Into<MultiSpan>, |
68 | | - explain: &str, |
69 | | -) -> DiagnosticBuilder<'a> { |
70 | | - feature_err_issue(sess, feature, span, GateIssue::Language, explain) |
71 | | -} |
72 | | - |
73 | | -pub fn feature_err_issue<'a>( |
74 | | - sess: &'a ParseSess, |
75 | | - feature: Symbol, |
76 | | - span: impl Into<MultiSpan>, |
77 | | - issue: GateIssue, |
78 | | - explain: &str, |
79 | | -) -> DiagnosticBuilder<'a> { |
80 | | - leveled_feature_err(sess, feature, span, issue, explain, GateStrength::Hard) |
81 | | -} |
82 | | - |
83 | | -fn leveled_feature_err<'a>( |
84 | | - sess: &'a ParseSess, |
85 | | - feature: Symbol, |
86 | | - span: impl Into<MultiSpan>, |
87 | | - issue: GateIssue, |
88 | | - explain: &str, |
89 | | - level: GateStrength, |
90 | | -) -> DiagnosticBuilder<'a> { |
91 | | - let diag = &sess.span_diagnostic; |
92 | | - |
93 | | - let mut err = match level { |
94 | | - GateStrength::Hard => diag.struct_span_err_with_code(span, explain, error_code!(E0658)), |
95 | | - GateStrength::Soft => diag.struct_span_warn(span, explain), |
96 | | - }; |
97 | | - |
98 | | - if let Some(n) = find_feature_issue(feature, issue) { |
99 | | - err.note(&format!( |
100 | | - "for more information, see https://github.com/rust-lang/rust/issues/{}", |
101 | | - n, |
102 | | - )); |
103 | | - } |
104 | | - |
105 | | - // #23973: do not suggest `#![feature(...)]` if we are in beta/stable |
106 | | - if sess.unstable_features.is_nightly_build() { |
107 | | - err.help(&format!("add `#![feature({})]` to the crate attributes to enable", feature)); |
108 | | - } |
109 | | - |
110 | | - // If we're on stable and only emitting a "soft" warning, add a note to |
111 | | - // clarify that the feature isn't "on" (rather than being on but |
112 | | - // warning-worthy). |
113 | | - if !sess.unstable_features.is_nightly_build() && level == GateStrength::Soft { |
114 | | - err.help("a nightly build of the compiler is required to enable this feature"); |
115 | | - } |
116 | | - |
117 | | - err |
118 | | -} |
119 | | - |
120 | 55 | struct PostExpansionVisitor<'a> { |
121 | 56 | parse_sess: &'a ParseSess, |
122 | 57 | features: &'a Features, |
|
0 commit comments