Skip to content

Commit 55afad1

Browse files
committed
Auto merge of #157487 - CrooseGit:dev/reucru01/only, r=<try>
crater: reserve `only` keyword
2 parents 877a131 + 7730a25 commit 55afad1

24 files changed

Lines changed: 61 additions & 40 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
shallow = true
55
[submodule "src/tools/cargo"]
66
path = src/tools/cargo
7-
url = https://github.com/rust-lang/cargo.git
7+
url = https://github.com/lqd/cargo.git
88
shallow = true
99
[submodule "src/doc/reference"]
1010
path = src/doc/reference

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3179,6 +3179,8 @@ pub enum BoundPolarity {
31793179
Negative(Span),
31803180
/// `Type: ?Trait`
31813181
Maybe(Span),
3182+
/// `Type: only Trait`,
3183+
Only(Span),
31823184
}
31833185

31843186
impl BoundPolarity {
@@ -3187,6 +3189,7 @@ impl BoundPolarity {
31873189
Self::Positive => "",
31883190
Self::Negative(_) => "!",
31893191
Self::Maybe(_) => "?",
3192+
Self::Only(_) => "only",
31903193
}
31913194
}
31923195
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2778,6 +2778,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
27782778
BoundPolarity::Positive => BoundPolarity::Positive,
27792779
BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
27802780
BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2781+
BoundPolarity::Only(span) => BoundPolarity::Only(self.lower_span(span)),
27812782
};
27822783
hir::TraitBoundModifiers { constness, polarity }
27832784
}

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,9 @@ impl<'a> State<'a> {
14781478
}
14791479
match polarity {
14801480
ast::BoundPolarity::Positive => {}
1481-
ast::BoundPolarity::Negative(_) | ast::BoundPolarity::Maybe(_) => {
1481+
ast::BoundPolarity::Negative(_)
1482+
| ast::BoundPolarity::Maybe(_)
1483+
| ast::BoundPolarity::Only(_) => {
14821484
self.word(polarity.as_str());
14831485
}
14841486
}

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub(crate) struct EmptyConfusables {
331331
}
332332

333333
#[derive(Diagnostic)]
334-
#[help("`#[{$name}{$attribute_args}]` can {$only}be applied to {$applied}")]
334+
#[help("`#[{$name}{$attribute_args}]` can {$only_prefix}be applied to {$applied}")]
335335
#[diag("`#[{$name}{$attribute_args}]` attribute cannot be used on {$target}")]
336336
pub(crate) struct InvalidTarget {
337337
#[primary_span]
@@ -345,7 +345,7 @@ pub(crate) struct InvalidTarget {
345345
pub name: AttrPath,
346346
pub target: &'static str,
347347
pub applied: DiagArgValue,
348-
pub only: &'static str,
348+
pub only_prefix: &'static str,
349349
pub attribute_args: &'static str,
350350
#[subdiagnostic]
351351
pub help: Option<InvalidTargetHelp>,

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,13 @@ impl<'sess> AttributeParser<'sess> {
128128
}
129129

130130
let allowed_targets = allowed_targets.allowed_targets();
131-
let (applied, only) = allowed_targets_applied(allowed_targets, cx.target, cx.features);
131+
let (applied, only_prefix) =
132+
allowed_targets_applied(allowed_targets, cx.target, cx.features);
132133
let diag = InvalidTarget {
133134
span: cx.attr_span.clone(),
134135
name: cx.attr_path.clone(),
135136
target: cx.target.plural_name(),
136-
only: if only { "only " } else { "" },
137+
only_prefix: if only_prefix { "only " } else { "" },
137138
applied: DiagArgValue::StrListSepByAnd(applied.into_iter().map(Cow::Owned).collect()),
138139
attribute_args,
139140
help: Self::target_checking_help(attribute_args, cx),

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1430,7 +1430,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
14301430
span.push_span_label(expr.span, "you could clone this value");
14311431
let types: Vec<_> = types.into_iter().collect();
14321432
let msg = match &types[..] {
1433-
[only] => format!("`{only}`"),
1433+
[single] => format!("`{single}`"),
14341434
[head @ .., last] => format!(
14351435
"{} and `{last}`",
14361436
head.iter().map(|t| format!("`{t}`")).collect::<Vec<_>>().join(", ")

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ struct CollectedBound {
3131
maybe: bool,
3232
/// `!Trait`
3333
negative: bool,
34+
/// `only Trait`
35+
only_modifier: bool,
3436
}
3537

3638
impl CollectedBound {
@@ -112,6 +114,7 @@ fn collect_bounds<'a, 'tcx>(
112114
match ptr.modifiers.polarity {
113115
hir::BoundPolarity::Maybe(_) => collect_into.maybe = true,
114116
hir::BoundPolarity::Negative(_) => collect_into.negative = true,
117+
hir::BoundPolarity::Only(_) => collect_into.only_modifier = true,
115118
hir::BoundPolarity::Positive => collect_into.positive = true,
116119
}
117120
});

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -986,13 +986,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
986986
self.require_bound_to_relax_default_trait(trait_ref, span);
987987
true
988988
}
989+
hir::BoundPolarity::Only(_) => true,
989990
};
990991
let bounds = if transient { &mut Vec::new() } else { bounds };
991992

992993
let polarity = match polarity {
993-
hir::BoundPolarity::Positive | hir::BoundPolarity::Maybe(_) => {
994-
ty::PredicatePolarity::Positive
995-
}
994+
hir::BoundPolarity::Positive
995+
| hir::BoundPolarity::Maybe(_)
996+
| hir::BoundPolarity::Only(_) => ty::PredicatePolarity::Positive,
996997
hir::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative,
997998
};
998999

compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ impl<'a> State<'a> {
824824
hir::BoundPolarity::Positive => {}
825825
hir::BoundPolarity::Negative(_) => self.word("!"),
826826
hir::BoundPolarity::Maybe(_) => self.word("?"),
827+
hir::BoundPolarity::Only(_) => self.word_space("only"),
827828
}
828829
self.print_formal_generic_params(t.bound_generic_params);
829830
self.print_trait_ref(&t.trait_ref);

0 commit comments

Comments
 (0)