Skip to content

Commit 96787c4

Browse files
committed
Auto merge of #103903 - matthiaskrgr:rollup-r5xcvrp, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #99801 (fix(generic_const_exprs): Fix predicate inheritance for children of opaque types) - #103610 (Allow use of `-Clto=thin` with `-Ccodegen-units=1` in general) - #103870 (Fix `inferred_kind` ICE) - #103875 (Simplify astconv item def id handling) - #103886 (rustdoc: Fix merge of attributes for reexports of local items) - #103890 (rustdoc: remove unused mobile CSS `.rustdoc { padding-top: 0 }`) Failed merges: - #103884 (Add visit_fn_ret_ty to hir intravisit) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5b1304a + 36d8134 commit 96787c4

File tree

15 files changed

+213
-50
lines changed

15 files changed

+213
-50
lines changed

Diff for: compiler/rustc_hir_analysis/src/astconv/errors.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
177177
.all_traits()
178178
.filter(|trait_def_id| {
179179
let viz = self.tcx().visibility(*trait_def_id);
180-
if let Some(def_id) = self.item_def_id() {
181-
viz.is_accessible_from(def_id, self.tcx())
182-
} else {
183-
viz.is_visible_locally()
184-
}
180+
let def_id = self.item_def_id();
181+
viz.is_accessible_from(def_id, self.tcx())
185182
})
186183
.collect();
187184

Diff for: compiler/rustc_hir_analysis/src/astconv/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct PathSeg(pub DefId, pub usize);
5454
pub trait AstConv<'tcx> {
5555
fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
5656

57-
fn item_def_id(&self) -> Option<DefId>;
57+
fn item_def_id(&self) -> DefId;
5858

