Skip to content

Commit 715ff60

Browse files
committed
Auto merge of rust-lang#116727 - matthiaskrgr:rollup-3qqdrny, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#116630 (Add ability to get lines/filename for Span in smir) - rust-lang#116644 (remove outdated bootstrap FIXME) - rust-lang#116695 (Fix a comment) - rust-lang#116696 (Misc improvements) - rust-lang#116704 (Fix AFIT lint message to mention pitfall) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 96c4dba + 24116ae commit 715ff60

File tree

9 files changed

+97
-24
lines changed

9 files changed

+97
-24
lines changed

compiler/rustc_ast/src/token.rs

+27
Original file line numberDiff line numberDiff line change
@@ -229,35 +229,61 @@ fn ident_can_begin_type(name: Symbol, span: Span, is_raw: bool) -> bool {
229229
#[derive(PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
230230
pub enum TokenKind {
231231
/* Expression-operator symbols. */
232+
/// `=`
232233
Eq,
234+
/// `<`
233235
Lt,
236+
/// `<=`
234237
Le,
238+
/// `==`
235239
EqEq,
240+
/// `!=`
236241
Ne,
242+
/// `>`
237243
Ge,
244+
/// `>=`
238245
Gt,
246+
/// `&&`
239247
AndAnd,
248+
/// `||`
240249
OrOr,
250+
/// `!`
241251
Not,
252+
/// `~`
242253
Tilde,
243254
BinOp(BinOpToken),
244255
BinOpEq(BinOpToken),
245256

246257
/* Structural symbols */
258+
/// `@`
247259
At,
260+
/// `.`
248261
Dot,
262+
/// `..`
249263
DotDot,
264+
/// `...`
250265
DotDotDot,
266+
/// `..=`
251267
DotDotEq,
268+
/// `,`
252269
Comma,
270+
/// `;`
253271
Semi,
272+
/// `:`
254273
Colon,
274+
/// `::`
255275
ModSep,
276+
/// `->`
256277
RArrow,
278+
/// `<-`
257279
LArrow,
280+
/// `=>`
258281
FatArrow,
282+
/// `#`
259283
Pound,
284+
/// `$`
260285
Dollar,
286+
/// `?`
261287
Question,
262288
/// Used by proc macros for representing lifetimes, not generated by lexer right now.
263289
SingleQuote,
@@ -296,6 +322,7 @@ pub enum TokenKind {
296322
/// similarly to symbols in string literal tokens.
297323
DocComment(CommentKind, ast::AttrStyle, Symbol),
298324

325+
/// End Of File
299326
Eof,
300327
}
301328

compiler/rustc_builtin_macros/src/lib.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -71,33 +71,35 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
7171
}
7272

7373
register_bang! {
74+
// tidy-alphabetical-start
7475
asm: asm::expand_asm,
7576
assert: assert::expand_assert,
7677
cfg: cfg::expand_cfg,
7778
column: source_util::expand_column,
7879
compile_error: compile_error::expand_compile_error,
80+
concat: concat::expand_concat,
7981
concat_bytes: concat_bytes::expand_concat_bytes,
8082
concat_idents: concat_idents::expand_concat_idents,
81-
concat: concat::expand_concat,
83+
const_format_args: format::expand_format_args,
84+
core_panic: edition_panic::expand_panic,
8285
env: env::expand_env,
8386
file: source_util::expand_file,
84-
format_args_nl: format::expand_format_args_nl,
8587
format_args: format::expand_format_args,
86-
const_format_args: format::expand_format_args,
88+
format_args_nl: format::expand_format_args_nl,
8789
global_asm: asm::expand_global_asm,
90+
include: source_util::expand_include,
8891
include_bytes: source_util::expand_include_bytes,
8992
include_str: source_util::expand_include_str,
90-
include: source_util::expand_include,
9193
line: source_util::expand_line,
9294
log_syntax: log_syntax::expand_log_syntax,
9395
module_path: source_util::expand_mod,
9496
option_env: env::expand_option_env,
95-
core_panic: edition_panic::expand_panic,
9697
std_panic: edition_panic::expand_panic,
97-
unreachable: edition_panic::expand_unreachable,
9898
stringify: source_util::expand_stringify,
9999
trace_macros: trace_macros::expand_trace_macros,
100100
type_ascribe: type_ascribe::expand_type_ascribe,
101+
unreachable: edition_panic::expand_unreachable,
102+
// tidy-alphabetical-end
101103
}
102104

103105
register_attr! {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
180180
//
181181
// default impl Foo for Bar { .. }
182182
//
183-
// we add a default where clause `Foo: Bar`. We do a similar thing for traits
183+
// we add a default where clause `Bar: Foo`. We do a similar thing for traits
184184
// (see below). Recall that a default impl is not itself an impl, but rather a
185185
// set of defaults that can be incorporated into another impl.
186186
if let Some(trait_ref) = is_default_impl_trait {

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ lint_array_into_iter =
77
88
lint_async_fn_in_trait = use of `async fn` in public traits is discouraged as auto trait bounds cannot be specified
99
.note = you can suppress this lint if you plan to use the trait only in your own code, or do not care about auto traits like `Send` on the `Future`
10-
.suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`
10+
.suggestion = you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change
1111
1212
lint_atomic_ordering_fence = memory fences cannot have `Relaxed` ordering
1313
.help = consider using ordering modes `Acquire`, `Release`, `AcqRel` or `SeqCst`

compiler/rustc_smir/src/rustc_smir/mod.rs

+22-3
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Variance};
1717
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
1818
use rustc_target::abi::FieldIdx;
1919
use stable_mir::mir::{CopyNonOverlapping, Statement, UserTypeProjection, VariantIdx};
20-
use stable_mir::ty::{FloatTy, GenericParamDef, IntTy, Movability, RigidTy, Span, TyKind, UintTy};
21-
use stable_mir::{self, opaque, Context};
20+
use stable_mir::ty::{
21+
FloatTy, GenericParamDef, IntTy, LineInfo, Movability, RigidTy, Span, TyKind, UintTy,
22+
};
23+
use stable_mir::{self, opaque, Context, Filename};
2224
use tracing::debug;
2325

2426
mod alloc;
@@ -50,10 +52,27 @@ impl<'tcx> Context for Tables<'tcx> {
5052
self.tcx.def_path_str(self[def_id])
5153
}
5254

53-
fn print_span(&self, span: stable_mir::ty::Span) -> String {
55+
fn span_to_string(&self, span: stable_mir::ty::Span) -> String {
5456
self.tcx.sess.source_map().span_to_diagnostic_string(self[span])
5557
}
5658

59+
fn get_filename(&self, span: &Span) -> Filename {
60+
opaque(
61+
&self
62+
.tcx
63+
.sess
64+
.source_map()
65+
.span_to_filename(self[*span])
66+
.display(rustc_span::FileNameDisplayPreference::Local)
67+
.to_string(),
68+
)
69+
}
70+
71+
fn get_lines(&self, span: &Span) -> LineInfo {
72+
let lines = &self.tcx.sess.source_map().span_to_location_info(self[*span]);
73+
LineInfo { start_line: lines.1, start_col: lines.2, end_line: lines.3, end_col: lines.4 }
74+
}
75+
5776
fn def_kind(&mut self, def_id: stable_mir::DefId) -> stable_mir::DefKind {
5877
self.tcx.def_kind(self[def_id]).stable(self)
5978
}

compiler/stable_mir/src/lib.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use std::fmt;
2222
use std::fmt::Debug;
2323

2424
use self::ty::{
25-
GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, Span, TraitDecl, TraitDef, Ty,
26-
TyKind,
25+
GenericPredicates, Generics, ImplDef, ImplTrait, IndexedVal, LineInfo, Span, TraitDecl,
26+
TraitDef, Ty, TyKind,
2727
};
2828

2929
#[macro_use]
@@ -108,6 +108,7 @@ pub struct Crate {
108108
}
109109

110110
pub type DefKind = Opaque;
111+
pub type Filename = Opaque;
111112

112113
/// Holds information about an item in the crate.
113114
/// For now, it only stores the item DefId. Use functions inside `rustc_internal` module to
@@ -196,13 +197,19 @@ pub trait Context {
196197
/// Find a crate with the given name.
197198
fn find_crates(&self, name: &str) -> Vec<Crate>;
198199

199-
/// Prints the name of given `DefId`
200+
/// Returns the name of given `DefId`
200201
fn name_of_def_id(&self, def_id: DefId) -> String;
201202

202-
/// Prints a human readable form of `Span`
203-
fn print_span(&self, span: Span) -> String;
203+
/// Returns printable, human readable form of `Span`
204+
fn span_to_string(&self, span: Span) -> String;
204205

205-
/// Prints the kind of given `DefId`
206+
/// Return filename from given `Span`, for diagnostic purposes
207+
fn get_filename(&self, span: &Span) -> Filename;
208+
209+
/// Return lines corresponding to this `Span`
210+
fn get_lines(&self, span: &Span) -> LineInfo;
211+
212+
/// Returns the `kind` of given `DefId`
206213
fn def_kind(&mut self, def_id: DefId) -> DefKind;
207214

208215
/// `Span` of an item

compiler/stable_mir/src/ty.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::{
33
mir::{Body, Mutability},
44
with, AllocId, DefId, Symbol,
55
};
6-
use crate::Opaque;
6+
use crate::{Filename, Opaque};
77
use std::fmt::{self, Debug, Formatter};
88

99
#[derive(Copy, Clone)]
@@ -81,11 +81,33 @@ impl Debug for Span {
8181
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
8282
f.debug_struct("Span")
8383
.field("id", &self.0)
84-
.field("repr", &with(|cx| cx.print_span(*self)))
84+
.field("repr", &with(|cx| cx.span_to_string(*self)))
8585
.finish()
8686
}
8787
}
8888

89+
impl Span {
90+
/// Return filename for diagnostic purposes
91+
pub fn get_filename(&self) -> Filename {
92+
with(|c| c.get_filename(self))
93+
}
94+
95+
/// Return lines that corespond to this `Span`
96+
pub fn get_lines(&self) -> LineInfo {
97+
with(|c| c.get_lines(&self))
98+
}
99+
}
100+
101+
#[derive(Clone, Copy, Debug)]
102+
/// Information you get from `Span` in a struct form.
103+
/// Line and col start from 1.
104+
pub struct LineInfo {
105+
pub start_line: usize,
106+
pub start_col: usize,
107+
pub end_line: usize,
108+
pub end_col: usize,
109+
}
110+
89111
impl IndexedVal for Span {
90112
fn to_val(index: usize) -> Self {
91113
Span(index)

src/bootstrap/test.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2940,10 +2940,6 @@ impl Step for TestHelpers {
29402940
let _guard = builder.msg_unstaged(Kind::Build, "test helpers", target);
29412941
t!(fs::create_dir_all(&dst));
29422942
let mut cfg = cc::Build::new();
2943-
// FIXME: Workaround for https://github.com/emscripten-core/emscripten/issues/9013
2944-
if target.contains("emscripten") {
2945-
cfg.pic(false);
2946-
}
29472943

29482944
// We may have found various cross-compilers a little differently due to our
29492945
// extra configuration, so inform cc of these compilers. Note, though, that

tests/ui/async-await/in-trait/warn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: the lint level is defined here
1010
|
1111
LL | #![deny(async_fn_in_trait)]
1212
| ^^^^^^^^^^^^^^^^^
13-
help: you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`
13+
help: you can alternatively desugar to a normal `fn` that returns `impl Future` and add any desired bounds such as `Send`, but these cannot be relaxed without a breaking API change
1414
|
1515
LL - async fn not_send();
1616
LL + fn not_send() -> impl std::future::Future<Output = ()> + Send;

0 commit comments

Comments
 (0)