Skip to content

Commit ad46af2

Browse files
committed
Auto merge of rust-lang#92883 - matthiaskrgr:rollup-uoudywx, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#92045 (Don't fall back to crate-level opaque type definitions.) - rust-lang#92381 (Suggest `return`ing tail expressions in async functions) - rust-lang#92768 (Partially stabilize `maybe_uninit_extra`) - rust-lang#92810 (Deduplicate box deref and regular deref suggestions) - rust-lang#92818 (Update documentation for doc_cfg feature) - rust-lang#92840 (Fix some lints documentation) - rust-lang#92849 (Clippyup) - rust-lang#92854 (Use the updated Rust logo in rustdoc) - rust-lang#92864 (Fix a missing dot in the main item heading) Failed merges: - rust-lang#92838 (Clean up some links in RELEASES) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 02c9e73 + 2ae4afd commit ad46af2

File tree

251 files changed

+3535
-1783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

251 files changed

+3535
-1783
lines changed

Cargo.lock

+6-3
Original file line numberDiff line numberDiff line change
@@ -639,14 +639,15 @@ dependencies = [
639639

640640
[[package]]
641641
name = "clippy"
642-
version = "0.1.59"
642+
version = "0.1.60"
643643
dependencies = [
644644
"cargo_metadata 0.14.0",
645645
"clippy_lints",
646646
"clippy_utils",
647647
"compiletest_rs",
648648
"derive-new",
649649
"filetime",
650+
"futures 0.3.12",
650651
"if_chain",
651652
"itertools 0.10.1",
652653
"parking_lot",
@@ -659,6 +660,7 @@ dependencies = [
659660
"syn",
660661
"tempfile",
661662
"tester",
663+
"tokio",
662664
]
663665

664666
[[package]]
@@ -678,7 +680,7 @@ dependencies = [
678680

679681
[[package]]
680682
name = "clippy_lints"
681-
version = "0.1.59"
683+
version = "0.1.60"
682684
dependencies = [
683685
"cargo_metadata 0.14.0",
684686
"clippy_utils",
@@ -699,8 +701,9 @@ dependencies = [
699701

700702
[[package]]
701703
name = "clippy_utils"
702-
version = "0.1.59"
704+
version = "0.1.60"
703705
dependencies = [
706+
"arrayvec",
704707
"if_chain",
705708
"rustc-semver",
706709
]

compiler/rustc_infer/src/infer/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
1010

1111
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine};
1212

13-
use hir::def_id::CRATE_DEF_ID;
1413
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1514
use rustc_data_structures::sync::Lrc;
1615
use rustc_data_structures::undo_log::Rollback;
@@ -291,7 +290,12 @@ pub struct InferCtxt<'a, 'tcx> {
291290

292291
/// The `DefId` of the item in whose context we are performing inference or typeck.
293292
/// It is used to check whether an opaque type use is a defining use.
294-
pub defining_use_anchor: LocalDefId,
293+
///
294+
/// If it is `None`, we can't resolve opaque types here and need to bubble up
295+
/// the obligation. This frequently happens for
296+
/// short lived InferCtxt within queries. The opaque type obligations are forwarded
297+
/// to the outside until the end up in an `InferCtxt` for typeck or borrowck.
298+
pub defining_use_anchor: Option<LocalDefId>,
295299

296300
/// During type-checking/inference of a body, `in_progress_typeck_results`
297301
/// contains a reference to the typeck results being built up, which are
@@ -547,7 +551,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
547551
pub struct InferCtxtBuilder<'tcx> {
548552
tcx: TyCtxt<'tcx>,
549553
fresh_typeck_results: Option<RefCell<ty::TypeckResults<'tcx>>>,
550-
defining_use_anchor: LocalDefId,
554+
defining_use_anchor: Option<LocalDefId>,
551555
}
552556

553557
pub trait TyCtxtInferExt<'tcx> {
@@ -556,11 +560,7 @@ pub trait TyCtxtInferExt<'tcx> {
556560

557561
impl<'tcx> TyCtxtInferExt<'tcx> for TyCtxt<'tcx> {
558562
fn infer_ctxt(self) -> InferCtxtBuilder<'tcx> {
559-
InferCtxtBuilder {
560-
tcx: self,
561-
defining_use_anchor: CRATE_DEF_ID,
562-
fresh_typeck_results: None,
563-
}
563+
InferCtxtBuilder { tcx: self, defining_use_anchor: None, fresh_typeck_results: None }
564564
}
565565
}
566566

@@ -580,7 +580,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
580580
/// (via `with_fresh_in_progress_typeck_results`) and for the inference context used
581581
/// in mir borrowck.
582582
pub fn with_opaque_type_inference(mut self, defining_use_anchor: LocalDefId) -> Self {
583-
self.defining_use_anchor = defining_use_anchor;
583+
self.defining_use_anchor = Some(defining_use_anchor);
584584
self
585585
}
586586

compiler/rustc_infer/src/infer/opaque_types.rs

+27-23
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,31 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
328328
},
329329
});
330330
}
331+
332+
fn opaque_type_origin(&self, def_id: LocalDefId) -> Option<hir::OpaqueTyOrigin> {
333+
let tcx = self.tcx;
334+
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
335+
let parent_def_id = self.defining_use_anchor?;
336+
let item_kind = &tcx.hir().expect_item(def_id).kind;
337+
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else {
338+
span_bug!(
339+
tcx.def_span(def_id),
340+
"weird opaque type: {:#?}",
341+
item_kind
342+
)
343+
};
344+
let in_definition_scope = match *origin {
345+
// Async `impl Trait`
346+
hir::OpaqueTyOrigin::AsyncFn(parent) => parent == parent_def_id,
347+
// Anonymous `impl Trait`
348+
hir::OpaqueTyOrigin::FnReturn(parent) => parent == parent_def_id,
349+
// Named `type Foo = impl Bar;`
350+
hir::OpaqueTyOrigin::TyAlias => {
351+
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id)
352+
}
353+
};
354+
in_definition_scope.then_some(*origin)
355+
}
331356
}
332357

