Skip to content

Split elided_lifetime_in_paths into tied and untied #120808

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use hir::{BodyId, HirId};
use rustc_abi::ExternAbi;
use rustc_ast::*;
use rustc_errors::ErrorGuaranteed;
use rustc_hir::TySource;
use rustc_hir::def_id::DefId;
use rustc_middle::span_bug;
use rustc_middle::ty::{Asyncness, ResolverAstLowering};
Expand Down Expand Up @@ -174,12 +175,14 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: self.next_id(),
kind: hir::TyKind::InferDelegation(sig_id, hir::InferDelegationKind::Input(arg)),
span,
source: TySource::Other,
}));

let output = self.arena.alloc(hir::Ty {
hir_id: self.next_id(),
kind: hir::TyKind::InferDelegation(sig_id, hir::InferDelegationKind::Output),
span,
source: TySource::Other,
});

self.arena.alloc(hir::FnDecl {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ use rustc_ast::ptr::P as AstP;
use rustc_ast::*;
use rustc_ast_pretty::pprust::expr_to_string;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir as hir;
use rustc_hir::HirId;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::{self as hir, HirId, TySource};
use rustc_middle::span_bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::errors::report_lit_error;
Expand Down Expand Up @@ -761,6 +760,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir_id: self.next_id(),
kind: hir::TyKind::Path(resume_ty),
span: unstable_span,
source: TySource::Other,
};
let inputs = arena_vec![self; input_ty];

Expand Down
39 changes: 32 additions & 7 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE, LocalDefId};
use rustc_hir::{
self as hir, AngleBrackets, ConstArg, GenericArg, HirId, ItemLocalMap, LangItem,
LifetimeSource, LifetimeSyntax, ParamName, TraitCandidate,
LifetimeSource, LifetimeSyntax, ParamName, TraitCandidate, TySource,
};
use rustc_index::{Idx, IndexSlice, IndexVec};
use rustc_macros::extension;
Expand Down Expand Up @@ -1181,7 +1181,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
bounds,
TaggedRef::new(lifetime_bound, TraitObjectSyntax::None),
);
return hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.next_id() };
return hir::Ty {
kind,
span: self.lower_span(t.span),
hir_id: self.next_id(),
source: TySource::Other,
};
}

let id = self.lower_node_id(t.id);
Expand All @@ -1198,7 +1203,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn ty(&mut self, span: Span, kind: hir::TyKind<'hir>) -> hir::Ty<'hir> {
hir::Ty { hir_id: self.next_id(), kind, span: self.lower_span(span) }
hir::Ty {
hir_id: self.next_id(),
kind,
span: self.lower_span(span),
source: TySource::Other,
}
}

fn ty_tup(&mut self, span: Span, tys: &'hir [hir::Ty<'hir>]) -> hir::Ty<'hir> {
Expand All @@ -1219,7 +1229,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let lifetime = self.lower_ty_direct_lifetime(t, *region);
let kind = hir::TyKind::Ref(lifetime, self.lower_mt(mt, itctx));
let span = self.lower_span(t.span);
let arg = hir::Ty { kind, span, hir_id: self.next_id() };
let arg = hir::Ty { kind, span, hir_id: self.next_id(), source: TySource::Other };
let args = self.arena.alloc(hir::GenericArgs {
args: self.arena.alloc([hir::GenericArg::Type(self.arena.alloc(arg))]),
constraints: &[],
Expand Down Expand Up @@ -1384,7 +1394,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
};

hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
hir::Ty {
kind,
span: self.lower_span(t.span),
hir_id: self.lower_node_id(t.id),
source: TySource::Other,
}
}

fn lower_ty_direct_lifetime(
Expand Down Expand Up @@ -2382,7 +2397,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}
}

