Skip to content

Commit 4d44e09

Browse files
committed
Auto merge of rust-lang#102165 - matthiaskrgr:rollup-n5oquhe, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#100734 (Split out async_fn_in_trait into a separate feature) - rust-lang#101664 (Note if mismatched types have a similar name) - rust-lang#101815 (Migrated the rustc_passes annotation without effect diagnostic infrastructure) - rust-lang#102042 (Distribute rust-docs-json via rustup.) - rust-lang#102066 (rustdoc: remove unnecessary `max-width` on headers) - rust-lang#102095 (Deduplicate two functions that would soon have been three) - rust-lang#102104 (Set 'exec-env:RUST_BACKTRACE=0' in const-eval-select tests) - rust-lang#102112 (Allow full relro on powerpc64-unknown-linux-gnu) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents bc4d574 + 8e3b9bc commit 4d44e09

37 files changed

+442
-72
lines changed

compiler/rustc_ast_lowering/src/lib.rs

+18-5
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ impl FnDeclKind {
332332
_ => false,
333333
}
334334
}
335+
336+
fn async_fn_allowed(&self, tcx: TyCtxt<'_>) -> bool {
337+
match self {
338+
FnDeclKind::Fn | FnDeclKind::Inherent => true,
339+
FnDeclKind::Impl if tcx.features().async_fn_in_trait => true,
340+
FnDeclKind::Trait if tcx.features().async_fn_in_trait => true,
341+
_ => false,
342+
}
343+
}
335344
}
336345

337346
#[derive(Copy, Clone)]
@@ -1692,14 +1701,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
16921701
}));
16931702

