Skip to content

Commit 0f706af

Browse files
committed
Auto merge of rust-lang#122763 - matthiaskrgr:rollup-o8a2mye, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#121543 (various clippy fixes) - rust-lang#122540 (Do not use `?`-induced skewing of type inference in the compiler) - rust-lang#122730 (Expose `ucred::peer_cred` on QNX targets to enable dist builds) - rust-lang#122732 (Remove redundant coroutine captures note) - rust-lang#122739 (Add "put" as a confusable for insert on hash map/set) - rust-lang#122748 (Reduce `pub` usage in `rustc_session`.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b7dcabe + 53a753e commit 0f706af

File tree

38 files changed

+335
-264
lines changed

38 files changed

+335
-264
lines changed

compiler/rustc_ast/src/token.rs

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1111
use rustc_data_structures::sync::Lrc;
1212
use rustc_macros::HashStable_Generic;
1313
use rustc_span::symbol::{kw, sym};
14+
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
1415
#[allow(hidden_glob_reexports)]
1516
use rustc_span::symbol::{Ident, Symbol};
1617
use rustc_span::{edition::Edition, ErrorGuaranteed, Span, DUMMY_SP};

compiler/rustc_builtin_macros/src/asm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ pub fn parse_asm_args<'a>(
189189
args.templates.push(template);
190190
continue;
191191
} else {
192-
return p.unexpected();
192+
p.unexpected_any()?
193193
};
194194

195195
allow_templates = false;

compiler/rustc_builtin_macros/src/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn parse_assert<'a>(cx: &mut ExtCtxt<'a>, sp: Span, stream: TokenStream) -> PRes
151151
};
152152

153153
if parser.token != token::Eof {
154-
return parser.unexpected();
154+
parser.unexpected()?;
155155
}
156156

157157
Ok(Assert { cond_expr, custom_message })