fn ty_path(&mut self, mut hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
fn ty_path(&mut self, hir_id: HirId, span: Span, qpath: hir::QPath<'hir>) -> hir::Ty<'hir> {
self.ty_path_with_source(hir_id, span, qpath, TySource::Other)
}

fn ty_path_with_source(
&mut self,
mut hir_id: HirId,
span: Span,
qpath: hir::QPath<'hir>,
source: TySource,
) -> hir::Ty<'hir> {
let kind = match qpath {
hir::QPath::Resolved(None, path) => {
// Turn trait object paths into `TyKind::TraitObject` instead.
Expand All @@ -2409,7 +2434,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
_ => hir::TyKind::Path(qpath),
};

hir::Ty { hir_id, kind, span: self.lower_span(span) }
hir::Ty { hir_id, kind, span: self.lower_span(span), source }
}

/// Invoked to create the lifetime argument(s) for an elided trait object
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_ast_lowering/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use rustc_ast::{self as ast, *};
use rustc_hir::def::{DefKind, PartialRes, PerNS, Res};
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, GenericArg};
use rustc_hir::{self as hir, GenericArg, TySource};
use rustc_middle::{span_bug, ty};
use rustc_session::parse::add_feature_diagnostics;
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
Expand Down Expand Up @@ -169,7 +169,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// e.g., `Vec` in `Vec::new` or `<I as Iterator>::Item` in
// `<I as Iterator>::Item::default`.
let new_id = self.next_id();
self.arena.alloc(self.ty_path(new_id, path.span, hir::QPath::Resolved(qself, path)))
self.arena.alloc(self.ty_path_with_source(
new_id,
path.span,
hir::QPath::Resolved(qself, path),
TySource::ImplicitSelf,
))
};

// Anything after the base path are associated "extensions",
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_baked_icu_data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
//! ```

// tidy-alphabetical-start
#![allow(elided_lifetimes_in_paths)]
#![allow(internal_features)]
#![allow(unreachable_pub)] // because this crate is mostly generated code
#![doc(rust_logo)]
#![feature(rustdoc_internals)]
// #![warn(unreachable_pub)] // don't use because this crate is mostly generated code
// tidy-alphabetical-end
#![cfg_attr(bootstrap, allow(elided_lifetimes_in_paths))]
#![cfg_attr(not(bootstrap), allow(hidden_lifetimes_in_paths))]

mod data {
include!("data/mod.rs");
Expand Down
20 changes: 18 additions & 2 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,12 @@ pub struct InferArg {

impl InferArg {
pub fn to_ty(&self) -> Ty<'static> {
Ty { kind: TyKind::Infer(()), span: self.span, hir_id: self.hir_id }
Ty {
kind: TyKind::Infer(()),
span: self.span,
hir_id: self.hir_id,
source: TySource::Other,
}
}
}

Expand Down Expand Up @@ -3274,6 +3279,16 @@ impl<'hir> AssocItemConstraintKind<'hir> {
}
}

#[derive(Debug, Clone, Copy, PartialEq, HashStable_Generic)]
pub enum TySource {
/// `Vec` in `Vec::new`
ImplicitSelf,

/// Details not yet needed. Feel free to give useful
/// categorization to these usages.
Other,
}

/// An uninhabited enum used to make `Infer` variants on [`Ty`] and [`ConstArg`] be
/// unreachable. Zero-Variant enums are guaranteed to have the same layout as the never
/// type.
Expand All @@ -3293,6 +3308,7 @@ pub struct Ty<'hir, Unambig = ()> {
pub hir_id: HirId,
pub span: Span,
pub kind: TyKind<'hir, Unambig>,
pub source: TySource,
}