16941703
let output = if let Some((ret_id, span)) = make_ret_async {
1695-
if !kind.impl_trait_allowed(self.tcx) {
1704+
if !kind.async_fn_allowed(self.tcx) {
16961705
match kind {
16971706
FnDeclKind::Trait | FnDeclKind::Impl => {
16981707
self.tcx
16991708
.sess
17001709
.create_feature_err(
17011710
TraitFnAsync { fn_span, span },
1702-
sym::return_position_impl_trait_in_trait,
1711+
sym::async_fn_in_trait,
17031712
)
17041713
.emit();
17051714
}
@@ -1917,9 +1926,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19171926
let future_bound = this.lower_async_fn_output_type_to_future_bound(
19181927
output,
19191928
span,
1920-
ImplTraitContext::ReturnPositionOpaqueTy {
1921-
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1922-
in_trait,
1929+
if in_trait && !this.tcx.features().return_position_impl_trait_in_trait {
1930+
ImplTraitContext::Disallowed(ImplTraitPosition::TraitReturn)
1931+
} else {
1932+
ImplTraitContext::ReturnPositionOpaqueTy {
1933+
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
1934+
in_trait,
1935+
}
19231936
},
19241937
);
19251938

compiler/rustc_error_messages/locales/en-US/passes.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,6 @@ passes_link_ordinal = attribute should be applied to a foreign function or stati
268268
269269
passes_collapse_debuginfo = `collapse_debuginfo` attribute should be applied to macro definitions
270270
.label = not a macro definition
271+
272+
passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect
273+
.suggestion = remove the unnecessary deprecation attribute

compiler/rustc_feature/src/active.rs

+2
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,8 @@ declare_features! (
312312
(active, associated_type_defaults, "1.2.0", Some(29661), None),
313313
/// Allows `async || body` closures.
314314
(active, async_closure, "1.37.0", Some(62290), None),
315+
/// Alows async functions to be declared, implemented, and used in traits.
316+
(incomplete, async_fn_in_trait, "CURRENT_RUSTC_VERSION", Some(91611), None),
315317
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
316318
(active, c_unwind, "1.52.0", Some(74990), None),
317319
/// Allows using C-variadics.

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

+111-4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use super::{InferCtxt, RegionVariableOrigin, SubregionOrigin, TypeTrace, ValuePa
5151

5252
use crate::infer;
5353
use crate::infer::error_reporting::nice_region_error::find_anon_type::find_anon_type;
54+
use crate::infer::ExpectedFound;
5455
use crate::traits::error_reporting::report_object_safety_error;
5556
use crate::traits::{
5657
IfExpressionCause, MatchExpressionArmCause, ObligationCause, ObligationCauseCode,
@@ -1653,8 +1654,114 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16531654
),
16541655
Mismatch::Fixed(s) => (s.into(), s.into(), None),
16551656
};
1656-
match (&terr, expected == found) {
1657-
(TypeError::Sorts(values), extra) => {
1657+
1658+
enum Similar<'tcx> {
1659+
Adts { expected: ty::AdtDef<'tcx>, found: ty::AdtDef<'tcx> },
1660+
PrimitiveFound { expected: ty::AdtDef<'tcx>, found: Ty<'tcx> },
1661+
PrimitiveExpected { expected: Ty<'tcx>, found: ty::AdtDef<'tcx> },
1662+
}
1663+
1664+
let similarity = |ExpectedFound { expected, found }: ExpectedFound<Ty<'tcx>>| {
1665+
if let ty::Adt(expected, _) = expected.kind() && let Some(primitive) = found.primitive_symbol() {
1666+
let path = self.tcx.def_path(expected.did()).data;
1667+
let name = path.last().unwrap().data.get_opt_name();
1668+
if name == Some(primitive) {
1669+
return Some(Similar::PrimitiveFound { expected: *expected, found });
1670+
}
1671+
} else if let Some(primitive) = expected.primitive_symbol() && let ty::Adt(found, _) = found.kind() {
1672+
let path = self.tcx.def_path(found.did()).data;
1673+
let name = path.last().unwrap().data.get_opt_name();
1674+
if name == Some(primitive) {
1675+
return Some(Similar::PrimitiveExpected { expected, found: *found });
1676+
}
1677+
} else if let ty::Adt(expected, _) = expected.kind() && let ty::Adt(found, _) = found.kind() {
1678+
if !expected.did().is_local() && expected.did().krate == found.did().krate {
1679+
// Most likely types from different versions of the same crate
1680+
// are in play, in which case this message isn't so helpful.
1681+
// A "perhaps two different versions..." error is already emitted for that.
1682+
return None;
1683+
}
1684+
let f_path = self.tcx.def_path(found.did()).data;
1685+
let e_path = self.tcx.def_path(expected.did()).data;
1686+
1687+
if let (Some(e_last), Some(f_last)) = (e_path.last(), f_path.last()) && e_last == f_last {
1688+
return Some(Similar::Adts{expected: *expected, found: *found});
1689+
}
1690+
}
1691+
None
1692+
};
1693+
1694+
match terr {
1695+
// If two types mismatch but have similar names, mention that specifically.
1696+
TypeError::Sorts(values) if let Some(s) = similarity(values) => {
1697+
let diagnose_primitive =
1698+
|prim: Ty<'tcx>,
1699+
shadow: Ty<'tcx>,
1700+
defid: DefId,
1701+
diagnostic: &mut Diagnostic| {
1702+
let name = shadow.sort_string(self.tcx);
1703+
diagnostic.note(format!(
1704+
"{prim} and {name} have similar names, but are actually distinct types"
1705+
));
1706+
diagnostic
1707+
.note(format!("{prim} is a primitive defined by the language"));
1708+
let def_span = self.tcx.def_span(defid);
1709+
let msg = if defid.is_local() {
1710+
format!("{name} is defined in the current crate")
1711+
} else {
1712+
let crate_name = self.tcx.crate_name(defid.krate);
1713+
format!("{name} is defined in crate `{crate_name}")
1714+
};
1715+
diagnostic.span_note(def_span, msg);
1716+
};
1717+
1718+
let diagnose_adts =
1719+
|expected_adt : ty::AdtDef<'tcx>,
1720+
found_adt: ty::AdtDef<'tcx>,
1721+
diagnostic: &mut Diagnostic| {
1722+
let found_name = values.found.sort_string(self.tcx);
1723+
let expected_name = values.expected.sort_string(self.tcx);
1724+
1725+
let found_defid = found_adt.did();
1726+
let expected_defid = expected_adt.did();
1727+
1728+
diagnostic.note(format!("{found_name} and {expected_name} have similar names, but are actually distinct types"));
1729+
for (defid, name) in
1730+
[(found_defid, found_name), (expected_defid, expected_name)]
1731+
{
1732+
let def_span = self.tcx.def_span(defid);
1733+
1734+
let msg = if found_defid.is_local() && expected_defid.is_local() {
1735+
let module = self
1736+
.tcx
1737+
.parent_module_from_def_id(defid.expect_local())
1738+
.to_def_id();
1739+
let module_name = self.tcx.def_path(module).to_string_no_crate_verbose();
1740+
format!("{name} is defined in module `crate{module_name}` of the current crate")
1741+
} else if defid.is_local() {
1742+
format!("{name} is defined in the current crate")
1743+
} else {
1744+
let crate_name = self.tcx.crate_name(defid.krate);
1745+
format!("{name} is defined in crate `{crate_name}`")
1746+
};
1747+
diagnostic.span_note(def_span, msg);
1748+
}
1749+
};
1750+
1751+
match s {
1752+
Similar::Adts{expected, found} => {
1753+
diagnose_adts(expected, found, diag)
1754+
}
1755+
Similar::PrimitiveFound{expected, found: prim} => {
1756+
diagnose_primitive(prim, values.expected, expected.did(), diag)
1757+
}
1758+
Similar::PrimitiveExpected{expected: prim, found} => {
1759+
diagnose_primitive(prim, values.found, found.did(), diag)
1760+
}
1761+
}
1762+
}
1763+
TypeError::Sorts(values) => {
1764+
let extra = expected == found;
16581765
let sort_string = |ty: Ty<'tcx>| match (extra, ty.kind()) {
16591766
(true, ty::Opaque(def_id, _)) => {
16601767
let sm = self.tcx.sess.source_map();
@@ -1707,10 +1814,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17071814
);
17081815
}
17091816
}
1710-
(TypeError::ObjectUnsafeCoercion(_), _) => {
1817+
TypeError::ObjectUnsafeCoercion(_) => {
17111818
diag.note_unsuccessful_coercion(found, expected);
17121819
}
1713-
(_, _) => {
1820+
_ => {
17141821
debug!(
17151822
"note_type_err: exp_found={:?}, expected={:?} found={:?}",
17161823
exp_found, expected, found

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#![cfg_attr(bootstrap, feature(label_break_value))]
2121
#![feature(let_chains)]
2222
#![cfg_attr(bootstrap, feature(let_else))]
23+
#![feature(if_let_guard)]
2324
#![feature(min_specialization)]
2425
#![feature(never_type)]
2526
#![feature(try_blocks)]

compiler/rustc_middle/src/ty/sty.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_hir as hir;
1919
use rustc_hir::def_id::DefId;
2020
use rustc_index::vec::Idx;
2121
use rustc_macros::HashStable;
22-
use rustc_span::symbol::{kw, Symbol};
22+
use rustc_span::symbol::{kw, sym, Symbol};
2323
use rustc_target::abi::VariantIdx;
2424
use rustc_target::spec::abi;
2525
use std::borrow::Cow;
@@ -2207,6 +2207,35 @@ impl<'tcx> Ty<'tcx> {
22072207
}
22082208
}
22092209
}
2210+
2211+
// If `self` is a primitive, return its [`Symbol`].
2212+
pub fn primitive_symbol(self) -> Option<Symbol> {
2213+
match self.kind() {
2214+
ty::Bool => Some(sym::bool),
2215+
ty::Char => Some(sym::char),
2216+
ty::Float(f) => match f {
2217+
ty::FloatTy::F32 => Some(sym::f32),
2218+
ty::FloatTy::F64 => Some(sym::f64),
2219+
},
2220+
ty::Int(f) => match f {
2221+
ty::IntTy::Isize => Some(sym::isize),
2222+
ty::IntTy::I8 => Some(sym::i8),
2223+
ty::IntTy::I16 => Some(sym::i16),
2224+
ty::IntTy::I32 => Some(sym::i32),
2225+
ty::IntTy::I64 => Some(sym::i64),
2226+
ty::IntTy::I128 => Some(sym::i128),
2227+
},
2228+
ty::Uint(f) => match f {
2229+
ty::UintTy::Usize => Some(sym::usize),
2230+
ty::UintTy::U8 => Some(sym::u8),
2231+
ty::UintTy::U16 => Some(sym::u16),
2232+
ty::UintTy::U32 => Some(sym::u32),
2233+
ty::UintTy::U64 => Some(sym::u64),
2234+
ty::UintTy::U128 => Some(sym::u128),
2235+
},
2236+
_ => None,
2237+
}
2238+
}
22102239
}
22112240

22122241
/// Extra information about why we ended up with a particular variance.

compiler/rustc_passes/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -658,3 +658,10 @@ pub struct CollapseDebuginfo {
658658
#[label]
659659
pub defn_span: Span,
660660
}
661+
662+
#[derive(LintDiagnostic)]
663+
#[diag(passes::deprecated_annotation_has_no_effect)]
664+
pub struct DeprecatedAnnotationHasNoEffect {
665+
#[suggestion(applicability = "machine-applicable", code = "")]
666+
pub span: Span,
667+
}

compiler/rustc_passes/src/stability.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! A pass that annotates every item and method with its stability level,
22
//! propagating default levels lexically from parent to children ast nodes.
33
4+
use crate::errors;
45
use rustc_attr::{
56
self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable,
67
UnstableReason, VERSION_PLACEHOLDER,
@@ -122,16 +123,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
122123

123124
if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
124125
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
125-
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
126-
lint.build("this `#[deprecated]` annotation has no effect")
127-
.span_suggestion_short(
128-
*span,
129-
"remove the unnecessary deprecation attribute",
130-
"",
131-
rustc_errors::Applicability::MachineApplicable,
132-
)
133-
.emit();
134-
});
126+
self.tcx.emit_spanned_lint(
127+
USELESS_DEPRECATED,
128+
hir_id,
129+
*span,
130+
errors::DeprecatedAnnotationHasNoEffect { span: *span },
131+
);
135132
}
136133

137134
// `Deprecation` is just two pointers, no need to intern it

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ symbols! {
396396
assume_init,
397397
async_await,
398398
async_closure,
399+
async_fn_in_trait,
399400
atomic,
400401
atomic_mod,
401402
atomics,

compiler/rustc_target/src/spec/powerpc64_unknown_linux_gnu.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
use crate::abi::Endian;
2-
use crate::spec::{LinkerFlavor, RelroLevel, Target, TargetOptions};
2+
use crate::spec::{LinkerFlavor, Target, TargetOptions};
33

44
pub fn target() -> Target {
55
let mut base = super::linux_gnu_base::opts();
66
base.cpu = "ppc64".into();
77
base.add_pre_link_args(LinkerFlavor::Gcc, &["-m64"]);
88
base.max_atomic_width = Some(64);
99

10-
// ld.so in at least RHEL6 on ppc64 has a bug related to BIND_NOW, so only enable partial RELRO
11-
// for now. https://github.com/rust-lang/rust/pull/43170#issuecomment-315411474
12-
base.relro_level = RelroLevel::Partial;
13-
1410
Target {
1511
llvm_target: "powerpc64-unknown-linux-gnu".into(),
1612
pointer_width: 64,

compiler/rustc_typeck/src/check/writeback.rs

+4-18
Original file line numberDiff line numberDiff line change
@@ -717,27 +717,13 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
717717
Resolver { tcx: fcx.tcx, infcx: fcx, span, body, replaced_with_error: false }
718718
}
719719

720-
fn report_type_error(&self, t: Ty<'tcx>) {
720+
fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) {
721721
if !self.tcx.sess.has_errors().is_some() {
722722
self.infcx
723723
.emit_inference_failure_err(
724724
Some(self.body.id()),
725725
self.span.to_span(self.tcx),
726-
t.into(),
727-
E0282,
728-
false,
729-
)
730-
.emit();
731-
}
732-
}
733-
734-
fn report_const_error(&self, c: ty::Const<'tcx>) {
735-
if self.tcx.sess.has_errors().is_none() {
736-
self.infcx
737-
.emit_inference_failure_err(
738-
Some(self.body.id()),
739-
self.span.to_span(self.tcx),
740-
c.into(),
726+
p.into(),
741727
E0282,
742728
false,
743729
)
@@ -782,7 +768,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
782768
}
783769
Err(_) => {
784770
debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t);
785-
self.report_type_error(t);
771+
self.report_error(t);
786772
self.replaced_with_error = true;
787773
self.tcx().ty_error()
788774
}
@@ -799,7 +785,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
799785
Ok(ct) => self.tcx.erase_regions(ct),
800786
Err(_) => {
801787
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
802-
self.report_const_error(ct);
788+
self.report_error(ct);
803789
self.replaced_with_error = true;
804790
self.tcx().const_error(ct.ty())
805791
}

0 commit comments

Comments
 (0)