Skip to content

Commit 9e2f655

Browse files
committedMay 23, 2022
Auto merge of rust-lang#97304 - Dylan-DPC:rollup-qxrfddc, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#97087 (Clarify slice and Vec iteration order) - rust-lang#97254 (Remove feature: `crate` visibility modifier) - rust-lang#97271 (Add regression test for rust-lang#91949) - rust-lang#97294 (std::time : fix variable name in the doc) - rust-lang#97303 (Fix some typos in arg checking algorithm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 03c8b0b + b5ff4ad commit 9e2f655

File tree

26 files changed

+118
-148
lines changed

26 files changed

+118
-148
lines changed
 

‎compiler/rustc_ast/src/ast.rs

-10
Original file line numberDiff line numberDiff line change
@@ -2552,15 +2552,6 @@ impl PolyTraitRef {
25522552
}
25532553
}
25542554

2555-
#[derive(Copy, Clone, Encodable, Decodable, Debug, HashStable_Generic)]
2556-
pub enum CrateSugar {
2557-
/// Source is `pub(crate)`.
2558-
PubCrate,
2559-
2560-
/// Source is (just) `crate`.
2561-
JustCrate,
2562-
}
2563-
25642555
#[derive(Clone, Encodable, Decodable, Debug)]
25652556
pub struct Visibility {
25662557
pub kind: VisibilityKind,
@@ -2571,7 +2562,6 @@ pub struct Visibility {
25712562
#[derive(Clone, Encodable, Decodable, Debug)]
25722563
pub enum VisibilityKind {
25732564
Public,
2574-
Crate(CrateSugar),
25752565
Restricted { path: P<Path>, id: NodeId },
25762566
Inherited,
25772567
}

‎compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1469,7 +1469,7 @@ pub fn noop_flat_map_stmt_kind<T: MutVisitor>(
14691469

14701470
pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) {
14711471
match &mut visibility.kind {
1472-
VisibilityKind::Public | VisibilityKind::Crate(_) | VisibilityKind::Inherited => {}
1472+
VisibilityKind::Public | VisibilityKind::Inherited => {}
14731473
VisibilityKind::Restricted { path, id } => {
14741474
vis.visit_path(path);
14751475
vis.visit_id(id);

‎compiler/rustc_ast_passes/src/feature_gate.rs

-13
Original file line numberDiff line numberDiff line change
@@ -697,18 +697,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
697697
}
698698
visit::walk_assoc_item(self, i, ctxt)
699699
}
700-
701-
fn visit_vis(&mut self, vis: &'a ast::Visibility) {
702-
if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.kind {
703-
gate_feature_post!(
704-
&self,
705-
crate_visibility_modifier,
706-
vis.span,
707-
"`crate` visibility modifier is experimental"
708-
);
709-
}
710-
visit::walk_vis(self, vis)
711-
}
712700
}
713701

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

771759
gate_all!(trait_alias, "trait aliases are experimental");
772760
gate_all!(associated_type_bounds, "associated type bounds are unstable");
773-
gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
774761
gate_all!(decl_macro, "`macro` is experimental");
775762
gate_all!(box_patterns, "box pattern syntax is experimental");
776763
gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");

‎compiler/rustc_ast_pretty/src/pprust/state/item.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -403,13 +403,9 @@ impl<'a> State<'a> {
403403
pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) {
404404
match vis.kind {
405405
ast::VisibilityKind::Public => self.word_nbsp("pub"),
406-
ast::VisibilityKind::Crate(sugar) => match sugar {
407-
ast::CrateSugar::PubCrate => self.word_nbsp("pub(crate)"),
408-
ast::CrateSugar::JustCrate => self.word_nbsp("crate"),
409-
},
410406
ast::VisibilityKind::Restricted { ref path, .. } => {
411407
let path = Self::to_string(|s| s.print_path(path, false, 0));
412-
if path == "self" || path == "super" {
408+
if path == "crate" || path == "self" || path == "super" {
413409
self.word_nbsp(format!("pub({})", path))
414410
} else {
415411
self.word_nbsp(format!("pub(in {})", path))

‎compiler/rustc_feature/src/active.rs

-2
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,6 @@ declare_features! (
351351
(active, const_trait_impl, "1.42.0", Some(67792), None),
352352
/// Allows the `?` operator in const contexts.
353353
(active, const_try, "1.56.0", Some(74935), None),
354-
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
355-
(active, crate_visibility_modifier, "1.23.0", Some(53120), None),
356354
/// Allows non-builtin attributes in inner attribute position.
357355
(active, custom_inner_attributes, "1.30.0", Some(54726), None),
358356
/// Allows custom test frameworks with `#![test_runner]` and `#[test_case]`.

‎compiler/rustc_feature/src/removed.rs

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ declare_features! (
7272
/// Allows `T: ?const Trait` syntax in bounds.
7373
(removed, const_trait_bound_opt_out, "1.42.0", Some(67794), None,
7474
Some("Removed in favor of `~const` bound in #![feature(const_trait_impl)]")),
75+
/// Allows using `crate` as visibility modifier, synonymous with `pub(crate)`.
76+
(removed, crate_visibility_modifier, "1.63.0", Some(53120), None, Some("removed in favor of `pub(crate)`")),
7577
/// Allows using custom attributes (RFC 572).
7678
(removed, custom_attribute, "1.0.0", Some(29642), None,
7779
Some("removed in favor of `#![register_tool]` and `#![register_attr]`")),

‎compiler/rustc_lint/src/builtin.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1372,17 +1372,11 @@ impl UnreachablePub {
13721372
let def_span = cx.tcx.sess.source_map().guess_head_span(span);
13731373
cx.struct_span_lint(UNREACHABLE_PUB, def_span, |lint| {
13741374
let mut err = lint.build(&format!("unreachable `pub` {}", what));
1375-
let replacement = if cx.tcx.features().crate_visibility_modifier {
1376-
"crate"
1377-
} else {
1378-
"pub(crate)"
1379-
}
1380-
.to_owned();
13811375

13821376
err.span_suggestion(
13831377
vis_span,
13841378
"consider restricting its visibility",
1385-
replacement,
1379+
"pub(crate)".to_owned(),
13861380
applicability,
13871381
);
13881382
if exportable {

‎compiler/rustc_parse/src/parser/item.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ impl<'a> Parser<'a> {
302302

303303
/// When parsing a statement, would the start of a path be an item?
304304
pub(super) fn is_path_start_item(&mut self) -> bool {
305-
self.is_crate_vis() // no: `crate::b`, yes: `crate $item`
306-
|| self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
305+
self.is_kw_followed_by_ident(kw::Union) // no: `union::b`, yes: `union U { .. }`
307306
|| self.check_auto_or_unsafe_trait_item() // no: `auto::b`, yes: `auto trait X { .. }`
308307
|| self.is_async_fn() // no(2015): `async::b`, yes: `async fn`
309308
|| matches!(self.is_macro_rules_item(), IsMacroRulesItem::Yes{..}) // no: `macro_rules::b`, yes: `macro_rules! mac`

‎compiler/rustc_parse/src/parser/mod.rs

+7-35
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
2525
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2626
use rustc_ast::AttrId;
2727
use rustc_ast::DUMMY_NODE_ID;
28-
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern};
28+
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, Extern};
2929
use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacArgsEq, MacDelimiter, Mutability, StrLit};
3030
use rustc_ast::{HasAttrs, HasTokens, Unsafe, Visibility, VisibilityKind};
3131
use rustc_ast_pretty::pprust;
@@ -1245,30 +1245,15 @@ impl<'a> Parser<'a> {
12451245
res
12461246
}
12471247

1248-
fn is_crate_vis(&self) -> bool {
1249-
self.token.is_keyword(kw::Crate) && self.look_ahead(1, |t| t != &token::ModSep)
1250-
}
1251-
1252-
/// Parses `pub`, `pub(crate)` and `pub(in path)` plus shortcuts `crate` for `pub(crate)`,
1253-
/// `pub(self)` for `pub(in self)` and `pub(super)` for `pub(in super)`.
1248+
/// Parses `pub` and `pub(in path)` plus shortcuts `pub(crate)` for `pub(in crate)`, `pub(self)`
1249+
/// for `pub(in self)` and `pub(super)` for `pub(in super)`.
12541250
/// If the following element can't be a tuple (i.e., it's a function definition), then
12551251
/// it's not a tuple struct field), and the contents within the parentheses aren't valid,
12561252
/// so emit a proper diagnostic.
12571253
// Public for rustfmt usage.
12581254
pub fn parse_visibility(&mut self, fbt: FollowedByType) -> PResult<'a, Visibility> {
12591255
maybe_whole!(self, NtVis, |x| x.into_inner());
12601256

1261-
self.expected_tokens.push(TokenType::Keyword(kw::Crate));
1262-
if self.is_crate_vis() {
1263-
self.bump(); // `crate`
1264-
self.sess.gated_spans.gate(sym::crate_visibility_modifier, self.prev_token.span);
1265-
return Ok(Visibility {
1266-
span: self.prev_token.span,
1267-
kind: VisibilityKind::Crate(CrateSugar::JustCrate),
1268-
tokens: None,
1269-
});
1270-
}
1271-
12721257
if !self.eat_keyword(kw::Pub) {
12731258
// We need a span for our `Spanned<VisibilityKind>`, but there's inherently no
12741259
// keyword to grab a span from for inherited visibility; an empty span at the
@@ -1286,20 +1271,7 @@ impl<'a> Parser<'a> {
12861271
// `()` or a tuple might be allowed. For example, `struct Struct(pub (), pub (usize));`.
12871272
// Because of this, we only `bump` the `(` if we're assured it is appropriate to do so
12881273
// by the following tokens.
1289-
if self.is_keyword_ahead(1, &[kw::Crate]) && self.look_ahead(2, |t| t != &token::ModSep)
1290-
// account for `pub(crate::foo)`
1291-
{
1292-
// Parse `pub(crate)`.
1293-
self.bump(); // `(`
1294-
self.bump(); // `crate`
1295-
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
1296-
let vis = VisibilityKind::Crate(CrateSugar::PubCrate);
1297-
return Ok(Visibility {
1298-
span: lo.to(self.prev_token.span),
1299-
kind: vis,
1300-
tokens: None,
1301-
});
1302-
} else if self.is_keyword_ahead(1, &[kw::In]) {
1274+
if self.is_keyword_ahead(1, &[kw::In]) {
13031275
// Parse `pub(in path)`.
13041276
self.bump(); // `(`
13051277
self.bump(); // `in`
@@ -1312,11 +1284,11 @@ impl<'a> Parser<'a> {
13121284
tokens: None,
13131285
});
13141286
} else if self.look_ahead(2, |t| t == &token::CloseDelim(Delimiter::Parenthesis))
1315-
&& self.is_keyword_ahead(1, &[kw::Super, kw::SelfLower])
1287+
&& self.is_keyword_ahead(1, &[kw::Crate, kw::Super, kw::SelfLower])
13161288
{
1317-
// Parse `pub(self)` or `pub(super)`.
1289+
// Parse `pub(crate)`, `pub(self)`, or `pub(super)`.
13181290
self.bump(); // `(`
1319-
let path = self.parse_path(PathStyle::Mod)?; // `super`/`self`
1291+
let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self`
13201292
self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)`
13211293
let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID };
13221294
return Ok(Visibility {

‎compiler/rustc_resolve/src/build_reduced_graph.rs

-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
249249
let parent_scope = &self.parent_scope;
250250
match vis.kind {
251251
ast::VisibilityKind::Public => Ok(ty::Visibility::Public),
252-
ast::VisibilityKind::Crate(..) => {
253-
Ok(ty::Visibility::Restricted(CRATE_DEF_ID.to_def_id()))
254-
}
255252
ast::VisibilityKind::Inherited => {
256253
Ok(match self.parent_scope.module.kind {
257254
// Any inherited visibility resolved directly inside an enum or trait

‎compiler/rustc_typeck/src/check/fn_ctxt/checks.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
768768
let second_input_ty =
769769
self.resolve_vars_if_possible(expected_input_tys[second_idx]);
770770
let third_input_ty =
771-
self.resolve_vars_if_possible(expected_input_tys[second_idx]);
771+
self.resolve_vars_if_possible(expected_input_tys[third_idx]);
772772
let span = if third_idx < provided_arg_count {
773773
let first_arg_span = provided_args[first_idx].span;
774774
let third_arg_span = provided_args[third_idx].span;
@@ -809,16 +809,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
809809
}
810810
missing_idxs => {
811811
let first_idx = *missing_idxs.first().unwrap();
812-
let second_idx = *missing_idxs.last().unwrap();
812+
let last_idx = *missing_idxs.last().unwrap();
813813
// NOTE: Because we might be re-arranging arguments, might have extra arguments, etc.
814814
// It's hard to *really* know where we should provide this error label, so this is a
815815
// decent heuristic
816-
let span = if first_idx < provided_arg_count {
816+
let span = if last_idx < provided_arg_count {
817817
let first_arg_span = provided_args[first_idx].span;
818-
let second_arg_span = provided_args[second_idx].span;
818+
let last_arg_span = provided_args[last_idx].span;
819819
Span::new(
820820
first_arg_span.lo(),
821-
second_arg_span.hi(),
821+
last_arg_span.hi(),
822822
first_arg_span.ctxt(),
823823
None,
824824
)

‎library/alloc/src/vec/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2626,10 +2626,13 @@ impl<T, A: Allocator> IntoIterator for Vec<T, A> {
26262626
///
26272627
/// ```
26282628
/// let v = vec!["a".to_string(), "b".to_string()];
2629-
/// for s in v.into_iter() {
2630-
/// // s has type String, not &String
2631-
/// println!("{s}");
2632-
/// }
2629+
/// let mut v_iter = v.into_iter();
2630+
///
2631+
/// let first_element: Option<String> = v_iter.next();
2632+
///
2633+
/// assert_eq!(first_element, Some("a".to_string()));
2634+
/// assert_eq!(v_iter.next(), Some("b".to_string()));
2635+
/// assert_eq!(v_iter.next(), None);
26332636
/// ```
26342637
#[inline]
26352638
fn into_iter(self) -> IntoIter<T, A> {

‎library/core/src/slice/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,8 @@ impl<T> [T] {
716716

717717
/// Returns an iterator over the slice.
718718
///
719+
/// The iterator yields all items from start to end.
720+
///
719721
/// # Examples
720722
///
721723
/// ```
@@ -735,6 +737,8 @@ impl<T> [T] {
735737

736738
/// Returns an iterator that allows modifying each value.
737739
///
740+
/// The iterator yields all items from start to end.
741+
///
738742
/// # Examples
739743
///
740744
/// ```

‎library/std/src/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ pub use core::time::FromFloatSecsError;
9595
/// use std::time::{Instant, Duration};
9696
///
9797
/// let now = Instant::now();
98-
/// let max_nanoseconds = u64::MAX / 1_000_000_000;
99-
/// let duration = Duration::new(max_nanoseconds, 0);
98+
/// let max_seconds = u64::MAX / 1_000_000_000;
99+
/// let duration = Duration::new(max_seconds, 0);
100100
/// println!("{:?}", now + duration);
101101
/// ```
102102
///

‎src/doc/unstable-book/src/language-features/crate-visibility-modifier.md

-20
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
g((), ());
3+
//~^ ERROR this function takes 6 arguments but 2 arguments were supplied
4+
}
5+
6+
pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0061]: this function takes 6 arguments but 2 arguments were supplied
2+
--> $DIR/issue-97197.rs:2:5
3+
|
4+
LL | g((), ());
5+
| ^-------- multiple arguments are missing
6+
|
7+
note: function defined here
8+
--> $DIR/issue-97197.rs:6:8
9+
|
10+
LL | pub fn g(a1: (), a2: bool, a3: bool, a4: bool, a5: bool, a6: ()) -> () {}
11+
| ^ ------ -------- -------- -------- -------- ------
12+
help: provide the arguments
13+
|
14+
LL | g((), {bool}, {bool}, {bool}, {bool}, ());
15+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0061`.

‎src/test/ui/argument-suggestions/missing_arguments.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ error[E0061]: this function takes 5 arguments but 2 arguments were supplied
293293
--> $DIR/missing_arguments.rs:39:3
294294
|
295295
LL | complex( 1, "" );
296-
| ^^^^^^^--------------------------------- three arguments of type `f32`, `i32`, and `i32` are missing
296+
| ^^^^^^^--------------------------------- three arguments of type `f32`, `i32`, and `f32` are missing
297297
|
298298
note: function defined here
299299
--> $DIR/missing_arguments.rs:7:4

‎src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.rs

-8
This file was deleted.

‎src/test/ui/feature-gates/feature-gate-crate_visibility_modifier.stderr

-12
This file was deleted.

‎src/test/ui/macros/stringify.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -861,10 +861,8 @@ fn test_vis() {
861861
// VisibilityKind::Public
862862
assert_eq!(stringify_vis!(pub), "pub ");
863863

864-
// VisibilityKind::Crate
865-
assert_eq!(stringify_vis!(crate), "crate ");
866-
867864
// VisibilityKind::Restricted
865+
assert_eq!(stringify_vis!(pub(crate)), "pub(crate) ");
868866
assert_eq!(stringify_vis!(pub(self)), "pub(self) ");
869867
assert_eq!(stringify_vis!(pub(super)), "pub(super) ");
870868
assert_eq!(stringify_vis!(pub(in self)), "pub(self) ");

0 commit comments

Comments
 (0)
Please sign in to comment.