Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking for missing stability annotations #43270

Merged
merged 1 commit into from
Jul 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,10 @@ mod std {
pub enum Bound<T> {
/// An inclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Included(T),
Included(#[stable(feature = "collections_bound", since = "1.17.0")] T),
/// An exclusive bound.
#[stable(feature = "collections_bound", since = "1.17.0")]
Excluded(T),
Excluded(#[stable(feature = "collections_bound", since = "1.17.0")] T),
/// An infinite endpoint. Indicates that there is no bound in this direction.
#[stable(feature = "collections_bound", since = "1.17.0")]
Unbounded,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,9 @@ struct MissingStabilityAnnotations<'a, 'tcx: 'a> {
impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> {
fn check_missing_stability(&self, id: NodeId, span: Span) {
let def_id = self.tcx.hir.local_def_id(id);
let stab = self.tcx.stability.borrow().stab_map.get(&def_id).cloned();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I doubt this has any serious implications, the cloned here seems unnecessary since AFAICT we never use anything but (one of) the None variants inside. Could we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It clones a reference to Stability, not Stability itself. cloned is necessary to avoid borrow checking error with a short living temporary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so just to clarify this goes from &&T to &T? Unfortunate that it causes borrow checking problems. Perhaps map_or could help?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so just to clarify this goes from &&T to &T?

Yes.

let is_error = !self.tcx.sess.opts.test &&
!self.tcx.stability.borrow().stab_map.contains_key(&def_id) &&
(stab == None || stab == Some(None)) &&
self.access_levels.is_reachable(id);
if is_error {
self.tcx.sess.span_err(span, "This node does not have a stability attribute");
Expand Down Expand Up @@ -420,7 +421,6 @@ impl<'a, 'tcx> Index<'tcx> {
let is_staged_api =
sess.opts.debugging_opts.force_unstable_if_unmarked ||
sess.features.borrow().staged_api;

let mut staged_api = FxHashMap();
staged_api.insert(LOCAL_CRATE, is_staged_api);
Index {
Expand Down
1 change: 0 additions & 1 deletion src/libterm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#![deny(missing_docs)]
#![deny(warnings)]

#![feature(staged_api)]
#![cfg_attr(windows, feature(libc))]
// Handle rustfmt skips
#![feature(custom_attribute)]
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail-fulldeps/explore-issue-38412.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// aux-build:pub_and_stability.rs

#![feature(staged_api)]
#![feature(unused_feature)]

// A big point of this test is that we *declare* `unstable_declared`,
Expand Down
1 change: 0 additions & 1 deletion src/test/compile-fail/lint-forbid-cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

// compile-flags: -F deprecated

#![feature(staged_api)]
#[allow(deprecated)] //~ ERROR allow(deprecated) overruled by outer forbid(deprecated)
fn main() {
}
20 changes: 20 additions & 0 deletions src/test/compile-fail/stability-attribute-issue-43027.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright 2017 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(staged_api)]
#![stable(feature = "test", since = "0")]

#[stable(feature = "test", since = "0")]
pub struct Reverse<T>(pub T); //~ ERROR This node does not have a stability attribute

fn main() {
// Make sure the field is used to fill the stability cache
Reverse(0).0;
}