Skip to content

Commit

Permalink
Specialize future-incompatibility warning for UNSTABLE_NAME_COLLISION.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm committed Mar 23, 2018
1 parent 0232744 commit 28b2bba
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
20 changes: 13 additions & 7 deletions src/librustc/lint/mod.rs
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/method/probe.rs
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/inference_unstable.rs
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions src/test/ui/inference_unstable.stderr
@@ -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`
Expand Down

0 comments on commit 28b2bba

Please sign in to comment.