Skip to content

Commit ea16527

Browse files
committed
Auto merge of #157487 - CrooseGit:dev/reucru01/only, r=<try>
crater: reserve `only` keyword
2 parents 39ec825 + 0463146 commit ea16527

21 files changed

Lines changed: 59 additions & 35 deletions

File tree

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3181,6 +3181,8 @@ pub enum BoundPolarity {
31813181
Negative(Span),
31823182
/// `Type: ?Trait`
31833183
Maybe(Span),
3184+
/// `Type: only Trait`,
3185+
Only(Span),
31843186
}
31853187

31863188
impl BoundPolarity {
@@ -3189,6 +3191,7 @@ impl BoundPolarity {
31893191
Self::Positive => "",
31903192
Self::Negative(_) => "!",
31913193
Self::Maybe(_) => "?",
3194+
Self::Only(_) => "only",
31923195
}
31933196
}
31943197
}

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,6 +2773,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
27732773
BoundPolarity::Positive => BoundPolarity::Positive,
27742774
BoundPolarity::Negative(span) => BoundPolarity::Negative(self.lower_span(span)),
27752775
BoundPolarity::Maybe(span) => BoundPolarity::Maybe(self.lower_span(span)),
2776+
BoundPolarity::Only(span) => BoundPolarity::Only(self.lower_span(span)),
27762777
};
27772778
hir::TraitBoundModifiers { constness, polarity }
27782779
}

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);

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11521152
has_ref_dupes && missing_trait_names.len() > 1 && matches!(rcvr_ty.kind(), ty::Adt(..));
11531153
let missing_trait_list = if should_condense {
11541154
Some(match missing_trait_names.as_slice() {
1155-
[only] => only.clone(),
1155+
[single] => single.clone(),
11561156
[first, second] => format!("{first} or {second}"),
11571157
[rest @ .., last] => format!("{} or {last}", rest.join(", ")),
11581158
[] => String::new(),
@@ -1493,13 +1493,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14931493
inherent_impls_candidate.dedup();
14941494
let msg = match &inherent_impls_candidate[..] {
14951495
[] => return,
1496-
[only] => {
1496+
[single] => {
14971497
vec![
14981498
StringPart::normal(format!("the {item_kind} was found for `")),
14991499
StringPart::highlighted(
15001500
self.tcx
15011501
.at(span)
1502-
.type_of(*only)
1502+
.type_of(*single)
15031503
.instantiate_identity()
15041504
.skip_norm_wip()
15051505
.to_string(),

0 commit comments

Comments
 (0)