Change:
<!-- Thank you for filing a regression report! A regression is something that changed between versions of Rust but was not supposed to. Please provide a short summary of the regression, along with any information you feel is relevant to replicate it. --I tried this code: I expected to see this happen: it to print . Instead, this happened: it prints . <!-- Provide the most recent version this worked on, for example: It most recently worked on: Rust 1.47 --It most recently worked on: 1.62.1 <!-- Provide the version you are using that has the regression. --: <!-- Did the compiler crash? If so, please provide a backtrace. --<!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summaryBacktrace</summary<p</p</details<!-- If you know when this regression occurred, please add a line like below, replacing with one of stable, beta, or nightly. modify labels: +regression-from-stable-to-beta -regression-untriaged -- modify labels: +regression-from-stable-to-beta -regression-untriaged
Similar effect can already be observed on stable too prints already. But it is indeed a (small?) behavior change in this beta for the case.
I would expect to see this issue in 2020, but not now when we are collecting tokens in (almost) all cases instead of converting them from AST. Apparently for visibilities they are collected incorrectly for some reason. cc (in case you have time for this)
bisection points to searched nightlies: from nightly-2022-01-01 to nightly-2022-08-03 regressed nightly: nightly-2022-05-24 searched commit range: regressed commit: <details<summarybisected with <a href=''cargo-bisect-rustc</av0.6.3</summaryHost triple: x8664-unknown-linux-gnu Reproduce with: </detailsThe commit is a rollup so I think_ it's in cc ?
Without even looking at the rest of the rollup, it's definitely my PR. Short of storing whether was used, I'm not sure what could be done.
This will slip into 1.63.
I'll work on this this evening to get it resolved quickly, even if it is too late to patch the beta. I don't think it'll be too difficult.
PR is up: . This also fixes to be , which is certainly better than the status quo of .

Discussion:
#[derive(Clone, Encodable, Decodable, Debug)] pub enum VisibilityKind { Public, <del> Restricted { path: P<Path>, id: NodeId }, </del> <ins> Restricted { path: P<Path>, id: NodeId, shorthand: bool }, </ins> Inherited, }

pub fn noop_visit_vis<T: MutVisitor>(visibility: &mut Visibility, vis: &mut T) { match &mut visibility.kind { VisibilityKind::Public | VisibilityKind::Inherited => {} <del> VisibilityKind::Restricted { path, id } => { </del> <ins> VisibilityKind::Restricted { path, id, shorthand: _ } => { </ins> vis.visit_path(path); vis.visit_id(id); }

} pub fn walk_vis<'a, V: Visitor<'a>>(visitor: &mut V, vis: &'a Visibility) { <del> if let VisibilityKind::Restricted { ref path, id } = vis.kind { </del> <ins> if let VisibilityKind::Restricted { ref path, id, shorthand: _ } = vis.kind { </ins> visitor.visit_path(path, id); } }

pub(crate) fn print_visibility(&mut self, vis: &ast::Visibility) { match vis.kind { ast::VisibilityKind::Public => self.word_nbsp("pub"), <del> ast::VisibilityKind::Restricted { ref path, .. } => { </del> <ins> ast::VisibilityKind::Restricted { ref path, id: _, shorthand } => { </ins> let path = Self::to_string(|s| s.print_path(path, false, 0)); <del> if path == "crate" || path == "self" || path == "super" { </del> <ins> if shorthand && (path == "crate" || path == "self" || path == "super") { </ins> self.word_nbsp(format!("pub({})", path)) } else { self.word_nbsp(format!("pub(in {})", path))

self.bump(); // `in` let path = self.parse_path(PathStyle::Mod)?; // `path` self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)` <del> let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID }; </del> <ins> let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID, shorthand: false, }; </ins> return Ok(Visibility { span: lo.to(self.prev_token.span), kind: vis,

self.bump(); // `(` let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self` self.expect(&token::CloseDelim(Delimiter::Parenthesis))?; // `)` <del> let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID }; </del> <ins> let vis = VisibilityKind::Restricted { path: P(path), id: ast::DUMMY_NODE_ID, shorthand: true, }; </ins> return Ok(Visibility { span: lo.to(self.prev_token.span), kind: vis,

assert_eq!(stringify_vis!(pub(crate)), "pub(crate) "); assert_eq!(stringify_vis!(pub(self)), "pub(self) "); assert_eq!(stringify_vis!(pub(super)), "pub(super) "); <del> assert_eq!(stringify_vis!(pub(in self)), "pub(self) "); assert_eq!(stringify_vis!(pub(in super)), "pub(super) "); </del> <ins> assert_eq!(stringify_vis!(pub(in crate)), "pub(in crate) "); assert_eq!(stringify_vis!(pub(in self)), "pub(in self) "); assert_eq!(stringify_vis!(pub(in super)), "pub(in super) "); </ins> assert_eq!(stringify_vis!(pub(in path::to)), "pub(in path::to) "); assert_eq!(stringify_vis!(pub(in ::path::to)), "pub(in ::path::to) "); assert_eq!(stringify_vis!(pub(in self::path::to)), "pub(in self::path::to) ");