Skip to content

Commit 357bc27

Browse files
committed
Auto merge of #97795 - Dylan-DPC:rollup-dxilagr, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #97312 (Compute lifetimes in scope at diagnostic time) - #97495 (Add E0788 for improper #[no_coverage] usage) - #97579 (Avoid creating `SmallVec`s in `global_llvm_features`) - #97767 (interpret: do not claim UB until we looked more into variadic functions) - #97787 (E0432: rust 2018 -> rust 2018 or later in --explain message) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9d20fd1 + 99afe26 commit 357bc27

File tree

23 files changed

+406
-251
lines changed

23 files changed

+406
-251
lines changed

compiler/rustc_ast_lowering/src/index.rs

+7
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
313313
});
314314
}
315315

316+
fn visit_assoc_type_binding(&mut self, type_binding: &'hir TypeBinding<'hir>) {
317+
self.insert(type_binding.span, type_binding.hir_id, Node::TypeBinding(type_binding));
318+
self.with_parent(type_binding.hir_id, |this| {
319+
intravisit::walk_assoc_type_binding(this, type_binding)
320+
})
321+
}
322+
316323
fn visit_trait_item_ref(&mut self, ii: &'hir TraitItemRef) {
317324
// Do not visit the duplicate information in TraitItemRef. We want to
318325
// map the actual nodes, not the duplicate ones in the *Ref.

compiler/rustc_codegen_llvm/src/llvm_util.rs

+37-33
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,17 @@ pub fn check_tied_features(
218218
sess: &Session,
219219
features: &FxHashMap<&str, bool>,
220220
) -> Option<&'static [&'static str]> {
221-
for tied in tied_target_features(sess) {
222-
// Tied features must be set to the same value, or not set at all
223-
let mut tied_iter = tied.iter();
224-
let enabled = features.get(tied_iter.next().unwrap());
225-
if tied_iter.any(|f| enabled != features.get(f)) {
226-
return Some(tied);
221+
if !features.is_empty() {
222+
for tied in tied_target_features(sess) {
223+
// Tied features must be set to the same value, or not set at all
224+
let mut tied_iter = tied.iter();
225+
let enabled = features.get(tied_iter.next().unwrap());
226+
if tied_iter.any(|f| enabled != features.get(f)) {
227+
return Some(tied);
228+
}
227229
}
228230
}
229-
None
231+
return None;
230232
}
231233

232234
// Used to generate cfg variables and apply features
@@ -440,6 +442,7 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
440442

441443
// -Ctarget-features
442444
let supported_features = supported_target_features(sess);
445+
let mut featsmap = FxHashMap::default();
443446
let feats = sess
444447
.opts
445448
.cg
@@ -485,35 +488,36 @@ pub(crate) fn global_llvm_features(sess: &Session, diagnostics: bool) -> Vec<Str
485488
}
486489
diag.emit();
487490
}
488-
Some((enable_disable, feature))
491+
492+
if diagnostics {
493+
// FIXME(nagisa): figure out how to not allocate a full hashset here.
494+
featsmap.insert(feature, enable_disable == '+');
495+
}
496+
497+
// rustc-specific features do not get passed down to LLVM…
498+
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
499+
return None;
500+
}
501+
// ... otherwise though we run through `to_llvm_features` when
502+
// passing requests down to LLVM. This means that all in-language
503+
// features also work on the command line instead of having two
504+
// different names when the LLVM name and the Rust name differ.
505+
Some(
506+
to_llvm_features(sess, feature)
507+
.into_iter()
508+
.map(move |f| format!("{}{}", enable_disable, f)),
509+
)
489510
})
490-
.collect::<SmallVec<[(char, &str); 8]>>();
491-
492-
if diagnostics {
493-
// FIXME(nagisa): figure out how to not allocate a full hashset here.
494-
let featmap = feats.iter().map(|&(flag, feat)| (feat, flag == '+')).collect();
495-
if let Some(f) = check_tied_features(sess, &featmap) {
496-
sess.err(&format!(
497-
"target features {} must all be enabled or disabled together",
498-
f.join(", ")
499-
));
500-
}
511+
.flatten();
512+
features.extend(feats);
513+
514+
if diagnostics && let Some(f) = check_tied_features(sess, &featsmap) {
515+
sess.err(&format!(
516+
"target features {} must all be enabled or disabled together",
517+
f.join(", ")
518+
));
501519
}
502520

503-
features.extend(feats.into_iter().flat_map(|(enable_disable, feature)| {
504-
// rustc-specific features do not get passed down to LLVM…
505-
if RUSTC_SPECIFIC_FEATURES.contains(&feature) {
506-
return SmallVec::<[_; 2]>::new();
507-
}
508-
// ... otherwise though we run through `to_llvm_features` when
509-
// passing requests down to LLVM. This means that all in-language
510-
// features also work on the command line instead of having two
511-
// different names when the LLVM name and the Rust name differ.
512-
to_llvm_features(sess, feature)
513-
.into_iter()
514-
.map(|f| format!("{}{}", enable_disable, f))
515-
.collect()
516-
}));
517521
features
518522
}
519523

