Skip to content

Rollup of 5 pull requests #97304

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

Merged
merged 11 commits into from
May 23, 2022
10 changes: 0 additions & 10 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2552,15 +2552,6 @@ impl PolyTraitRef {
}
}

#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)]
pub enum CrateSugar {
/// Source is `pub(crate)`.
PubCrate,

/// Source is (just) `crate`.
JustCrate,
}

#[derive(Clone, Encodable, Decodable, Debug)]
pub struct Visibility {
pub kind: VisibilityKind,
Expand All @@ -2571,7 +2562,6 @@ pub struct Visibility {
#[derive(Clone, Encodable, Decodable, Debug)]
pub enum VisibilityKind {
Public,
Crate(CrateSugar),
Restricted { path: P<Path>, id: NodeId },
Inherited,
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(

pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
match &mut visibility.kind {
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
VisibilityKind::Public | VisibilityKind::Inherited => {}
VisibilityKind::Restricted { path, id } => {
vis.visit_path(path);
vis.visit_id(id);
Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -697,18 +697,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
visit::walk_assoc_item(self, i, ctxt)
}

fn visit_vis(&mut self, vis: &'a ast::Visibility) {
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.kind {
gate_feature_post!(
&self,
crate_visibility_modifier,
vis.span,
"`crate` visibility modifier is experimental"
);
}
visit::walk_vis(self, vis)
}
}

pub fn check_crate(krate: &ast::Crate, sess: &Session) {
Expand Down Expand Up @@ -770,7 +758,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {

gate_all!(trait_alias, "trait aliases are experimental");
gate_all!(associated_type_bounds, "associated type bounds are unstable");
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
gate_all!(decl_macro, "`macro` is experimental");
gate_all!(box_patterns, "box pattern syntax is experimental");
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,9 @@ impl<'a> State<'a> {
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
match vis.kind {
ast::VisibilityKind::Public => self.word_nbsp("pub"),
ast::VisibilityKind::Crate(sugar) => match sugar {
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
},
ast::VisibilityKind::Restricted { ref path, .. } => {
let path = Self::to_string(|s| s.print_path(path, false, 0));
if path == "self" || path == "super" {
if path == "crate" || path == "self" || path == "super" {
self.word_nbsp(format!("pub({})", path))
} else {
self.word_nbsp(format!("pub(in {})", path))
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,6 @@ declare_features! (
(active, const_trait_impl, "1.42.0", Some(67792), None),
/// Allows the `?` operator in const contexts.
(active, const_try, "1.56.0", Some(74935), None),
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
(active, crate_visibility_modifier, "1.23.0", Some(53120), None),
/// Allows non-builtin attributes in inner attribute position.
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ declare_features! (
/// Allows `T: ?const Trait` syntax in bounds.
(removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None,
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")),
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
(removed, crate_visibility_modifier, "1.63.0", Some(53120), None, Some("removed in favor of `pub(crate)`")),
/// Allows using custom attributes (RFC 572).
(removed, custom_attribute, "1.0.0", Some(29642), None,
Some("removed in favor of `#![register_tool]` and `#![register_attr]`")),
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_lint/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1372,17 +1372,11 @@ impl UnreachablePub {
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
let mut err = lint.build(&format!("unreachable `pub` {}", what));
let replacement = if cx.tcx.features().crate_visibility_modifier {
"crate"
} else {
"pub(crate)"
}
.to_owned();

err.span_suggestion(
vis_span,
"consider restricting its visibility",
replacement,
"pub(crate)".to_owned(),
applicability,
);
if exportable {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,7 @@ impl<'a> Parser<'a> {

/// When parsing a statement, would the start of a path be an item?
pub(super) fn is_path_start_item(&mut self) -> bool {
self.is_crate_vis() // no: `crate::b`, yes: `crate $item`
|| self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
|| self.check_auto_or_unsafe_trait_item() // no: `auto::b`, yes: `auto trait X { .. }`
|| self.is_async_fn() // no(2015): `async::b`, yes: `async fn`
|| matches!(self.is_macro_rules_item(), IsMacroRulesItem::Yes{..}) // no: `macro_rules::b`, yes: `macro_rules! mac`
Expand Down
42 changes: 7 additions & 35 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
use rustc_ast::tokenstream::{TokenStream, TokenTree};
use rustc_ast::AttrId;
use rustc_ast::DUMMY_NODE_ID;
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern};
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, Extern};
use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacArgsEq, MacDelimiter, Mutability, StrLit};
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
use rustc_ast_pretty::pprust;
Expand Down Expand Up @@ -1245,30 +1245,15 @@ impl<'a> Parser<'a> {
res
}

fn is_crate_vis(&self) -> bool {
self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
}

/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
/// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in crate)`, `pub(self)`
/// for `pub(in self)` and `pub(super)` for `pub(in super)`.
/// If the following element can't be a tuple (i.e., it's a function definition), then
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
/// so emit a proper diagnostic.
// Public for rustfmt usage.
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
maybe_whole!(self, NtVis, |x| x.into_inner());

self.expected_tokens.push(TokenType::Keyword(kw::Crate));
if self.is_crate_vis() {
self.bump(); // `crate`
self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_token.span);
return Ok(Visibility {
span: self.prev_token.span,
kind: VisibilityKind::Crate(CrateSugar::JustCrate),
tokens: None,
});
}

if !self.eat_keyword(kw::Pub) {
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
// keyword to grab a span from for inherited visibility; an empty span at the
Expand All @@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
// by the following tokens.
if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep)
// account for `pub(crate::foo)`
{
// Parse `pub(crate)`.
self.bump(); // `(`
self.bump(); // `crate`
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
let vis = VisibilityKind::Crate(CrateSugar::PubCrate);
return Ok(Visibility {
span: lo.to(self.prev_token.span),
kind: vis,
tokens: None,
});
} else if self.is_keyword_ahead(1, &[kw::In]) {
if self.is_keyword_ahead(1, &[kw::In]) {
// Parse `pub(in path)`.
self.bump(); // `(`
self.bump(); // `in`
Expand All @@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
tokens: None,
});
} else if self.look_ahead(2, |t| t == &token::CloseDelim(Delimiter::Parenthesis))
&& self.is_keyword_ahead(1, &[kw::Super, kw::SelfLower])
&& self.is_keyword_ahead(1, &[kw::Crate, kw::Super, kw::SelfLower])
{
// Parse `pub(self)` or `pub(super)`.
// Parse `pub(crate)`, `pub(self)`, or `pub(super)`.
self.bump(); // `(`
let path = self.parse_path(PathStyle::Mod)?; // `super`/`self`
let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self`
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
return Ok(Visibility {
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let parent_scope = &self.parent_scope;
match vis.kind {
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
ast::VisibilityKind::Crate(..) => {
Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))
}
ast::VisibilityKind::Inherited => {
Ok(match self.parent_scope.module.kind {
// Any inherited visibility resolved directly inside an enum or trait
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_typeck/src/check/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let second_input_ty =
self.resolve_vars_if_possible(expected_input_tys[second_idx]);
let third_input_ty =
self.resolve_vars_if_possible(expected_input_tys[second_idx]);
self.resolve_vars_if_possible(expected_input_tys[third_idx]);
let span = if third_idx < provided_arg_count {
let first_arg_span = provided_args[first_idx].span;
let third_arg_span = provided_args[third_idx].span;
Expand Down Expand Up @@ -809,16 +809,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
missing_idxs => {
let first_idx = *missing_idxs.first().unwrap();
let second_idx = *missing_idxs.last().unwrap();
let last_idx = *missing_idxs.last().unwrap();
// NOTE: Because we might be re-arranging arguments, might have extra arguments, etc.
// It's hard to *really* know where we should provide this error label, so this is a
// decent heuristic
let span = if first_idx < provided_arg_count {
let span = if last_idx < provided_arg_count {
let first_arg_span = provided_args[first_idx].span;
let second_arg_span = provided_args[second_idx].span;
let last_arg_span = provided_args[last_idx].span;
Span::new(
first_arg_span.lo(),
second_arg_span.hi(),
last_arg_span.hi(),
first_arg_span.ctxt(),
None,
)
Expand Down
11 changes: 7 additions & 4 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2626,10 +2626,13 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> {
///
/// ```
/// let v = vec!["a".to_string(), "b".to_string()];
/// for s in v.into_iter() {
/// // s has type String, not &String
/// println!("{s}");
/// }
/// let mut v_iter = v.into_iter();
///
/// let first_element: Option<String> = v_iter.next();
///
/// assert_eq!(first_element, Some("a".to_string()));
/// assert_eq!(v_iter.next(), Some("b".to_string()));
/// assert_eq!(v_iter.next(), None);
/// ```
#[inline]
fn into_iter(self) -> IntoIter<T, A> {
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,8 @@ impl<T> [T] {

/// Returns an iterator over the slice.
///
/// The iterator yields all items from start to end.
///
/// # Examples
///
/// ```
Expand All @@ -735,6 +737,8 @@ impl<T> [T] {

/// Returns an iterator that allows modifying each value.
///
/// The iterator yields all items from start to end.
///
/// # Examples
///
/// ```
Expand Down
4 changes: 2 additions & 2 deletions library/std/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ pub use core::time::FromFloatSecsError;
/// use std::time::{Instant, Duration};
///
/// let now = Instant::now();
/// let max_nanoseconds = u64::MAX / 1_000_000_000;
/// let duration = Duration::new(max_nanoseconds, 0);
/// let max_seconds = u64::MAX / 1_000_000_000;
/// let duration = Duration::new(max_seconds, 0);
/// println!("{:?}", now + duration);
/// ```
///
Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions src/test/ui/argument-suggestions/issue-97197.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn main() {
g((), ());
//~^ ERROR this function takes 6 arguments but 2 arguments were supplied
}

pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
19 changes: 19 additions & 0 deletions src/test/ui/argument-suggestions/issue-97197.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error[E0061]: this function takes 6 arguments but 2 arguments were supplied
--> $DIR/issue-97197.rs:2:5
|
LL | g((), ());
| ^-------- multiple arguments are missing
|
note: function defined here
--> $DIR/issue-97197.rs:6:8
|
LL | pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
| ^ ------ -------- -------- -------- -------- ------
help: provide the arguments
|
LL | g((), {bool}, {bool}, {bool}, {bool}, ());
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

error: aborting due to previous error

For more information about this error, try `rustc --explain E0061`.
2 changes: 1 addition & 1 deletion src/test/ui/argument-suggestions/missing_arguments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ error[E0061]: this function takes 5 arguments but 2 arguments were supplied
--> $DIR/missing_arguments.rs:39:3
|
LL | complex( 1, "" );
| ^^^^^^^--------------------------------- three arguments of type `f32`, `i32`, and `i32` are missing
| ^^^^^^^--------------------------------- three arguments of type `f32`, `i32`, and `f32` are missing
|
note: function defined here
--> $DIR/missing_arguments.rs:7:4
Expand Down

This file was deleted.

This file was deleted.

4 changes: 1 addition & 3 deletions src/test/ui/macros/stringify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,10 +861,8 @@ fn test_vis() {
// VisibilityKind::Public
assert_eq!(stringify_vis!(pub), "pub ");

// VisibilityKind::Crate
assert_eq!(stringify_vis!(crate), "crate ");

// VisibilityKind::Restricted
assert_eq!(stringify_vis!(pub(crate)), "pub(crate) ");
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");
Expand Down
Loading