Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
069c52f
Check if the archive has already been added to avoid duplicates
petrhosek Jul 2, 2019
6de8e39
in which the `non_ascii_idents` lint appears (RFC 2457)
zackmdavis Jun 16, 2019
bed54cf
rustdoc: set cfg(doctest) when collecting doctests
QuietMisdreavus Jun 28, 2019
cff6ce6
force single-threaded text execution
QuietMisdreavus Jul 2, 2019
03ac053
syntax: Remove `NodeId` from `SyntaxExtension`
petrochenkov Jun 20, 2019
3b6370b
resolve/expand: Move macro stability checking to an earlier point
petrochenkov Jun 20, 2019
290475e
Collect library features from non-exported macros
petrochenkov Jun 20, 2019
73dec4a
resolve: Check stability for local macros as well
petrochenkov Jun 20, 2019
3542995
syntax: Keep full `Stability` in `SyntaxExtension`
petrochenkov Jun 21, 2019
d9ee97e
resolve: Use standard stability diagnostics for macros
petrochenkov Jun 21, 2019
0817fc6
Support deprecation checking for macros
petrochenkov Jun 21, 2019
1ee0ce8
syntax: Migrate built-in macros to the regular stability checking
petrochenkov Jun 22, 2019
b6d522a
syntax: Pre-intern names of all built-in macros
petrochenkov Jun 23, 2019
941653b
Address review comments + Fix rebase
petrochenkov Jul 5, 2019
9cd75fb
Rollup merge of #61883 - zackmdavis:non_ascii_idents_lint, r=Manishearth
Centril Jul 7, 2019
3250b8e
Rollup merge of #62042 - petrochenkov:macstab, r=matthewjasper
Centril Jul 7, 2019
fe807fc
Rollup merge of #62213 - QuietMisdreavus:cfg-doctest, r=GuillaumeGomez
Centril Jul 7, 2019
a2500db
Rollup merge of #62286 - petrhosek:rustc-no-duplicate-archives, r=cra…
Centril Jul 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
resolve: Use standard stability diagnostics for macros
  • Loading branch information
petrochenkov committed Jul 7, 2019
commit d9ee97e896125b38dba199c763e5e35c5107a735
60 changes: 32 additions & 28 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,36 @@ pub fn provide(providers: &mut Providers<'_>) {
};
}

pub fn report_unstable(
sess: &Session, feature: Symbol, reason: Option<Symbol>, issue: u32, span: Span
) {
let msg = match reason {
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
None => format!("use of unstable library feature '{}'", &feature)
};

let msp: MultiSpan = span.into();
let cm = &sess.parse_sess.source_map();
let span_key = msp.primary_span().and_then(|sp: Span|
if !sp.is_dummy() {
let file = cm.lookup_char_pos(sp.lo()).file;
if file.name.is_macros() {
None
} else {
Some(span)
}
} else {
None
}
);

let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
let fresh = sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
emit_feature_err(&sess.parse_sess, feature, span, GateIssue::Library(Some(issue)), &msg);
}
}

/// Checks whether an item marked with `deprecated(since="X")` is currently
/// deprecated (i.e., whether X is not greater than the current rustc version).
pub fn deprecation_in_effect(since: &str) -> bool {
Expand Down Expand Up @@ -715,34 +745,8 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
match self.eval_stability(def_id, id, span) {
EvalResult::Allow => {}
EvalResult::Deny { feature, reason, issue } => {
let msg = match reason {
Some(r) => format!("use of unstable library feature '{}': {}", feature, r),
None => format!("use of unstable library feature '{}'", &feature)
};

let msp: MultiSpan = span.into();
let cm = &self.sess.parse_sess.source_map();
let span_key = msp.primary_span().and_then(|sp: Span|
if !sp.is_dummy() {
let file = cm.lookup_char_pos(sp.lo()).file;
if file.name.is_macros() {
None
} else {
Some(span)
}
} else {
None
}
);

let error_id = (DiagnosticMessageId::StabilityId(issue), span_key, msg.clone());
let fresh = self.sess.one_time_diagnostics.borrow_mut().insert(error_id);
if fresh {
emit_feature_err(&self.sess.parse_sess, feature, span,
GateIssue::Library(Some(issue)), &msg);
}
}
EvalResult::Deny { feature, reason, issue } =>
report_unstable(self.sess, feature, reason, issue, span),
EvalResult::Unmarked => {
// The API could be uncallable for other reasons, for example when a private module
// was referenced.
Expand Down
15 changes: 7 additions & 8 deletions src/librustc_resolve/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::resolve_imports::ImportResolver;
use rustc::hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
use rustc::hir::def::{self, DefKind, NonMacroAttrKind};
use rustc::hir::map::{self, DefCollector};
use rustc::middle::stability;
use rustc::{ty, lint, span_bug};
use syntax::ast::{self, Ident};
use syntax::attr::{self, StabilityLevel};
Expand All @@ -18,7 +19,7 @@ use syntax::ext::base::{MacroKind, SyntaxExtension};
use syntax::ext::expand::{AstFragment, Invocation, InvocationKind};
use syntax::ext::hygiene::Mark;
use syntax::ext::tt::macro_rules;
use syntax::feature_gate::{feature_err, emit_feature_err, is_builtin_attr_name};
use syntax::feature_gate::{feature_err, is_builtin_attr_name};
use syntax::feature_gate::{AttributeGate, GateIssue, Stability, BUILTIN_ATTRIBUTES};
use syntax::symbol::{Symbol, kw, sym};
use syntax::visit::Visitor;
Expand Down Expand Up @@ -237,13 +238,11 @@ impl<'a> base::Resolver for Resolver<'a> {
invoc.expansion_data.mark.set_expn_info(ext.expn_info(span, &format));

if let Some(stability) = ext.stability {
if let StabilityLevel::Unstable { issue, .. } = stability.level {
let features = self.session.features_untracked();
if !span.allows_unstable(stability.feature) &&
features.declared_lib_features.iter().all(|(feat, _)| *feat != stability.feature) {
let msg = format!("macro {}! is unstable", path);
emit_feature_err(&self.session.parse_sess, stability.feature, span,
GateIssue::Library(Some(issue)), &msg);
if let StabilityLevel::Unstable { reason, issue } = stability.level {
let (feature, features) = (stability.feature, self.session.features_untracked());
if !span.allows_unstable(feature) &&
features.declared_lib_features.iter().all(|(feat, _)| *feat != feature) {
stability::report_unstable(self.session, feature, reason, issue, span);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/macros/macro-stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
macro_rules! local_unstable { () => () }

fn main() {
local_unstable!(); //~ ERROR: macro local_unstable! is unstable
unstable_macro!(); //~ ERROR: macro unstable_macro! is unstable
local_unstable!(); //~ ERROR use of unstable library feature 'local_unstable'
unstable_macro!(); //~ ERROR use of unstable library feature 'unstable_macros'
}
4 changes: 2 additions & 2 deletions src/test/ui/macros/macro-stability.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0658]: macro local_unstable! is unstable
error[E0658]: use of unstable library feature 'local_unstable'
--> $DIR/macro-stability.rs:10:5
|
LL | local_unstable!();
| ^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(local_unstable)] to the crate attributes to enable

error[E0658]: macro unstable_macro! is unstable
error[E0658]: use of unstable library feature 'unstable_macros'
--> $DIR/macro-stability.rs:11:5
|
LL | unstable_macro!();
Expand Down