Skip to content

Commit f577b0e

Browse files
committed
Auto merge of #66982 - Centril:rollup-yq2281i, r=Centril
Rollup of 6 pull requests Successful merges: - #66148 (Show the sign for signed ops on `exact_div`) - #66651 (Add `enclosing scope` parameter to `rustc_on_unimplemented`) - #66904 (Adding docs for keyword match, move) - #66935 (syntax: Unify macro and attribute arguments in AST) - #66941 (Remove `ord` lang item) - #66967 (Remove hack for top-level or-patterns in match checking) Failed merges: r? @ghost
2 parents 7d80865 + bce7798 commit f577b0e

Some content is hidden

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

63 files changed

+1096
-551
lines changed

src/libcore/cmp.rs

-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ impl<T: Ord> Ord for Reverse<T> {
534534
/// }
535535
/// }
536536
/// ```
537-
#[lang = "ord"]
538537
#[doc(alias = "<")]
539538
#[doc(alias = ">")]
540539
#[doc(alias = "<=")]

src/libcore/ops/try.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,20 @@
55
/// extracting those success or failure values from an existing instance and
66
/// creating a new instance from a success or failure value.
77
#[unstable(feature = "try_trait", issue = "42327")]
8-
#[rustc_on_unimplemented(
8+
#[cfg_attr(not(bootstrap), rustc_on_unimplemented(
99
on(all(
1010
any(from_method="from_error", from_method="from_ok"),
1111
from_desugaring="QuestionMark"),
1212
message="the `?` operator can only be used in {ItemContext} \
1313
that returns `Result` or `Option` \
1414
(or another type that implements `{Try}`)",
15-
label="cannot use the `?` operator in {ItemContext} that returns `{Self}`"),
15+
label="cannot use the `?` operator in {ItemContext} that returns `{Self}`",
16+
enclosing_scope="this function should return `Result` or `Option` to accept `?`"),
1617
on(all(from_method="into_result", from_desugaring="QuestionMark"),
1718
message="the `?` operator can only be applied to values \
1819
that implement `{Try}`",
1920
label="the `?` operator cannot be applied to type `{Self}`")
20-
)]
21+
))]
2122
#[doc(alias = "?")]
2223
pub trait Try {
2324
/// The type of this value when viewed as successful.

src/librustc/hir/lowering.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ impl<'a> LoweringContext<'a> {
10031003
AttrKind::Normal(ref item) => {
10041004
AttrKind::Normal(AttrItem {
10051005
path: item.path.clone(),
1006-
tokens: self.lower_token_stream(item.tokens.clone()),
1006+
args: self.lower_mac_args(&item.args),
10071007
})
10081008
}
10091009
AttrKind::DocComment(comment) => AttrKind::DocComment(comment)
@@ -1017,6 +1017,16 @@ impl<'a> LoweringContext<'a> {
10171017
}
10181018
}
10191019

1020+
fn lower_mac_args(&mut self, args: &MacArgs) -> MacArgs {
1021+
match *args {
1022+
MacArgs::Empty => MacArgs::Empty,
1023+
MacArgs::Delimited(dspan, delim, ref tokens) =>
1024+
MacArgs::Delimited(dspan, delim, self.lower_token_stream(tokens.clone())),
1025+
MacArgs::Eq(eq_span, ref tokens) =>
1026+
MacArgs::Eq(eq_span, self.lower_token_stream(tokens.clone())),
1027+
}
1028+
}
1029+
10201030
fn lower_token_stream(&mut self, tokens: TokenStream) -> TokenStream {
10211031
tokens
10221032
.into_trees()

src/librustc/hir/lowering/item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl LoweringContext<'_> {
233233

234234
if let ItemKind::MacroDef(ref def) = i.kind {
235235
if !def.legacy || attr::contains_name(&i.attrs, sym::macro_export) {
236-
let body = self.lower_token_stream(def.stream());
236+
let body = self.lower_token_stream(def.body.inner_tokens());
237237
let hir_id = self.lower_node_id(i.id);
238238
self.exported_macros.push(hir::MacroDef {
239239
name: ident.name,

src/librustc/middle/lang_items.rs

-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ language_item_table! {
358358
// Don't be fooled by the naming here: this lang item denotes `PartialEq`, not `Eq`.
359359
EqTraitLangItem, "eq", eq_trait, Target::Trait;
360360
PartialOrdTraitLangItem, "partial_ord", partial_ord_trait, Target::Trait;
361-
OrdTraitLangItem, "ord", ord_trait, Target::Trait;
362361

363362
// A number of panic-related lang items. The `panic` item corresponds to
364363
// divide-by-zero and various panic cases with `match`. The

src/librustc/traits/error_reporting.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
521521
) {
522522
command.evaluate(self.tcx, trait_ref, &flags[..])
523523
} else {
524-
OnUnimplementedNote::empty()
524+
OnUnimplementedNote::default()
525525
}
526526
}
527527

@@ -697,6 +697,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
697697
fallback_has_occurred: bool,
698698
points_at_arg: bool,
699699
) {
700+
let tcx = self.tcx;
700701
let span = obligation.cause.span;
701702

702703
let mut err = match *error {
@@ -732,6 +733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
732733
message,
733734
label,
734735
note,
736+
enclosing_scope,
735737
} = self.on_unimplemented_note(trait_ref, obligation);
736738
let have_alt_message = message.is_some() || label.is_some();
737739
let is_try = self.tcx.sess.source_map().span_to_snippet(span)
@@ -798,6 +800,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
798800
// If it has a custom `#[rustc_on_unimplemented]` note, let's display it
799801
err.note(s.as_str());
800802
}
803+
if let Some(ref s) = enclosing_scope {
804+
let enclosing_scope_span = tcx.def_span(
805+
tcx.hir()
806+
.opt_local_def_id(obligation.cause.body_id)
807+
.unwrap_or_else(|| {
808+
tcx.hir().body_owner_def_id(hir::BodyId {
809+
hir_id: obligation.cause.body_id,
810+
})
811+
}),
812+
);
813+
814+
err.span_label(enclosing_scope_span, s.as_str());
815+
}
801816

802817
self.suggest_borrow_on_unsized_slice(&obligation.cause.code, &mut err);
803818
self.suggest_fn_call(&obligation, &mut err, &trait_ref, points_at_arg);

src/librustc/traits/on_unimplemented.rs

+33-13
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,15 @@ pub struct OnUnimplementedDirective {
2222
pub message: Option<OnUnimplementedFormatString>,
2323
pub label: Option<OnUnimplementedFormatString>,
2424
pub note: Option<OnUnimplementedFormatString>,
25+
pub enclosing_scope: Option<OnUnimplementedFormatString>,
2526
}
2627

28+
#[derive(Default)]
2729
pub struct OnUnimplementedNote {
2830
pub message: Option<String>,
2931
pub label: Option<String>,
3032
pub note: Option<String>,
31-
}
32-
33-
impl OnUnimplementedNote {
34-
pub fn empty() -> Self {
35-
OnUnimplementedNote { message: None, label: None, note: None }
36-
}
33+
pub enclosing_scope: Option<String>,
3734
}
3835

3936
fn parse_error(
@@ -85,24 +82,33 @@ impl<'tcx> OnUnimplementedDirective {
8582
let mut message = None;
8683
let mut label = None;
8784
let mut note = None;
85+
let mut enclosing_scope = None;
8886
let mut subcommands = vec![];
87+
88+
let parse_value = |value_str| {
89+
OnUnimplementedFormatString::try_parse(tcx, trait_def_id, value_str, span)
90+
.map(Some)
91+
};
92+
8993
for item in item_iter {
9094
if item.check_name(sym::message) && message.is_none() {
9195
if let Some(message_) = item.value_str() {
92-
message = Some(OnUnimplementedFormatString::try_parse(
93-
tcx, trait_def_id, message_, span)?);
96+
message = parse_value(message_)?;
9497
continue;
9598
}
9699
} else if item.check_name(sym::label) && label.is_none() {
97100
if let Some(label_) = item.value_str() {
98-
label = Some(OnUnimplementedFormatString::try_parse(
99-
tcx, trait_def_id, label_, span)?);
101+
label = parse_value(label_)?;
100102
continue;
101103
}
102104
} else if item.check_name(sym::note) && note.is_none() {
103105
if let Some(note_) = item.value_str() {
104-
note = Some(OnUnimplementedFormatString::try_parse(
105-
tcx, trait_def_id, note_, span)?);
106+
note = parse_value(note_)?;
107+
continue;
108+
}
109+
} else if item.check_name(sym::enclosing_scope) && enclosing_scope.is_none() {
110+
if let Some(enclosing_scope_) = item.value_str() {
111+
enclosing_scope = parse_value(enclosing_scope_)?;
106112
continue;
107113
}
108114
} else if item.check_name(sym::on) && is_root &&
@@ -130,7 +136,14 @@ impl<'tcx> OnUnimplementedDirective {
130136
if errored {
131137
Err(ErrorReported)
132138
} else {
133-
Ok(OnUnimplementedDirective { condition, message, label, subcommands, note })
139+
Ok(OnUnimplementedDirective {
140+
condition,
141+
subcommands,
142+
message,
143+
label,
144+
note,
145+
enclosing_scope
146+
})
134147
}
135148
}
136149

@@ -157,6 +170,7 @@ impl<'tcx> OnUnimplementedDirective {
157170
label: Some(OnUnimplementedFormatString::try_parse(
158171
tcx, trait_def_id, value, attr.span)?),
159172
note: None,
173+
enclosing_scope: None,
160174
}))
161175
} else {
162176
return Err(ErrorReported);
@@ -174,6 +188,7 @@ impl<'tcx> OnUnimplementedDirective {
174188
let mut message = None;
175189
let mut label = None;
176190
let mut note = None;
191+
let mut enclosing_scope = None;
177192
info!("evaluate({:?}, trait_ref={:?}, options={:?})", self, trait_ref, options);
178193

179194
for command in self.subcommands.iter().chain(Some(self)).rev() {
@@ -202,6 +217,10 @@ impl<'tcx> OnUnimplementedDirective {
202217
if let Some(ref note_) = command.note {
203218
note = Some(note_.clone());
204219
}
220+
221+
if let Some(ref enclosing_scope_) = command.enclosing_scope {
222+
enclosing_scope = Some(enclosing_scope_.clone());
223+
}
205224
}
206225

207226
let options: FxHashMap<Symbol, String> = options.into_iter()
@@ -211,6 +230,7 @@ impl<'tcx> OnUnimplementedDirective {
211230
label: label.map(|l| l.format(tcx, trait_ref, &options)),
212231
message: message.map(|m| m.format(tcx, trait_ref, &options)),
213232
note: note.map(|n| n.format(tcx, trait_ref, &options)),
233+
enclosing_scope: enclosing_scope.map(|e_s| e_s.format(tcx, trait_ref, &options)),
214234
}
215235
}
216236
}

