Specialize future-incompatibility warning for UNSTABLE_NAME_COLLISION.

This commit is contained in:
kennytm 2018-03-03 19:27:49 +08:00
parent 023274483e
commit 28b2bba585
No known key found for this signature in database
GPG Key ID: FEF6C8051D0E013C
4 changed files with 18 additions and 12 deletions

View File

@ -498,15 +498,21 @@ pub fn struct_lint_level<'a>(sess: &'a Session,
// Check for future incompatibility lints and issue a stronger warning.
let lints = sess.lint_store.borrow();
if let Some(future_incompatible) = lints.future_incompatible(LintId::of(lint)) {
let future = if let Some(edition) = future_incompatible.edition {
format!("the {} edition", edition)
let lint_id = LintId::of(lint);
if let Some(future_incompatible) = lints.future_incompatible(lint_id) {
const STANDARD_MESSAGE: &str =
"this was previously accepted by the compiler but is being phased out; \
it will become a hard error";
let explanation = if lint_id == LintId::of(::lint::builtin::UNSTABLE_NAME_COLLISION) {
"once this method is added to the standard library, \
there will be ambiguity here, which will cause a hard error!"
.to_owned()
} else if let Some(edition) = future_incompatible.edition {
format!("{} in the {} edition!", STANDARD_MESSAGE, edition)
} else {
"a future release".to_owned()
format!("{} in a future release!", STANDARD_MESSAGE)
};
let explanation = format!("this was previously accepted by the compiler \
but is being phased out; \
it will become a hard error in {}!", future);
let citation = format!("for more information, see {}",
future_incompatible.reference);
err.warn(&explanation);

View File

@ -1042,7 +1042,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
lint::builtin::UNSTABLE_NAME_COLLISION,
self.fcx.body_id,
self.span,
"a method with this name will be added to the standard library in the future",
"a method with this name may be added to the standard library in the future",
);
// FIXME: This should be a `span_suggestion` instead of `help`. However `self.span` only

View File

@ -24,6 +24,6 @@ use inference_unstable_itertools::IpuItertools;
fn main() {
assert_eq!('x'.ipu_flatten(), 1);
//~^ WARN a method with this name will be added to the standard library in the future
//~^^ WARN it will become a hard error in a future release
//~^ WARN a method with this name may be added to the standard library in the future
//~^^ WARN once this method is added to the standard library, there will be ambiguity here
}

View File

@ -1,11 +1,11 @@
warning: a method with this name will be added to the standard library in the future
warning: a method with this name may be added to the standard library in the future
--> $DIR/inference_unstable.rs:26:20
|
LL | assert_eq!('x'.ipu_flatten(), 1);
| ^^^^^^^^^^^
|
= note: #[warn(unstable_name_collision)] on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= warning: once this method is added to the standard library, there will be ambiguity here, which will cause a hard error!
= note: for more information, see pr #48552 <https://github.com/rust-lang/rust/pull/48552>
= help: call with fully qualified syntax `inference_unstable_itertools::IpuItertools::ipu_flatten(...)` to keep using the current method
= note: add #![feature(ipu_flatten)] to the crate attributes to enable `inference_unstable_iterator::IpuIterator::ipu_flatten`