impl<'hir> Ty<'hir, AmbigArg> {
Expand Down Expand Up @@ -4991,7 +5007,7 @@ mod size_asserts {
static_assert_size!(StmtKind<'_>, 16);
static_assert_size!(TraitItem<'_>, 88);
static_assert_size!(TraitItemKind<'_>, 48);
static_assert_size!(Ty<'_>, 48);
static_assert_size!(Ty<'_>, 56);
static_assert_size!(TyKind<'_>, 32);
// tidy-alphabetical-end
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir/src/hir/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ macro_rules! define_tests {

define_tests! {
cast_never TyKind Never {}
cast_tup TyKind Tup { 0: &[Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }] }
cast_ptr TyKind Ptr { 0: MutTy { ty: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never }, mutbl: Mutability::Not }}
cast_tup TyKind Tup { 0: &[Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never, source: TySource::Other }] }
cast_ptr TyKind Ptr { 0: MutTy { ty: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never, source: TySource::Other }, mutbl: Mutability::Not }}
cast_array TyKind Array {
0: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never },
0: &Ty { span: DUMMY_SP, hir_id: HirId::INVALID, kind: TyKind::Never, source: TySource::Other },
1: &ConstArg { hir_id: HirId::INVALID, kind: ConstArgKind::Anon(&AnonConst {
hir_id: HirId::INVALID,
def_id: LocalDefId { local_def_index: DefIndex::ZERO },
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir/src/intravisit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -978,15 +978,15 @@ pub fn walk_unambig_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) ->
match typ.try_as_ambig_ty() {
Some(ambig_ty) => visitor.visit_ty(ambig_ty),
None => {
let Ty { hir_id, span, kind: _ } = typ;
let Ty { hir_id, span, kind: _, source: _ } = typ;
try_visit!(visitor.visit_id(*hir_id));
visitor.visit_infer(*hir_id, *span, InferKind::Ty(typ))
}
}
}

pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) -> V::Result {
let Ty { hir_id, span: _, kind } = typ;
let Ty { hir_id, span: _, kind, source: _ } = typ;
try_visit!(visitor.visit_id(*hir_id));

match *kind {
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ lint_hidden_glob_reexport = private item shadows public glob re-export
.note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here
.note_private_item = but the private item here shadows it

lint_hidden_lifetime_parameters = hidden lifetime parameters in types are deprecated
lint_hidden_lifetime_in_path =
paths containing hidden lifetime parameters are deprecated

lint_hidden_lifetime_in_path_suggestion =
indicate the anonymous lifetime

lint_hidden_unicode_codepoints = unicode codepoint changing visible direction of text present in {$label}
.label = this {$label} contains {$count ->
Expand Down
20 changes: 20 additions & 0 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,26 @@ impl LintStore {
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
}

#[track_caller]
pub fn register_renamed_group(&mut self, old_name: &'static str, new_name: &'static str) {
let prev_lint = self.lint_groups.insert(
old_name,
LintGroup {
lint_ids: vec![],
is_externally_loaded: false,
depr: Some(LintAlias { name: new_name, silent: false }),
},
);

if prev_lint.is_some() {
bug!("The lint group {old_name} has already been registered");
}

if !self.lint_groups.contains_key(new_name) {
bug!("The lint group {new_name} has not been registered");
}
}

pub fn register_removed(&mut self, name: &str, reason: &str) {
self.by_name.insert(name.into(), Removed(reason.into()));
}
Expand Down
17 changes: 1 addition & 16 deletions compiler/rustc_lint/src/early/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
use std::borrow::Cow;

use rustc_ast::util::unicode::TEXT_FLOW_CONTROL_CHARS;
use rustc_errors::{
Applicability, Diag, DiagArgValue, LintDiagnostic, elided_lifetime_in_path_suggestion,
};
use rustc_errors::{Applicability, Diag, DiagArgValue, LintDiagnostic};
use rustc_middle::middle::stability;
use rustc_middle::ty::TyCtxt;
use rustc_session::Session;
Expand Down Expand Up @@ -75,19 +73,6 @@ pub fn decorate_builtin_lint(
lints::MacroExpandedMacroExportsAccessedByAbsolutePaths { definition: span_def }
.decorate_lint(diag)
}

BuiltinLintDiag::ElidedLifetimesInPaths(n, path_span, incl_angl_brckt, insertion_span) => {
lints::ElidedLifetimesInPaths {
subdiag: elided_lifetime_in_path_suggestion(
sess.source_map(),
n,
path_span,
incl_angl_brckt,
insertion_span,
),
}
.decorate_lint(diag);
}
BuiltinLintDiag::UnknownCrateTypes { span, candidate } => {
let sugg = candidate.map(|candidate| lints::UnknownCrateTypesSub { span, candidate });
lints::UnknownCrateTypes { sugg }.decorate_lint(diag);
Expand Down
Loading
Loading