src/librustc_lint/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1450,10 +1450,10 @@ impl KeywordIdents {
14501450

14511451
impl EarlyLintPass for KeywordIdents {
14521452
fn check_mac_def(&mut self, cx: &EarlyContext<'_>, mac_def: &ast::MacroDef, _id: ast::NodeId) {
1453-
self.check_tokens(cx, mac_def.stream());
1453+
self.check_tokens(cx, mac_def.body.inner_tokens());
14541454
}
14551455
fn check_mac(&mut self, cx: &EarlyContext<'_>, mac: &ast::Mac) {
1456-
self.check_tokens(cx, mac.tts.clone().into());
1456+
self.check_tokens(cx, mac.args.inner_tokens());
14571457
}
14581458
fn check_ident(&mut self, cx: &EarlyContext<'_>, ident: ast::Ident) {
14591459
self.check_ident_token(cx, UnderMacro(false), ident);

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ use syntax::source_map;
3232
use syntax::source_map::Spanned;
3333
use syntax::symbol::Symbol;
3434
use syntax::expand::allocator::AllocatorKind;
35+
use syntax::ptr::P;
36+
use syntax::tokenstream::DelimSpan;
3537
use syntax_pos::{Span, FileName};
3638

3739
macro_rules! provide {
@@ -427,6 +429,7 @@ impl CStore {
427429

428430
let source_file = sess.parse_sess.source_map().new_source_file(source_name, def.body);
429431
let local_span = Span::with_root_ctxt(source_file.start_pos, source_file.end_pos);
432+
let dspan = DelimSpan::from_single(local_span);
430433
let (body, mut errors) = source_file_to_stream(&sess.parse_sess, source_file, None);
431434
emit_unclosed_delims(&mut errors, &sess.parse_sess);
432435

@@ -448,7 +451,7 @@ impl CStore {
448451
span: local_span,
449452
attrs: attrs.iter().cloned().collect(),
450453
kind: ast::ItemKind::MacroDef(ast::MacroDef {
451-
tokens: body.into(),
454+
body: P(ast::MacArgs::Delimited(dspan, ast::MacDelimiter::Brace, body)),
452455
legacy: def.legacy,
453456
}),
454457
vis: source_map::respan(local_span.shrink_to_lo(), ast::VisibilityKind::Inherited),

0 commit comments

Comments
 (0)