Skip to content

Commit

Permalink
Auto merge of #122763 - matthiaskrgr:rollup-o8a2mye, r=matthiaskrgr
Browse files Browse the repository at this point in the history
Rollup of 6 pull requests

Successful merges:

 - #121543 (various clippy fixes)
 - #122540 (Do not use `?`-induced skewing of type inference in the compiler)
 - #122730 (Expose `ucred::peer_cred` on QNX targets to enable dist builds)
 - #122732 (Remove redundant coroutine captures note)
 - #122739 (Add "put" as a confusable for insert on hash map/set)
 - #122748 (Reduce `pub` usage in `rustc_session`.)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 20, 2024
2 parents b7dcabe + 53a753e commit 0f706af
Show file tree
Hide file tree
Showing 38 changed files with 335 additions and 264 deletions.
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::sync::Lrc;
use rustc_macros::HashStable_Generic;
use rustc_span::symbol::{kw, sym};
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
#[allow(hidden_glob_reexports)]
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ pub fn parse_asm_args<'a>(
args.templates.push(template);
continue;
} else {
return p.unexpected();
p.unexpected_any()?
};

allow_templates = false;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes
};

if parser.token != token::Eof {
return parser.unexpected();
parser.unexpected()?;
}

Ok(Assert { cond_expr, custom_message })
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ pub unsafe fn create_module<'ll>(
//
// On the wasm targets it will get hooked up to the "producer" sections
// `processed-by` information.
#[allow(clippy::option_env_unwrap)]
let rustc_producer =
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
let name_metadata = llvm::LLVMMDStringInContext(
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ pub fn intern_const_alloc_for_constprop<
return Ok(());
}
// Move allocation to `tcx`.
for _ in intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))? {
if let Some(_) =
(intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))?).next()
{
// We are not doing recursive interning, so we don't currently support provenance.
// (If this assertion ever triggers, we should just implement a
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_expand/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#![feature(proc_macro_internals)]
#![feature(proc_macro_span)]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![allow(rustc::diagnostic_outside_of_impl)]
#![allow(internal_features)]

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub(crate) fn parse_external_mod(

// Ensure file paths are acyclic.
if let Some(pos) = module.file_path_stack.iter().position(|p| p == &mp.file_path) {
Err(ModError::CircularInclusion(module.file_path_stack[pos..].to_vec()))?;
do yeet ModError::CircularInclusion(module.file_path_stack[pos..].to_vec());
}

// Actually parse the external file as a module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
let generics_def_id = tcx.res_generics_def_id(path.res)?;
let generics = tcx.generics_of(generics_def_id);
if generics.has_impl_trait() {
None?;
do yeet ();
}
let insert_span =
path.segments.last().unwrap().ident.span.shrink_to_hi().with_hi(path.span.hi());
Expand Down Expand Up @@ -1044,7 +1044,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
let generics = tcx.generics_of(def_id);
let segment: Option<_> = try {
if !segment.infer_args || generics.has_impl_trait() {
None?;
do yeet ();
}
let span = tcx.hir().span(segment.hir_id);
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_infer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#![feature(iterator_try_collect)]
#![cfg_attr(bootstrap, feature(min_specialization))]
#![feature(try_blocks)]
#![feature(yeet_expr)]
#![recursion_limit = "512"] // For rustdoc

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2198,7 +2198,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
let mmap = if len > 0 {
let mut mmap = MmapMut::map_anon(len).unwrap();
for _ in 0..len {
(&mut mmap[..]).write(&[d.read_u8()]).unwrap();
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
}
mmap.flush().unwrap();
Some(mmap.make_read_only().unwrap())
Expand Down
20 changes: 8 additions & 12 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,16 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
if self.current_id == CRATE_HIR_ID {
return None;
}
loop {
// There are nodes that do not have entries, so we need to skip them.
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;

let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
let def_id = LocalDefId { local_def_index };
self.map.tcx.local_def_id_to_hir_id(def_id).owner
});
self.current_id = HirId::make_owner(parent_id.def_id);
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
let def_id = LocalDefId { local_def_index };
self.map.tcx.local_def_id_to_hir_id(def_id).owner
});
self.current_id = HirId::make_owner(parent_id.def_id);

// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
return Some((self.current_id.owner, node));
}
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
return Some((self.current_id.owner, node));
}
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -671,11 +671,11 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i
// So we do not read exactly 16 bytes into the u128, just the "payload".
let uint = match endianness {
Endian::Little => {
source.read(&mut buf)?;
source.read_exact(&mut buf[..source.len()])?;
Ok(u128::from_le_bytes(buf))
}
Endian::Big => {
source.read(&mut buf[16 - source.len()..])?;
source.read_exact(&mut buf[16 - source.len()..])?;
Ok(u128::from_be_bytes(buf))
}
};
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
span: Span,
scrutinee_span: Span,
) -> BlockAnd<()> {
let scrutinee_span = scrutinee_span;
let scrutinee_place =
unpack!(block = self.lower_scrutinee(block, scrutinee_id, scrutinee_span));

Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_parse/src/parser/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ impl<'a> Parser<'a> {
};

if let Some(item) = nt_meta {
return match item.meta(item.path.span) {
match item.meta(item.path.span) {
Some(meta) => {
self.bump();
Ok(meta)
return Ok(meta);
}
None => self.unexpected(),
None => self.unexpected()?,
};
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ impl<'a> Parser<'a> {
}))
} else {
self.maybe_recover_bounds_doubled_colon(&ty)?;
self.unexpected()
self.unexpected_any()
}
}

Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,7 @@ impl<'a> Parser<'a> {
let ident = this.parse_field_ident("enum", vlo)?;

if this.token == token::Not {
if let Err(err) = this.unexpected::<()>() {
if let Err(err) = this.unexpected() {
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
}

Expand Down Expand Up @@ -1937,7 +1937,7 @@ impl<'a> Parser<'a> {
) -> PResult<'a, FieldDef> {
let name = self.parse_field_ident(adt_ty, lo)?;
if self.token.kind == token::Not {
if let Err(mut err) = self.unexpected::<FieldDef>() {
if let Err(mut err) = self.unexpected() {
// Encounter the macro invocation
err.subdiagnostic(self.dcx(), MacroExpandsToAdtField { adt_ty });
return Err(err);
Expand Down Expand Up @@ -2067,7 +2067,7 @@ impl<'a> Parser<'a> {
let params = self.parse_token_tree(); // `MacParams`
let pspan = params.span();
if !self.check(&token::OpenDelim(Delimiter::Brace)) {
return self.unexpected();
self.unexpected()?;
}
let body = self.parse_token_tree(); // `MacBody`
// Convert `MacParams MacBody` into `{ MacParams => MacBody }`.
Expand All @@ -2077,7 +2077,7 @@ impl<'a> Parser<'a> {
let dspan = DelimSpan::from_pair(pspan.shrink_to_lo(), bspan.shrink_to_hi());
P(DelimArgs { dspan, delim: Delimiter::Brace, tokens })
} else {
return self.unexpected();
self.unexpected_any()?
};

self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span));
Expand Down Expand Up @@ -2692,7 +2692,7 @@ impl<'a> Parser<'a> {
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
let (pat, colon) = this.parse_fn_param_pat_colon()?;
if !colon {
let mut err = this.unexpected::<()>().unwrap_err();
let mut err = this.unexpected().unwrap_err();
return if let Some(ident) =
this.parameter_without_type(&mut err, pat, is_name_required, first_param)
{
Expand All @@ -2716,7 +2716,7 @@ impl<'a> Parser<'a> {
{
// This wasn't actually a type, but a pattern looking like a type,
// so we are going to rollback and re-parse for recovery.
ty = this.unexpected();
ty = this.unexpected_any();
}
match ty {
Ok(ty) => {
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,9 @@ impl<'a> Parser<'a> {
matches!(self.recovery, Recovery::Allowed)
}

pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
/// Version of [`unexpected`](Parser::unexpected) that "returns" any type in the `Ok`
/// (both those functions never return "Ok", and so can lie like that in the type).
pub fn unexpected_any<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
Err(e) => Err(e),
// We can get `Ok(true)` from `recover_closing_delimiter`
Expand All @@ -474,6 +476,10 @@ impl<'a> Parser<'a> {
}
}

pub fn unexpected(&mut self) -> PResult<'a, ()> {
self.unexpected_any()
}

/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
if self.expected_tokens.is_empty() {
Expand Down Expand Up @@ -1278,7 +1284,11 @@ impl<'a> Parser<'a> {
}

fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>> {
if let Some(args) = self.parse_delim_args_inner() { Ok(P(args)) } else { self.unexpected() }
if let Some(args) = self.parse_delim_args_inner() {
Ok(P(args))
} else {
self.unexpected_any()
}
}

fn parse_attr_args(&mut self) -> PResult<'a, AttrArgs> {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ impl<'a> Parser<'a> {
// Add `>` to the list of expected tokens.
self.check(&token::Gt);
// Handle `,` to `;` substitution
let mut err = self.unexpected::<()>().unwrap_err();
let mut err = self.unexpected().unwrap_err();
self.bump();
err.span_suggestion_verbose(
self.prev_token.span.until(self.token.span),
Expand Down
Loading

0 comments on commit 0f706af

Please sign in to comment.