mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Auto merge of #97304 - Dylan-DPC:rollup-qxrfddc, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #97087 (Clarify slice and Vec iteration order) - #97254 (Remove feature: `crate` visibility modifier) - #97271 (Add regression test for #91949) - #97294 (std::time : fix variable name in the doc) - #97303 (Fix some typos in arg checking algorithm) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
9e2f655863
@ -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,
|
||||
@ -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,
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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) {
|
||||
@ -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");
|
||||
|
@ -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))
|
||||
|
@ -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]`.
|
||||
|
@ -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]`")),
|
||||
|
@ -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 {
|
||||
|
@ -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`
|
||||
|
@ -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;
|
||||
@ -1245,12 +1245,8 @@ 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.
|
||||
@ -1258,17 +1254,6 @@ impl<'a> Parser<'a> {
|
||||
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
|
||||
@ -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`
|
||||
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
@ -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,
|
||||
)
|
||||
|
@ -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> {
|
||||
|
@ -716,6 +716,8 @@ impl<T> [T] {
|
||||
|
||||
/// Returns an iterator over the slice.
|
||||
///
|
||||
/// The iterator yields all items from start to end.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
@ -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
|
||||
///
|
||||
/// ```
|
||||
|
@ -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);
|
||||
/// ```
|
||||
///
|
||||
|
@ -1,20 +0,0 @@
|
||||
# `crate_visibility_modifier`
|
||||
|
||||
The tracking issue for this feature is: [#53120]
|
||||
|
||||
[#53120]: https://github.com/rust-lang/rust/issues/53120
|
||||
|
||||
-----
|
||||
|
||||
The `crate_visibility_modifier` feature allows the `crate` keyword to be used
|
||||
as a visibility modifier synonymous to `pub(crate)`, indicating that a type
|
||||
(function, _&c._) is to be visible to the entire enclosing crate, but not to
|
||||
other crates.
|
||||
|
||||
```rust
|
||||
#![feature(crate_visibility_modifier)]
|
||||
|
||||
crate struct Foo {
|
||||
bar: usize,
|
||||
}
|
||||
```
|
6
src/test/ui/argument-suggestions/issue-97197.rs
Normal file
6
src/test/ui/argument-suggestions/issue-97197.rs
Normal file
@ -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
src/test/ui/argument-suggestions/issue-97197.stderr
Normal file
19
src/test/ui/argument-suggestions/issue-97197.stderr
Normal file
@ -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`.
|
@ -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
|
||||
|
@ -1,8 +0,0 @@
|
||||
crate struct Bender { //~ ERROR `crate` visibility modifier is experimental
|
||||
earth: bool,
|
||||
fire: bool,
|
||||
air: bool,
|
||||
water: bool,
|
||||
}
|
||||
|
||||
fn main() {}
|
@ -1,12 +0,0 @@
|
||||
error[E0658]: `crate` visibility modifier is experimental
|
||||
--> $DIR/feature-gate-crate_visibility_modifier.rs:1:1
|
||||
|
|
||||
LL | crate struct Bender {
|
||||
| ^^^^^
|
||||
|
|
||||
= note: see issue #53120 <https://github.com/rust-lang/rust/issues/53120> for more information
|
||||
= help: add `#![feature(crate_visibility_modifier)]` to the crate attributes to enable
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0658`.
|
@ -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) ");
|
||||
|
30
src/test/ui/traits/issue-91949-hangs-on-recursion.rs
Normal file
30
src/test/ui/traits/issue-91949-hangs-on-recursion.rs
Normal file
@ -0,0 +1,30 @@
|
||||
// build-fail
|
||||
// error-pattern: overflow evaluating the requirement `(): Sized`
|
||||
// error-pattern: function cannot return without recursing
|
||||
|
||||
// Regression test for #91949.
|
||||
// This hanged *forever* on 1.56, fixed by #90423.
|
||||
|
||||
#![recursion_limit = "256"]
|
||||
|
||||
struct Wrapped<T>(T);
|
||||
|
||||
struct IteratorOfWrapped<T, I: Iterator<Item = T>>(I);
|
||||
|
||||
impl<T, I: Iterator<Item = T>> Iterator for IteratorOfWrapped<T, I> {
|
||||
type Item = Wrapped<T>;
|
||||
fn next(&mut self) -> Option<Wrapped<T>> {
|
||||
self.0.next().map(Wrapped)
|
||||
}
|
||||
}
|
||||
|
||||
fn recurse<T>(elements: T) -> Vec<char>
|
||||
where
|
||||
T: Iterator<Item = ()>,
|
||||
{
|
||||
recurse(IteratorOfWrapped(elements).map(|t| t.0))
|
||||
}
|
||||
|
||||
fn main() {
|
||||
recurse(std::iter::empty());
|
||||
}
|
25
src/test/ui/traits/issue-91949-hangs-on-recursion.stderr
Normal file
25
src/test/ui/traits/issue-91949-hangs-on-recursion.stderr
Normal file
File diff suppressed because one or more lines are too long
@ -545,7 +545,7 @@ pub fn eq_defaultness(l: Defaultness, r: Defaultness) -> bool {
|
||||
pub fn eq_vis(l: &Visibility, r: &Visibility) -> bool {
|
||||
use VisibilityKind::*;
|
||||
match (&l.kind, &r.kind) {
|
||||
(Public, Public) | (Inherited, Inherited) | (Crate(_), Crate(_)) => true,
|
||||
(Public, Public) | (Inherited, Inherited) => true,
|
||||
(Restricted { path: l, .. }, Restricted { path: r, .. }) => eq_path(l, r),
|
||||
_ => false,
|
||||
}
|
||||
|
@ -1361,7 +1361,7 @@ pub(crate) fn format_struct_struct(
|
||||
|
||||
fn get_bytepos_after_visibility(vis: &ast::Visibility, default_span: Span) -> BytePos {
|
||||
match vis.kind {
|
||||
ast::VisibilityKind::Crate(..) | ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
|
||||
ast::VisibilityKind::Restricted { .. } => vis.span.hi(),
|
||||
_ => default_span.lo(),
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std::borrow::Cow;
|
||||
|
||||
use rustc_ast::ast::{
|
||||
self, Attribute, CrateSugar, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||
self, Attribute, MetaItem, MetaItemKind, NestedMetaItem, NodeId, Path, Visibility,
|
||||
VisibilityKind,
|
||||
};
|
||||
use rustc_ast::ptr;
|
||||
@ -44,15 +44,7 @@ pub(crate) fn is_same_visibility(a: &Visibility, b: &Visibility) -> bool {
|
||||
VisibilityKind::Restricted { path: q, .. },
|
||||
) => pprust::path_to_string(p) == pprust::path_to_string(q),
|
||||
(VisibilityKind::Public, VisibilityKind::Public)
|
||||
| (VisibilityKind::Inherited, VisibilityKind::Inherited)
|
||||
| (
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate),
|
||||
)
|
||||
| (
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate),
|
||||
) => true,
|
||||
| (VisibilityKind::Inherited, VisibilityKind::Inherited) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
@ -65,8 +57,6 @@ pub(crate) fn format_visibility(
|
||||
match vis.kind {
|
||||
VisibilityKind::Public => Cow::from("pub "),
|
||||
VisibilityKind::Inherited => Cow::from(""),
|
||||
VisibilityKind::Crate(CrateSugar::PubCrate) => Cow::from("pub(crate) "),
|
||||
VisibilityKind::Crate(CrateSugar::JustCrate) => Cow::from("crate "),
|
||||
VisibilityKind::Restricted { ref path, .. } => {
|
||||
let Path { ref segments, .. } = **path;
|
||||
let mut segments_iter = segments.iter().map(|seg| rewrite_ident(context, seg.ident));
|
||||
@ -75,7 +65,7 @@ pub(crate) fn format_visibility(
|
||||
.next()
|
||||
.expect("Non-global path in pub(restricted)?");
|
||||
}
|
||||
let is_keyword = |s: &str| s == "self" || s == "super";
|
||||
let is_keyword = |s: &str| s == "crate" || s == "self" || s == "super";
|
||||
let path = segments_iter.collect::<Vec<_>>().join("::");
|
||||
let in_str = if is_keyword(&path) { "" } else { "in " };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user