Skip to content

Commit 88d1109

Browse files
committed
Auto merge of #68115 - Centril:rollup-e2fszdv, r=Centril
Rollup of 8 pull requests Successful merges: - #67666 (make use of pointer::is_null) - #67806 (Extract `rustc_ast_passes`, move gating, & refactor linting) - #68043 (Add some missing timers) - #68074 (Add `llvm-skip-rebuild` flag to `x.py`) - #68079 (Clarify suggestion for E0013) - #68084 (Do not ICE on unicode next point) - #68102 (Inline some conversion methods around OsStr) - #68106 (Fix issue with using `self` module via indirection) Failed merges: r? @ghost
2 parents e621797 + 04a340f commit 88d1109

File tree

104 files changed

+983
-783
lines changed

Some content is hidden

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

104 files changed

+983
-783
lines changed

Cargo.lock

+23-1
Original file line numberDiff line numberDiff line change
@@ -3363,6 +3363,21 @@ dependencies = [
33633363
"syntax",
33643364
]
33653365

3366+
[[package]]
3367+
name = "rustc_ast_passes"
3368+
version = "0.0.0"
3369+
dependencies = [
3370+
"log",
3371+
"rustc_data_structures",
3372+
"rustc_error_codes",
3373+
"rustc_errors",
3374+
"rustc_feature",
3375+
"rustc_parse",
3376+
"rustc_session",
3377+
"rustc_span",
3378+
"syntax",
3379+
]
3380+
33663381
[[package]]
33673382
name = "rustc_builtin_macros"
33683383
version = "0.0.0"
@@ -3375,6 +3390,7 @@ dependencies = [
33753390
"rustc_expand",
33763391
"rustc_feature",
33773392
"rustc_parse",
3393+
"rustc_session",
33783394
"rustc_span",
33793395
"rustc_target",
33803396
"smallvec 1.0.0",
@@ -3528,11 +3544,13 @@ name = "rustc_expand"
35283544
version = "0.0.0"
35293545
dependencies = [
35303546
"log",
3547+
"rustc_ast_passes",
35313548
"rustc_data_structures",
35323549
"rustc_errors",
35333550
"rustc_feature",
35343551
"rustc_lexer",
35353552
"rustc_parse",
3553+
"rustc_session",
35363554
"rustc_span",
35373555
"serialize",
35383556
"smallvec 1.0.0",
@@ -3602,6 +3620,7 @@ dependencies = [
36023620
"rustc",
36033621
"rustc-rayon",
36043622
"rustc_ast_lowering",
3623+
"rustc_ast_passes",
36053624
"rustc_builtin_macros",
36063625
"rustc_codegen_llvm",
36073626
"rustc_codegen_ssa",
@@ -3619,6 +3638,7 @@ dependencies = [
36193638
"rustc_plugin_impl",
36203639
"rustc_privacy",
36213640
"rustc_resolve",
3641+
"rustc_session",
36223642
"rustc_span",
36233643
"rustc_target",
36243644
"rustc_traits",
@@ -3735,6 +3755,7 @@ dependencies = [
37353755
"rustc_errors",
37363756
"rustc_feature",
37373757
"rustc_lexer",
3758+
"rustc_session",
37383759
"rustc_span",
37393760
"smallvec 1.0.0",
37403761
"syntax",
@@ -3753,7 +3774,7 @@ dependencies = [
37533774
"rustc_feature",
37543775
"rustc_hir",
37553776
"rustc_index",
3756-
"rustc_parse",
3777+
"rustc_session",
37573778
"rustc_span",
37583779
"rustc_target",
37593780
"syntax",
@@ -3833,6 +3854,7 @@ dependencies = [
38333854
"log",
38343855
"num_cpus",
38353856
"rustc_data_structures",
3857+
"rustc_error_codes",
38363858
"rustc_errors",
38373859
"rustc_feature",
38383860
"rustc_fs_util",

src/bootstrap/config.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -493,9 +493,13 @@ impl Config {
493493
config.mandir = install.mandir.clone().map(PathBuf::from);
494494
}
495495

496+
// We want the llvm-skip-rebuild flag to take precedence over the
497+
// skip-rebuild config.toml option so we store it separately
498+
// so that we can infer the right value
499+
let mut llvm_skip_rebuild = flags.llvm_skip_rebuild;
500+
496501
// Store off these values as options because if they're not provided
497502
// we'll infer default values for them later
498-
let mut llvm_skip_rebuild = None;
499503
let mut llvm_assertions = None;
500504
let mut debug = None;
501505
let mut debug_assertions = None;
@@ -517,7 +521,7 @@ impl Config {
517521
}
518522
set(&mut config.ninja, llvm.ninja);
519523
llvm_assertions = llvm.assertions;
520-
llvm_skip_rebuild = llvm.skip_rebuild;
524+
llvm_skip_rebuild = llvm_skip_rebuild.or(llvm.skip_rebuild);
521525
set(&mut config.llvm_optimize, llvm.optimize);
522526
set(&mut config.llvm_thin_lto, llvm.thin_lto);
523527
set(&mut config.llvm_release_debuginfo, llvm.release_debuginfo);

src/bootstrap/flags.rs

+13
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ pub struct Flags {
3838
//
3939
// true => deny, false => warn
4040
pub deny_warnings: Option<bool>,
41+
42+
pub llvm_skip_rebuild: Option<bool>,
4143
}
4244

4345
pub enum Subcommand {
@@ -150,6 +152,14 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
150152
"VALUE",
151153
);
152154
opts.optopt("", "error-format", "rustc error format", "FORMAT");
155+
opts.optopt(
156+
"",
157+
"llvm-skip-rebuild",
158+
"whether rebuilding llvm should be skipped \
159+
a VALUE of TRUE indicates that llvm will not be rebuilt \
160+
VALUE overrides the skip-rebuild option in config.toml.",
161+
"VALUE",
162+
);
153163

154164
// fn usage()
155165
let usage =
@@ -487,6 +497,9 @@ Arguments:
487497
.map(|p| p.into())
488498
.collect::<Vec<_>>(),
489499
deny_warnings: parse_deny_warnings(&matches),
500+
llvm_skip_rebuild: matches.opt_str("llvm-skip-rebuild").map(|s| s.to_lowercase()).map(
501+
|s| s.parse::<bool>().expect("`llvm-skip-rebuild` should be either true or false"),
502+
),
490503
}
491504
}
492505
}

src/libpanic_unwind/emcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub unsafe fn cleanup(ptr: *mut u8) -> Box<dyn Any + Send> {
6363
pub unsafe fn panic(data: Box<dyn Any + Send>) -> u32 {
6464
let sz = mem::size_of_val(&data);
6565
let exception = __cxa_allocate_exception(sz);
66-
if exception == ptr::null_mut() {
66+
if exception.is_null() {
6767
return uw::_URC_FATAL_PHASE1_ERROR as u32;
6868
}
6969
ptr::write(exception as *mut _, data);

src/librustc/lint/context.rs

+125-15
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@
1717
use self::TargetLint::*;
1818

1919
use crate::hir::map::{definitions::DisambiguatedDefPathData, DefPathData};
20-
use crate::lint::builtin::BuiltinLintDiagnostics;
2120
use crate::lint::levels::{LintLevelSets, LintLevelsBuilder};
2221
use crate::lint::{EarlyLintPassObject, LateLintPassObject};
23-
use crate::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
2422
use crate::middle::privacy::AccessLevels;
23+
use crate::middle::stability;
2524
use crate::session::Session;
2625
use crate::ty::layout::{LayoutError, LayoutOf, TyLayout};
2726
use crate::ty::{self, print::Printer, subst::GenericArg, Ty, TyCtxt};
2827
use rustc_data_structures::fx::FxHashMap;
2928
use rustc_data_structures::sync;
3029
use rustc_error_codes::*;
31-
use rustc_errors::{struct_span_err, DiagnosticBuilder};
30+
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder};
3231
use rustc_hir as hir;
3332
use rustc_hir::def_id::{CrateNum, DefId};
33+
use rustc_session::lint::BuiltinLintDiagnostics;
34+
use rustc_session::lint::{FutureIncompatibleInfo, Level, Lint, LintBuffer, LintId};
3435
use rustc_span::{symbol::Symbol, MultiSpan, Span, DUMMY_SP};
3536
use syntax::ast;
3637
use syntax::util::lev_distance::find_best_match_for_name;
@@ -64,17 +65,6 @@ pub struct LintStore {
6465
lint_groups: FxHashMap<&'static str, LintGroup>,
6566
}
6667

67-
/// Lints that are buffered up early on in the `Session` before the
68-
/// `LintLevels` is calculated
69-
#[derive(PartialEq, Debug)]
70-
pub struct BufferedEarlyLint {
71-
pub lint_id: LintId,
72-
pub ast_id: ast::NodeId,
73-
pub span: MultiSpan,
74-
pub msg: String,
75-
pub diagnostic: BuiltinLintDiagnostics,
76-
}
77-
7868
/// The target of the `by_name` map, which accounts for renaming/deprecation.
7969
enum TargetLint {
8070
/// A direct lint target
@@ -477,6 +467,48 @@ impl LintPassObject for EarlyLintPassObject {}
477467

478468
impl LintPassObject for LateLintPassObject {}
479469

470+
pub fn add_elided_lifetime_in_path_suggestion(
471+
sess: &Session,
472+
db: &mut DiagnosticBuilder<'_>,
473+
n: usize,
474+
path_span: Span,
475+
incl_angl_brckt: bool,
476+
insertion_span: Span,
477+
anon_lts: String,
478+
) {
479+
let (replace_span, suggestion) = if incl_angl_brckt {
480+
(insertion_span, anon_lts)
481+
} else {
482+
// When possible, prefer a suggestion that replaces the whole
483+
// `Path<T>` expression with `Path<'_, T>`, rather than inserting `'_, `
484+
// at a point (which makes for an ugly/confusing label)
485+
if let Ok(snippet) = sess.source_map().span_to_snippet(path_span) {
486+
// But our spans can get out of whack due to macros; if the place we think
487+
// we want to insert `'_` isn't even within the path expression's span, we
488+
// should bail out of making any suggestion rather than panicking on a
489+
// subtract-with-overflow or string-slice-out-out-bounds (!)
490+
// FIXME: can we do better?
491+
if insertion_span.lo().0 < path_span.lo().0 {
492+
return;
493+
}
494+
let insertion_index = (insertion_span.lo().0 - path_span.lo().0) as usize;
495+
if insertion_index > snippet.len() {
496+
return;
497+
}
498+
let (before, after) = snippet.split_at(insertion_index);
499+
(path_span, format!("{}{}{}", before, anon_lts, after))
500+
} else {
501+
(insertion_span, anon_lts)
502+
}
503+
};
504+
db.span_suggestion(
505+
replace_span,
506+
&format!("indicate the anonymous lifetime{}", pluralize!(n)),
507+
suggestion,
508+
Applicability::MachineApplicable,
509+
);
510+
}
511+
480512
pub trait LintContext: Sized {
481513
type PassObject: LintPassObject;
482514

@@ -495,7 +527,85 @@ pub trait LintContext: Sized {
495527
diagnostic: BuiltinLintDiagnostics,
496528
) {
497529
let mut db = self.lookup(lint, span, msg);
498-
diagnostic.run(self.sess(), &mut db);
530+
531+
let sess = self.sess();
532+
match diagnostic {
533+
BuiltinLintDiagnostics::Normal => (),
534+
BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
535+
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
536+
Ok(s) if is_global => {
537+
(format!("dyn ({})", s), Applicability::MachineApplicable)
538+
}
539+
Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
540+
Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
541+
};
542+
db.span_suggestion(span, "use `dyn`", sugg, app);
543+
}
544+
BuiltinLintDiagnostics::AbsPathWithModule(span) => {
545+
let (sugg, app) = match sess.source_map().span_to_snippet(span) {
546+
Ok(ref s) => {
547+
// FIXME(Manishearth) ideally the emitting code
548+
// can tell us whether or not this is global
549+
let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };
550+
551+
(format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
552+
}
553+
Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
554+
};
555+
db.span_suggestion(span, "use `crate`", sugg, app);
556+
}
557+
BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => {
558+
db.span_label(
559+
span,
560+
"names from parent modules are not accessible without an explicit import",
561+
);
562+
}
563+
BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
564+
db.span_note(span_def, "the macro is defined here");
565+
}
566+
BuiltinLintDiagnostics::ElidedLifetimesInPaths(
567+
n,
568+
path_span,
569+
incl_angl_brckt,
570+
insertion_span,
571+
anon_lts,
572+
) => {
573+
add_elided_lifetime_in_path_suggestion(
574+
sess,
575+
&mut db,
576+
n,
577+
path_span,
578+
incl_angl_brckt,
579+
insertion_span,
580+
anon_lts,
581+
);
582+
}
583+
BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
584+
db.span_suggestion(span, &note, sugg, Applicability::MaybeIncorrect);
585+
}
586+
BuiltinLintDiagnostics::UnusedImports(message, replaces) => {
587+
if !replaces.is_empty() {
588+
db.tool_only_multipart_suggestion(
589+
&message,
590+
replaces,
591+
Applicability::MachineApplicable,
592+
);
593+
}
594+
}
595+
BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
596+
for (span, is_imported) in spans {
597+
let introduced = if is_imported { "imported" } else { "defined" };
598+
db.span_label(
599+
span,
600+
format!("the item `{}` is already {} here", ident, introduced),
601+
);
602+
}
603+
}
604+
BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
605+
stability::deprecation_suggestion(&mut db, suggestion, span)
606+
}
607+
}
608+
499609
db.emit();
500610
}
501611

src/librustc/lint/internal.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//! Some lints that are only useful in the compiler or crates that use compiler internals, such as
22
//! Clippy.
33
4-
use crate::lint::{
5-
EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintArray, LintContext, LintPass,
6-
};
4+
use crate::lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass, LintContext};
75
use rustc_data_structures::fx::FxHashMap;
86
use rustc_errors::Applicability;
97
use rustc_hir::{GenericArg, HirId, MutTy, Mutability, Path, PathSegment, QPath, Ty, TyKind};
10-
use rustc_session::declare_tool_lint;
8+
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
119
use rustc_span::symbol::{sym, Symbol};
1210
use syntax::ast::{Ident, Item, ItemKind};
1311

src/librustc/lint/levels.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_span::source_map::MultiSpan;
1313
use rustc_span::symbol::{sym, Symbol};
1414
use syntax::ast;
1515
use syntax::attr;
16-
use syntax::feature_gate;
1716
use syntax::print::pprust;
17+
use syntax::sess::feature_err;
1818

1919
use rustc_error_codes::*;
2020

@@ -223,7 +223,7 @@ impl<'a> LintLevelsBuilder<'a> {
223223
// don't have any lint names (`#[level(reason = "foo")]`)
224224
if let ast::LitKind::Str(rationale, _) = name_value.kind {
225225
if !self.sess.features_untracked().lint_reasons {
226-
feature_gate::feature_err(
226+
feature_err(
227227
&self.sess.parse_sess,
228228
sym::lint_reasons,
229229
item.span,

0 commit comments

Comments
 (0)