compiler/rustc_const_eval/src/interpret/terminator.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -353,12 +353,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
353353
// FIXME: for variadic support, do we have to somehow determine callee's extra_args?
354354
let callee_fn_abi = self.fn_abi_of_instance(instance, ty::List::empty())?;
355355

356-
if callee_fn_abi.c_variadic != caller_fn_abi.c_variadic {
357-
throw_ub_format!(
358-
"calling a c-variadic function via a non-variadic call site, or vice versa"
359-
);
360-
}
361-
if callee_fn_abi.c_variadic {
356+
if callee_fn_abi.c_variadic || caller_fn_abi.c_variadic {
362357
throw_unsup_format!("calling a c-variadic function is not supported");
363358
}
364359

compiler/rustc_error_codes/src/error_codes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ E0784: include_str!("./error_codes/E0784.md"),
491491
E0785: include_str!("./error_codes/E0785.md"),
492492
E0786: include_str!("./error_codes/E0786.md"),
493493
E0787: include_str!("./error_codes/E0787.md"),
494+
E0788: include_str!("./error_codes/E0788.md"),
494495
;
495496
// E0006, // merged with E0005
496497
// E0008, // cannot bind by-move into a pattern guard

compiler/rustc_error_codes/src/error_codes/E0432.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ In Rust 2015, paths in `use` statements are relative to the crate root. To
1010
import items relative to the current and parent modules, use the `self::` and
1111
`super::` prefixes, respectively.
1212

13-
In Rust 2018, paths in `use` statements are relative to the current module
14-
unless they begin with the name of a crate or a literal `crate::`, in which
15-
case they start from the crate root. As in Rust 2015 code, the `self::` and
16-
`super::` prefixes refer to the current and parent modules respectively.
13+
In Rust 2018 or later, paths in `use` statements are relative to the current
14+
module unless they begin with the name of a crate or a literal `crate::`, in
15+
which case they start from the crate root. As in Rust 2015 code, the `self::`
16+
and `super::` prefixes refer to the current and parent modules respectively.
1717

1818
Also verify that you didn't misspell the import name and that the import exists
1919
in the module from where you tried to import it. Example:
@@ -38,8 +38,8 @@ use core::any;
3838
# fn main() {}
3939
```
4040

41-
In Rust 2018 the `extern crate` declaration is not required and you can instead
42-
just `use` it:
41+
Since Rust 2018 the `extern crate` declaration is not required and
42+
you can instead just `use` it:
4343

4444
```edition2018
4545
use core::any; // No extern crate required in Rust 2018.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
A `#[no_coverage]` attribute was applied to something which does not show up
2+
in code coverage, or is too granular to be excluded from the coverage report.
3+
4+
For now, this attribute can only be applied to function, method, and closure
5+
definitions. In the future, it may be added to statements, blocks, and
6+
expressions, and for the time being, using this attribute in those places
7+
will just emit an `unused_attributes` lint instead of this error.
8+
9+
Example of erroneous code:
10+
11+
```compile_fail,E0788
12+
#[no_coverage]
13+
struct Foo;
14+
15+
#[no_coverage]
16+
const FOO: Foo = Foo;
17+
```
18+
19+
`#[no_coverage]` tells the compiler to not generate coverage instrumentation for
20+
a piece of code when the `-C instrument-coverage` flag is passed. Things like
21+
structs and consts are not coverable code, and thus cannot do anything with this
22+
attribute.
23+
24+
If you wish to apply this attribute to all methods in an impl or module,
25+
manually annotate each method; it is not possible to annotate the entire impl
26+
with a `#[no_coverage]` attribute.

compiler/rustc_hir/src/hir.rs

+2
Original file line numberDiff line numberDiff line change
@@ -3302,6 +3302,7 @@ pub enum Node<'hir> {
33023302
Stmt(&'hir Stmt<'hir>),
33033303
PathSegment(&'hir PathSegment<'hir>),
33043304
Ty(&'hir Ty<'hir>),
3305+
TypeBinding(&'hir TypeBinding<'hir>),
33053306
TraitRef(&'hir TraitRef<'hir>),
33063307
Binding(&'hir Pat<'hir>),
33073308
Pat(&'hir Pat<'hir>),
@@ -3347,6 +3348,7 @@ impl<'hir> Node<'hir> {
33473348
| Node::PathSegment(PathSegment { ident, .. }) => Some(*ident),
33483349
Node::Lifetime(lt) => Some(lt.name.ident()),
33493350
Node::GenericParam(p) => Some(p.name.ident()),
3351+
Node::TypeBinding(b) => Some(b.ident),
33503352
Node::Param(..)
33513353
| Node::AnonConst(..)
33523354
| Node::Expr(..)

compiler/rustc_hir_pretty/src/lib.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ impl<'a> State<'a> {
8585
Node::Stmt(a) => self.print_stmt(&a),
8686
Node::PathSegment(a) => self.print_path_segment(&a),
8787
Node::Ty(a) => self.print_type(&a),
88+
Node::TypeBinding(a) => self.print_type_binding(&a),
8889
Node::TraitRef(a) => self.print_trait_ref(&a),
8990
Node::Binding(a) | Node::Pat(a) => self.print_pat(&a),
9091
Node::Arm(a) => self.print_arm(&a),
@@ -1703,21 +1704,7 @@ impl<'a> State<'a> {
17031704

17041705
for binding in generic_args.bindings.iter() {
17051706
start_or_comma(self);
1706-
self.print_ident(binding.ident);
1707-
self.print_generic_args(binding.gen_args, false, false);
1708-
self.space();
1709-
match generic_args.bindings[0].kind {
1710-
hir::TypeBindingKind::Equality { ref term } => {
1711-
self.word_space("=");
1712-
match term {
1713-
Term::Ty(ref ty) => self.print_type(ty),
1714-
Term::Const(ref c) => self.print_anon_const(c),
1715-
}
1716-
}
1717-
hir::TypeBindingKind::Constraint { bounds } => {
1718-
self.print_bounds(":", bounds);
1719-
}
1720-
}
1707+
self.print_type_binding(binding);
17211708
}
17221709

17231710
if !empty.get() {
@@ -1726,6 +1713,24 @@ impl<'a> State<'a> {
17261713
}
17271714
}
17281715

1716+
pub fn print_type_binding(&mut self, binding: &hir::TypeBinding<'_>) {
1717+
self.print_ident(binding.ident);
1718+
self.print_generic_args(binding.gen_args, false, false);
1719+
self.space();
1720+
match binding.kind {
1721+
hir::TypeBindingKind::Equality { ref term } => {
1722+
self.word_space("=");
1723+
match term {
1724+
Term::Ty(ref ty) => self.print_type(ty),
1725+
Term::Const(ref c) => self.print_anon_const(c),
1726+
}
1727+
}
1728+
hir::TypeBindingKind::Constraint { bounds } => {
1729+
self.print_bounds(":", bounds);
1730+
}
1731+
}
1732+
}
1733+
17291734
pub fn print_pat(&mut self, pat: &hir::Pat<'_>) {
17301735
self.maybe_print_comment(pat.span.lo());
17311736
self.ann.pre(self, AnnNode::Pat(pat));

compiler/rustc_middle/src/hir/map/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ impl<'hir> Map<'hir> {
298298
Node::Stmt(_)
299299
| Node::PathSegment(_)
300300
| Node::Ty(_)
301+
| Node::TypeBinding(_)
301302
| Node::Infer(_)
302303
| Node::TraitRef(_)
303304
| Node::Pat(_)
@@ -323,7 +324,8 @@ impl<'hir> Map<'hir> {
323324
}
324325

325326
pub fn get_parent_node(self, hir_id: HirId) -> HirId {
326-
self.find_parent_node(hir_id).unwrap()
327+
self.find_parent_node(hir_id)
328+
.unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id)))
327329
}
328330

329331
/// Retrieves the `Node` corresponding to `id`, returning `None` if cannot be found.
@@ -973,6 +975,7 @@ impl<'hir> Map<'hir> {
973975
.with_hi(seg.args.map_or_else(|| ident_span.hi(), |args| args.span_ext.hi()))
974976
}
975977
Node::Ty(ty) => ty.span,
978+
Node::TypeBinding(tb) => tb.span,
976979
Node::TraitRef(tr) => tr.path.span,
977980
Node::Binding(pat) => pat.span,
978981
Node::Pat(pat) => pat.span,
@@ -1205,6 +1208,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
12051208
Some(Node::Stmt(_)) => node_str("stmt"),
12061209
Some(Node::PathSegment(_)) => node_str("path segment"),
12071210
Some(Node::Ty(_)) => node_str("type"),
1211+
Some(Node::TypeBinding(_)) => node_str("type binding"),
12081212
Some(Node::TraitRef(_)) => node_str("trait ref"),
12091213
Some(Node::Binding(_)) => node_str("local"),
12101214
Some(Node::Pat(_)) => node_str("pat"),

compiler/rustc_middle/src/middle/resolve_lifetime.rs

-14
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ pub enum Region {
1616
Free(DefId, /* lifetime decl */ DefId),
1717
}
1818

19-
/// This is used in diagnostics to improve suggestions for missing generic arguments.
20-
/// It gives information on the type of lifetimes that are in scope for a particular `PathSegment`,
21-
/// so that we can e.g. suggest elided-lifetimes-in-paths of the form <'_, '_> e.g.
22-
#[derive(Clone, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
23-
pub enum LifetimeScopeForPath {
24-
/// Contains all lifetime names that are in scope and could possibly be used in generics
25-
/// arguments of path.
26-
NonElided(Vec<LocalDefId>),
27-
28-
/// Information that allows us to suggest args of the form `<'_>` in case
29-
/// no generic arguments were provided for a path.
30-
Elided,
31-
}
32-
3319
/// A set containing, at most, one known element.
3420
/// If two distinct values are inserted into a set, then it
3521
/// becomes `Many`, which can be used to detect ambiguities.

compiler/rustc_middle/src/query/mod.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1599,11 +1599,6 @@ rustc_queries! {
15991599
desc { "looking up late bound vars" }
16001600
}
16011601

1602-
query lifetime_scope_map(_: LocalDefId) -> Option<FxHashMap<ItemLocalId, LifetimeScopeForPath>> {
1603-
storage(ArenaCacheSelector<'tcx>)
1604-
desc { "finds the lifetime scope for an HirId of a PathSegment" }
1605-
}
1606-
16071602
query visibility(def_id: DefId) -> ty::Visibility {
16081603
desc { |tcx| "computing visibility of `{}`", tcx.def_path_str(def_id) }
16091604
separate_provide_extern

compiler/rustc_middle/src/ty/context.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::hir::place::Place as HirPlace;
66
use crate::infer::canonical::{Canonical, CanonicalVarInfo, CanonicalVarInfos};
77
use crate::lint::{struct_lint_level, LintDiagnosticBuilder, LintLevelSource};
88
use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
9-
use crate::middle::resolve_lifetime::{self, LifetimeScopeForPath};
9+
use crate::middle::resolve_lifetime;
1010
use crate::middle::stability;
1111
use crate::mir::interpret::{self, Allocation, ConstAllocation, ConstValue, Scalar};
1212
use crate::mir::{
@@ -2821,10 +2821,6 @@ impl<'tcx> TyCtxt<'tcx> {
28212821
)
28222822
}
28232823

2824-
pub fn lifetime_scope(self, id: HirId) -> Option<&'tcx LifetimeScopeForPath> {
2825-
self.lifetime_scope_map(id.owner).as_ref().and_then(|map| map.get(&id.local_id))
2826-
}
2827-
28282824
/// Whether the `def_id` counts as const fn in the current crate, considering all active
28292825
/// feature gates
28302826
pub fn is_const_fn(self, def_id: DefId) -> bool {

compiler/rustc_middle/src/ty/query.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrs;
66
use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
77
use crate::middle::lib_features::LibFeatures;
88
use crate::middle::privacy::AccessLevels;
9-
use crate::middle::resolve_lifetime::{
10-
LifetimeScopeForPath, ObjectLifetimeDefault, Region, ResolveLifetimes,
11-
};
9+
use crate::middle::resolve_lifetime::{ObjectLifetimeDefault, Region, ResolveLifetimes};
1210
use crate::middle::stability::{self, DeprecationEntry};
1311
use crate::mir;
1412
use crate::mir::interpret::GlobalId;

0 commit comments

Comments
 (0)