compiler/rustc_codegen_llvm/src/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ pub unsafe fn create_module<'ll>(
315315
//
316316
// On the wasm targets it will get hooked up to the "producer" sections
317317
// `processed-by` information.
318+
#[allow(clippy::option_env_unwrap)]
318319
let rustc_producer =
319320
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
320321
let name_metadata = llvm::LLVMMDStringInContext(

compiler/rustc_const_eval/src/interpret/intern.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,9 @@ pub fn intern_const_alloc_for_constprop<
293293
return Ok(());
294294
}
295295
// Move allocation to `tcx`.
296-
for _ in intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))? {
296+
if let Some(_) =
297+
(intern_shallow(ecx, alloc_id, Mutability::Not).map_err(|()| err_ub!(DeadLocal))?).next()
298+
{
297299
// We are not doing recursive interning, so we don't currently support provenance.
298300
// (If this assertion ever triggers, we should just implement a
299301
// proper recursive interning loop -- or just call `intern_const_alloc_recursive`.

compiler/rustc_expand/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#![feature(proc_macro_internals)]
1313
#![feature(proc_macro_span)]
1414
#![feature(try_blocks)]
15+
#![feature(yeet_expr)]
1516
#![allow(rustc::diagnostic_outside_of_impl)]
1617
#![allow(internal_features)]
1718

compiler/rustc_expand/src/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub(crate) fn parse_external_mod(
6262

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

6868
// Actually parse the external file as a module.

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
990990
let generics_def_id = tcx.res_generics_def_id(path.res)?;
991991
let generics = tcx.generics_of(generics_def_id);
992992
if generics.has_impl_trait() {
993-
None?;
993+
do yeet ();
994994
}
995995
let insert_span =
996996
path.segments.last().unwrap().ident.span.shrink_to_hi().with_hi(path.span.hi());
@@ -1044,7 +1044,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10441044
let generics = tcx.generics_of(def_id);
10451045
let segment: Option<_> = try {
10461046
if !segment.infer_args || generics.has_impl_trait() {
1047-
None?;
1047+
do yeet ();
10481048
}
10491049
let span = tcx.hir().span(segment.hir_id);
10501050
let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#![feature(iterator_try_collect)]
2828
#![cfg_attr(bootstrap, feature(min_specialization))]
2929
#![feature(try_blocks)]
30+
#![feature(yeet_expr)]
3031
#![recursion_limit = "512"] // For rustdoc
3132

3233
#[macro_use]

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2198,7 +2198,7 @@ impl<D: Decoder> Decodable<D> for EncodedMetadata {
21982198
let mmap = if len > 0 {
21992199
let mut mmap = MmapMut::map_anon(len).unwrap();
22002200
for _ in 0..len {
2201-
(&mut mmap[..]).write(&[d.read_u8()]).unwrap();
2201+
(&mut mmap[..]).write_all(&[d.read_u8()]).unwrap();
22022202
}
22032203
mmap.flush().unwrap();
22042204
Some(mmap.make_read_only().unwrap())

compiler/rustc_middle/src/hir/map/mod.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,16 @@ impl<'hir> Iterator for ParentOwnerIterator<'hir> {
7676
if self.current_id == CRATE_HIR_ID {
7777
return None;
7878
}
79-
loop {
80-
// There are nodes that do not have entries, so we need to skip them.
81-
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;
8279

83-
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
84-
let def_id = LocalDefId { local_def_index };
85-
self.map.tcx.local_def_id_to_hir_id(def_id).owner
86-
});
87-
self.current_id = HirId::make_owner(parent_id.def_id);
80+
let parent_id = self.map.def_key(self.current_id.owner.def_id).parent;
81+
let parent_id = parent_id.map_or(CRATE_OWNER_ID, |local_def_index| {
82+
let def_id = LocalDefId { local_def_index };
83+
self.map.tcx.local_def_id_to_hir_id(def_id).owner
84+
});
85+
self.current_id = HirId::make_owner(parent_id.def_id);
8886

89-
// If this `HirId` doesn't have an entry, skip it and look for its `parent_id`.
90-
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
91-
return Some((self.current_id.owner, node));
92-
}
87+
let node = self.map.tcx.hir_owner_node(self.current_id.owner);
88+
return Some((self.current_id.owner, node));
9389
}
9490
}
9591

compiler/rustc_middle/src/mir/interpret/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -671,11 +671,11 @@ pub fn read_target_uint(endianness: Endian, mut source: &[u8]) -> Result<u128, i
671671
// So we do not read exactly 16 bytes into the u128, just the "payload".
672672
let uint = match endianness {
673673
Endian::Little => {
674-
source.read(&mut buf)?;
674+
source.read_exact(&mut buf[..source.len()])?;
675675
Ok(u128::from_le_bytes(buf))
676676
}
677677
Endian::Big => {
678-
source.read(&mut buf[16 - source.len()..])?;
678+
source.read_exact(&mut buf[16 - source.len()..])?;
679679
Ok(u128::from_be_bytes(buf))
680680
}
681681
};

compiler/rustc_mir_build/src/build/matches/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
229229
span: Span,
230230
scrutinee_span: Span,
231231
) -> BlockAnd<()> {
232-
let scrutinee_span = scrutinee_span;
233232
let scrutinee_place =
234233
unpack!(block = self.lower_scrutinee(block, scrutinee_id, scrutinee_span));
235234

compiler/rustc_parse/src/parser/attr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ impl<'a> Parser<'a> {
380380
};
381381

382382
if let Some(item) = nt_meta {
383-
return match item.meta(item.path.span) {
383+
match item.meta(item.path.span) {
384384
Some(meta) => {
385385
self.bump();
386-
Ok(meta)
386+
return Ok(meta);
387387
}
388-
None => self.unexpected(),
388+
None => self.unexpected()?,
389389
};
390390
}
391391

compiler/rustc_parse/src/parser/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ impl<'a> Parser<'a> {
481481
}))
482482
} else {
483483
self.maybe_recover_bounds_doubled_colon(&ty)?;
484-
self.unexpected()
484+
self.unexpected_any()
485485
}
486486
}
487487

