Skip to content

Commit 6fdaa71

Browse files
committed
Auto merge of #165244 - JonathanBrouwer:rollup-qKlclC9, r=JonathanBrouwer
Rollup of 7 perf-sensitive pull requests Successful merges: - #163339 (MIR move elimination [5/6]: Storage reconstruction) - #163359 (MIR move elimination [1.5/6]: Ensure ZSTs are always initialized) - #163525 (Move lang item collection to the resolver) - #163928 (do not prefer trivially true candidates with `-Znext-solver` ) - #164341 (Expand an early return case in `coerce_unsized`) - #164484 (Use adaptive sparse encoding for metadata tables) - #164607 (destringlyfy lint infrastructure)
2 parents f9ceb4a + 64a8aa5 commit 6fdaa71

283 files changed

Lines changed: 3226 additions & 1521 deletions

File tree

Some content is hidden

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

‎Cargo.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4658,7 +4658,6 @@ dependencies = [
46584658
"rustc_ast_lowering",
46594659
"rustc_attr_ir",
46604660
"rustc_attr_parsing",
4661-
"rustc_crate_store",
46624661
"rustc_data_structures",
46634662
"rustc_errors",
46644663
"rustc_feature",
@@ -4783,6 +4782,7 @@ dependencies = [
47834782
"rustc_ast_pretty",
47844783
"rustc_attr_ir",
47854784
"rustc_attr_parsing",
4785+
"rustc_crate_store",
47864786
"rustc_data_structures",
47874787
"rustc_errors",
47884788
"rustc_expand",

‎compiler/rustc_attr_ir/src/lint.rs‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use rustc_macros::{Decodable, Encodable, PrintAttribute, StableHash};
2-
use rustc_span::{Ident, Span, Symbol, sym};
2+
use rustc_span::{Span, Symbol, sym};
3+
use rustc_structures::LintName;
34

45
use crate::{HashIgnoredAttrId, PrintAttribute};
6+
57
#[derive(Clone, Copy, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
68
pub enum LintCheckKind {
79
Allow,
@@ -43,21 +45,7 @@ impl LintCheckKind {
4345
/// ```
4446
#[derive(Clone, Debug, StableHash, Encodable, Decodable, PrintAttribute)]
4547
pub struct LintCheck {
46-
/// The lint's tool name, if present.
47-
pub tool: Option<Ident>,
48-
/// The lint's name, minus the tool name if any.
49-
///
50-
/// For example:
51-
/// - `clippy::blah` -> `blah`
52-
/// - `unstable_imports` -> `unstable_imports`
53-
/// - `custom_tool::blah::bleh` -> `blah::bleh`
54-
pub lint_name: Symbol,
55-
/// The span of the lint name.
56-
///
57-
/// For example `#[deny(foo, bar, reason = "reason")]`
58-
/// produces multiple `LintCheck`s, one with a span pointing to `foo`
59-
/// and another pointing to `bar`.
60-
pub lint_span: Span,
48+
pub lint_name: LintName,
6149
pub kind: LintCheckKind,
6250
pub reason: Option<Symbol>,
6351
/// Needed by `LintExpectationId` to track fulfilled expectations
@@ -68,4 +56,10 @@ pub struct LintCheck {
6856
/// inside one attribute are all smooshed and flattened together, so
6957
/// multiple `LintCheck`s can have the same `attr_span`.
7058
pub attr_span: Span,
59+
/// The span of the entire lint name.
60+
///
61+
/// #[deny(foo::bar::baz)]
62+
/// ^^^^^^^^^^^^^
63+
pub lint_span: Span,
64+
pub tool_span: Option<Span>,
7165
}

‎compiler/rustc_attr_ir/src/pretty_printing.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ use rustc_data_structures::fx::FxIndexMap;
1414
use rustc_span::def_id::DefId;
1515
use rustc_span::hygiene::Transparency;
1616
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
17-
use rustc_structures::{CollapseMacroDebuginfo, CrateType, Limit, NativeLibKind, SanitizerSet};
17+
use rustc_structures::{
18+
CollapseMacroDebuginfo, CrateType, Limit, LintName, NativeLibKind, SanitizerSet,
19+
};
1820
use thin_vec::ThinVec;
1921

2022
use crate::HashIgnoredAttrId;
@@ -223,4 +225,5 @@ print_debug!(
223225
CrateType,
224226
NativeLibKind,
225227
CollapseMacroDebuginfo,
228+
LintName,
226229
);

‎compiler/rustc_attr_parsing/src/attributes/lint.rs‎

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use rustc_ast::join_path_syms;
21
use rustc_attr_ir::AttributeKind;
32
use rustc_attr_ir::lint::{LintCheck, LintCheckKind};
43
use rustc_attr_ir::target::{AssocCtxt, MethodKind, Target};
54
use rustc_lint_defs::builtin::UNUSED_ATTRIBUTES;
6-
use rustc_span::{Symbol, sym};
5+
use rustc_span::sym;
6+
use rustc_structures::LintName;
77
use thin_vec::ThinVec;
88

99
use crate::attributes::{AcceptMapping, AttributeParser, AttributeStability};
@@ -52,33 +52,21 @@ impl LintParser {
5252
match item {
5353
MetaItemOrLitParser::MetaItemParser(p) => {
5454
match p.args() {
55-
ArgParser::NoArgs => {
56-
let (tool, lint_name) = match &*p.path().0.segments {
57-
[] => unreachable!(),
58-
[lint_name] => (None, lint_name.ident.name),
59-
[tool, lint_name] => (Some(tool.ident), lint_name.ident.name),
60-
// Not reachable for any builtin lints,
61-
// but reachable using `register_tool`.
62-
[tool, multi_segment_lint_name @ ..] => (
63-
Some(tool.ident),
64-
Symbol::intern(&join_path_syms(
65-
multi_segment_lint_name
66-
.iter()
67-
.map(|seg| seg.ident.name),
68-
)),
69-
),
70-
};
71-
72-
self.lints.push(LintCheck {
73-
tool,
74-
lint_name,
75-
lint_span: p.span(),
76-
kind,
77-
attr_id,
78-
reason,
79-
attr_span,
80-
})
81-
}
55+
ArgParser::NoArgs => self.lints.push(LintCheck {
56+
lint_name: LintName::new(
57+
p.path().0.segments.iter().map(|s| s.ident.name),
58+
),
59+
kind,
60+
attr_id,
61+
reason,
62+
attr_span,
63+
lint_span: p.span(),
64+
tool_span: if let [tool, _, ..] = &*p.path().0.segments {
65+
Some(tool.span())
66+
} else {
67+
None
68+
},
69+
}),
8270
// We've found a `reason = "reason"` but we're not the last element.
8371
ArgParser::NameValue(nv) if p.path().word_is(sym::reason) => {
8472
cx.emit_err(diagnostics::MalformedAttribute {

‎compiler/rustc_driver_impl/src/lib.rs‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_session::output::invalid_output_for_target;
5959
use rustc_session::{EarlyDiagCtxt, Session, config};
6060
use rustc_span::def_id::LOCAL_CRATE;
6161
use rustc_span::{DUMMY_SP, FileName};
62-
use rustc_structures::CrateType;
62+
use rustc_structures::{CrateType, LintName};
6363
use rustc_target::json::ToJson;
6464
use rustc_target::spec::{Target, TargetTuple};
6565
use tracing::trace;
@@ -990,11 +990,9 @@ Available lint options:
990990
lints
991991
}
992992

993-
fn sort_lint_groups(
994-
lints: Vec<(&'static str, Vec<LintId>, bool)>,
995-
) -> Vec<(&'static str, Vec<LintId>)> {
993+
fn sort_lint_groups(lints: Vec<(LintName, Vec<LintId>, bool)>) -> Vec<(LintName, Vec<LintId>)> {
996994
let mut lints: Vec<_> = lints.into_iter().map(|(x, y, _)| (x, y)).collect();
997-
lints.sort_by_key(|l| l.0);
995+
lints.sort_by(|left, right| Ord::cmp(&left.0, &right.0));
998996
lints
999997
}
1000998

@@ -1041,7 +1039,7 @@ Available lint options:
10411039
loaded_groups
10421040
.iter()
10431041
.chain(&builtin_groups)
1044-
.map(|&(s, _)| s.chars().count())
1042+
.map(|(s, _)| s.name.as_str().chars().count())
10451043
.max()
10461044
.unwrap_or(0),
10471045
);
@@ -1054,7 +1052,7 @@ Available lint options:
10541052

10551053
safe_println!("Lint groups provided by rustc:\n");
10561054

1057-
let print_lint_groups = |lints: Vec<(&'static str, Vec<LintId>)>, all_warnings| {
1055+
let print_lint_groups = |lints: Vec<(LintName, Vec<LintId>)>, all_warnings| {
10581056
safe_println!(" {} sub-lints", padded("name"));
10591057
safe_println!(" {} ---------", padded("----"));
10601058

@@ -1063,7 +1061,7 @@ Available lint options:
10631061
}
10641062

10651063
for (name, to) in lints {
1066-
let name = name.to_lowercase().replace('_', "-");
1064+
let name = name.to_string().to_lowercase().replace('_', "-");
10671065
let desc = to
10681066
.into_iter()
10691067
.map(|x| x.to_string().replace('_', "-"))

‎compiler/rustc_hir_typeck/src/coercion.rs‎

Lines changed: 97 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
267267
}
268268

269269
// Consider coercing the subtype to a DST
270-
//
271-
// NOTE: this is wrapped in a `commit_if_ok` because it creates
272-
// a "spurious" type variable, and we don't want to have that
273-
// type variable in memory if the coercion fails.
274-
let unsize = self.commit_if_ok(|_| self.coerce_unsized(a, b));
270+
let unsize = self.coerce_unsized(a, b);
275271
match unsize {
276272
Ok(_) => {
277273
debug!("coerce: unsize successful");
@@ -589,8 +585,15 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
589585
// and call arg (among other positions).
590586
//
591587
// These targets are known to never be RHS in `LHS: CoerceUnsized<RHS>`.
592-
// That's because these are built-in types for which a core-provided impl
593-
// doesn't exist, and for which a user-written impl is invalid.
588+
// That's because one of the following is true.
589+
// - For the built-in types, a core-provided impl doesn't exist and a
590+
// user-written impl is invalid.
591+
// - For enums and unions, they can never be the target of a
592+
// `CoerceUnsized` impl.
593+
// - For structs, they can only be the target of a `CoerceUnsized` impl
594+
// if `LHS` and `RHS` are instances of the same struct type but with
595+
// at least one differing field type. This is impossible when we
596+
// exclude structs with any generic args.
594597
//
595598
// This is technically incomplete when users write impossible bounds like
596599
// `where T: CoerceUnsized<usize>`, for example, but that trait is unstable
@@ -619,6 +622,11 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
619622
| ty::CoroutineWitness(_, _)
620623
| ty::Never
621624
| ty::Tuple(_) => return Err(TypeError::Mismatch),
625+
ty::Adt(adt, args) => match adt.adt_kind() {
626+
ty::AdtKind::Enum | ty::AdtKind::Union => return Err(TypeError::Mismatch),
627+
ty::AdtKind::Struct if args.is_empty() => return Err(TypeError::Mismatch),
628+
_ => {}
629+
},
622630
_ => {}
623631
}
624632
// `&str: CoerceUnsized<&str>` does not hold but is encountered frequently
@@ -642,85 +650,92 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
642650
// a DST unless we have to. This currently comes out in the wash since
643651
// we can't unify [T] with U. But to properly support DST, we need to allow
644652
// that, at which point we will need extra checks on the target here.
653+
//
654+
// NOTE: this is wrapped in a `commit_if_ok` because it creates
655+
// a "spurious" type variable, and we don't want to have that
656+
// type variable in memory if the coercion fails.
657+
self.commit_if_ok(|_| {
658+
// Handle reborrows before selecting `Source: CoerceUnsized<Target>`.
659+
let reborrow = match (source.kind(), target.kind()) {
660+
(&ty::Ref(_, ty_a, mutbl_a), &ty::Ref(_, _, mutbl_b)) => {
661+
coerce_mutbls(mutbl_a, mutbl_b)?;
645662

646-
// Handle reborrows before selecting `Source: CoerceUnsized<Target>`.
647-
let reborrow = match (source.kind(), target.kind()) {
648-
(&ty::Ref(_, ty_a, mutbl_a), &ty::Ref(_, _, mutbl_b)) => {
649-
coerce_mutbls(mutbl_a, mutbl_b)?;
650-
651-
let coercion = RegionVariableOrigin::Coercion(self.cause.span);
652-
let r_borrow = self.next_region_var(coercion);
653-
654-
// We don't allow two-phase borrows here, at least for initial
655-
// implementation. If it happens that this coercion is a function argument,
656-
// the reborrow in coerce_borrowed_ptr will pick it up.
657-
let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
658-
659-
Some((
660-
Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
661-
Adjustment {
662-
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
663-
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
664-
},
665-
))
666-
}
667-
(&ty::Ref(_, ty_a, mt_a), &ty::RawPtr(_, mt_b)) => {
668-
coerce_mutbls(mt_a, mt_b)?;
669-
670-
Some((
671-
Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
672-
Adjustment {
673-
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
674-
target: Ty::new_ptr(self.tcx, ty_a, mt_b),
675-
},
676-
))
677-
}
678-
_ => None,
679-
};
680-
let coerce_source = reborrow.as_ref().map_or(source, |(_, r)| r.target);
681-
682-
// Setup either a subtyping or a LUB relationship between
683-
// the `CoerceUnsized` target type and the expected type.
684-
// We only have the latter, so we use an inference variable
685-
// for the former and let type inference do the rest.
686-
let coerce_target = self.next_ty_var(self.cause.span);
687-
688-
let mut coercion = self.unify_and(
689-
coerce_target,
690-
target,
691-
reborrow.map(|(deref, autoref)| [deref, autoref]).into_flat_iter(),
692-
Adjust::Pointer(PointerCoercion::Unsize),
693-
ForceLeakCheck::No,
694-
)?;
695-
696-
// Create an obligation for `Source: CoerceUnsized<Target>`.
697-
let cause = self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target });
698-
let pred = ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]);
699-
let obligation = Obligation::new(self.tcx, cause, self.fcx.param_env, pred);
700-
701-
if self.next_trait_solver() {
702-
coercion.obligations.push(obligation);
663+
let coercion = RegionVariableOrigin::Coercion(self.cause.span);
664+
let r_borrow = self.next_region_var(coercion);
665+
666+
// We don't allow two-phase borrows here, at least for initial
667+
// implementation. If it happens that this coercion is a function argument,
668+
// the reborrow in coerce_borrowed_ptr will pick it up.
669+
let mutbl = AutoBorrowMutability::new(mutbl_b, AllowTwoPhase::No);
670+
671+
Some((
672+
Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
673+
Adjustment {
674+
kind: Adjust::Borrow(AutoBorrow::Ref(mutbl)),
675+
target: Ty::new_ref(self.tcx, r_borrow, ty_a, mutbl_b),
676+
},
677+
))
678+
}
679+
(&ty::Ref(_, ty_a, mt_a), &ty::RawPtr(_, mt_b)) => {
680+
coerce_mutbls(mt_a, mt_b)?;
681+
682+
Some((
683+
Adjustment { kind: Adjust::Deref(DerefAdjustKind::Builtin), target: ty_a },
684+
Adjustment {
685+
kind: Adjust::Borrow(AutoBorrow::RawPtr(mt_b)),
686+
target: Ty::new_ptr(self.tcx, ty_a, mt_b),
687+
},
688+
))
689+
}
690+
_ => None,
691+
};
692+
let coerce_source = reborrow.as_ref().map_or(source, |(_, r)| r.target);
693+
694+
// Setup either a subtyping or a LUB relationship between
695+
// the `CoerceUnsized` target type and the expected type.
696+
// We only have the latter, so we use an inference variable
697+
// for the former and let type inference do the rest.
698+
let coerce_target = self.next_ty_var(self.cause.span);
699+
700+
let mut coercion = self.unify_and(
701+
coerce_target,
702+
target,
703+
reborrow.map(|(deref, autoref)| [deref, autoref]).into_flat_iter(),
704+
Adjust::Pointer(PointerCoercion::Unsize),
705+
ForceLeakCheck::No,
706+
)?;
703707

704-
if self
705-
.infcx
706-
.visit_proof_tree(
707-
Goal::new(self.tcx, self.param_env, pred),
708-
&mut CoerceVisitor { fcx: self.fcx, span: self.cause.span, errored: false },
709-
)
710-
.is_break()
711-
{
712-
return Err(TypeError::Mismatch);
708+
// Create an obligation for `Source: CoerceUnsized<Target>`.
709+
let cause =
710+
self.cause(self.cause.span, ObligationCauseCode::Coercion { source, target });
711+
let pred =
712+
ty::TraitRef::new(self.tcx, coerce_unsized_did, [coerce_source, coerce_target]);
713+
let obligation = Obligation::new(self.tcx, cause, self.fcx.param_env, pred);
714+
715+
if self.next_trait_solver() {
716+
coercion.obligations.push(obligation);
717+
718+
if self
719+
.infcx
720+
.visit_proof_tree(
721+
Goal::new(self.tcx, self.param_env, pred),
722+
&mut CoerceVisitor { fcx: self.fcx, span: self.cause.span, errored: false },
723+
)
724+
.is_break()
725+
{
726+
return Err(TypeError::Mismatch);
727+
}
728+
} else {
729+
self.coerce_unsized_old_solver(
730+
obligation,
731+
&mut coercion,
732+
coerce_unsized_did,
733+
unsize_did,
734+
)?;
713735
}
714-
} else {
715-
self.coerce_unsized_old_solver(
716-
obligation,
717-
&mut coercion,
718-
coerce_unsized_did,
719-
unsize_did,
720-
)?;
721-
}
722736

723-
Ok(coercion)
737+
Ok(coercion)
738+
})
724739
}
725740

726741
fn coerce_unsized_old_solver(

0 commit comments

Comments
 (0)