333358
// Visitor that requires that (almost) all regions in the type visited outlive
@@ -459,31 +484,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
459484
// }
460485
// ```
461486
if let Some(def_id) = def_id.as_local() {
462-
let opaque_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
463-
let parent_def_id = self.infcx.defining_use_anchor;
464-
let item_kind = &tcx.hir().expect_item(def_id).kind;
465-
let hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) = item_kind else {
466-
span_bug!(
467-
self.value_span,
468-
"weird opaque type: {:#?}, {:#?}",
469-
ty.kind(),
470-
item_kind
471-
)
472-
};
473-
let in_definition_scope = match *origin {
474-
// Async `impl Trait`
475-
hir::OpaqueTyOrigin::AsyncFn(parent) => parent == parent_def_id,
476-
// Anonymous `impl Trait`
477-
hir::OpaqueTyOrigin::FnReturn(parent) => parent == parent_def_id,
478-
// Named `type Foo = impl Bar;`
479-
hir::OpaqueTyOrigin::TyAlias => {
480-
may_define_opaque_type(tcx, parent_def_id, opaque_hir_id)
481-
}
482-
};
483-
if in_definition_scope {
487+
if let Some(origin) = self.infcx.opaque_type_origin(def_id) {
484488
let opaque_type_key =
485489
OpaqueTypeKey { def_id: def_id.to_def_id(), substs };
486-
return self.fold_opaque_ty(ty, opaque_type_key, *origin);
490+
return self.fold_opaque_ty(ty, opaque_type_key, origin);
487491
}
488492

489493
debug!(

compiler/rustc_lint_defs/src/builtin.rs

+37-5
Original file line numberDiff line numberDiff line change
@@ -1805,7 +1805,7 @@ declare_lint! {
18051805
///
18061806
/// ### Example
18071807
///
1808-
/// ```
1808+
/// ```rust
18091809
/// if let _ = 123 {
18101810
/// println!("always runs!");
18111811
/// }
@@ -2431,7 +2431,19 @@ declare_lint! {
24312431
/// }
24322432
/// ```
24332433
///
2434-
/// {{produces}}
2434+
/// This will produce:
2435+
///
2436+
/// ```text
2437+
/// warning: formatting may not be suitable for sub-register argument
2438+
/// --> src/main.rs:7:19
2439+
/// |
2440+
/// 7 | asm!("mov {0}, {0}", in(reg) 0i16);
2441+
/// | ^^^ ^^^ ---- for this argument
2442+
/// |
2443+
/// = note: `#[warn(asm_sub_register)]` on by default
2444+
/// = help: use the `x` modifier to have the register formatted as `ax`
2445+
/// = help: or use the `r` modifier to keep the default formatting of `rax`
2446+
/// ```
24352447
///
24362448
/// ### Explanation
24372449
///
@@ -2470,7 +2482,17 @@ declare_lint! {
24702482
/// }
24712483
/// ```
24722484
///
2473-
/// {{produces}}
2485+
/// This will produce:
2486+
///
2487+
/// ```text
2488+
/// warning: avoid using `.att_syntax`, prefer using `options(att_syntax)` instead
2489+
/// --> src/main.rs:8:14
2490+
/// |
2491+
/// 8 | ".att_syntax",
2492+
/// | ^^^^^^^^^^^
2493+
/// |
2494+
/// = note: `#[warn(bad_asm_style)]` on by default
2495+
/// ```
24742496
///
24752497
/// ### Explanation
24762498
///
@@ -2788,7 +2810,7 @@ declare_lint! {
27882810
///
27892811
/// ### Example
27902812
///
2791-
/// ```compile_fail
2813+
/// ```rust,compile_fail
27922814
/// #![feature(staged_api)]
27932815
///
27942816
/// #[derive(Clone)]
@@ -3618,7 +3640,17 @@ declare_lint! {
36183640
/// fn foo() {}
36193641
/// ```
36203642
///
3621-
/// {{produces}}
3643+
/// This will produce:
3644+
///
3645+
/// ```text
3646+
/// warning: duplicated attribute
3647+
/// --> src/lib.rs:2:1
3648+
/// |
3649+
/// 2 | #[test]
3650+
/// | ^^^^^^^
3651+
/// |
3652+
/// = note: `#[warn(duplicate_macro_attributes)]` on by default
3653+
/// ```
36223654
///
36233655
/// ### Explanation
36243656
///

compiler/rustc_typeck/src/check/demand.rs

+11-26
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3131
error: TypeError<'tcx>,
3232
) {
3333
self.annotate_expected_due_to_let_ty(err, expr, error);
34-
self.suggest_box_deref(err, expr, expected, expr_ty);
35-
self.suggest_compatible_variants(err, expr, expected, expr_ty);
3634
self.suggest_deref_ref_or_into(err, expr, expected, expr_ty, expected_ty_expr);
35+
self.suggest_compatible_variants(err, expr, expected, expr_ty);
3736
if self.suggest_calling_boxed_future_when_appropriate(err, expr, expected, expr_ty) {
3837
return;
3938
}
@@ -259,23 +258,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
259258
}
260259
}
261260

262-
fn suggest_box_deref(
263-
&self,
264-
err: &mut DiagnosticBuilder<'_>,
265-
expr: &hir::Expr<'_>,
266-
expected: Ty<'tcx>,
267-
expr_ty: Ty<'tcx>,
268-
) {
269-
if expr_ty.is_box() && expr_ty.boxed_ty() == expected {
270-
err.span_suggestion_verbose(
271-
expr.span.shrink_to_lo(),
272-
"try dereferencing the `Box`",
273-
"*".to_string(),
274-
Applicability::MachineApplicable,
275-
);
276-
}
277-
}
278-
279261
/// If the expected type is an enum (Issue #55250) with any variants whose
280262
/// sole field is of the found type, suggest such variants. (Issue #42764)
281263
fn suggest_compatible_variants(
@@ -857,14 +839,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
857839
Applicability::MachineApplicable,
858840
false,
859841
));
860-
} else if self.infcx.type_is_copy_modulo_regions(
861-
self.param_env,
862-
expected,
863-
sp,
864-
) {
865-
// For this suggestion to make sense, the type would need to be `Copy`.
842+
}
843+
844+
// For this suggestion to make sense, the type would need to be `Copy`,
845+
// or we have to be moving out of a `Box<T>`
846+
if self.infcx.type_is_copy_modulo_regions(self.param_env, expected, sp)
847+
|| checked_ty.is_box()
848+
{
866849
if let Ok(code) = sm.span_to_snippet(expr.span) {
867-
let message = if checked_ty.is_region_ptr() {
850+
let message = if checked_ty.is_box() {
851+
"consider unboxing the value"
852+
} else if checked_ty.is_region_ptr() {
868853
"consider dereferencing the borrow"
869854
} else {
870855
"consider dereferencing the type"

compiler/rustc_typeck/src/check/fn_ctxt/suggestions.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir as hir;
99
use rustc_hir::def::{CtorOf, DefKind};
1010
use rustc_hir::lang_items::LangItem;
1111
use rustc_hir::{Expr, ExprKind, ItemKind, Node, Path, QPath, Stmt, StmtKind, TyKind};
12-
use rustc_infer::infer;
12+
use rustc_infer::infer::{self, TyCtxtInferExt};
1313
use rustc_middle::lint::in_external_macro;
1414
use rustc_middle::ty::{self, Binder, Ty};
1515
use rustc_span::symbol::{kw, sym};
@@ -608,6 +608,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
608608
let bound_vars = self.tcx.late_bound_vars(fn_id);
609609
let ty = self.tcx.erase_late_bound_regions(Binder::bind_with_vars(ty, bound_vars));
610610
let ty = self.normalize_associated_types_in(expr.span, ty);
611+
let ty = match self.tcx.asyncness(fn_id.owner) {
612+
hir::IsAsync::Async => self.tcx.infer_ctxt().enter(|infcx| {
613+
infcx.get_impl_future_output_ty(ty).unwrap_or_else(|| {
614+
span_bug!(
615+
fn_decl.output.span(),
616+
"failed to get output type of async function"
617+
)
618+
})
619+
}),
620+
hir::IsAsync::NotAsync => ty,
621+
};
611622
if self.can_coerce(found, ty) {
612623
err.multipart_suggestion(
613624
"you might have meant to return this value",

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
#![feature(inplace_iteration)]
120120
#![feature(iter_advance_by)]
121121
#![feature(layout_for_ptr)]
122-
#![feature(maybe_uninit_extra)]
123122
#![feature(maybe_uninit_slice)]
124123
#![cfg_attr(test, feature(new_uninit))]
125124
#![feature(nonnull_slice_from_raw_parts)]

library/core/src/mem/maybe_uninit.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ impl<T> MaybeUninit<T> {
330330
/// # Examples
331331
///
332332
/// ```no_run
333-
/// #![feature(maybe_uninit_uninit_array, maybe_uninit_extra, maybe_uninit_slice)]
333+
/// #![feature(maybe_uninit_uninit_array, maybe_uninit_slice)]
334334
///
335335
/// use std::mem::MaybeUninit;
336336
///
@@ -662,7 +662,6 @@ impl<T> MaybeUninit<T> {
662662
/// Correct usage of this method:
663663
///
664664
/// ```rust
665-
/// #![feature(maybe_uninit_extra)]
666665
/// use std::mem::MaybeUninit;
667666
///
668667
/// let mut x = MaybeUninit::<u32>::uninit();
@@ -683,7 +682,6 @@ impl<T> MaybeUninit<T> {
683682
/// *Incorrect* usage of this method:
684683
///
685684
/// ```rust,no_run
686-
/// #![feature(maybe_uninit_extra)]
687685
/// use std::mem::MaybeUninit;
688686
///
689687
/// let mut x = MaybeUninit::<Option<Vec<u32>>>::uninit();
@@ -693,8 +691,8 @@ impl<T> MaybeUninit<T> {
693691
/// // We now created two copies of the same vector, leading to a double-free ⚠️ when
694692
/// // they both get dropped!
695693
/// ```
696-
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
697-
#[rustc_const_unstable(feature = "maybe_uninit_extra", issue = "63567")]
694+
#[stable(feature = "maybe_uninit_extra", since = "1.60.0")]
695+
#[rustc_const_unstable(feature = "const_maybe_uninit_assume_init_read", issue = "63567")]
698696
#[inline(always)]
699697
#[track_caller]
700698
pub const unsafe fn assume_init_read(&self) -> T {
@@ -728,7 +726,7 @@ impl<T> MaybeUninit<T> {
728726
///
729727
/// [`assume_init`]: MaybeUninit::assume_init
730728
/// [`Vec<T>`]: ../../std/vec/struct.Vec.html
731-
#[unstable(feature = "maybe_uninit_extra", issue = "63567")]
729+
#[stable(feature = "maybe_uninit_extra", since = "1.60.0")]
732730
pub unsafe fn assume_init_drop(&mut self) {
733731
// SAFETY: the caller must guarantee that `self` is initialized and
734732
// satisfies all invariants of `T`.

library/core/tests/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#![feature(const_convert)]
1616
#![feature(const_maybe_uninit_as_mut_ptr)]
1717
#![feature(const_maybe_uninit_assume_init)]
18+
#![feature(const_maybe_uninit_assume_init_read)]
1819
#![feature(const_num_from_num)]
1920
#![feature(const_ptr_read)]
2021
#![feature(const_ptr_write)]
@@ -46,7 +47,6 @@
4647
#![feature(slice_take)]
4748
#![feature(maybe_uninit_uninit_array)]
4849
#![feature(maybe_uninit_array_assume_init)]
49-
#![feature(maybe_uninit_extra)]
5050
#![feature(maybe_uninit_write_slice)]
5151
#![feature(min_specialization)]
5252
#![feature(numfmt)]

0 commit comments

Comments
 (0)