compiler/rustc_parse/src/parser/item.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,7 @@ impl<'a> Parser<'a> {
15141514
let ident = this.parse_field_ident("enum", vlo)?;
15151515

15161516
if this.token == token::Not {
1517-
if let Err(err) = this.unexpected::<()>() {
1517+
if let Err(err) = this.unexpected() {
15181518
err.with_note(fluent::parse_macro_expands_to_enum_variant).emit();
15191519
}
15201520

@@ -1937,7 +1937,7 @@ impl<'a> Parser<'a> {
19371937
) -> PResult<'a, FieldDef> {
19381938
let name = self.parse_field_ident(adt_ty, lo)?;
19391939
if self.token.kind == token::Not {
1940-
if let Err(mut err) = self.unexpected::<FieldDef>() {
1940+
if let Err(mut err) = self.unexpected() {
19411941
// Encounter the macro invocation
19421942
err.subdiagnostic(self.dcx(), MacroExpandsToAdtField { adt_ty });
19431943
return Err(err);
@@ -2067,7 +2067,7 @@ impl<'a> Parser<'a> {
20672067
let params = self.parse_token_tree(); // `MacParams`
20682068
let pspan = params.span();
20692069
if !self.check(&token::OpenDelim(Delimiter::Brace)) {
2070-
return self.unexpected();
2070+
self.unexpected()?;
20712071
}
20722072
let body = self.parse_token_tree(); // `MacBody`
20732073
// Convert `MacParams MacBody` into `{ MacParams => MacBody }`.
@@ -2077,7 +2077,7 @@ impl<'a> Parser<'a> {
20772077
let dspan = DelimSpan::from_pair(pspan.shrink_to_lo(), bspan.shrink_to_hi());
20782078
P(DelimArgs { dspan, delim: Delimiter::Brace, tokens })
20792079
} else {
2080-
return self.unexpected();
2080+
self.unexpected_any()?
20812081
};
20822082

20832083
self.psess.gated_spans.gate(sym::decl_macro, lo.to(self.prev_token.span));
@@ -2692,7 +2692,7 @@ impl<'a> Parser<'a> {
26922692
debug!("parse_param_general parse_pat (is_name_required:{})", is_name_required);
26932693
let (pat, colon) = this.parse_fn_param_pat_colon()?;
26942694
if !colon {
2695-
let mut err = this.unexpected::<()>().unwrap_err();
2695+
let mut err = this.unexpected().unwrap_err();
26962696
return if let Some(ident) =
26972697
this.parameter_without_type(&mut err, pat, is_name_required, first_param)
26982698
{
@@ -2716,7 +2716,7 @@ impl<'a> Parser<'a> {
27162716
{
27172717
// This wasn't actually a type, but a pattern looking like a type,
27182718
// so we are going to rollback and re-parse for recovery.
2719-
ty = this.unexpected();
2719+
ty = this.unexpected_any();
27202720
}
27212721
match ty {
27222722
Ok(ty) => {

compiler/rustc_parse/src/parser/mod.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ impl<'a> Parser<'a> {
465465
matches!(self.recovery, Recovery::Allowed)
466466
}
467467

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

479+
pub fn unexpected(&mut self) -> PResult<'a, ()> {
480+
self.unexpected_any()
481+
}
482+
477483
/// Expects and consumes the token `t`. Signals an error if the next token is not `t`.
478484
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, Recovered> {
479485
if self.expected_tokens.is_empty() {
@@ -1278,7 +1284,11 @@ impl<'a> Parser<'a> {
12781284
}
12791285

12801286
fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>> {
1281-
if let Some(args) = self.parse_delim_args_inner() { Ok(P(args)) } else { self.unexpected() }
1287+
if let Some(args) = self.parse_delim_args_inner() {
1288+
Ok(P(args))
1289+
} else {
1290+
self.unexpected_any()
1291+
}
12821292
}
12831293

12841294
fn parse_attr_args(&mut self) -> PResult<'a, AttrArgs> {

compiler/rustc_parse/src/parser/path.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl<'a> Parser<'a> {
660660
// Add `>` to the list of expected tokens.
661661
self.check(&token::Gt);
662662
// Handle `,` to `;` substitution
663-
let mut err = self.unexpected::<()>().unwrap_err();
663+
let mut err = self.unexpected().unwrap_err();
664664
self.bump();
665665
err.span_suggestion_verbose(
666666
self.prev_token.span.until(self.token.span),

0 commit comments

Comments
 (0)