5959
/// Returns predicates in scope of the form `X: Foo<T>`, where `X`
6060
/// is a type parameter `X` with the given id `def_id` and T
@@ -500,6 +500,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
500500
}
501501
GenericParamDefKind::Const { has_default } => {
502502
let ty = tcx.at(self.span).type_of(param.def_id);
503+
if ty.references_error() {
504+
return tcx.const_error(ty).into();
505+
}
503506
if !infer_args && has_default {
504507
tcx.bound_const_param_default(param.def_id)
505508
.subst(tcx, substs.unwrap())
@@ -2079,17 +2082,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20792082

20802083
debug!("qpath_to_ty: self.item_def_id()={:?}", def_id);
20812084

2082-
let parent_def_id = def_id
2083-
.and_then(|def_id| {
2084-
def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
2085-
})
2085+
let parent_def_id = def_id.as_local().map(|def_id| tcx.hir().local_def_id_to_hir_id(def_id))
20862086
.map(|hir_id| tcx.hir().get_parent_item(hir_id).to_def_id());
20872087

20882088
debug!("qpath_to_ty: parent_def_id={:?}", parent_def_id);
20892089

20902090
// If the trait in segment is the same as the trait defining the item,
20912091
// use the `<Self as ..>` syntax in the error.
2092-
let is_part_of_self_trait_constraints = def_id == Some(trait_def_id);
2092+
let is_part_of_self_trait_constraints = def_id == trait_def_id;
20932093
let is_part_of_fn_in_self_trait = parent_def_id == Some(trait_def_id);
20942094

20952095
let type_name = if is_part_of_self_trait_constraints || is_part_of_fn_in_self_trait {

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,8 @@ impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx> {
379379
self.tcx
380380
}
381381

382-
fn item_def_id(&self) -> Option<DefId> {
383-
Some(self.item_def_id)
382+
fn item_def_id(&self) -> DefId {
383+
self.item_def_id
384384
}
385385

386386
fn get_type_parameter_bounds(

Diff for: compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,8 @@ pub(super) fn explicit_predicates_of<'tcx>(
427427
} else {
428428
if matches!(def_kind, DefKind::AnonConst) && tcx.lazy_normalization() {
429429
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
430+
let parent_def_id = tcx.hir().get_parent_item(hir_id);
431+
430432
if tcx.hir().opt_const_param_default_param_hir_id(hir_id).is_some() {
431433
// In `generics_of` we set the generics' parent to be our parent's parent which means that
432434
// we lose out on the predicates of our actual parent if we dont return those predicates here.
@@ -439,8 +441,33 @@ pub(super) fn explicit_predicates_of<'tcx>(
439441
// parent of generics returned by `generics_of`
440442
//
441443
// In the above code we want the anon const to have predicates in its param env for `T: Trait`
442-
let item_def_id = tcx.hir().get_parent_item(hir_id);
443-
// In the above code example we would be calling `explicit_predicates_of(Foo)` here
444+
// and we would be calling `explicit_predicates_of(Foo)` here
445+
return tcx.explicit_predicates_of(parent_def_id);
446+
}
447+
448+
let parent_def_kind = tcx.def_kind(parent_def_id);
449+
if matches!(parent_def_kind, DefKind::OpaqueTy) {
450+
// In `instantiate_identity` we inherit the predicates of our parent.
451+
// However, opaque types do not have a parent (see `gather_explicit_predicates_of`), which means
452+
// that we lose out on the predicates of our actual parent if we dont return those predicates here.
453+
//
454+
//
455+
// fn foo<T: Trait>() -> impl Iterator<Output = Another<{ <T as Trait>::ASSOC }> > { todo!() }
456+
// ^^^^^^^^^^^^^^^^^^^ the def id we are calling
457+
// explicit_predicates_of on
458+
//
459+
// In the above code we want the anon const to have predicates in its param env for `T: Trait`.
460+
// However, the anon const cannot inherit predicates from its parent since it's opaque.
461+
//
462+
// To fix this, we call `explicit_predicates_of` directly on `foo`, the parent's parent.
463+
464+
// In the above example this is `foo::{opaque#0}` or `impl Iterator`
465+
let parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent_def_id.def_id);
466+
467+
// In the above example this is the function `foo`
468+
let item_def_id = tcx.hir().get_parent_item(parent_hir_id);
469+
470+
// In the above code example we would be calling `explicit_predicates_of(foo)` here
444471
return tcx.explicit_predicates_of(item_def_id);
445472
}
446473
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
194194
self.tcx
195195
}
196196

197-
fn item_def_id(&self) -> Option<DefId> {
198-
None
197+
fn item_def_id(&self) -> DefId {
198+
self.body_id.owner.to_def_id()
199199
}
200200

201201
fn get_type_parameter_bounds(

Diff for: compiler/rustc_session/src/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ impl Default for Options {
738738
actually_rustdoc: false,
739739
trimmed_def_paths: TrimmedDefPaths::default(),
740740
cli_forced_codegen_units: None,
741-
cli_forced_thinlto_off: false,
741+
cli_forced_local_thinlto_off: false,
742742
remap_path_prefix: Vec::new(),
743743
real_rust_source_base_dir: None,
744744
edition: DEFAULT_EDITION,
@@ -1721,7 +1721,7 @@ fn should_override_cgus_and_disable_thinlto(
17211721
error_format: ErrorOutputType,
17221722
mut codegen_units: Option<usize>,
17231723
) -> (bool, Option<usize>) {
1724-
let mut disable_thinlto = false;
1724+
let mut disable_local_thinlto = false;
17251725
// Issue #30063: if user requests LLVM-related output to one
17261726
// particular path, disable codegen-units.
17271727
let incompatible: Vec<_> = output_types
@@ -1746,12 +1746,12 @@ fn should_override_cgus_and_disable_thinlto(
17461746
}
17471747
early_warn(error_format, "resetting to default -C codegen-units=1");
17481748
codegen_units = Some(1);
1749-
disable_thinlto = true;
1749+
disable_local_thinlto = true;
17501750
}
17511751
}
17521752
_ => {
17531753
codegen_units = Some(1);
1754-
disable_thinlto = true;
1754+
disable_local_thinlto = true;
17551755
}
17561756
}
17571757
}
@@ -1760,7 +1760,7 @@ fn should_override_cgus_and_disable_thinlto(
17601760
early_error(error_format, "value for codegen units must be a positive non-zero integer");
17611761
}
17621762

1763-
(disable_thinlto, codegen_units)
1763+
(disable_local_thinlto, codegen_units)
17641764
}
17651765

17661766
fn check_thread_count(unstable_opts: &UnstableOptions, error_format: ErrorOutputType) {
@@ -2265,7 +2265,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
22652265
let output_types = parse_output_types(&unstable_opts, matches, error_format);
22662266

22672267
let mut cg = CodegenOptions::build(matches, error_format);
2268-
let (disable_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
2268+
let (disable_local_thinlto, mut codegen_units) = should_override_cgus_and_disable_thinlto(
22692269
&output_types,
22702270
matches,
22712271
error_format,
@@ -2508,7 +2508,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
25082508
actually_rustdoc: false,
25092509
trimmed_def_paths: TrimmedDefPaths::default(),
25102510
cli_forced_codegen_units: codegen_units,
2511-
cli_forced_thinlto_off: disable_thinlto,
2511+
cli_forced_local_thinlto_off: disable_local_thinlto,
25122512
remap_path_prefix,
25132513
real_rust_source_base_dir,
25142514
edition,

Diff for: compiler/rustc_session/src/options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ top_level_options!(
181181
#[rustc_lint_opt_deny_field_access("use `Session::codegen_units` instead of this field")]
182182
cli_forced_codegen_units: Option<usize> [UNTRACKED],
183183
#[rustc_lint_opt_deny_field_access("use `Session::lto` instead of this field")]
184-
cli_forced_thinlto_off: bool [UNTRACKED],
184+
cli_forced_local_thinlto_off: bool [UNTRACKED],
185185

186186
/// Remap source path prefixes in all output (messages, object files, debug, etc.).
187187
remap_path_prefix: Vec<(PathBuf, PathBuf)> [TRACKED_NO_CRATE_HASH],

Diff for: compiler/rustc_session/src/session.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1018,11 +1018,8 @@ impl Session {
10181018
return config::Lto::Fat;
10191019
}
10201020
config::LtoCli::Thin => {
1021-
return if self.opts.cli_forced_thinlto_off {
1022-
config::Lto::Fat
1023-
} else {
1024-
config::Lto::Thin
1025-
};
1021+
// The user explicitly asked for ThinLTO
1022+
return config::Lto::Thin;
10261023
}
10271024
}
10281025

@@ -1034,7 +1031,7 @@ impl Session {
10341031

10351032
// If processing command line options determined that we're incompatible
10361033
// with ThinLTO (e.g., `-C lto --emit llvm-ir`) then return that option.
1037-
if self.opts.cli_forced_thinlto_off {
1034+
if self.opts.cli_forced_local_thinlto_off {
10381035
return config::Lto::No;
10391036
}
10401037

Diff for: src/librustdoc/clean/mod.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
7474
// This covers the case where somebody does an import which should pull in an item,
7575
// but there's already an item with the same namespace and same name. Rust gives
7676
// priority to the not-imported one, so we should, too.
77-
items.extend(doc.items.iter().flat_map(|(item, renamed)| {
77+
items.extend(doc.items.iter().flat_map(|(item, renamed, import_id)| {
7878
// First, lower everything other than imports.
7979
if matches!(item.kind, hir::ItemKind::Use(_, hir::UseKind::Glob)) {
8080
return Vec::new();
8181
}
82-
let v = clean_maybe_renamed_item(cx, item, *renamed);
82+
let v = clean_maybe_renamed_item(cx, item, *renamed, *import_id);
8383
for item in &v {
8484
if let Some(name) = item.name && !item.attrs.lists(sym::doc).has_word(sym::hidden) {
8585
inserted.insert((item.type_(), name));
8686
}
8787
}
8888
v
8989
}));
90-
items.extend(doc.items.iter().flat_map(|(item, renamed)| {
90+
items.extend(doc.items.iter().flat_map(|(item, renamed, _)| {
9191
// Now we actually lower the imports, skipping everything else.
9292
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
9393
let name = renamed.unwrap_or_else(|| cx.tcx.hir().name(item.hir_id()));
@@ -1911,6 +1911,7 @@ fn clean_maybe_renamed_item<'tcx>(
19111911
cx: &mut DocContext<'tcx>,
19121912
item: &hir::Item<'tcx>,
19131913
renamed: Option<Symbol>,
1914+
import_id: Option<hir::HirId>,
19141915
) -> Vec<Item> {
19151916
use hir::ItemKind;
19161917

@@ -1987,8 +1988,23 @@ fn clean_maybe_renamed_item<'tcx>(
19871988
}
19881989
_ => unreachable!("not yet converted"),
19891990
};
1990-
1991-
vec![Item::from_def_id_and_parts(def_id, Some(name), kind, cx)]
1991+
if let Some(import_id) = import_id {
1992+
let (attrs, cfg) = inline::merge_attrs(
1993+
cx,
1994+
Some(cx.tcx.parent_module(import_id).to_def_id()),
1995+
inline::load_attrs(cx, def_id),
1996+
Some(inline::load_attrs(cx, cx.tcx.hir().local_def_id(import_id).to_def_id())),
1997+
);
1998+
vec![Item::from_def_id_and_attrs_and_parts(
1999+
def_id,
2000+
Some(name),
2001+
kind,
2002+
Box::new(attrs),
2003+
cfg,
2004+
)]
2005+
} else {
2006+
vec![Item::from_def_id_and_parts(def_id, Some(name), kind, cx)]
2007+
}
19922008
})
19932009
}
19942010

Diff for: src/librustdoc/html/static/css/rustdoc.css

-1
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,6 @@ in storage.js
16771677
}
16781678

16791679
.rustdoc {
1680-
padding-top: 0px;
16811680
/* Sidebar should overlay main content, rather than pushing main content to the right.
16821681
Turn off `display: flex` on the body element. */
16831682
display: block;

0 commit comments

Comments
 (0)