From e77110e1f61e42c0f0e9e3288edb0d663eb39bba Mon Sep 17 00:00:00 2001 From: "Zack M. Davis" Date: Sun, 15 Apr 2018 11:12:33 -0700 Subject: [PATCH] don't see issue #0 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The unstable-feature attribute requires an issue (neglecting it is E0547), which gets used in the error messages. Unfortunately, there are some cases where "0" is apparently used a placeholder where no issue exists, directing the user to see the (nonexistent) issue #0. (It would have been better to either let `issue` be optional—compare to how issue is an `Option` in the feature-gate declarations in libsyntax/feature-gate.rs—or actually require that an issue be created.) Rather than endeavoring to change how `#[unstable]` works at this time (given competing contributor and reviewer priorities), this simple patch proposes the less-ambitious solution of just not adding the "(see issue)" note when the number is zero. Resolves #49983. --- src/libsyntax/feature_gate.rs | 7 +++---- .../ui/feature-gate/issue-49983-see-issue-0.rs | 16 ++++++++++++++++ .../feature-gate/issue-49983-see-issue-0.stderr | 11 +++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/feature-gate/issue-49983-see-issue-0.rs create mode 100644 src/test/ui/feature-gate/issue-49983-see-issue-0.stderr diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index 73ebfc20876..5413a05a364 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -1228,10 +1228,9 @@ fn leveled_feature_err<'a>(sess: &'a ParseSess, feature: &str, span: Span, issue GateIssue::Library(lib) => lib, }; - let explanation = if let Some(n) = issue { - format!("{} (see issue #{})", explain, n) - } else { - explain.to_owned() + let explanation = match issue { + None | Some(0) => explain.to_owned(), + Some(n) => format!("{} (see issue #{})", explain, n) }; let mut err = match level { diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.rs b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs new file mode 100644 index 00000000000..1e0039aba04 --- /dev/null +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.rs @@ -0,0 +1,16 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern crate core; + +// error should not say "(see issue #0)" +#[allow(unused_imports)] use core::ptr::Unique; //~ ERROR use of unstable library feature + +fn main() {} diff --git a/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr new file mode 100644 index 00000000000..986a2d88e00 --- /dev/null +++ b/src/test/ui/feature-gate/issue-49983-see-issue-0.stderr @@ -0,0 +1,11 @@ +error[E0658]: use of unstable library feature 'ptr_internals': use NonNull instead and consider PhantomData (if you also use #[may_dangle]), Send, and/or Sync + --> $DIR/issue-49983-see-issue-0.rs:14:30 + | +LL | #[allow(unused_imports)] use core::ptr::Unique; //~ ERROR use of unstable library feature + | ^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(ptr_internals)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. -- 2.44.0