Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #99520

Merged
merged 30 commits into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
d672fea
Use typeck_results to avoid duplicate ast_ty_to_ty call
compiler-errors Jul 16, 2022
dd109c8
better error for bad depth on macro metavar expr
compiler-errors Jul 17, 2022
b3c1b95
Fix crate filter select display
GuillaumeGomez Jul 20, 2022
512db7e
Fix CSS on search input focus
GuillaumeGomez Jul 20, 2022
45382e6
compiletest: allow using revisions with debuginfo tests
luqmana Jul 20, 2022
8de7f04
Use revision support to remove near identical debuginfo test.
luqmana Jul 20, 2022
5d7cd65
compiletest: dedup revision line logic.
luqmana Jul 20, 2022
57a155b
avoid a `Symbol` to `String` conversion
TaKO8Ki Jul 20, 2022
56e7777
avoid `&str` to String conversions
TaKO8Ki Jul 20, 2022
b8c8250
Remove CSS transition for search input border-color
GuillaumeGomez Jul 20, 2022
f4be88e
Add GUI tests for search input border color
GuillaumeGomez Jul 20, 2022
6f0b8f1
attr/passes: comment -> doc comment
davidtwco Jul 13, 2022
a1d5af2
attr: fix expected meta-item for `#[stable]`
davidtwco Jul 13, 2022
62187b1
Add diagnostic width span when '0$' is used as width.
miam-miam Jul 19, 2022
f8dfc4b
Fix off by one error and add ui test.
miam-miam Jul 20, 2022
dcd02ab
adapt assembly/static-relocation-model test for LLVM change
krasimirgg Jul 20, 2022
224aec2
middle: add `implies_by` to `#[unstable]`
davidtwco Jul 13, 2022
97edb9f
span: add `span_extend_to_line` helper
davidtwco Jul 13, 2022
6246d66
passes: improved partial stabilization diagnostic
davidtwco Jul 13, 2022
e587299
passes: check implied feature exists
davidtwco Jul 20, 2022
12ff7a0
Use new tracking issue for proc_macro::tracked_*.
m-ou-se Jul 20, 2022
857afc7
Rollup merge of #99212 - davidtwco:partial-stability-implies, r=micha…
matthiaskrgr Jul 20, 2022
43f6366
Rollup merge of #99352 - compiler-errors:tighter-spans-on-generic-cal…
matthiaskrgr Jul 20, 2022
82d9ae9
Rollup merge of #99355 - compiler-errors:macro-metavar-less-than-zero…
matthiaskrgr Jul 20, 2022
9e197b7
Rollup merge of #99480 - miam-miam100:arg-format, r=oli-obk
matthiaskrgr Jul 20, 2022
a0c6964
Rollup merge of #99488 - luqmana:debuginfo-revisions, r=tmiasko
matthiaskrgr Jul 20, 2022
73ef81d
Rollup merge of #99489 - GuillaumeGomez:gui-fixes, r=notriddle
matthiaskrgr Jul 20, 2022
4b21ad2
Rollup merge of #99508 - TaKO8Ki:avoid-symbol-to-string-conversion-in…
matthiaskrgr Jul 20, 2022
2638f3a
Rollup merge of #99510 - krasimirgg:movb, r=nikic
matthiaskrgr Jul 20, 2022
a5a6811
Rollup merge of #99516 - m-ou-se:proc-macro-tracked-tracking-issue, r…
matthiaskrgr Jul 20, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,42 @@ impl ConstStability {
#[derive(Encodable, Decodable, PartialEq, Copy, Clone, Debug, Eq, Hash)]
#[derive(HashStable_Generic)]
pub enum StabilityLevel {
// Reason for the current stability level and the relevant rust-lang issue
Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
Stable { since: Symbol, allowed_through_unstable_modules: bool },
/// `#[unstable]`
Unstable {
/// Reason for the current stability level.
reason: Option<Symbol>,
/// Relevant `rust-lang/rust` issue.
issue: Option<NonZeroU32>,
is_soft: bool,
/// If part of a feature is stabilized and a new feature is added for the remaining parts,
/// then the `implied_by` attribute is used to indicate which now-stable feature previously
/// contained a item.
///
/// ```pseudo-Rust
/// #[unstable(feature = "foo", issue = "...")]
/// fn foo() {}
/// #[unstable(feature = "foo", issue = "...")]
/// fn foobar() {}
/// ```
///
/// ...becomes...
///
/// ```pseudo-Rust
/// #[stable(feature = "foo", since = "1.XX.X")]
/// fn foo() {}
/// #[unstable(feature = "foobar", issue = "...", implied_by = "foo")]
/// fn foobar() {}
/// ```
implied_by: Option<Symbol>,
},
/// `#[stable]`
Stable {
/// Rust release which stabilized this feature.
since: Symbol,
/// Is this item allowed to be referred to on stable, despite being contained in unstable
/// modules?
allowed_through_unstable_modules: bool,
},
}

impl StabilityLevel {
Expand Down Expand Up @@ -243,6 +276,7 @@ where
let mut issue = None;
let mut issue_num = None;
let mut is_soft = false;
let mut implied_by = None;
for meta in metas {
let Some(mi) = meta.meta_item() else {
handle_errors(
Expand Down Expand Up @@ -308,6 +342,11 @@ where
}
is_soft = true;
}
sym::implied_by => {
if !get(mi, &mut implied_by) {
continue 'outer;
}
}
_ => {
handle_errors(
&sess.parse_sess,
Expand All @@ -332,7 +371,7 @@ where
);
continue;
}
let level = Unstable { reason, issue: issue_num, is_soft };
let level = Unstable { reason, issue: issue_num, is_soft, implied_by };
if sym::unstable == meta_name {
stab = Some((Stability { level, feature }, attr.span));
} else {
Expand Down Expand Up @@ -391,7 +430,7 @@ where
meta.span(),
AttrError::UnknownMetaItem(
pprust::path_to_string(&mi.path),
&["since", "note"],
&["feature", "since"],
),
);
continue 'outer;
Expand Down
6 changes: 2 additions & 4 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ impl<'a, 'b> Context<'a, 'b> {
if let Some(span) = fmt.width_span {
let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
match fmt.width {
parse::CountIsParam(pos) if pos > self.num_args() => {
parse::CountIsParam(pos) if pos >= self.num_args() => {
e.span_label(
span,
&format!(
Expand Down Expand Up @@ -1004,9 +1004,7 @@ fn lint_named_arguments_used_positionally(
node_id: ast::CRATE_NODE_ID,
lint_id: LintId::of(&NAMED_ARGUMENTS_USED_POSITIONALLY),
diagnostic: BuiltinLintDiagnostics::NamedArgumentUsedPositionally(
arg_span,
span,
symbol.to_string(),
arg_span, span, symbol,
),
});
}
Expand Down
15 changes: 7 additions & 8 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,17 @@ impl Diagnostic {
expected: DiagnosticStyledString,
found: DiagnosticStyledString,
) -> &mut Self {
let mut msg: Vec<_> =
vec![("required when trying to coerce from type `".to_string(), Style::NoStyle)];
let mut msg: Vec<_> = vec![("required when trying to coerce from type `", Style::NoStyle)];
msg.extend(expected.0.iter().map(|x| match *x {
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
}));
msg.push(("` to type '".to_string(), Style::NoStyle));
msg.push(("` to type '", Style::NoStyle));
msg.extend(found.0.iter().map(|x| match *x {
StringPart::Normal(ref s) => (s.to_owned(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.to_owned(), Style::Highlight),
StringPart::Normal(ref s) => (s.as_str(), Style::NoStyle),
StringPart::Highlighted(ref s) => (s.as_str(), Style::Highlight),
}));
msg.push(("`".to_string(), Style::NoStyle));
msg.push(("`", Style::NoStyle));

// For now, just attach these as notes
self.highlighted_note(msg);
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,18 @@ fn out_of_bounds_err<'a>(
span: Span,
ty: &str,
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
cx.struct_span_err(span, &format!("{ty} depth must be less than {max}"))
let msg = if max == 0 {
format!(
"meta-variable expression `{ty}` with depth parameter \
must be called inside of a macro repetition"
)
} else {
format!(
"depth parameter on meta-variable expression `{ty}` \
must be less than {max}"
)
};
cx.struct_span_err(span, &msg)
}

fn transcribe_metavar_expr<'a>(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ pub enum BuiltinLintDiagnostics {
/// If true, the lifetime will be fully elided.
use_span: Option<(Span, bool)>,
},
NamedArgumentUsedPositionally(Option<Span>, Span, String),
NamedArgumentUsedPositionally(Option<Span>, Span, Symbol),
}

/// Lints that are buffered up early on in the `Session` before the
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
tcx.arena.alloc_from_iter(self.root.lib_features.decode(self))
}

/// Iterates over the stability implications in the given crate (when a `#[unstable]` attribute
/// has an `implied_by` meta item, then the mapping from the implied feature to the actual
/// feature is a stability implication).
fn get_stability_implications(self, tcx: TyCtxt<'tcx>) -> &'tcx [(Symbol, Symbol)] {
tcx.arena.alloc_from_iter(self.root.stability_implications.decode(self))
}

/// Iterates over the language items in the given crate.
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
tcx.arena.alloc_from_iter(
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ provide! { <'tcx> tcx, def_id, other, cdata,
tcx.arena.alloc_slice(&result)
}
defined_lib_features => { cdata.get_lib_features(tcx) }
stability_implications => {
cdata.get_stability_implications(tcx).iter().copied().collect()
}
is_intrinsic => { cdata.get_is_intrinsic(def_id.index) }
defined_lang_items => { cdata.get_lang_items(tcx) }
diagnostic_items => { cdata.get_diagnostic_items() }
Expand Down
15 changes: 15 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let lib_features = self.encode_lib_features();
let lib_feature_bytes = self.position() - i;

// Encode the stability implications.
i = self.position();
let stability_implications = self.encode_stability_implications();
let stability_implications_bytes = self.position() - i;

// Encode the language items.
i = self.position();
let lang_items = self.encode_lang_items();
Expand Down Expand Up @@ -686,6 +691,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
crate_deps,
dylib_dependency_formats,
lib_features,
stability_implications,
lang_items,
diagnostic_items,
lang_items_missing,
Expand All @@ -710,6 +716,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let computed_total_bytes = preamble_bytes
+ dep_bytes
+ lib_feature_bytes
+ stability_implications_bytes
+ lang_item_bytes
+ diagnostic_item_bytes
+ native_lib_bytes
Expand Down Expand Up @@ -761,6 +768,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
p("preamble", preamble_bytes);
p("dep", dep_bytes);
p("lib feature", lib_feature_bytes);
p("stability_implications", stability_implications_bytes);
p("lang item", lang_item_bytes);
p("diagnostic item", diagnostic_item_bytes);
p("native lib", native_lib_bytes);
Expand Down Expand Up @@ -1777,6 +1785,13 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
self.lazy_array(lib_features.to_vec())
}

fn encode_stability_implications(&mut self) -> LazyArray<(Symbol, Symbol)> {
empty_proc_macro!(self);
let tcx = self.tcx;
let implications = tcx.stability_implications(LOCAL_CRATE);
self.lazy_array(implications.iter().map(|(k, v)| (*k, *v)))
}

fn encode_diagnostic_items(&mut self) -> LazyArray<(Symbol, DefIndex)> {
empty_proc_macro!(self);
let tcx = self.tcx;
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ pub(crate) struct CrateRoot {
crate_deps: LazyArray<CrateDep>,
dylib_dependency_formats: LazyArray<Option<LinkagePreference>>,
lib_features: LazyArray<(Symbol, Option<Symbol>)>,
stability_implications: LazyArray<(Symbol, Symbol)>,
lang_items: LazyArray<(DefIndex, usize)>,
lang_items_missing: LazyArray<lang_items::LangItem>,
diagnostic_items: LazyArray<(Symbol, DefIndex)>,
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_middle/src/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ pub mod dependency_format;
pub mod exported_symbols;
pub mod lang_items;
pub mod lib_features {
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_span::symbol::Symbol;
use rustc_data_structures::fx::FxHashMap;
use rustc_span::{symbol::Symbol, Span};

#[derive(HashStable, Debug)]
pub struct LibFeatures {
// A map from feature to stabilisation version.
pub stable: FxHashMap<Symbol, Symbol>,
pub unstable: FxHashSet<Symbol>,
/// A map from feature to stabilisation version.
pub stable: FxHashMap<Symbol, (Symbol, Span)>,
pub unstable: FxHashMap<Symbol, Span>,
}

impl LibFeatures {
pub fn to_vec(&self) -> Vec<(Symbol, Option<Symbol>)> {
let mut all_features: Vec<_> = self
.stable
.iter()
.map(|(f, s)| (*f, Some(*s)))
.chain(self.unstable.iter().map(|f| (*f, None)))
.map(|(f, (s, _))| (*f, Some(*s)))
.chain(self.unstable.iter().map(|(f, _)| (*f, None)))
.collect();
all_features.sort_unstable_by(|a, b| a.0.as_str().partial_cmp(b.0.as_str()).unwrap());
all_features
Expand Down
24 changes: 23 additions & 1 deletion compiler/rustc_middle/src/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ pub struct Index {
pub stab_map: FxHashMap<LocalDefId, Stability>,
pub const_stab_map: FxHashMap<LocalDefId, ConstStability>,
pub depr_map: FxHashMap<LocalDefId, DeprecationEntry>,
/// Mapping from feature name to feature name based on the `implied_by` field of `#[unstable]`
/// attributes. If a `#[unstable(feature = "implier", implied_by = "impliee")]` attribute
/// exists, then this map will have a `impliee -> implier` entry.
///
/// This mapping is necessary unless both the `#[stable]` and `#[unstable]` attributes should
/// specify their implications (both `implies` and `implied_by`). If only one of the two
/// attributes do (as in the current implementation, `implied_by` in `#[unstable]`), then this
/// mapping is necessary for diagnostics. When a "unnecessary feature attribute" error is
/// reported, only the `#[stable]` attribute information is available, so the map is necessary
/// to know that the feature implies another feature. If it were reversed, and the `#[stable]`
/// attribute had an `implies` meta item, then a map would be necessary when avoiding a "use of
/// unstable feature" error for a feature that was implied.
pub implications: FxHashMap<Symbol, Symbol>,
}

impl Index {
Expand Down Expand Up @@ -423,7 +436,9 @@ impl<'tcx> TyCtxt<'tcx> {

match stability {
Some(Stability {
level: attr::Unstable { reason, issue, is_soft }, feature, ..
level: attr::Unstable { reason, issue, is_soft, implied_by },
feature,
..
}) => {
if span.allows_unstable(feature) {
debug!("stability: skipping span={:?} since it is internal", span);
Expand All @@ -433,6 +448,13 @@ impl<'tcx> TyCtxt<'tcx> {
return EvalResult::Allow;
}

// If this item was previously part of a now-stabilized feature which is still
// active (i.e. the user hasn't removed the attribute for the stabilized feature
// yet) then allow use of this item.
if let Some(implied_by) = implied_by && self.features().active(implied_by) {
return EvalResult::Allow;
}

// When we're compiling the compiler itself we may pull in
// crates from crates.io, but those crates may depend on other
// crates also pulled in from crates.io. We want to ideally be
Expand Down
8 changes: 6 additions & 2 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,11 +1634,15 @@ rustc_queries! {
storage(ArenaCacheSelector<'tcx>)
desc { "calculating the lib features map" }
}
query defined_lib_features(_: CrateNum)
-> &'tcx [(Symbol, Option<Symbol>)] {
query defined_lib_features(_: CrateNum) -> &'tcx [(Symbol, Option<Symbol>)] {
desc { "calculating the lib features defined in a crate" }
separate_provide_extern
}
query stability_implications(_: CrateNum) -> FxHashMap<Symbol, Symbol> {
storage(ArenaCacheSelector<'tcx>)
desc { "calculating the implications between `#[unstable]` features defined in a crate" }
separate_provide_extern
}
/// Whether the function is an intrinsic
query is_intrinsic(def_id: DefId) -> bool {
desc { |tcx| "is_intrinsic({})", tcx.def_path_str(def_id) }
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ impl<'a> Parser<'a> {
// '0' flag and then an ill-formatted format string with just a '$'
// and no count, but this is better if we instead interpret this as
// no '0' flag and '0$' as the width instead.
if self.consume('$') {
if let Some(end) = self.consume_pos('$') {
spec.width = CountIsParam(0);
havewidth = true;
spec.width_span = Some(self.to_span_index(end - 1).to(self.to_span_index(end + 1)));
} else {
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
}
Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_parse_format/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,23 @@ fn format_counts() {
},
})],
);
same(
"{1:0$.10x}",
&[NextArgument(Argument {
position: ArgumentIs(1),
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: 0,
precision: CountIs(10),
width: CountIsParam(0),
precision_span: None,
width_span: Some(InnerSpan::new(4, 6)),
ty: "x",
ty_span: None,
},
})],
);
same(
"{:.*x}",
&[NextArgument(Argument {
Expand Down
Loading