Skip to content

Commit 62270fb

Browse files
committed
Auto merge of #117204 - nnethercote:rustc_ast_passes, r=compiler-errors
Minor improvements to `rustc_ast_passes` Some improvements I found while looking at this code. r? `@compiler-errors`
2 parents 46455dc + 5b391b0 commit 62270fb

File tree

6 files changed

+145
-176
lines changed

6 files changed

+145
-176
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -3512,7 +3512,6 @@ dependencies = [
35123512
"rustc_span",
35133513
"rustc_target",
35143514
"thin-vec",
3515-
"tracing",
35163515
]
35173516

35183517
[[package]]

compiler/rustc_ast_passes/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ rustc_session = { path = "../rustc_session" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
2121
thin-vec = "0.2.12"
22-
tracing = "0.1"
2322
# tidy-alphabetical-end

compiler/rustc_ast_passes/src/ast_validation.rs

+45-53
Original file line numberDiff line numberDiff line change
@@ -1442,62 +1442,54 @@ fn deny_equality_constraints(
14421442
let mut err = errors::EqualityInWhere { span: predicate.span, assoc: None, assoc2: None };
14431443

14441444
// Given `<A as Foo>::Bar = RhsTy`, suggest `A: Foo<Bar = RhsTy>`.
1445-
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind {
1446-
if let TyKind::Path(None, path) = &qself.ty.kind {
1447-
match &path.segments[..] {
1448-
[PathSegment { ident, args: None, .. }] => {
1449-
for param in &generics.params {
1450-
if param.ident == *ident {
1451-
let param = ident;
1452-
match &full_path.segments[qself.position..] {
1453-
[PathSegment { ident, args, .. }] => {
1454-
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1455-
let mut assoc_path = full_path.clone();
1456-
// Remove `Bar` from `Foo::Bar`.
1457-
assoc_path.segments.pop();
1458-
let len = assoc_path.segments.len() - 1;
1459-
let gen_args = args.as_deref().cloned();
1460-
// Build `<Bar = RhsTy>`.
1461-
let arg = AngleBracketedArg::Constraint(AssocConstraint {
1462-
id: rustc_ast::node_id::DUMMY_NODE_ID,
1463-
ident: *ident,
1464-
gen_args,
1465-
kind: AssocConstraintKind::Equality {
1466-
term: predicate.rhs_ty.clone().into(),
1467-
},
1468-
span: ident.span,
1469-
});
1470-
// Add `<Bar = RhsTy>` to `Foo`.
1471-
match &mut assoc_path.segments[len].args {
1472-
Some(args) => match args.deref_mut() {
1473-
GenericArgs::Parenthesized(_) => continue,
1474-
GenericArgs::AngleBracketed(args) => {
1475-
args.args.push(arg);
1476-
}
1477-
},
1478-
empty_args => {
1479-
*empty_args = Some(
1480-
AngleBracketedArgs {
1481-
span: ident.span,
1482-
args: thin_vec![arg],
1483-
}
1484-
.into(),
1485-
);
1486-
}
1487-
}
1488-
err.assoc = Some(errors::AssociatedSuggestion {
1489-
span: predicate.span,
1490-
ident: *ident,
1491-
param: *param,
1492-
path: pprust::path_to_string(&assoc_path),
1493-
})
1494-
}
1495-
_ => {}
1496-
};
1445+
if let TyKind::Path(Some(qself), full_path) = &predicate.lhs_ty.kind
1446+
&& let TyKind::Path(None, path) = &qself.ty.kind
1447+
&& let [PathSegment { ident, args: None, .. }] = &path.segments[..]
1448+
{
1449+
for param in &generics.params {
1450+
if param.ident == *ident
1451+
&& let [PathSegment { ident, args, .. }] = &full_path.segments[qself.position..]
1452+
{
1453+
// Make a new `Path` from `foo::Bar` to `Foo<Bar = RhsTy>`.
1454+
let mut assoc_path = full_path.clone();
1455+
// Remove `Bar` from `Foo::Bar`.
1456+
assoc_path.segments.pop();
1457+
let len = assoc_path.segments.len() - 1;
1458+
let gen_args = args.as_deref().cloned();
1459+
// Build `<Bar = RhsTy>`.
1460+
let arg = AngleBracketedArg::Constraint(AssocConstraint {
1461+
id: rustc_ast::node_id::DUMMY_NODE_ID,
1462+
ident: *ident,
1463+
gen_args,
1464+
kind: AssocConstraintKind::Equality {
1465+
term: predicate.rhs_ty.clone().into(),
1466+
},
1467+
span: ident.span,
1468+
});
1469+
// Add `<Bar = RhsTy>` to `Foo`.
1470+
match &mut assoc_path.segments[len].args {
1471+
Some(args) => match args.deref_mut() {
1472+
GenericArgs::Parenthesized(_) => continue,
1473+
GenericArgs::AngleBracketed(args) => {
1474+
args.args.push(arg);
14971475
}
1476+
},
1477+
empty_args => {
1478+
*empty_args = Some(
1479+
AngleBracketedArgs {
1480+
span: ident.span,
1481+
args: thin_vec![arg],
1482+
}
1483+
.into(),
1484+
);
14981485
}
14991486
}
1500-
_ => {}
1487+
err.assoc = Some(errors::AssociatedSuggestion {
1488+
span: predicate.span,
1489+
ident: *ident,
1490+
param: param.ident,
1491+
path: pprust::path_to_string(&assoc_path),
1492+
})
15011493
}
15021494
}
15031495
}

0 commit comments

Comments
 (0)