Skip to content

2018 edition allows ungated access to unstable crates #52489

Closed

Description

@alexcrichton

When compiled with --edition 2018 this code compiles just fine:

use rustc;

fn main() {}

That's bad!

Activity

  1. Mark-Simulacrum commented on Jul 31, 2018

    @Mark-Simulacrum
    Member

    @rust-lang/compiler Can we get some eyes on this, not necessarily to fix but at least to confirm that we believe a fix can be made and landed in time for RC? This is a hard-stop blocker for RC.

  2. eddyb commented on Aug 1, 2018

    @eddyb
    Contributor

    So this is generally harmless (you can't actually get anything from the unstable crate), except for it being a minor dead-code-but-allowed hazard.

    The culprit appears to be this special-casing:

    // FIXME: Last path segment is treated specially in import resolution, so extern crate
    // mode for absolute paths needs some special support for single-segment imports.
    if module_path.len() == 1 && (module_path[0].name == keywords::CrateRoot.name() ||
    module_path[0].name == keywords::Extern.name()) {
    let is_extern = module_path[0].name == keywords::Extern.name() ||
    (self.session.features_untracked().extern_absolute_paths &&
    self.session.rust_2018());

    Which loads the crate (producing an error if no crate with that name exists), but doesn't record the resolution. So there's nothing to check - and presumably no way to use that broken import.

    The part that's missing is this (recording the import resolutions):

    // Record what this import resolves to for later uses in documentation,
    // this may resolve to either a value or a type, but for documentation
    // purposes it's good enough to just favor one over the other.
    self.per_ns(|this, ns| if let Some(binding) = result[ns].get().ok() {
    let import = this.import_map.entry(directive.id).or_default();
    import[ns] = Some(PathResolution::new(binding.def()));
    });

    But the special-casing exits early:

    let _ = self.try_define(directive.parent, target, TypeNS, binding);
    return None;

    Expected minimal diff (between the two lines in the last snippet):

    let import = self.import_map.entry(directive.id).or_default(); 
    import[TypeNS] = Some(PathResolution::new(binding.def())); 
  3. added a commit that references this issue on Aug 1, 2018
    af12be2
  4. added a commit that references this issue on Aug 1, 2018
    2893bd0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionF-rust_2018_preview`#![feature(rust_2018_preview)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions