Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #102149

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,15 @@ impl FnDeclKind {
_ => false,
}
}

fn async_fn_allowed(&self, tcx: TyCtxt<'_>) -> bool {
match self {
FnDeclKind::Fn | FnDeclKind::Inherent => true,
FnDeclKind::Impl if tcx.features().async_fn_in_trait => true,
FnDeclKind::Trait if tcx.features().async_fn_in_trait => true,
_ => false,
}
}
}

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

let output = if let Some((ret_id, span)) = make_ret_async {
if !kind.impl_trait_allowed(self.tcx) {
if !kind.async_fn_allowed(self.tcx) {
match kind {
FnDeclKind::Trait | FnDeclKind::Impl => {
self.tcx
.sess
.create_feature_err(
TraitFnAsync { fn_span, span },
sym::return_position_impl_trait_in_trait,
sym::async_fn_in_trait,
)
.emit();
}
Expand Down Expand Up @@ -1917,9 +1926,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let future_bound = this.lower_async_fn_output_type_to_future_bound(
output,
span,
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
in_trait,
if in_trait && !this.tcx.features().return_position_impl_trait_in_trait {
ImplTraitContext::Disallowed(ImplTraitPosition::TraitReturn)
} else {
ImplTraitContext::ReturnPositionOpaqueTy {
origin: hir::OpaqueTyOrigin::FnReturn(fn_def_id),
in_trait,
}
},
);

Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/passes.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,6 @@ passes_link_ordinal = attribute should be applied to a foreign function or stati

passes_collapse_debuginfo = `collapse_debuginfo` attribute should be applied to macro definitions
.label = not a macro definition

passes_deprecated_annotation_has_no_effect = this `#[deprecated]` annotation has no effect
.suggestion = remove the unnecessary deprecation attribute
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,8 @@ declare_features! (
(active, associated_type_defaults, "1.2.0", Some(29661), None),
/// Allows `async || body` closures.
(active, async_closure, "1.37.0", Some(62290), None),
/// Alows async functions to be declared, implemented, and used in traits.
(incomplete, async_fn_in_trait, "CURRENT_RUSTC_VERSION", Some(91611), None),
/// Allows `extern "C-unwind" fn` to enable unwinding across ABI boundaries.
(active, c_unwind, "1.52.0", Some(74990), None),
/// Allows using C-variadics.
Expand Down
81 changes: 54 additions & 27 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,9 @@ pub struct FmtPrinterData<'a, 'tcx> {
in_value: bool,
pub print_alloc_ids: bool,

// set of all named (non-anonymous) region names
used_region_names: FxHashSet<Symbol>,

region_index: usize,
binder_depth: usize,
printed_type_count: usize,
Expand Down Expand Up @@ -2139,23 +2141,31 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
where
T: Print<'tcx, Self, Output = Self, Error = fmt::Error> + TypeFoldable<'tcx>,
{
fn name_by_region_index(index: usize) -> Symbol {
match index {
0 => Symbol::intern("'r"),
1 => Symbol::intern("'s"),
i => Symbol::intern(&format!("'t{}", i - 2)),
fn name_by_region_index(
index: usize,
available_names: &mut Vec<Symbol>,
num_available: usize,
) -> Symbol {
if let Some(name) = available_names.pop() {
name
} else {
Symbol::intern(&format!("'z{}", index - num_available))
}
}

debug!("name_all_regions");

// Replace any anonymous late-bound regions with named
// variants, using new unique identifiers, so that we can
// clearly differentiate between named and unnamed regions in
// the output. We'll probably want to tweak this over time to
// decide just how much information to give.
if self.binder_depth == 0 {
self.prepare_late_bound_region_info(value);
self.prepare_region_info(value);
}

debug!("self.used_region_names: {:?}", &self.used_region_names);

let mut empty = true;
let mut start_or_continue = |cx: &mut Self, start: &str, cont: &str| {
let w = if empty {
Expand All @@ -2172,13 +2182,24 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {

define_scoped_cx!(self);

let possible_names =
('a'..='z').rev().map(|s| Symbol::intern(&format!("'{s}"))).collect::<Vec<_>>();

let mut available_names = possible_names
.into_iter()
.filter(|name| !self.used_region_names.contains(&name))
.collect::<Vec<_>>();
debug!(?available_names);
let num_available = available_names.len();

let mut region_index = self.region_index;
let mut next_name = |this: &Self| loop {
let name = name_by_region_index(region_index);
let mut next_name = |this: &Self| {
let name = name_by_region_index(region_index, &mut available_names, num_available);
debug!(?name);
region_index += 1;
if !this.used_region_names.contains(&name) {
break name;
}
assert!(!this.used_region_names.contains(&name));

name
};

// If we want to print verbosely, then print *all* binders, even if they
Expand All @@ -2199,6 +2220,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
ty::BrAnon(_) | ty::BrEnv => {
start_or_continue(&mut self, "for<", ", ");
let name = next_name(&self);
debug!(?name);
do_continue(&mut self, name);
ty::BrNamed(CRATE_DEF_ID.to_def_id(), name)
}
Expand Down Expand Up @@ -2292,29 +2314,37 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
Ok(inner)
}

fn prepare_late_bound_region_info<T>(&mut self, value: &ty::Binder<'tcx, T>)
fn prepare_region_info<T>(&mut self, value: &ty::Binder<'tcx, T>)
where
T: TypeVisitable<'tcx>,
{
struct LateBoundRegionNameCollector<'a, 'tcx> {
used_region_names: &'a mut FxHashSet<Symbol>,
struct RegionNameCollector<'tcx> {
used_region_names: FxHashSet<Symbol>,
type_collector: SsoHashSet<Ty<'tcx>>,
}

impl<'tcx> ty::visit::TypeVisitor<'tcx> for LateBoundRegionNameCollector<'_, 'tcx> {
impl<'tcx> RegionNameCollector<'tcx> {
fn new() -> Self {
RegionNameCollector {
used_region_names: Default::default(),
type_collector: SsoHashSet::new(),
}
}
}

impl<'tcx> ty::visit::TypeVisitor<'tcx> for RegionNameCollector<'tcx> {
type BreakTy = ();

fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
trace!("address: {:p}", r.0.0);
if let ty::ReLateBound(_, ty::BoundRegion { kind: ty::BrNamed(_, name), .. }) = *r {
self.used_region_names.insert(name);
} else if let ty::RePlaceholder(ty::PlaceholderRegion {
name: ty::BrNamed(_, name),
..
}) = *r
{

// Collect all named lifetimes. These allow us to prevent duplication
// of already existing lifetime names when introducing names for
// anonymous late-bound regions.
if let Some(name) = r.get_name() {
self.used_region_names.insert(name);
}

r.super_visit_with(self)
}

Expand All @@ -2330,12 +2360,9 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
}
}

self.used_region_names.clear();
let mut collector = LateBoundRegionNameCollector {
used_region_names: &mut self.used_region_names,
type_collector: SsoHashSet::new(),
};
let mut collector = RegionNameCollector::new();
value.visit_with(&mut collector);
self.used_region_names = collector.used_region_names;
self.region_index = 0;
}
}
Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,17 @@ impl BoundRegionKind {
_ => false,
}
}

pub fn get_name(&self) -> Option<Symbol> {
if self.is_named() {
match *self {
BoundRegionKind::BrNamed(_, name) => return Some(name),
_ => unreachable!(),
}
}

None
}
}

pub trait Article {
Expand Down Expand Up @@ -1441,6 +1452,23 @@ impl<'tcx> Region<'tcx> {
*self.0.0
}

pub fn get_name(self) -> Option<Symbol> {
if self.has_name() {
let name = match *self {
ty::ReEarlyBound(ebr) => Some(ebr.name),
ty::ReLateBound(_, br) => br.kind.get_name(),
ty::ReFree(fr) => fr.bound_region.get_name(),
ty::ReStatic => Some(kw::StaticLifetime),
ty::RePlaceholder(placeholder) => placeholder.name.get_name(),
_ => None,
};

return name;
}

None
}

/// Is this region named by the user?
pub fn has_name(self) -> bool {
match *self {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,10 @@ pub struct CollapseDebuginfo {
#[label]
pub defn_span: Span,
}

#[derive(LintDiagnostic)]
#[diag(passes::deprecated_annotation_has_no_effect)]
pub struct DeprecatedAnnotationHasNoEffect {
#[suggestion(applicability = "machine-applicable", code = "")]
pub span: Span,
}
17 changes: 7 additions & 10 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! A pass that annotates every item and method with its stability level,
//! propagating default levels lexically from parent to children ast nodes.

use crate::errors;
use rustc_attr::{
self as attr, rust_version_symbol, ConstStability, Stability, StabilityLevel, Unstable,
UnstableReason, VERSION_PLACEHOLDER,
Expand Down Expand Up @@ -122,16 +123,12 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {

if kind == AnnotationKind::Prohibited || kind == AnnotationKind::DeprecationProhibited {
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
self.tcx.struct_span_lint_hir(USELESS_DEPRECATED, hir_id, *span, |lint| {
lint.build("this `#[deprecated]` annotation has no effect")
.span_suggestion_short(
*span,
"remove the unnecessary deprecation attribute",
"",
rustc_errors::Applicability::MachineApplicable,
)
.emit();
});
self.tcx.emit_spanned_lint(
USELESS_DEPRECATED,
hir_id,
*span,
errors::DeprecatedAnnotationHasNoEffect { span: *span },
);
}

// `Deprecation` is just two pointers, no need to intern it
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ symbols! {
assume_init,
async_await,
async_closure,
async_fn_in_trait,
atomic,
atomic_mod,
atomics,
Expand Down
22 changes: 4 additions & 18 deletions compiler/rustc_typeck/src/check/writeback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,27 +717,13 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
Resolver { tcx: fcx.tcx, infcx: fcx, span, body, replaced_with_error: false }
}

fn report_type_error(&self, t: Ty<'tcx>) {
fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) {
if !self.tcx.sess.has_errors().is_some() {
self.infcx
.emit_inference_failure_err(
Some(self.body.id()),
self.span.to_span(self.tcx),
t.into(),
E0282,
false,
)
.emit();
}
}

fn report_const_error(&self, c: ty::Const<'tcx>) {
if self.tcx.sess.has_errors().is_none() {
self.infcx
.emit_inference_failure_err(
Some(self.body.id()),
self.span.to_span(self.tcx),
c.into(),
p.into(),
E0282,
false,
)
Expand Down Expand Up @@ -782,7 +768,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
}
Err(_) => {
debug!("Resolver::fold_ty: input type `{:?}` not fully resolvable", t);
self.report_type_error(t);
self.report_error(t);
self.replaced_with_error = true;
self.tcx().ty_error()
}
Expand All @@ -799,7 +785,7 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Resolver<'cx, 'tcx> {
Ok(ct) => self.tcx.erase_regions(ct),
Err(_) => {
debug!("Resolver::fold_const: input const `{:?}` not fully resolvable", ct);
self.report_const_error(ct);
self.report_error(ct);
self.replaced_with_error = true;
self.tcx().const_error(ct.ty())
}
Expand Down
14 changes: 4 additions & 10 deletions src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,23 @@ impl Step for JsonDocs {

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
let default = run.builder.config.docs;
run.alias("rust-json-docs").default_condition(default)
run.alias("rust-docs-json").default_condition(default)
}

fn make_run(run: RunConfig<'_>) {
run.builder.ensure(JsonDocs { host: run.target });
}

/// Builds the `rust-json-docs` installer component.
/// Builds the `rust-docs-json` installer component.
fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> {
// This prevents JSON docs from being built for "dist" or "install"
// on the stable/beta channels. The JSON format is not stable yet and
// should not be included in stable/beta toolchains.
if !builder.build.unstable_features() {
return None;
}

let host = self.host;
builder.ensure(crate::doc::JsonStd { stage: builder.top_stage, target: host });

let dest = "share/doc/rust/json";

let mut tarball = Tarball::new(builder, "rust-json-docs", &host.triple);
let mut tarball = Tarball::new(builder, "rust-docs-json", &host.triple);
tarball.set_product_name("Rust Documentation In JSON Format");
tarball.is_preview(true);
tarball.add_bulk_dir(&builder.json_doc_out(host), dest);
Some(tarball.generate())
}
Expand Down
1 change: 0 additions & 1 deletion src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,6 @@ h2.location a {
}

.method > .code-header, .trait-impl > .code-header {
max-width: calc(100% - 41px);
display: block;
}

Expand Down
Loading